Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
arg = args[0]
if isdir(join(arg, backup.ExtrasPaths.PATH)):
backup_extract_path = arg
else:
try:
try:
hbr = get_backup_record(arg)
except hub.Backups.NotInitialized, e:
print >> sys.stderr, "error: " + str(e)
print >> sys.stderr, "tip: you can still use tklbam-restore with --address or a backup extract"
sys.exit(1)
credentials = hub.Backups(registry.sub_apikey).get_credentials()
except Error, e:
fatal(e)
else:
if not opt_address:
usage()
if backup_extract_path:
for opt, val in opts:
if opt[2:] in ('time', 'keyfile', 'address', 'restore-cache-size', 'restore-cache-dir'):
fatal("%s is incompatible with restoring from path %s" % (opt, backup_extract_path))
else:
if opt_address:
if hbr:
fatal("a manual --address is incompatible with a ")
hbr = None
credentials = None
if args:
if len(args) != 1:
usage("incorrect number of arguments")
arg = args[0]
if isdir(join(arg, backup.ExtrasPaths.PATH)):
backup_extract_path = arg
else:
try:
try:
hbr = get_backup_record(arg)
except hub.Backups.NotInitialized, e:
print >> sys.stderr, "error: " + str(e)
print >> sys.stderr, "tip: you can still use tklbam-restore with --address or a backup extract"
sys.exit(1)
credentials = hub.Backups(registry.sub_apikey).get_credentials()
except Error, e:
fatal(e)
else:
if not opt_address:
usage()
if backup_extract_path:
for opt, val in opts:
if opt[2:] in ('time', 'keyfile', 'address', 'restore-cache-size', 'restore-cache-dir'):
def hub_backups():
import sys
try:
hb = hub.Backups(registry.sub_apikey)
except hub.Backups.NotInitialized:
raise NotInitialized()
return hb
try:
credentials = hb.get_credentials()
registry.registry.credentials = credentials
print "Linked TKLBAM to your Hub account."
except hub.NotSubscribed, e:
print "Linked TKLBAM to your Hub account but there's a problem:"
print
elif not force_profile and registry.registry.profile:
fatal("already initialized")
if force_profile or not registry.registry.profile:
try:
registry.update_profile(conf.force_profile)
except hub.Backups.NotInitialized:
fatal("--solo requires --force-profile=empty or --force-profile=path/to/custom/profile ")
def _update_profile(self, profile_id=None):
"""Get a new profile if we don't have a profile in the registry or the Hub
has a newer profile for this appliance. If we can't contact the Hub raise
an error if we don't already have profile."""
if not profile_id:
if self.profile:
profile_id = self.profile.profile_id
else:
profile_id = detect_profile_id()
if profile_id == self.EMPTY_PROFILE or isdir(profile_id):
self.profile = profile_id
return
hub_backups = hub.Backups(self.sub_apikey)
if self.profile and self.profile.profile_id == profile_id:
profile_timestamp = self.profile.timestamp
else:
# forced profile is not cached in the self
profile_timestamp = None
try:
new_profile = hub_backups.get_new_profile(profile_id, profile_timestamp)
if new_profile:
self.profile = new_profile
print "Downloaded %s profile" % self.profile.profile_id
except hub.NotSubscribed:
raise
except hub_backups.Error, e:
while True:
apikey = raw_input("API-KEY: ").strip()
if apikey:
break
if not is_valid_apikey(apikey):
fatal("'%s' is an invalid API-KEY" % apikey)
try:
sub_apikey = hub.Backups.get_sub_apikey(apikey)
except Exception, e:
fatal(e)
registry.registry.sub_apikey = sub_apikey
hb = hub.Backups(sub_apikey)
try:
credentials = hb.get_credentials()
registry.registry.credentials = credentials
print "Linked TKLBAM to your Hub account."
except hub.NotSubscribed, e:
print "Linked TKLBAM to your Hub account but there's a problem:"
print
elif not force_profile and registry.registry.profile:
fatal("already initialized")
if force_profile or not registry.registry.profile:
try:
registry.update_profile(conf.force_profile)
except hub.Backups.NotInitialized:
def __init__(self):
command = "tklbam-init"
if registry.path != registry.DEFAULT_PATH:
command = "%s=%s %s" % (registry.ENV_VARNAME, registry.path, command)
hub.Backups.NotInitialized.__init__(self, 'Hub link required, run "%s" first' % command)