Permalink
Browse files

UX: fail with the same helpful error message when TKLBAM not initialized

  • Loading branch information...
1 parent 676ec06 commit 3c2ba2bd92a54b1b9a0737a735c8d61eb3a52c2b @lirazsiri lirazsiri committed Nov 6, 2013
Showing with 25 additions and 15 deletions.
  1. +2 −9 cmd_backup.py
  2. +2 −2 cmd_list.py
  3. +2 −2 cmd_passphrase.py
  4. +2 −2 cmd_restore.py
  5. +1 −0 hub.py
  6. +16 −0 registry.py
View
11 cmd_backup.py
@@ -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
@@ -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)
View
4 cmd_list.py
@@ -40,7 +40,7 @@
import hub
import keypacket
-from registry import registry
+from registry import registry, hub_backups
def usage(e=None):
if e:
@@ -101,7 +101,7 @@ def main():
else:
format = None
- hb = hub.Backups(registry.sub_apikey)
+ hb = hub_backups()
hbrs = hb.list_backups()
if format:
View
4 cmd_passphrase.py
@@ -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):
@@ -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()
View
4 cmd_restore.py
@@ -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
@@ -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
View
1 hub.py
@@ -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
+
View
16 registry.py
@@ -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.