当前位置: 首页>>代码示例>>Python>>正文


Python Texttable.set_cols_align方法代码示例

本文整理汇总了Python中texttable.Texttable.set_cols_align方法的典型用法代码示例。如果您正苦于以下问题:Python Texttable.set_cols_align方法的具体用法?Python Texttable.set_cols_align怎么用?Python Texttable.set_cols_align使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在texttable.Texttable的用法示例。


在下文中一共展示了Texttable.set_cols_align方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_list

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
        def do_list(self, args):
                try:
                        doParser = self.arg_list()
                        doArgs = doParser.parse_args(shlex.split(args))

                        org = org_utils.org_get(self.api, doArgs.org)
                        printer.out("Getting user list for ["+org.name+"] . . .")
                        allUsers = self.api.Orgs(org.dbId).Members.Getall()
                        allUsers = order_list_object_by(allUsers.users.user, "loginName")

                        table = Texttable(200)
                        table.set_cols_align(["l", "l", "c"])
                        table.header(["Login", "Email", "Active"])

                        for item in allUsers:
                                if item.active:
                                        active = "X"
                                else:
                                        active = ""
                                table.add_row([item.loginName, item.email, active])

                        print table.draw() + "\n"
                        return 0

                except ArgumentParserError as e:
                        printer.out("In Arguments: "+str(e), printer.ERROR)
                        self.help_list()
                except Exception as e:
                        return handle_uforge_exception(e)
开发者ID:DimitriSCOLE,项目名称:uforge-cli,代码行数:31,代码来源:org_user.py

示例2: long_format

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
 def long_format(self, records):
     """Format records in long format.
     
     Args:
         records: Controlled records to format.
     
     Returns:
         str: Record data in long format.
     """
     title = util.hline(self.title_fmt % {'model_name': records[0].name.capitalize(), 
                                          'storage_path': records[0].storage}, 'cyan')
     retval = [title]
     for record in records:
         rows = [['Attribute', 'Value', 'Command Flag', 'Description']]
         populated = record.populate()
         for key, val in sorted(populated.iteritems()):
             if key != self.model.key_attribute:
                 rows.append(self._format_long_item(key, val))
         table = Texttable(logger.LINE_WIDTH)
         table.set_cols_align(['r', 'c', 'l', 'l'])
         table.set_deco(Texttable.HEADER | Texttable.VLINES)
         table.add_rows(rows)
         retval.append(util.hline(populated[self.model.key_attribute], 'cyan'))
         retval.extend([table.draw(), ''])
     return retval
开发者ID:ParaToolsInc,项目名称:taucmdr,代码行数:27,代码来源:cli_view.py

示例3: list

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
    def list(self):
        """List the Drbd volumes and statuses"""
        # Create table and add headers
        table = Texttable()
        table.set_deco(Texttable.HEADER | Texttable.VLINES)
        table.header(('Volume Name', 'VM', 'Minor', 'Port', 'Role', 'Connection State',
                      'Disk State', 'Sync Status'))

        # Set column alignment and widths
        table.set_cols_width((30, 20, 5, 5, 20, 20, 20, 13))
        table.set_cols_align(('l', 'l', 'c', 'c', 'l', 'c', 'l', 'c'))

        # Iterate over Drbd objects, adding to the table
        for drbd_object in self.get_all_drbd_hard_drive_object(True):
            table.add_row((drbd_object.resource_name,
                           drbd_object.vm_object.get_name(),
                           drbd_object.drbd_minor,
                           drbd_object.drbd_port,
                           'Local: %s, Remote: %s' % (drbd_object._drbdGetRole()[0].name,
                                                      drbd_object._drbdGetRole()[1].name),
                           drbd_object._drbdGetConnectionState().name,
                           'Local: %s, Remote: %s' % (drbd_object._drbdGetDiskState()[0].name,
                                                      drbd_object._drbdGetDiskState()[1].name),
                           'In Sync' if drbd_object._isInSync() else 'Out of Sync'))
        return table.draw()
开发者ID:joesingo,项目名称:MCVirt,代码行数:27,代码来源:drbd.py

示例4: main

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def main(args):
    """
    process each argument
    """
    table = Texttable()
    table.set_cols_align(["r", "r", "r", "r", "r"])
    rows = [["Number", "File Name", "File Size", "Video Duration (H:MM:SS)", "Conversion Time"]]
    total_time = 0.0
    total_file_size = 0

    for index, arg in enumerate(args, start=1):
        timer = utils.Timer()
        with timer:
            result = resize(arg, (index, len(args)))
        #
        result.elapsed_time = timer.elapsed_time()
        rows.append([index,
                     result.file_name,
                     utils.sizeof_fmt(result.file_size),
                     utils.sec_to_hh_mm_ss(utils.get_video_length(result.file_name)) if result.file_name else "--",
                     "{0:.1f} sec.".format(result.elapsed_time) if result.status else FAILED])
        #
        if rows[-1][-1] != FAILED:
            total_time += result.elapsed_time
        total_file_size += result.file_size

    table.add_rows(rows)
    print table.draw()
    print 'Total file size:', utils.sizeof_fmt(total_file_size)
    print 'Total time: {0} (H:MM:SS)'.format(utils.sec_to_hh_mm_ss(total_time))
    print utils.get_unix_date()
开发者ID:jabbalaci,项目名称:movie2android,代码行数:33,代码来源:movie2android.py

示例5: _dataframe_to_texttable

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def _dataframe_to_texttable(df, align=None):
    """Convert data frame to texttable. Sets column widths to the
    widest entry in each column."""
    ttab = Texttable()
    ttab.set_precision(1)
    h = [[x for x in df]]
    h.extend([x for x in df.to_records(index=False)])
    if align:
        colWidths = [max(len(x), len(".. class:: {}".format(y))) for x,y in izip(df.columns, align)]
    else:
        colWidths = [len(x) for x in df.columns]
    for row in h:
        for i in range(0, len(row)):
            if type(row[i]) == str:
                colWidths[i] = max([len(str(x)) for x in row[i].split("\n")] + [colWidths[i]])
            colWidths[i] = max(len(str(row[i])), colWidths[i])
    table_data = []
    if align:
        for row in h:
            table_row = []
            i = 0
            for col, aln in izip(row, align):
                table_row.append(".. class:: {}".format(aln) + " " * colWidths[i] + "{}".format(col))
                i = i + 1
            table_data.append(table_row)
    else:
        table_data = h
    ttab.add_rows(table_data)
    ttab.set_cols_width(colWidths)
    # Note: this does not affect the final pdf output
    ttab.set_cols_align(["r"] * len(colWidths))
    return ttab
开发者ID:Galithil,项目名称:scilifelab,代码行数:34,代码来源:best_practice.py

示例6: top

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def top(db):
    count_query = '''
    SELECT count(*)
    FROM commands
    WHERE
        timestamp > ?
    '''
    percentage = 100 / float(execute_scalar(db, count_query, TIMESTAMP))

    query = '''
    SELECT count(*) AS counts, command
    FROM commands
    WHERE timestamp > ?
    GROUP BY command
    ORDER BY counts DESC
    LIMIT 20
    '''

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_align(('r', 'r', 'l'))
    table.header(('count', '%', 'command'))
    for row in db.execute(query, (TIMESTAMP,)):
        table.add_row((row[0], int(row[0]) * percentage, row[1]))
    print table.draw()
开发者ID:minyoung,项目名称:dotfiles,代码行数:27,代码来源:top-commands.py

示例7: do_info

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
        def do_info(self, args):
                try:
                        doParser = self.arg_info()
                        doArgs = doParser.parse_args(shlex.split(args))
                        
                        printer.out("Getting user ["+doArgs.account+"] ...")
                        user = self.api.Users(doArgs.account).Get()
                        if user is None:
                                printer.out("user "+ doArgs.account +" does not exist", printer.ERROR)
                        else:
                                if user.active:
                                        active = "X"
                                else:
                                        active = ""

                                printer.out("Informations about " + doArgs.account + ":",)
                                table = Texttable(200)
                                table.set_cols_align(["c", "l", "c", "c", "c", "c", "c", "c"])
                                table.header(["Login", "Email", "Lastname",  "Firstname",  "Created", "Active", "Promo Code", "Creation Code"])
                                table.add_row([user.loginName, user.email, user.surname , user.firstName, user.created.strftime("%Y-%m-%d %H:%M:%S"), active, user.promoCode, user.creationCode])
                                print table.draw() + "\n"
                        return 0

                except ArgumentParserError as e:
                        printer.out("In Arguments: "+str(e), printer.ERROR)
                        self.help_info()
                except Exception as e:
                        return handle_uforge_exception(e)
开发者ID:DimitriSCOLE,项目名称:uforge-cli,代码行数:30,代码来源:user.py

示例8: test_texttable_header

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def test_texttable_header():
    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype([
        't',  # text
        'f',  # float (decimal)
        'e',  # float (exponent)
        'i',  # integer
        'a',  # automatic
    ])
    table.set_cols_align(["l", "r", "r", "r", "l"])
    table.add_rows([
        ["text",    "float", "exp", "int", "auto"],
        ["abcd",    "67",    654,   89,    128.001],
        ["efghijk", 67.5434, .654,  89.6,  12800000000000000000000.00023],
        ["lmn",     5e-78,   5e-78, 89.4,  .000000000000128],
        ["opqrstu", .023,    5e+78, 92.,   12800000000000000000000],
    ])
    assert clean(table.draw()) == dedent('''\
         text     float       exp      int     auto
        ==============================================
        abcd      67.000   6.540e+02    89   128.001
        efghijk   67.543   6.540e-01    90   1.280e+22
        lmn        0.000   5.000e-78    89   0.000
        opqrstu    0.023   5.000e+78    92   1.280e+22
    ''')
开发者ID:ah73,项目名称:pingSweep.py,代码行数:28,代码来源:tests.py

示例9: do_info_draw_general

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
    def do_info_draw_general(self, info_image):
        table = Texttable(0)
        table.set_cols_dtype(["a", "t"])
        table.set_cols_align(["l", "l"])

        table.add_row(["Name", info_image.name])
        table.add_row(["Format", info_image.targetFormat.name])
        table.add_row(["Id", info_image.dbId])
        table.add_row(["Version", info_image.version])
        table.add_row(["Revision", info_image.revision])
        table.add_row(["Uri", info_image.uri])

        self.do_info_draw_source(info_image.parentUri, table)

        table.add_row(["Created", info_image.created.strftime("%Y-%m-%d %H:%M:%S")])
        table.add_row(["Size", size(info_image.fileSize)])
        table.add_row(["Compressed", "Yes" if info_image.compress else "No"])

        if self.is_docker_based(info_image.targetFormat.format.name):
            registring_name = None
            if info_image.status.complete:
                registring_name = info_image.registeringName
            table.add_row(["RegisteringName",registring_name])
            table.add_row(["Entrypoint", info_image.entrypoint.replace("\\", "")])

        self.do_info_draw_generation(info_image, table)

        print table.draw() + "\n"
开发者ID:usharesoft,项目名称:hammr,代码行数:30,代码来源:image.py

示例10: find_commands

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def find_commands(db, *filters):
    user_filter = '\s+'.join(filters)
    user_re = re.compile(user_filter)
    RE_CACHE[user_filter] = user_re

    query = '''
    SELECT hostname, timestamp, duration, user_string
    FROM commands
    WHERE timestamp > ? AND user_string REGEXP ?
    ORDER BY timestamp
    '''

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_align(('l', 'r', 'r', 'l'))
    table.header(('host', 'date', 'duration', 'command'))

    host_width = 6
    max_command_width = 9
    now = time.time()
    for row in db.execute(query, (TIMESTAMP, user_filter)):
        host_width = max(host_width, len(row[0]))
        max_command_width = max(max_command_width, len(row[3]))
        table.add_row((
            row[0],
            format_time(row[1], now),
            format_duration(row[2]) if row[2] > 0 else '',
            highlight(row[3], user_re)))

    table.set_cols_width((host_width, 30, 10, max_command_width + 2))

    print table.draw()
开发者ID:minyoung,项目名称:dotfiles,代码行数:34,代码来源:find-commands.py

示例11: test_texttable

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def test_texttable():
    table = Texttable()
    table.set_cols_align(["l", "r", "c"])
    table.set_cols_valign(["t", "m", "b"])
    table.add_rows([
        ["Name", "Age", "Nickname"],
        ["Mr\nXavier\nHuon", 32, "Xav'"],
        ["Mr\nBaptiste\nClement", 1, "Baby"],
        ["Mme\nLouise\nBourgeau", 28, "Lou\n \nLoue"],
    ])
    assert clean(table.draw()) == dedent('''\
        +----------+-----+----------+
        |   Name   | Age | Nickname |
        +==========+=====+==========+
        | Mr       |     |          |
        | Xavier   |  32 |          |
        | Huon     |     |   Xav'   |
        +----------+-----+----------+
        | Mr       |     |          |
        | Baptiste |   1 |          |
        | Clement  |     |   Baby   |
        +----------+-----+----------+
        | Mme      |     |   Lou    |
        | Louise   |  28 |          |
        | Bourgeau |     |   Loue   |
        +----------+-----+----------+
    ''')
开发者ID:ah73,项目名称:pingSweep.py,代码行数:29,代码来源:tests.py

示例12: do_list

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
        def do_list(self, args):
                try:
                        doParser = self.arg_list()
                        doArgs = doParser.parse_args(shlex.split(args))

                        printer.out("Getting entitlements list of the UForge :")
                        entList = self.api.Entitlements.Getall()
                        if entList is None:
                                printer.out("No entitlements found.", printer.OK)
                        else:
                                entList=generics_utils.order_list_object_by(entList.entitlements.entitlement, "name")
                                printer.out("Entitlement list for the UForge :")
                                table = Texttable(200)
                                table.set_cols_align(["l", "l"])
                                table.header(["Name", "Description"])
                                table.set_cols_width([30,60])
                                for item in entList:
                                        table.add_row([item.name, item.description])
                                print table.draw() + "\n"
                        return 0

                except ArgumentParserError as e:
                        printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
                        self.help_list()
                except Exception as e:
                        return handle_uforge_exception(e)
开发者ID:DimitriSCOLE,项目名称:uforge-cli,代码行数:28,代码来源:entitlement.py

示例13: do_list

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
    def do_list(self, args):
        try:
            org_name = None
            if args:
                do_parser = self.arg_list()
                try:
                    do_args = do_parser.parse_args(shlex.split(args))
                except SystemExit as e:
                    return
                org_name = do_args.org

            # call UForge API
            printer.out("Getting all the roles for the organization...")
            org = org_utils.org_get(self.api, org_name)
            all_roles = self.api.Orgs(org.dbId).Roles().Getall(None)

            table = Texttable(200)
            table.set_cols_align(["c", "c"])
            table.header(["Name", "Description"])
            for role in all_roles.roles.role:
                table.add_row([role.name, role.description])
            print table.draw() + "\n"
            return 0
        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
            self.help_list()
        except Exception as e:
            return marketplace_utils.handle_uforge_exception(e)
开发者ID:hugo6,项目名称:marketplace-cli,代码行数:30,代码来源:rolecmds.py

示例14: do_list_changesets

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
 def do_list_changesets(self, arg, opts=None):
     """Show changesets needing review."""
     changesets = requests.get(
         "http://%s/api/v1/changeset/" % self.site, params={"review_status": "needs"}, auth=self.api_auth
     )
     objects = changesets.json().get("objects")
     table = Texttable()
     table.set_deco(Texttable.HEADER)
     table.set_cols_align(["c", "c", "c", "c", "c"])
     table.set_cols_width([5, 20, 15, 15, 10])
     rows = [["ID", "Type", "Classification", "Version Control URL", "Submitted By"]]
     for cs in objects:
         user = requests.get("http://%s%s" % (self.site, cs.get("submitted_by")), auth=self.api_auth)
         user_detail = user.json()
         rows.append(
             [
                 cs.get("id"),
                 cs.get("type"),
                 cs.get("classification"),
                 cs.get("version_control_url"),
                 user_detail.get("name"),
             ]
         )
     table.add_rows(rows)
     print "Changesets That Need To Be Reviewed:"
     print table.draw()
开发者ID:killkill,项目名称:schemanizer,代码行数:28,代码来源:signin.py

示例15: render_datasets_as_table

# 需要导入模块: from texttable import Texttable [as 别名]
# 或者: from texttable.Texttable import set_cols_align [as 别名]
def render_datasets_as_table(datasets, display_heading=True):
    """
    Returns ASCII table view of datasets.

    :param datasets: The datasets to be rendered.
    :type datasets: :class:`mytardisclient.models.resultset.ResultSet`
    :param render_format: The format to display the data in ('table' or
        'json').
    :param display_heading: Setting `display_heading` to True ensures
        that the meta information returned by the query is summarized
        in a 'heading' before displaying the table.  This meta
        information can be used to determine whether the query results
        have been truncated due to pagination.
    """
    heading = "\n" \
        "Model: Dataset\n" \
        "Query: %s\n" \
        "Total Count: %s\n" \
        "Limit: %s\n" \
        "Offset: %s\n\n" \
        % (datasets.url, datasets.total_count,
           datasets.limit, datasets.offset) if display_heading else ""

    table = Texttable(max_width=0)
    table.set_cols_align(["r", 'l', 'l', 'l'])
    table.set_cols_valign(['m', 'm', 'm', 'm'])
    table.header(["Dataset ID", "Experiment(s)", "Description", "Instrument"])
    for dataset in datasets:
        table.add_row([dataset.id, "\n".join(dataset.experiments),
                       dataset.description, dataset.instrument])
    return heading + table.draw() + "\n"
开发者ID:wettenhj,项目名称:mytardisclient,代码行数:33,代码来源:views.py


注:本文中的texttable.Texttable.set_cols_align方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。