Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ def fromfile(cls, path):
if not exists(path):
return None

d = simplejson.load(file(path))
d = simplejson.load(open(path))
return cls(*(d[attr]
for attr in ('profile_id', 'overrides', 'skip_files', 'skip_packages', 'skip_database')))

def tofile(self, path):
simplejson.dump(dict(self), file(path, "w"))
simplejson.dump(dict(self), open(path, "w"))

class Backup:
class Error(Exception):
Expand All @@ -97,38 +97,38 @@ def _write_new_packages(self, dest, base_packages):
self._log(" " + " ".join(new_packages))
self._log(" EOF\n")

fh = file(dest, "w")
fh = open(dest, "w")
for package in new_packages:
print >> fh, package
print(package, file=fh)

fh.close()

def _write_whatchanged(self, dest, dest_olist, dirindex, dirindex_conf,
overrides=[]):
paths = read_paths(file(dirindex_conf))
paths = read_paths(open(dirindex_conf))
paths += overrides

changes = whatchanged(dirindex, paths)
changes.sort(lambda a,b: cmp(a.path, b.path))
changes.sort(key=lambda a: a.path)

changes.tofile(dest)
olist = [ change.path for change in changes if change.OP == 'o' ]
file(dest_olist, "w").writelines((path + "\n" for path in olist))
open(dest_olist, "w").writelines((path + "\n" for path in olist))

if self.verbose:
if changes:
self._log("Save list of filesystem changes to %s:\n" % dest)

actions = list(changes.deleted(optimized=False)) + list(changes.statfixes(optimized=False))
actions.sort(lambda a,b: cmp(a.args[0], b.args[0]))
actions.sort(key=lambda a: a.args[0])

umask = os.umask(0)
os.umask(umask)

for action in actions:
if action.func is os.chmod:
path, mode = action.args
default_mode = (0777 if isdir(path) else 0666) ^ umask
default_mode = (0o777 if isdir(path) else 0o666) ^ umask
if default_mode == stat.S_IMODE(mode):
continue
elif action.func is os.lchown:
Expand All @@ -145,7 +145,7 @@ def _write_whatchanged(self, dest, dest_olist, dirindex, dirindex_conf,

def _create_extras(self, extras, profile, conf):
os.mkdir(extras.path)
os.chmod(extras.path, 0700)
os.chmod(extras.path, 0o700)

etc = str(extras.etc)
os.mkdir(etc)
Expand Down Expand Up @@ -180,7 +180,7 @@ def _create_extras(self, extras, profile, conf):
if mysql.MysqlService.is_running():
self._log("\n" + fmt_title("Serializing MySQL database to " + extras.myfs, '-'))
mysql.backup(extras.myfs, extras.etc.mysql,
limits=conf.overrides.mydb, callback=mysql.cb_print()) if self.verbose else None
limits=conf.overrides.mydb, callback=mysql.cb_print() if self.verbose else None)

except mysql.Error:
pass
Expand All @@ -194,7 +194,7 @@ def _create_extras(self, extras, profile, conf):

def _log(self, s=""):
if self.verbose:
print s
print(s)

def __init__(self, profile, overrides,
skip_files=False, skip_packages=False, skip_database=False, resume=False, verbose=True, extras_root="/"):
Expand Down Expand Up @@ -248,7 +248,7 @@ def __init__(self, profile, overrides,
fpaths= _fpaths(extras_paths.path)

if not skip_files:
fsdelta_olist = file(extras_paths.fsdelta_olist).read().splitlines()
fsdelta_olist = open(extras_paths.fsdelta_olist).read().splitlines()
fpaths += _filter_deleted(fsdelta_olist)

size = sum([ os.lstat(fpath).st_size
Expand All @@ -270,4 +270,4 @@ def r(p):
return join(path, p.lstrip('/'))

if exists(self.extras_paths.fsdelta_olist):
apply_overlay('/', path, self.extras_paths.fsdelta_olist)
apply_overlay('/', path, self.extras_paths.fsdelta_olist)
13 changes: 6 additions & 7 deletions changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def stat(self):
stat = property(stat)

def fmt(self, *args):
return "\t".join([self.OP, self.path] + map(str, args))
return "\t".join([self.OP, self.path] + list(map(str, args)))

def __str__(self):
return self.fmt()
Expand Down Expand Up @@ -119,7 +119,7 @@ def __str__(self):
@classmethod
def parse(cls, line):
op2class = dict((val.OP, val) for val in cls.__dict__.values()
if isinstance(val, types.ClassType))
if isinstance(val, type))
op = line[0]
if op not in op2class:
raise Error("illegal change line: " + line)
Expand All @@ -129,7 +129,7 @@ def parse(cls, line):
def mkdir(path):
try:
os.makedirs(path)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise

Expand Down Expand Up @@ -179,7 +179,7 @@ def fromfile(cls, f, paths=None):
if f == '-':
fh = sys.stdin
else:
fh = file(f)
fh = open(f)

changes = [ Change.parse(line) for line in fh.readlines() ]
if paths:
Expand All @@ -190,7 +190,7 @@ def fromfile(cls, f, paths=None):
return cls(changes)

def tofile(self, f):
file(f, "w").writelines((str(change) + "\n" for change in self))
open(f, "w").writelines((str(change) + "\n" for change in self))

def deleted(self, optimized=True):
for change in self:
Expand Down Expand Up @@ -269,5 +269,4 @@ def whatchanged(di_path, paths):
deleted = set(di_saved) - set(di_fs)
changes += [ Change.Deleted(path) for path in deleted ]

return changes

return changes
6 changes: 4 additions & 2 deletions cliwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import imp


class _Commands(dict):
@staticmethod
def _list_commands(paths):
Expand All @@ -37,6 +38,7 @@ def __init__(self, path):
for command in self._list_commands(path):
self[command] = self._get_internals_module(command, path)


class CliWrapper:
DESCRIPTION = ""
PATH = None
Expand All @@ -55,7 +57,7 @@ def _usage(cls, commands, e=None):
command_names = commands.keys()
command_names.sort()

maxlen = max([ len(name) for name in command_names ]) + 2
maxlen = max([len(name) for name in command_names]) + 2
tpl = " %%-%ds %%s" % (maxlen)

def shortdesc(command):
Expand All @@ -68,7 +70,7 @@ def shortdesc(command):
print >> sys.stderr, tpl % (command, shortdesc(command))

for command in set(commands.keys()) - set(cls.COMMANDS_USAGE_ORDER):
print >> sys.stderr, tpl % (command, shortdesc(command))
print >> sys.stderr, tpl % (command, shortdesc(command))

sys.exit(1)

Expand Down
11 changes: 7 additions & 4 deletions cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/python3
#
# Copyright (c) 2010-2012 Liraz Siri <liraz@turnkeylinux.org>
#
Expand Down Expand Up @@ -29,11 +29,13 @@
import conf
import registry


class CliWrapper(CliWrapper):
DESCRIPTION = Template(__doc__).substitute(TKLBAM_CONF=conf.Conf.DEFAULT_PATH,
TKLBAM_REGISTRY=registry._Registry.DEFAULT_PATH)
DESCRIPTION = Template(__doc__).substitute(
TKLBAM_CONF=conf.Conf.DEFAULT_PATH,
TKLBAM_REGISTRY=registry._Registry.DEFAULT_PATH)

PATH = [ dirname(realpath(__file__)) ]
PATH = [dirname(realpath(__file__))]
COMMANDS_USAGE_ORDER = ['init',
'',
'passphrase', 'escrow',
Expand All @@ -42,5 +44,6 @@ class CliWrapper(CliWrapper):
'',
'status', 'internal']


if __name__ == "__main__":
CliWrapper.main()
Loading