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 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)