Skip to content

Commit

Permalink
UX: fail with the same helpful error message when TKLBAM not initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
lirazsiri committed Nov 6, 2013
1 parent 676ec06 commit 3c2ba2b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
11 changes: 2 additions & 9 deletions cmd_backup.py
Expand Up @@ -135,7 +135,7 @@
import duplicity

import hooks
from registry import registry, update_profile
from registry import registry, update_profile, hub_backups
from conf import Conf

from version import Version
Expand Down Expand Up @@ -316,14 +316,7 @@ def main():
if conf.s3_parallel_uploads > 1 and conf.s3_parallel_uploads > (conf.volsize / 5):
warn("s3-parallel-uploads > volsize / 5 (minimum upload chunk is 5MB)")

try:
hb = hub.Backups(registry.sub_apikey)
except hub.Backups.NotInitialized:
command = "tklbam-init"
if registry.path != registry.DEFAULT_PATH:
command = "%s=%s %s" % (registry.ENV_VARNAME, registry.path, command)

fatal('You need to run "%s" first' % command)
hb = hub_backups()

if not raw_upload_path:
update_profile(conf.force_profile)
Expand Down
4 changes: 2 additions & 2 deletions cmd_list.py
Expand Up @@ -40,7 +40,7 @@
import hub
import keypacket

from registry import registry
from registry import registry, hub_backups

def usage(e=None):
if e:
Expand Down Expand Up @@ -101,7 +101,7 @@ def main():
else:
format = None

hb = hub.Backups(registry.sub_apikey)
hb = hub_backups()
hbrs = hb.list_backups()

if format:
Expand Down
4 changes: 2 additions & 2 deletions cmd_passphrase.py
Expand Up @@ -22,7 +22,7 @@

import hub
import keypacket
from registry import registry
from registry import registry, hub_backups
from passphrase import *

def usage(e=None):
Expand All @@ -47,7 +47,7 @@ def main():
if opt == '--random':
opt_random = True

hb = hub.Backups(registry.sub_apikey)
hb = hub_backups()

if opt_random:
passphrase = random_passphrase()
Expand Down
4 changes: 2 additions & 2 deletions cmd_restore.py
Expand Up @@ -144,7 +144,7 @@
import passphrase
import hooks

from registry import registry, update_profile
from registry import registry, update_profile, hub_backups

from version import Version
from utils import is_writeable, fmt_timestamp, fmt_title
Expand Down Expand Up @@ -200,7 +200,7 @@ def fmt(s):
fatal("You didn't answer 'yes'. Aborting!")

def get_backup_record(arg):
hb = hub.Backups(registry.sub_apikey)
hb = hub_backups()
if re.match(r'^\d+$', arg):
backup_id = arg

Expand Down
1 change: 1 addition & 0 deletions hub.py
Expand Up @@ -262,3 +262,4 @@ def __del__(self):
if os.environ.get("TKLBAM_DUMMYHUB") or os.path.exists(os.path.join(Conf.DEFAULT_PATH, "dummyhub")):
from dummyhub import Backups


16 changes: 16 additions & 0 deletions registry.py
Expand Up @@ -282,3 +282,19 @@ def update_profile(force_profile=None):

sys.exit(1)
os.environ['TKLBAM_PROFILE_ID'] = registry.profile.profile_id

def hub_backups():
import sys
global registry

try:
hb = hub.Backups(registry.sub_apikey)
except hub.Backups.NotInitialized:
command = "tklbam-init"
if registry.path != registry.DEFAULT_PATH:
command = "%s=%s %s" % (registry.ENV_VARNAME, registry.path, command)

print >> sys.stderr, 'error: you need to run "%s" first' % command
sys.exit(1)

return hb

0 comments on commit 3c2ba2b

Please sign in to comment.