def do_logout(self, args): opts = utils.CommandOptions(args) if not utils.clear_credentials(): if opts.address: print('Not logged in to {}'.format(opts.address)) else: print('Not logged in')
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) rows = [['NAME']] for table in archive.list_tables(): rows.append([ table.name, ]) utils.print_table(rows)
def mv(self, args): opts = utils.CommandOptions(args) client = storage.Client(**opts.client_kwargs) if self.cp(args) is not False: if '://' in args.src: parts = args.src.split('://', 1) client.remove_object( '_global', bucket_name=parts[0], object_name=parts[1]) else: os.remove(args.src)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'CLASS', 'STATUS']] for service in client.list_services(opts.instance): rows.append([ service.name, service.class_name, service.state, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'STATE', 'MISSION TIME']] for instance in client.list_instances(): rows.append([ instance.name, instance.state, instance.mission_time, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DESCRIPTION']] for algorithm in mdb.list_algorithms(): rows.append([ algorithm.qualified_name, algorithm.description, ]) utils.print_table(rows)
def cp(self, args): opts = utils.CommandOptions(args) if '://' in args.src: if '://' in args.dst: return self._cp_object_to_object(opts, args.src, args.dst) else: return self._cp_object_to_file(opts, args.src, args.dst) else: if '://' in args.dst: return self._cp_file_to_object(opts, args.src, args.dst) else: shutil.copy(args.src, args.dst)
def rm(self, args): opts = utils.CommandOptions(args) client = storage.Client(**opts.client_kwargs) for obj in args.object: if '://' not in obj: print('*** specify objects in the format bucket://object') return False parts = obj.split('://', 1) client.remove_object( '_global', bucket_name=parts[0], object_name=parts[1])
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DATA SOURCE']] for parameter in mdb.list_parameters(): rows.append([ parameter.qualified_name, parameter.data_source, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) rows = [['NAME', 'DESCRIPTION', 'ABSTRACT']] for command in mdb.list_commands(): rows.append([ command.qualified_name, command.description, command.abstract, ]) utils.print_table(rows)
def subscribe(self, args): def on_data(stream_data): print(stream_data._proto) #pylint: disable=protected-access opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) try: subscription = archive.create_stream_subscription(args.stream, on_data=on_data) subscription.result() except KeyboardInterrupt: pass
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['ID', 'USER', 'APPLICATION', 'LOGIN']] for client in client.list_clients(): rows.append([ client.id, client.username, client.application_name, client.login_time, ]) utils.print_table(rows)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [['NAME', 'CLASS', 'STATUS', 'IN', 'OUT']] for link in client.list_data_links(opts.instance): rows.append([ link.name, link.class_name, link.status, link.in_count, link.out_count, ]) utils.print_table(rows)
def load(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump.gz' if args.gzip else table + '.dump' if args.dir: path = os.path.join(args.dir, path) if args.gzip: with gzip.open(path, 'rb') as f: self.read_dump(f, archive, table, path) else: with open(path, 'rb') as f: self.read_dump(f, archive, table, path)
def load(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump' if args.dir: path = os.path.join(args.dir, path) with gzip.open(path, 'rb') as f: stdout.write(table) stdout.flush() n = archive.load_table(table, data=f) stdout.write('\r{}: loaded {} rows'.format(table, n)) stdout.write('\n')
def cat(self, args): opts = utils.CommandOptions(args) client = storage.Client(**opts.client_kwargs) for obj in args.object: if '://' not in obj: print('*** specify objects in the format bucket://object') return False parts = obj.split('://', 1) content = client.download_object( '_global', bucket_name=parts[0], object_name=parts[1]) sys.stdout.buffer.write(content)
def list_(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) rows = [[ 'NAME', 'TYPE', 'OWNER', 'PERSISTENT', 'MISSION TIME', 'STATE' ]] for processor in client.list_processors(opts.instance): rows.append([ processor.name, processor.type, processor.owner, processor.persistent, processor.mission_time, processor.state, ]) utils.print_table(rows)
def do_login(self, args): opts = utils.CommandOptions(args) address = args.address or self.read_address(opts) client = YamcsClient(address) auth_info = client.get_auth_info() if auth_info.require_authentication: credentials = self.read_credentials() client = YamcsClient(address, credentials=credentials) print('Login succeeded') else: user_info = client.get_user_info() print('Anonymous login succeeded (username: {})'.format( user_info.username)) self.save_client_config(client, opts.config)
def launch(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) shell = DbShell(client) shell.do_use(opts.instance) if args.command: shell.onecmd(args.command) else: server_info = client.get_server_info() intro = ('Yamcs DB Shell\n' 'Server version: {} - ID: {}\n\n' 'Type ' 'help' ' or ' '?' ' for help.\n').format(server_info.version, server_info.id) shell.cmdloop(intro)
def dump(self, args): if args.dir: if not os.path.exists(args.dir): os.makedirs(args.dir) opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump.gz' if args.gzip else table + '.dump' if args.dir: path = os.path.join(args.dir, path) if args.gzip: with gzip.open(path, 'wb', compresslevel=1) as f: self.write_dump(f, archive, table, path) else: with open(path, 'wb') as f: self.write_dump(f, archive, table, path)
def ls(self, args): opts = utils.CommandOptions(args) client = storage.Client(**opts.client_kwargs) if args.bucket: if '://' in args.bucket: bucket_name, prefix = args.bucket.split('://', 1) else: bucket_name = args.bucket prefix = None delimiter = '/' if args.recurse: delimiter = None listing = client.list_objects(opts.instance, bucket_name=bucket_name, delimiter=delimiter, prefix=prefix) rows = [] for prefix in listing.prefixes: url = '{}://{}'.format(bucket_name, prefix) if args.long: rows.append(['0', '', url]) else: rows.append([url]) for obj in listing.objects: url = '{}://{}'.format(bucket_name, obj.name) if args.long: rows.append( [str(obj.size), to_isostring(obj.created), url]) else: rows.append([url]) utils.print_table(rows) else: for bucket in client.list_buckets(opts.instance): print(bucket.name)
def dump(self, args): if args.dir: if not os.path.exists(args.dir): os.makedirs(args.dir) opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) for table in args.tables: path = table + '.dump' if args.dir: path = os.path.join(args.dir, path) with gzip.open(path, 'wb') as f: size = 0 t1 = time.time() for chunk in archive.dump_table(table): size += f.write(chunk) t2 = time.time() rate = (size / 1024 / 1024) / (t2 - t1) stdout.write('\r{}: {} MB/s'.format(table, round(rate, 2))) stdout.flush() if size > 0: stdout.write('\n')
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) command = mdb.get_command(args.command) print(command._proto) #pylint: disable=protected-access
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) archive = client.get_archive(opts.instance) table = archive.get_table(args.table) print(table._proto) #pylint: disable=protected-access
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) algorithm = mdb.get_algorithm(args.algorithm) print(algorithm._proto) #pylint: disable=protected-access
def disable(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) for link in args.links: client.disable_data_link(opts.instance, link=link)
def stop(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) for instance in args.instances: client.stop_instance(instance)
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) link = client.get_data_link(opts.instance, args.link) print(link._proto) #pylint: disable=protected-access
def stop(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) for service in args.services: client.stop_service(opts.instance, service=service)
def describe(self, args): opts = utils.CommandOptions(args) client = YamcsClient(**opts.client_kwargs) mdb = client.get_mdb(opts.instance) parameter = mdb.get_parameter(args.parameter) print(parameter._proto) #pylint: disable=protected-access