Skip to content

Commit

Permalink
cleaned out obsolete junk out of backup cli
Browse files Browse the repository at this point in the history
rational: prepare for re-implementation based on new paradigm

changes:

- cleaned up embedded documentation
- renamed keyfile => secretfile
- undocument --profile and --secretfile options (complicates user interface)
- disabled actual running of backup logic (it's not what we're testing)
  • Loading branch information
lirazsiri committed Jun 24, 2010
1 parent 7365847 commit 7755919
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 54 deletions.
26 changes: 11 additions & 15 deletions backup.py
Expand Up @@ -86,26 +86,23 @@ def __add__(self, b):
cls = type(self)
return cls(list.__add__(self, b))

class BackupConf:
profile = "/usr/share/tklbam/profile"
from utils import AttrDict

class BackupConf:
path = "/etc/tklbam"
class Paths(Paths):
files = [ 'address', 'key', 'overrides' ]
files = [ 'overrides' ]
paths = Paths(path)

@staticmethod
def _read_address(path):
try:
return file(path).read().strip()
except:
return None

def __init__(self):
self.keyfile = self.paths.key
self.address = self._read_address(self.paths.address)
self.secretfile = None
self.address = None
self.overrides = Limits.fromfile(self.paths.overrides)

def __repr__(self):
return "secretfile=%s, address=%s, overrides=%s" % \
(`self.secretfile`, `self.address`, `self.overrides`)

class ProfilePaths(Paths):
files = [ 'dirindex', 'dirindex.conf', 'packages' ]

Expand Down Expand Up @@ -140,7 +137,7 @@ def _write_whatchanged(dest, dest_olist, dirindex, dirindex_conf,
changes.tofile(dest)
file(dest_olist, "w").writelines((path + "\n" for path in olist))

def __init__(self, conf, key):
def __init__(self, conf):
profile = ProfilePaths(conf.profile)
paths = ExtrasPaths(self.EXTRAS_PATH)

Expand Down Expand Up @@ -175,10 +172,9 @@ def __init__(self, conf, key):
self.command = "duplicity " + " ".join(args)
self.paths = paths
self.conf = conf
self.key = key

def run(self):
os.environ['PASSPHRASE'] = self.key
os.environ['PASSPHRASE'] = file(self.secretfile).readline().strip()
exitcode = os.system(self.command)
del os.environ['PASSPHRASE']

Expand Down
66 changes: 27 additions & 39 deletions cmd_backup.py
Expand Up @@ -7,19 +7,9 @@
Default overrides read from $CONF_OVERRIDES
Resolution order for options:
1) command line (highest precedence)
2) configuration files ($CONF)
Options:
--profile=PATH base profile path
default: $DEFAULT_PROFILE
--keyfile=PATH secret keyfile
default: $CONF_KEY
--address=TARGET_URL duplicity target URL
default: read from $CONF_ADDRESS
--address=TARGET_URL manual backup target URL
default: automatically configured via Hub
-v --verbose Turn on verbosity
-s --simulate Simulate operation. Don't actually backup.
Expand All @@ -34,6 +24,7 @@
from string import Template

import backup
from registry import registry

def fatal(e):
print >> sys.stderr, "error: " + str(e)
Expand All @@ -47,35 +38,37 @@ def usage(e=None):
tpl = Template(__doc__.strip())
Conf = backup.BackupConf
print >> sys.stderr, tpl.substitute(CONF=Conf.paths.path,
CONF_OVERRIDES=Conf.paths.overrides,
CONF_KEY=Conf.paths.key,
CONF_ADDRESS=Conf.paths.address,
DEFAULT_PROFILE=Conf.profile)
CONF_OVERRIDES=Conf.paths.overrides)
sys.exit(1)

def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'svh',
['simulate', 'verbose',
'profile=', 'keyfile=', 'address='])
'profile=', 'secretfile=', 'address='])
except getopt.GetoptError, e:
usage(e)

conf = backup.BackupConf()
conf.secretfile = registry.path.secret

opt_simulate = False
opt_verbose = False

opt_profile = None
for opt, val in opts:
if opt in ('-v', '--verbose'):
opt_verbose = True
elif opt in ('-s', '--simulate'):
opt_simulate = True

elif opt == '--profile':
conf.profile = val
elif opt == '--keyfile':
opt_profile = val

elif opt == '--secretfile':
if not exists(val):
usage("keyfile %s does not exist" % `val`)
conf.keyfile = val
usage("secretfile %s does not exist" % `val`)
conf.secretfile = val
elif opt == '--address':
conf.address = val
elif opt == '-h':
Expand All @@ -84,29 +77,24 @@ def main():
conf.overrides += args

if not conf.address:
fatal("address not configured")

if not exists(conf.keyfile):
print "generating new secret key"
backup.Key.create(conf.keyfile)

key = backup.Key.read(conf.keyfile)

if not isdir(conf.profile):
fatal("profile dir %s doesn't exist" % `conf.profile`)
# TODO: auto-configure via Hub
fatal("not implemented yet")
conf.address = registry.hbr.address

if opt_simulate:
opt_verbose = True

b = backup.Backup(conf, key)
if opt_verbose:
print "PASSPHRASE=$(cat %s) %s" % (conf.keyfile, b.command)
print "backup.Backup(%s)" % (`conf`)

#b = backup.Backup(conf)
#if opt_verbose:
# print "PASSPHRASE=$(cat %s) %s" % (conf.secretfile, b.command)

if not opt_simulate:
try:
b.run()
finally:
b.cleanup()
#if not opt_simulate:
# try:
# b.run()
# finally:
# b.cleanup()

if __name__=="__main__":
main()

0 comments on commit 7755919

Please sign in to comment.