Esempio n. 1
0
    def run(self):
        args = self.args
        device_class = args.device_class
        conf_path = constants.CONF_PATH

        if not os.path.exists(conf_path):
            sys.stderr.write('{} does not exist.\n'.format(conf_path))
            sys.stderr.write("please run 'dataplicity init' first\n")
            return -1

        print("reading conf from {}".format(conf_path))
        cfg = settings.read(conf_path)
        serial = cfg.get('device', 'serial')
        auth_token = cfg.get('device', 'auth')
        server_url = cfg.get('server', 'url', constants.SERVER_URL)

        remote = jsonrpc.JSONRPC(server_url)

        print("downloading firmware...")
        with remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=auth_token,
                               name=args.name or serial,
                               serial=serial,
                               device_class_name=device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=device_class,
                               serial=serial,
                               auth_token=auth_token)
            batch.call_with_id('firmware_result',
                               'device.get_firmware')
        batch.get_result('register_result')
        batch.get_result('auth_result')
        fw = batch.get_result('firmware_result')

        if not fw['firmware']:
            sys.stderr.write('no firmware available!\n')
            return -1
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = BytesIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(device_class,
                         version,
                         firmware_fs,
                         dst_fs)

        fw_path = dst_fs.getsyspath('/')
        print("installed firmware {} to {}".format(version, fw_path))

        firmware.activate(device_class, version, dst_fs)
        print("activated {}".format(version))
Esempio n. 2
0
    def run(self):
        args = self.args
        device_class = args.device_class
        conf_path = constants.CONF_PATH

        if not os.path.exists(conf_path):
            sys.stderr.write('{} does not exist.\n'.format(conf_path))
            sys.stderr.write("please run 'dataplicity init' first\n")
            return -1

        print "reading conf from {}".format(conf_path)
        cfg = settings.read(conf_path)
        serial = cfg.get('device', 'serial')
        auth_token = cfg.get('device', 'auth')
        server_url = cfg.get('server', 'url', constants.SERVER_URL)

        remote = jsonrpc.JSONRPC(server_url)

        print "downloading firmware..."
        with remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=auth_token,
                               name=args.name or serial,
                               serial=serial,
                               device_class_name=device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=device_class,
                               serial=serial,
                               auth_token=auth_token)
            batch.call_with_id('firmware_result', 'device.get_firmware')
        batch.get_result('register_result')
        batch.get_result('auth_result')
        fw = batch.get_result('firmware_result')

        if not fw['firmware']:
            sys.stderr.write('no firmware available!\n')
            return -1
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = StringIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(device_class, version, firmware_fs, dst_fs)

        fw_path = dst_fs.getsyspath('/')
        print "installed firmware {} to {}".format(version, fw_path)

        firmware.activate(device_class, version, dst_fs)
        print "activated {}".format(version)
Esempio n. 3
0
    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)
Esempio n. 4
0
    def deploy(self):
        """Deploy latest firmware"""
        self.log.info("requesting firmware...")
        with self.remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=self.auth_token,
                               name=self.name or self.serial,
                               serial=self.serial,
                               device_class_name=self.device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=self.device_class,
                               serial=self.serial,
                               auth_token=self.auth_token)
            batch.call_with_id('firmware_result',
                               'device.get_firmware')
        try:
            batch.get_result('register_result')
        except Exception as e:
            self.log.warning(e)
        batch.get_result('auth_result')

        fw = batch.get_result('firmware_result')
        if not fw['firmware']:
            self.log.warning('no firmware available!')
            return False
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = StringIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(self.device_class,
                         version,
                         firmware_fs,
                         dst_fs)

        fw_path = dst_fs.getsyspath('/')
        self.log.info("installed firmware {:010} to {}".format(version, fw_path))

        firmware.activate(self.device_class, version, dst_fs)
        self.log.info("activated firmware {:010}".format(version))
Esempio n. 5
0
    def deploy(self):
        """Deploy latest firmware"""
        self.log.info("requesting firmware...")
        with self.remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=self.auth_token,
                               name=self.name or self.serial,
                               serial=self.serial,
                               device_class_name=self.device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=self.device_class,
                               serial=self.serial,
                               auth_token=self.auth_token)
            batch.call_with_id('firmware_result', 'device.get_firmware')
        try:
            batch.get_result('register_result')
        except Exception as e:
            self.log.warning(e)
        batch.get_result('auth_result')

        fw = batch.get_result('firmware_result')
        if not fw['firmware']:
            self.log.warning('no firmware available!')
            return False
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = StringIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(self.device_class, version, firmware_fs, dst_fs)

        fw_path = dst_fs.getsyspath('/')
        self.log.info("installed firmware {:010} to {}".format(
            version, fw_path))

        firmware.activate(self.device_class, version, dst_fs)
        self.log.info("activated firmware {:010}".format(version))
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)