def run(self): args = self.args firmware_fs = ZipFS(args.path) firmware_conf = firmware.get_conf(firmware_fs) version = firmware.get_version(firmware_fs) device_class = firmware_conf.get('device', 'class') print "installing firmware {:010} for device class {}...".format(version, device_class) if not os.path.exists(args.install_path): try: os.makedirs(args.install_path) except: raise else: print "created {}".format(args.install_path) dst_fs = OSFS(args.install_path) install_path = firmware.install(device_class, version, firmware_fs, dst_fs) print "installed {} to {}".format(args.path, install_path)
def run(self): log.setLevel(logging.ERROR) args = self.args conf_path = self.app.conf dataplicity_path = dirname(conf_path) client = self.app.make_client(log) conf = client.conf remote = client.remote device_class_name = conf.get('device', 'class') with fsopendir(dataplicity_path) as project_fs: version = firmware.get_version(project_fs) ui = firmware.get_ui(project_fs) sys.stdout.write( "uploading UI for firmware {:010}...\n".format(version)) with remote.batch() as batch: batch.call_with_id('auth_result', 'device.check_auth', device_class=device_class_name, serial=client.serial, auth_token=client.auth_token) batch.call_with_id('update_ui_result', 'device.update_ui', device_class=device_class_name, version=version, ui=ui) batch.call_with_id('url_result', 'device.get_manage_url') batch.get_result('auth_result') try: batch.get_result('update_ui_result') except JSONRPCError as e: if e.code == ErrorCodes.UI_INVALID: sys.stderr.write( "User Interface definition failed to validate!\n") if hasattr(e, 'message'): sys.stderr.write(" {}\n".format(e.message)) sys.stderr.write('Please check for errors and try again\n') return -1 raise url = batch.get_result('url_result') sys.stdout.write('UI updated on {}\n'.format(url))
def run(self): log.setLevel(logging.ERROR) args = self.args conf_path = self.app.conf dataplicity_path = dirname(conf_path) client = self.app.make_client(log) conf = client.conf remote = client.remote device_class_name = conf.get('device', 'class') with fsopendir(dataplicity_path) as project_fs: version = firmware.get_version(project_fs) ui = firmware.get_ui(project_fs) sys.stdout.write("uploading UI for firmware {:010}...\n".format(version)) with remote.batch() as batch: batch.call_with_id('auth_result', 'device.check_auth', device_class=device_class_name, serial=client.serial, auth_token=client.auth_token) batch.call_with_id('update_ui_result', 'device.update_ui', device_class=device_class_name, version=version, ui=ui) batch.call_with_id('url_result', 'device.get_manage_url') batch.get_result('auth_result') try: batch.get_result('update_ui_result') except JSONRPCError as e: if e.code == ErrorCodes.UI_INVALID: sys.stderr.write("User Interface definition failed to validate!\n") if hasattr(e, 'message'): sys.stderr.write(" {}\n".format(e.message)) sys.stderr.write('Please check for errors and try again\n') return -1 raise url = batch.get_result('url_result') sys.stdout.write('UI updated on {}\n'.format(url))
def do_build(dataplicity_path): """Build firmware in project directory""" with fsopendir(dataplicity_path) as src_fs: version = firmware.get_version(src_fs) print("Building version {:010}...".format(version)) filename = "firmware-{}.zip".format(version) firmware_path = join('__firmware__', filename) src_fs.makedir('__firmware__', allow_recreate=True) with src_fs.open(firmware_path, 'wb') as zip_file: dst_fs = ZipFS(zip_file, 'w') firmware.build(src_fs, dst_fs) dst_fs.close() size = src_fs.getsize(firmware_path) print("Wrote {} ({:,} bytes)".format(firmware_path, size))
def do_build(dataplicity_path): """Build firmware in project directory""" with fsopendir(dataplicity_path) as src_fs: version = firmware.get_version(src_fs) print "Building version {:010}...".format(version) filename = "firmware-{}.zip".format(version) firmware_path = join('__firmware__', filename) src_fs.makedir('__firmware__', allow_recreate=True) with src_fs.open(firmware_path, 'wb') as zip_file: dst_fs = ZipFS(zip_file, 'w') firmware.build(src_fs, dst_fs) dst_fs.close() size = src_fs.getsize(firmware_path) print "Wrote {} ({:,} bytes)".format(firmware_path, size)
def run(self): args = self.args if args.quiet: def out(text): pass else: def out(text): print(text) firmware_fs = ZipFS(args.path) firmware_conf = firmware.get_conf(firmware_fs) version = firmware.get_version(firmware_fs) device_class = firmware_conf.get('device', 'class') out("installing firmware {:010} for device class {}...".format(version, device_class)) dir_mode = int('775', 8) # Python 2/3 compatible octal number if not os.path.exists(args.install_path): try: os.makedirs(args.install_path, dir_mode) except: raise else: out("created {}".format(args.install_path)) dst_fs = OSFS(args.install_path, dir_mode=dir_mode) install_path = firmware.install(device_class, version, firmware_fs, dst_fs) out("installed {} to {}".format(args.path, install_path)) if args.make_active: firmware.activate(device_class, version, dst_fs, fw_path=args.install_path)
def run(self): args = self.args firmware_fs = ZipFS(args.path) firmware_conf = firmware.get_conf(firmware_fs) version = firmware.get_version(firmware_fs) device_class = firmware_conf.get('device', 'class') print "installing firmware {:010} for device class {}...".format( version, device_class) if not os.path.exists(args.install_path): try: os.makedirs(args.install_path) except: raise else: print "created {}".format(args.install_path) dst_fs = OSFS(args.install_path) install_path = firmware.install(device_class, version, firmware_fs, dst_fs) print "installed {} to {}".format(args.path, install_path)
def run(self): log.setLevel(logging.DEBUG) args = self.args username = args.username password = args.password if username is None: username = raw_input('username: '******'password: '******'dataplicity path is {}'.format(dataplicity_path)) if args.build: do_build(dataplicity_path) with fsopendir(dataplicity_path) as src_fs: version = firmware.get_version(src_fs) filename = "firmware-{}.zip".format(version) firmware_path = join('__firmware__', filename) try: firmware_contents = src_fs.getcontents(firmware_path, 'rb') except ResourceNotFoundError: print("{} is missing, you can build firmware with 'dataplicity build'".format(firmware_path)) return -1 firmware_b64 = b64encode(firmware_contents) client = self.app.make_client(log, create_m2m=False) conf = client.conf remote = client.remote device_class_name = conf.get('device', 'class') #serial = conf.get('device', 'serial') ui = firmware.get_ui(fsopendir(dataplicity_path)) remote = self.app.make_client(log, create_m2m=False, conf="/etc/dataplicity/dataplicity.conf").remote print("uploading firmware...") with remote.batch() as batch: # batch.call_with_id('auth_result', # 'device.check_auth', # device_class=device_class_name, # serial=client.serial, # auth_token=client.auth_token) batch.call_with_id("publish_result", "device.publish", device_class=device_class_name, version=version, firmware_b64=firmware_b64, ui=ui, username=username, password=password, company=company, replace=args.replace) #batch.get_result('auth_result') try: publish_result = batch.get_result('publish_result') except JSONRPCError as e: if e.code == ErrorCodes.FIRMWARE_EXISTS: print("Firmware {:010} exists!\nBump the version number in firmware.conf or use --replace to overwrite".format(version)) return -1 raise print("visit {} to manage firmware".format(publish_result['url'])) if args.bump: with fsopendir(dataplicity_path) as src_fs: firmware.bump(src_fs)
def run(self): log.setLevel(logging.ERROR) args = self.args conf_path = self.app.conf dataplicity_path = dirname(conf_path) if args.build: do_build(dataplicity_path) with fsopendir(dataplicity_path) as src_fs: version = firmware.get_version(src_fs) filename = "firmware-{}.zip".format(version) firmware_path = join('__firmware__', filename) try: firmware_contents = src_fs.getcontents(firmware_path, 'rb') except ResourceNotFoundError: print "{} is missing, you can build firmware with 'dataplicity build'".format(firmware_path) return -1 firmware_b64 = b64encode(firmware_contents) client = self.app.make_client(log) conf = client.conf remote = client.remote device_class_name = conf.get('device', 'class') #serial = conf.get('device', 'serial') ui = firmware.get_ui(fsopendir(dataplicity_path)) print "uploading firmware..." with remote.batch() as batch: batch.call_with_id('auth_result', 'device.check_auth', device_class=device_class_name, serial=client.serial, auth_token=client.auth_token) batch.call_with_id("publish_result", "device.publish", device_class=device_class_name, version=version, firmware_b64=firmware_b64, ui=ui, replace=args.replace) batch.get_result('auth_result') try: publish_result = batch.get_result('publish_result') except JSONRPCError as e: if e.code == ErrorCodes.FIRMWARE_EXISTS: print "Firmware {:010} exists!\nBump the version number in firmware.conf or use --replace to overwrite".format(version) return -1 raise print "visit {} to manage firmware".format(publish_result['url']) if args.bump: with fsopendir(dataplicity_path) as src_fs: firmware.bump(src_fs)