forked from M-Labs/artiq
1
0
Fork 0

afws_client: update

This commit is contained in:
Sebastien Bourdeauducq 2022-09-15 09:15:38 +08:00
parent 6085fe3319
commit a028b5c9f7
1 changed files with 29 additions and 7 deletions

View File

@ -29,7 +29,19 @@ def get_artiq_rev():
import artiq import artiq
except ImportError: except ImportError:
return None return None
return artiq._version.get_rev() rev = artiq._version.get_rev()
if rev == "unknown":
return None
return rev
def get_artiq_major_version():
try:
import artiq
except ImportError:
return None
version = artiq._version.get_version()
return version.split(".")[0]
def zip_unarchive(data, directory): def zip_unarchive(data, directory):
@ -70,17 +82,20 @@ class Client:
self.send_command("LOGIN", username, password) self.send_command("LOGIN", username, password)
return self.read_reply() == ["HELLO"] return self.read_reply() == ["HELLO"]
def build(self, rev, variant, log): def build(self, major_ver, rev, variant, log):
if not variant: if not variant:
variants = self.get_variants() variants = self.get_variants()
if len(variants) != 1: if len(variants) != 1:
raise ValueError("User can build more than 1 variant - need to specify") raise ValueError("User can build more than 1 variant - need to specify")
variant = variants[0][0] variant = variants[0][0]
print("Building variant: {}".format(variant)) print("Building variant: {}".format(variant))
if log: build_args = (
self.send_command("BUILD", rev, variant, "LOG_ENABLE") rev,
else: variant,
self.send_command("BUILD", rev, variant) "LOG_ENABLE" if log else "LOG_DISABLE",
major_ver,
)
self.send_command("BUILD", *build_args)
reply = self.read_reply()[0] reply = self.read_reply()[0]
if reply != "BUILDING": if reply != "BUILDING":
return reply, None return reply, None
@ -134,6 +149,7 @@ def main():
action = parser.add_subparsers(dest="action") action = parser.add_subparsers(dest="action")
action.required = True action.required = True
act_build = action.add_parser("build", help="build and download firmware") act_build = action.add_parser("build", help="build and download firmware")
act_build.add_argument("--major-ver", default=None, help="ARTIQ major version")
act_build.add_argument("--rev", default=None, help="revision to build (default: currently installed ARTIQ revision)") act_build.add_argument("--rev", default=None, help="revision to build (default: currently installed ARTIQ revision)")
act_build.add_argument("--log", action="store_true", help="Display the build log") act_build.add_argument("--log", action="store_true", help="Display the build log")
act_build.add_argument("directory", help="output directory") act_build.add_argument("directory", help="output directory")
@ -182,13 +198,19 @@ def main():
except NotADirectoryError: except NotADirectoryError:
print("A file with the same name as the output directory already exists. Please remove it and try again.") print("A file with the same name as the output directory already exists. Please remove it and try again.")
sys.exit(1) sys.exit(1)
major_ver = args.major_ver
if major_ver is None:
major_ver = get_artiq_major_version()
if major_ver is None:
print("Unable to determine currently installed ARTIQ major version. Specify manually using --major-ver.")
sys.exit(1)
rev = args.rev rev = args.rev
if rev is None: if rev is None:
rev = get_artiq_rev() rev = get_artiq_rev()
if rev is None: if rev is None:
print("Unable to determine currently installed ARTIQ revision. Specify manually using --rev.") print("Unable to determine currently installed ARTIQ revision. Specify manually using --rev.")
sys.exit(1) sys.exit(1)
result, contents = client.build(rev, args.variant, args.log) result, contents = client.build(major_ver, rev, args.variant, args.log)
if result != "OK": if result != "OK":
if result == "UNAUTHORIZED": if result == "UNAUTHORIZED":
print("You are not authorized to build this variant. Your firmware subscription may have expired. Contact helpdesk\x40m-labs.hk.") print("You are not authorized to build this variant. Your firmware subscription may have expired. Contact helpdesk\x40m-labs.hk.")