Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (50 sloc) 1.552 kb
767facb @lirazsiri cleanup whitespace
lirazsiri authored
1 #
d740e7a @lirazsiri updated copyright year
lirazsiri authored
2 # Copyright (c) 2010-2012 Liraz Siri <liraz@turnkeylinux.org>
767facb @lirazsiri cleanup whitespace
lirazsiri authored
3 #
0c11ee9 @lirazsiri added copyright notices to everything
lirazsiri authored
4 # This file is part of TKLBAM (TurnKey Linux BAckup and Migration).
767facb @lirazsiri cleanup whitespace
lirazsiri authored
5 #
e34925a @lirazsiri free software => open source software
lirazsiri authored
6 # TKLBAM is open source software; you can redistribute it and/or
0c11ee9 @lirazsiri added copyright notices to everything
lirazsiri authored
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 3 of
9 # the License, or (at your option) any later version.
767facb @lirazsiri cleanup whitespace
lirazsiri authored
10 #
01ab403 @lirazsiri refactor: create rollback and utils modules
lirazsiri authored
11 import os
12 from os.path import *
393b976 @lirazsiri allow transparent output from various commands (e.g., duplicity, apt-…
lirazsiri authored
13
01ab403 @lirazsiri refactor: create rollback and utils modules
lirazsiri authored
14 import shutil
4a67ee0 @lirazsiri another shutil.move across-filesystems bug fix (does not preserve own…
lirazsiri authored
15 import stat
01ab403 @lirazsiri refactor: create rollback and utils modules
lirazsiri authored
16
17 def remove_any(path):
767facb @lirazsiri cleanup whitespace
lirazsiri authored
18 """Remove a path whether it is a file or a directory.
01ab403 @lirazsiri refactor: create rollback and utils modules
lirazsiri authored
19 Return: True if removed, False if nothing to remove"""
20
21 if not lexists(path):
22 return False
23
24 if not islink(path) and isdir(path):
25 shutil.rmtree(path)
26 else:
27 os.remove(path)
28
29 return True
fa76050 @lirazsiri fully implemented passphrase logic
lirazsiri authored
30
31 class AttrDict(dict):
32 def __getattr__(self, name):
33 if name in self:
34 return self[name]
35 raise AttributeError("no such attribute '%s'" % name)
36
37 def __setattr__(self, name, val):
38 self[name] = val
39
ec47cf0 @lirazsiri implemented default logging
lirazsiri authored
40 def is_writeable(fpath):
41 try:
42 file(fpath, "w+")
43 return True
44 except IOError:
45 return False
46
4a67ee0 @lirazsiri another shutil.move across-filesystems bug fix (does not preserve own…
lirazsiri authored
47 # workaround for shutil.move across-filesystem bugs
48 def move(src, dst):
49 st = os.lstat(src)
50
51 is_symlink = stat.S_ISLNK(st.st_mode)
52
53 if os.path.isdir(dst):
54 dst = os.path.join(dst, os.path.basename(os.path.abspath(src)))
55
56 if is_symlink:
57 linkto = os.readlink(src)
58 os.symlink(linkto, dst)
59 os.unlink(src)
60 else:
61 shutil.move(src, dst)
62 os.lchown(dst, st.st_uid, st.st_gid)
Something went wrong with that request. Please try again.