Exemplo n.º 1
0
    def run(self):
        conf = settings.read(self.app.conf)
        serial = conf.get('device', 'serial')
        device_class = conf.get('device', 'class')
        auth_token = conf.get('device', 'auth')
        server = conf.get('server', 'url')

        remote = jsonrpc.JSONRPC(server)

        with remote.batch() as batch:
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=device_class,
                               serial=serial,
                               auth_token=auth_token)
            batch.call_with_id('url_result',
                               'device.get_manage_url')

        batch.get_result('auth_result')
        url = batch.get_result('url_result')

        if self.args.url_only:
            print url
        else:
            import webbrowser
            webbrowser.open(url)
Exemplo n.º 2
0
    def run(self):
        conf = settings.read(self.app.conf)
        serial = conf.get('device', 'serial')
        device_class = conf.get('device', 'class')
        auth_token = conf.get('device', 'auth')
        server = conf.get('server', 'url')

        remote = jsonrpc.JSONRPC(server)

        with remote.batch() as batch:
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=device_class,
                               serial=serial,
                               auth_token=auth_token)
            batch.call_with_id('url_result', 'device.get_manage_url')

        batch.get_result('auth_result')
        url = batch.get_result('url_result')

        if self.args.url_only:
            print url
        else:
            import webbrowser
            webbrowser.open(url)
Exemplo n.º 3
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))
Exemplo n.º 4
0
    def _init(self):
        try:
            conf = self.conf = settings.read(*self.conf_paths)
            conf_dir = os.path.dirname(conf.path)

            self.firmware_conf = settings.read_default(os.path.join(conf_dir, 'firmware.conf'))
            self.current_firmware_version = int(self.firmware_conf.get('firmware', 'version', 1))
            self.firmware_path = conf.get('firmware', 'path', None)
            self.log.info('running firmware {:010}'.format(self.current_firmware_version))
            if self.rpc_url is None:
                self.rpc_url = conf.get('server',
                                        'url',
                                        constants.SERVER_URL)
            self.log.debug('api url is %s', self.rpc_url)
            self.push_url = conf.get('server',
                                     'push_url',
                                     constants.PUSH_URL)
            self.remote = JSONRPC(self.rpc_url)

            self.serial = tools.resolve_value(conf.get('device', 'serial', None))
            if self.serial is None:
                self.serial = serial.get_default_serial()
                self.log.info('auto generated device serial, %r', self.serial)
            self.name = conf.get('device', 'name', self.serial)
            self.log.info('device name "%s", "serial" %s', self.name, self.serial)
            self.device_class = conf.get('device', 'class')
            self.subdomain = conf.get('device', 'subdomain', None)
            if not self.subdomain:
                # try legacy settings
                self.subdomain = conf.get('device', 'company', None)

            self._auth_token = conf.get('device', 'auth')
            self.auto_register_info = conf.get('device', 'auto_device_text', None)

            # Run this first, so it can work asynchronously
            if self.create_m2m:
                self.m2m = M2MManager.init_from_conf(self, conf)
            else:
                self.m2m = None

            if self.m2m:
                self.rc = RCManager.init_from_conf(self, conf)
            else:
                self.rc = None

            self.tasks = TaskManager.init_from_conf(self, conf)
            self.samplers = SamplerManager.init_from_conf(self, conf)
            self.livesettings = LiveSettingsManager.init_from_conf(self, conf)
            self.timelines = TimelineManager.init_from_conf(self, conf)

            self.sample_now = self.samplers.sample_now
            self.sample = self.samplers.sample

            self.get_timeline = self.timelines.get_timeline
        except:
            self.log.exception('unable to start')
            raise
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def _init(self):
        try:
            conf = self.conf = settings.read(*self.conf_paths)
            conf_dir = os.path.dirname(conf.path)

            self.firmware_conf = settings.read_default(
                os.path.join(conf_dir, 'firmware.conf'))
            self.current_firmware_version = int(
                self.firmware_conf.get('firmware', 'version', 1))
            self.firmware_path = conf.get('firmware', 'path')
            self.log.info('running firmware {:010}'.format(
                self.current_firmware_version))
            self.rpc_url = conf.get('server', 'url', constants.SERVER_URL)
            self.push_url = conf.get('server', 'push_url', constants.PUSH_URL)
            self.remote = JSONRPC(self.rpc_url)

            self.serial = conf.get('device', 'serial', None)
            if self.serial is None:
                self.serial = serial.get_default_serial()
                self.log.info('auto generated device serial, %r', self.serial)
            self.name = conf.get('device', 'name', self.serial)
            self.log.info('device name "{}", "serial" {}'.format(
                self.name, self.serial))
            self.device_class = conf.get('device', 'class')
            self.subdomain = conf.get('device', 'subdomain', None)
            if not self.subdomain:
                # try legacy settings
                self.subdomain = conf.get('device', 'company', None)

            self._auth_token = conf.get('device', 'auth')
            self.auto_register_info = conf.get('device', 'auto_device_text',
                                               None)

            self.tasks = TaskManager.init_from_conf(self, conf)
            self.samplers = SamplerManager.init_from_conf(self, conf)
            self.livesettings = LiveSettingsManager.init_from_conf(self, conf)
            self.timelines = TimelineManager.init_from_conf(self, conf)

            self.sample_now = self.samplers.sample_now
            self.sample = self.samplers.sample

            self.get_timeline = self.timelines.get_timeline
        except:
            self.log.exception('unable to start')
            raise
Exemplo n.º 7
0
    def make_daemon(self, debug=None):
        conf_path = self.args.conf or constants.CONF_PATH
        conf_path = abspath(conf_path)

        conf = settings.read(conf_path)
        firmware_conf_path = conf.get('daemon', 'conf', conf_path)
        # It may not exist if there is no installed firmware
        if os.path.exists(firmware_conf_path):
            log.error("daemon firmware conf '{}' does not exist".format(firmware_conf_path))
            conf_path = firmware_conf_path

        if debug is None:
            debug = self.args.debug or self.args.foreground

        self.app.init_logging(self.app.args.logging,
                              foreground=self.args.foreground)
        dataplicity_daemon = Daemon(conf_path,
                                    foreground=self.args.foreground,
                                    debug=debug)
        return dataplicity_daemon
Exemplo n.º 8
0
    def make_daemon(self, debug=None):
        conf_path = self.args.conf or constants.CONF_PATH
        conf_path = abspath(conf_path)

        conf = settings.read(conf_path)
        firmware_conf_path = conf.get('daemon', 'conf', conf_path)
        # It may not exist if there is no installed firmware
        if os.path.exists(firmware_conf_path):
            log.error("daemon firmware conf '{}' does not exist".format(
                firmware_conf_path))
            conf_path = firmware_conf_path

        if debug is None:
            debug = self.args.debug or self.args.foreground

        self.app.init_logging(self.app.args.logging,
                              foreground=self.args.foreground)
        dataplicity_daemon = Daemon(conf_path,
                                    foreground=self.args.foreground,
                                    debug=debug)
        return dataplicity_daemon
Exemplo n.º 9
0
 def get_conf(self):
     conf_path = self.args.conf or constants.CONF_PATH
     conf_path = abspath(conf_path)
     conf = settings.read(conf_path)
     return conf
Exemplo n.º 10
0
 def get_conf(self):
     conf_path = self.args.conf or constants.CONF_PATH
     conf_path = abspath(conf_path)
     conf = settings.read(conf_path)
     return conf