示例#1
0
    def filename_info(self, pip_exe):
        check.check_string(pip_exe)

        info = bes_pip_exe.filename_info(pip_exe)
        tt = text_table(data=zip(tuple(info._fields), info))
        print(tt)
        return 0
示例#2
0
    def images(clazz, blurber, untagged, repo, style):
        check.check_blurber(blurber)
        check.check_bool(untagged)
        check.check_string(repo, allow_none=True)
        check.check_string(style)

        images = docker_images.list_images()
        if untagged:
            images = images.untagged()

        if repo:
            images = images.matching_repository_pattern(repo)

        if not images:
            return 0

        if style == 'brief':
            for image in images:
                print(image.image_id)
        elif style == 'table':
            tt = text_table(data=images)
            tt.set_labels(
                ('ID', 'REPOSITORY', 'TAG', 'DIGEST', 'CREATED_AT', 'SIZE'))
            print(tt)
        elif style == 'repo':
            for image in images:
                print(image.tagged_repository)
        return 0
示例#3
0
  def _list_tags_both(self):
    local_tags = git.list_local_tags(self.options.root_dir)
    remote_tags = git.list_remote_tags(self.options.root_dir)
    slocal = set(local_tags)
    sremote = set(remote_tags)

    sboth = software_version.sort_versions(list(slocal & sremote))
    slocal_only = slocal - sremote
    sremote_only = sremote - slocal

    data = []
    for tag in sboth:
      if tag in sboth:
        tag_where = 'both'
      elif tag in slocal_only:
        tag_where = 'local'
      elif tag in sremote_only:
        tag_where = 'remote'
      data.append( ( tag, tag_where ) )
    if not data:
      return 0
    tt = text_table(data = data)
    tt.set_labels( ( 'TAG', 'WHERE' ) )
    print(tt)
    return 0
示例#4
0
 def vms(self):
     vms = self._client.vms()
     if not vms:
         return 0
     tt = text_table(data=vms)
     tt.set_labels(tuple([f.upper() for f in vms[0]._fields]))
     print(tt)
     return 0
示例#5
0
    def info(self, exe):
        python_exe.check_exe(exe)

        info = python_exe.info(exe)
        data = [item for item in zip(tuple(info._fields), info)]
        tt = text_table(data=data)
        print(tt)
        return 0
示例#6
0
文件: vmware.py 项目: reconstruir/bes
    def vm_info(self, vm_id):
        check.check_string(vm_id)

        self._log.log_method_d()
        vm = self._resolve_vmx_to_local_vm(vm_id)
        tt = text_table(data=[self._make_vm_data(vm)])
        tt.set_labels(self._INFO_LABELS)
        print(tt)
示例#7
0
    def vm_shared_folders(self, vm_id):
        check.check_string(vm_id)

        vm_id = self.resolve_vm_id(vm_id)
        shared_folders = self._client.vm_get_shared_folders(vm_id)
        tt = text_table(data=shared_folders)
        tt.set_labels(('FOLDER_ID', 'PATH', 'PATH_ABS', 'FLAGS'))
        print(tt)
        return 0
示例#8
0
    def ps(self):
        data = []
        for process in process_lister.list_processes():
            data.append((process.command, process.pid, process.user))

        tt = text_table(data=data)
        tt.set_labels(('COMMAND', 'PID', 'USER'))
        print(tt)
        return 0
示例#9
0
 def print_configs(self):
     data = sorted([(c.data.name, c.nice_filename)
                    for c in self.config_env.config_map.values()])
     from bes.text.text_cell_renderer import text_cell_renderer
     from bes.text.text_table import text_table
     max_width = max([len(row[0]) for row in data])
     tt = text_table(data=data, column_delimiter=' ')
     tt.set_col_renderer(
         0,
         text_cell_renderer(just=text_cell_renderer.JUST_LEFT,
                            width=max_width))
     print(tt)
示例#10
0
    def print_values(self, filename, verbose):
        check.check_string(filename, allow_none=True)
        check.check_bool(verbose)

        prefs = vmware_preferences(filename)
        values = sorted(prefs.values().items())
        if verbose:
            print('{}:'.format(prefs.filename))
        tt = text_table(data=values)
        tt.set_labels(('KEY', 'VALUE'))
        print(tt)
        return 0
示例#11
0
    def vm_add_shared_folder(self, vm_id, folder_id, host_path, flags):
        check.check_string(vm_id)
        check.check_string(folder_id)
        check.check_string(host_path)
        check.check_int(flags)

        vm_id = self.resolve_vm_id(vm_id)
        shared_folders = self._client.vm_add_shared_folder(
            vm_id, folder_id, host_path, flags)
        tt = text_table(data=shared_folders)
        tt.set_labels(('FOLDER_ID', 'PATH', 'PATH_ABS', 'FLAGS'))
        print(tt)
        return 0
示例#12
0
    def _ls_file(clazz, fs, info, options):
        'list files.'
        clazz.log.log_d('_ls_file: fs={} info={} options={}'.format(
            fs, info, options))
        s = clazz._format_file_info(info, options)
        print(s)
        if options.show_attributes:
            kvl = key_value_list.from_dict(info.attributes)
            t = text_table(data=kvl)
            print(t)
            #fields.append(kvl.to_string(delimiter = '=', value_delimiter = ' '))

        return 0
示例#13
0
文件: vmware.py 项目: reconstruir/bes
    def vms(self, show_info):
        check.check_bool(show_info)

        self._log.log_method_d()
        vms = self.local_vms.items()
        if show_info:
            data = [self._make_vm_data(vm) for _, vm in self.local_vms.items()]
            data = sorted(data, key=lambda row: row[0])
            tt = text_table(data=data)
            tt.set_labels(self._INFO_LABELS)
            print(tt)
        else:
            for _, vm in self.local_vms.items():
                print(vm)
示例#14
0
    def info(clazz, config, remote_filename):
        'info command.'
        check.check_string(config, allow_none=True)
        check.check_string(remote_filename)

        remote_filename = vfs_path_util.normalize(remote_filename)

        fs = clazz._create_fs_from_config(config)

        info = fs.file_info(remote_filename, vfs_file_info_options())
        clazz.log.log_d('info: info={}'.format(info))
        t = text_table(data=[info])
        print(t)
        return 0
示例#15
0
    def ps(clazz, blurber, brief, status):
        check.check_blurber(blurber)

        containers = docker_container.list_containers()
        if status:
            containers = [c for c in containers if c.status == status]
        if not containers:
            return 0
        if brief:
            for container in containers:
                print(container.container_id)
            return 0
        tt = text_table(data=containers)
        tt.set_labels(('ID', 'IMAGE', 'STATUS', 'SIZE', 'NAMES'))
        print(tt)
        return 0
示例#16
0
    def _output_table_to_stream(clazz, data, stream, options):
        if options.style == data_output_style.BRIEF:
            for item in data:
                stream.write(str(item[options.brief_column]))
                stream.write(line_break.DEFAULT_LINE_BREAK)
        elif options.style == data_output_style.JSON:
            data = clazz._normalize_table_for_structured_data(data)
            stream.write(json_util.to_json(data, indent=2, sort_keys=True))
        elif options.style == data_output_style.CSV:
            for item in data:
                item = clazz._normalize_table_item(item)
                stream.write(options.csv_delimiter.join(item))
                stream.write(line_break.DEFAULT_LINE_BREAK)
        elif options.style in [
                data_output_style.TABLE, data_output_style.PLAIN_TABLE
        ]:
            data = clazz._normalize_data(data)
            table_data = table(data=data, column_names=options.column_names)
            if table_data.empty:
                return
            is_plain = options.style == data_output_style.PLAIN_TABLE
            if is_plain:
                table_style = text_table_style(spacing=1, box=text_box_space())
            else:
                #table_style = text_table_style(spacing = 1, box = text_box_unicode())
                table_style = text_table_style(spacing=1, box=text_box_ascii())

            column_names = None
            if options.column_names:
                column_names = list(options.column_names)
            for column in sorted(options.remove_columns or [], reverse=True):
                table_data.remove_column(column)
                if column_names:
                    column_names.remove(column)
            if column_names:
                column_names = tuple(column_names)
            tt = text_table(data=table_data, style=table_style)
            if column_names:
                if not is_plain:
                    tt.set_labels(column_names)
                tt.set_column_names(column_names)
            if options.table_cell_renderers:
                for column_name, renderer in options.table_cell_renderers.items(
                ):
                    tt.set_col_renderer(column_name, renderer)
            if options.table_title and not is_plain:
                tt.set_title(options.table_title)

            text = str(tt)
            if options.table_flexible_column:
                flexible_index = table_data.resolve_x(
                    options.table_flexible_column)
                lines = text.split(line_break.DEFAULT_LINE_BREAK)
                render_width = len(lines[0])

                try:
                    terminal_width = console.terminal_width()
                except Exception as ex:
                    terminal_width = None

                if terminal_width != None:
                    max_column_width = tt._max_column_width(flexible_index)
                    if terminal_width < render_width:
                        overflow = render_width - terminal_width + 1
                        new_column_width = max(max_column_width - overflow, 0)
                    else:
                        new_column_width = max_column_width

                    tt.set_col_renderer(
                        options.table_flexible_column,
                        text_cell_renderer(width=new_column_width))
                    text = str(tt)

            stream.write(text)
            stream.write(line_break.DEFAULT_LINE_BREAK)
        else:
            raise RuntimeError('Unhandled data output style: {}'.format(style))