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


Python Command.is_usage_request方法代码示例

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


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

示例1: main

# 需要导入模块: from commandlines import Command [as 别名]
# 或者: from commandlines.Command import is_usage_request [as 别名]
def main():
    """Defines the logic for the `font-line` command line executable"""
    c = Command()

    if c.does_not_validate_missing_args():
        stderr("[font-line] ERROR: Please include one or more arguments with your command.")
        sys.exit(1)

    if c.is_help_request():
        stdout(settings.HELP)
        sys.exit(0)
    elif c.is_version_request():
        stdout(settings.VERSION)
        sys.exit(0)
    elif c.is_usage_request():
        stdout(settings.USAGE)
        sys.exit(0)

    # REPORT sub-command
    if c.subcmd == "report":
        if c.argc < 2:
            stderr("[font-line] ERROR: Missing file path argument(s) after the report subcommand.")
            sys.exit(1)
        else:
            for fontpath in c.argv[1:]:
                # test for existence of file on path
                if file_exists(fontpath):
                    # test that filepath includes file of a supported file type
                    if is_supported_filetype(fontpath):
                        stdout(get_font_report(fontpath))
                    else:
                        stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
                else:
                    stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
    # PERCENT sub-command
    elif c.subcmd == "percent":
        if c.argc < 3:
            stderr("[font-line] ERROR: Not enough arguments.")
            sys.exit(1)
        else:
            percent = c.argv[1]
            # test the percent integer argument
            try:
                percent_int = int(percent)  # test that the argument can be cast to an integer value
                if percent_int <= 0:
                    stderr("[font-line] ERROR: Please enter a percent value that is greater than zero.")
                    sys.exit(1)
                if percent_int > 100:
                    stdout("[font-line] Warning: You entered a percent value over 100%. Please confirm that this is "
                           "your intended metrics modification.")
            except ValueError:
                stderr("[font-line] ERROR: You entered '" + percent + "'. This argument needs to be an integer value.")
                sys.exit(1)
            for fontpath in c.argv[2:]:
                if file_exists(fontpath):
                    if is_supported_filetype(fontpath):
                        if modify_linegap_percent(fontpath, percent) is True:
                            outpath = get_linegap_percent_filepath(fontpath, percent)
                            stdout("[font-line] '" + fontpath + "' successfully modified to '" + outpath + "'.")
                        else:  # pragma: no cover
                            stderr("[font-line] ERROR: Unsuccessful modification of '" + fontpath + "'.")
                    else:
                        stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
                else:
                    stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
    else:
        stderr("[font-lines] ERROR: You used an unsupported argument to the executable. Please review the"
               " `font-line --help` documentation and try again.")
        sys.exit(1)
开发者ID:alphapapa,项目名称:font-line,代码行数:71,代码来源:app.py

示例2: main

# 需要导入模块: from commandlines import Command [as 别名]
# 或者: from commandlines.Command import is_usage_request [as 别名]
def main():
    import sys
    from commandlines import Command
    from Naked.toolshed.system import stderr, file_exists
    from fontTools import ttLib

    # Instantiate commandlines Command object
    c = Command()

    # Command line argument validation testing
    if c.does_not_validate_missing_args():
        from fontttfa.settings import usage as fontttfa_usage
        stderr("ERROR: missing arguments\n")
        stderr(fontttfa_usage)
        sys.exit(1)

    # Tests for help, usage, and version requests
    if c.is_help_request():  # User requested font-ttfa help information
        from fontttfa.settings import help as fontttfa_help
        print(fontttfa_help)
        sys.exit(0)
    elif c.is_usage_request():  # User requested font-ttfa usage information
        from fontttfa.settings import usage as fontttfa_usage
        print(fontttfa_usage)
        sys.exit(0)
    elif c.is_version_request():  # User requested font-ttfa version information
        from fontttfa.settings import app_name, major_version, minor_version, patch_version
        version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version
        print(version_display_string)
        sys.exit(0)
    # ------------------------------------------------------------------------------------------
    # [ PRIMARY COMMAND LOGIC ]
    #   Enter your command line parsing logic below
    # ------------------------------------------------------------------------------------------

    try:
        for fontpath in c.arguments:
            if file_exists(fontpath):
                if fontpath.endswith('.ttf'):
                    tt = ttLib.TTFont(fontpath)
                    if 'TTFA' in tt.keys():
                        length_fontpath = len(fontpath)
                        if length_fontpath < 80:
                            outline_string = "=" * length_fontpath
                        else:
                            outline_string = "=" * 80
                        print(" ")
                        print(outline_string)
                        print(fontpath)
                        print(outline_string)
                        ttfautohint = (tt['TTFA'].__dict__['data']).strip()
                        print(ttfautohint)
                    else:
                        stderr(
                            "[font-ttfa]: Unable to detect a TTFA table in '" + fontpath +
                            "'.  Please confirm that ttfautohint has been used on this file and that the TTFA table was added.")
                else:
                    stderr("[font-ttfa]: The file '" + fontpath + "' does not appear to be a TrueType font file.")
            else:
                stderr("[font-ttfa]: The path '" + fontpath + "' is not a valid file path.")
    except Exception as e:
        stderr("[font-ttfa]: Error: " + str(e))
开发者ID:source-foundry,项目名称:font-ttfa,代码行数:64,代码来源:app.py

示例3: test_command_default_usage_when_notusage

# 需要导入模块: from commandlines import Command [as 别名]
# 或者: from commandlines.Command import is_usage_request [as 别名]
def test_command_default_usage_when_notusage():
    set_sysargv(test_command_help_2)
    c = Command()
    assert c.is_usage_request() == False
开发者ID:chrissimpkins,项目名称:commandlines,代码行数:6,代码来源:test_command_methods_default_testmethods.py

示例4: main

# 需要导入模块: from commandlines import Command [as 别名]
# 或者: from commandlines.Command import is_usage_request [as 别名]
def main():
    import os
    import sys
    from commandlines import Command
    from fontunicode.commands.search import name_find, unicode_find

    c = Command()

    if c.does_not_validate_missing_args():
        from fontunicode.settings import usage as fontunicode_usage
        print(fontunicode_usage)
        sys.exit(1)

    if c.is_help_request():      # User requested fontunicode help information
        from fontunicode.settings import help as fontunicode_help
        print(fontunicode_help)
        sys.exit(0)
    elif c.is_usage_request():   # User requested fontunicode usage information
        from fontunicode.settings import usage as fontunicode_usage
        print(fontunicode_usage)
        sys.exit(0)
    elif c.is_version_request():  # User requested fontunicode version information
        from fontunicode.settings import app_name, major_version, minor_version, patch_version
        version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version
        print(version_display_string)
        sys.exit(0)

    # ------------------------------------------------------------------------------------------
    # [ PRIMARY COMMAND LOGIC ]
    # ------------------------------------------------------------------------------------------

    if c.subcmd == "list":
        if c.subsubcmd == "agl":
            adobeglyphlist_text = open(os.path.join(os.path.dirname(__file__), 'glyphlist', 'aglfn.txt')).read()
            print(adobeglyphlist_text)
            sys.exit(0)
        elif c.subsubcmd == "unicode":
            unicodenamelist_text = open(os.path.join(os.path.dirname(__file__), 'glyphlist', 'NamesList.txt')).read()
            print(unicodenamelist_text)
            sys.exit(0)
    elif c.subcmd == "search":
        # if there is not a search, term raise error message and exit
        if c.argc == 1:
            sys.stderr.write("[font-unicode]: Error: Please enter a Unicode search term.\n")
            sys.exit(1)

        search_list = c.argv[1:]  # include all command line arguments after the primary command
        unicode_search_list = []

        for needle in search_list:
            if needle.startswith('u+') or needle.startswith('U+'):
                unicode_search_list.append(needle[2:])  # remove the u+ before adding it to the list for search
            else:
                unicode_search_list.append(needle)

        if len(unicode_search_list) > 0:
            unicode_find(unicode_search_list)
    elif c.subcmd == "name":
        # if there is not a search, term raise error message and exit
        if c.argc == 1:
            sys.stderr.write("[font-unicode]: Error: Please enter a glyph name search term.\n")

        search_list = c.argv[1:]
        name_search_list = []

        for needle in search_list:
            name_search_list.append(needle)

        if len(name_search_list) > 0:
            name_find(name_search_list)
    # ------------------------------------------------------------------------------------------
    # [ DEFAULT MESSAGE FOR MATCH FAILURE ]
    #  Message to provide to the user when all above conditional logic fails to meet a true condition
    # ------------------------------------------------------------------------------------------
    else:
        print("Could not complete the command that you entered.  Please try again.")
        sys.exit(1)  # exit
开发者ID:source-foundry,项目名称:font-unicode,代码行数:79,代码来源:app.py

示例5: test_command_default_usage

# 需要导入模块: from commandlines import Command [as 别名]
# 或者: from commandlines.Command import is_usage_request [as 别名]
def test_command_default_usage():
    set_sysargv(test_command_usage_1)
    c = Command()
    assert c.is_usage_request() == True
开发者ID:chrissimpkins,项目名称:commandlines,代码行数:6,代码来源:test_command_methods_default_testmethods.py


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