diff --git a/README.md b/README.md index 60e3a64..2e002f1 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ bond livelog --level info You can upgrade your selected bond: ```bash -bond upgrade --release beta +bond upgrade beta ``` ## Getting Help diff --git a/bond/commands/select.py b/bond/commands/select.py index 7c4aafe..e969bf3 100644 --- a/bond/commands/select.py +++ b/bond/commands/select.py @@ -56,8 +56,6 @@ def run(self, args): print("Set %s port %s" % (bond_id, args.ip)) print("Selected Bond: %s" % BondDatabase().get("selected_bondid")) token = check_unlocked_token() - if token: - print("Set token: %s" % token) elif args.clear: BondDatabase.pop("selected_bondid", None) print("Cleared selected Bond") diff --git a/bond/commands/upgrade.py b/bond/commands/upgrade.py index 0dc53d1..fd9556f 100644 --- a/bond/commands/upgrade.py +++ b/bond/commands/upgrade.py @@ -11,21 +11,21 @@ def register(): UpgradeCommand() -def get_branch(args, target): - release = args.release - if release: - return "trunk" if release == "trunk" else f"{release}-{target}" +def get_branch_string(branch, target): + if branch in ("alpha", "beta", "master"): + return f"{branch}-{target}" + elif branch == "trunk": + return "trunk" else: - return args.branch.replace("/", "-") + return branch.replace("/", "-") def get_latest_version(target, branch): url = f"https://s3.amazonaws.com/bond-updates/v2/{target}/{branch}/versions_internal.json" rsp = requests.get(url) if rsp.status_code != 200: - raise Exception( - f"Failed to access version info on S3: {url}, {rsp.status_code}" - ) + print("Failed to find an upgrade for target %s on branch %s" % (target, branch)) + exit(1) return json.loads(rsp.content)["versions"][0] @@ -42,13 +42,17 @@ def do_upgrade(bondid, version_obj): pass for _ in range(120): time.sleep(1) - rsp = bond.proto.get(bondid, topic="sys/upgrade") + try: + rsp = bond.proto.get(bondid, topic="sys/upgrade") + except requests.exceptions.ReadTimeout: + sys.stdout.write(".") + sys.stdout.flush() + continue progress = rsp["b"]["progress"] - assert rsp["s"] in (200, 204) + print(f"Progress: {progress / 10}%") if rsp["s"] == 204 or progress == 1000: print("Upgrade installed.") break - print(f"Progress: {progress / 10}%") else: raise Exception("Download timeout") print("Rebooting...") @@ -62,14 +66,12 @@ def do_upgrade(bondid, version_obj): # check for in progress return get on upgrade try: rsp = bond.proto.get(bondid, topic="sys/version", timeout=2) - except: + except requests.exceptions.ConnectTimeout: sys.stdout.write(".") sys.stdout.flush() - rsp = None - - if rsp: - print("Reconnected!") - break + continue + print("Reconnected!") + break else: raise Exception("Download timeout") @@ -80,25 +82,18 @@ class UpgradeCommand(BaseCommand): subcmd = "upgrade" help = "Upgrade your Bond. Choose either a released firmware or a firmware from a specific branch" arguments = { - "--release": { - "help": """the release to use. Using trunk or alpha is not recommended unless - you really know what you're doing, master is the branch released to - the store mobile apps, beta is released to the public beta mobile apps""", - "choices": ["trunk", "alpha", "beta", "master"], + "branch": { + "help": "The branch. Release branches are 'trunk', 'alpha', 'beta', and 'master'. " + "'master' is the version distributed by the mobile apps in the app stores, " + "'alpha' and 'trunk' are for internal development use, and may be unstable." }, "--target": { "help": "override detected target. Useful in development, but may cause irreversible device malfunction!" }, - "--branch": { - "help": "choose a specific firmware branch, same deal as alpha: don't use unless you know what you're doing." - }, } def run(self, args): bondid = BondDatabase.get_assert_selected_bondid() - if (args.release and args.branch) or not (args.release or args.branch): - print("Unable to proceed: choose one and only one of release or branch") - exit(1) print("Connecting to BOND...") sys_version = bond.proto.get(bondid, topic="sys/version")["b"] target = sys_version["target"] @@ -123,7 +118,7 @@ def run(self, args): target = args.target print("Target manually overriden.") - branch = get_branch(args, target) + branch = get_branch_string(args.branch, target) print(f"Selected Branch: \t{branch}") print(f"Current Version: \t{current_ver}") version_obj = get_latest_version(target, branch) diff --git a/setup.py b/setup.py index c2733da..3fa64fc 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='bond-cli', - version='0.0.7', + version='0.0.8', author='Olibra', packages=find_packages(), scripts=['bond/bond'],