def test_command_default_verbose_when_notverbose():
    set_sysargv(test_command_help_1)
    c = Command()
    assert c.is_verbose_request() == False
def test_commandobj_property_arg0():
    """Test: obj.arg0 is defined as the first positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arg0 == "."
def test_commandobj_property_arg4():
    """Test: obj.arg4 is defined as the fifth positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arg4 == ""
def test_commandobj_property_has_mdefs():
    """Test obj.has_mdefs is defined as False when mdefs are not present"""
    set_sys_argv()
    c = Command()
    assert c.has_mdefs is False
def test_commandobj_property_argv():
    """Test: obj.argv Command object property uses 0 based index for first positional argument, not executable"""
    set_sys_argv()
    c = Command()
    assert c.argv == ['.', '-name', 'tests/aaa.txt']
def test_commandobj_property_defaults_dict_updates():
    set_sys_argv()
    c = Command()
    c.defaults.update({'thekey': 'thevalue'})
    assert len(c.defaults) == 1
    assert c.defaults['thekey'] == 'thevalue'
def test_commandobj_property_subsubcmd():
    """Test: obj.subsubcmd is defined as the second positional argument"""
    set_sys_argv()
    c = Command()
    assert c.subsubcmd == "-name"
def test_command_has_doubledash_false():
    set_sysargv(test_command_1)
    c = Command()
    assert c.has_double_dash() == False
def test_command_has_doubledash_present_3():
    set_sysargv(test_command_13)
    c = Command()
    assert c.has_double_dash() == True
예제 #10
0
def test_commandobj_property_has_switches():
    """Test obj.has_switches is defined as True when switches are present"""
    set_sys_argv()
    c = Command()
    assert c.has_switches is False
예제 #11
0
def test_commandobj_property_argv():
    """Test: obj.argv Command object property uses 0 based index for first positional argument, not executable"""
    set_sys_argv()
    c = Command()
    assert c.argv == ['install', 'git-all']
예제 #12
0
def test_commandobj_property_subcmd():
    """Test: obj.subcmd is defined as the first positional argument"""
    set_sys_argv()
    c = Command()
    assert c.subcmd == "install"
예제 #13
0
def manage_cmd():
    cli_args = Command()
    if cli_args.is_version_request():
        message_exit(SILKAJ_VERSION)

    subcmd = [
        "license",
        "about",
        "info",
        "diffi",
        "net",
        "network",
        "issuers",
        "argos",
        "amount",
        "tx",
        "transaction",
        "cert",
        "generate_auth_file",
        "id",
        "identities",
        "wot",
    ]
    if (
        cli_args.is_help_request()
        or cli_args.is_usage_request()
        or cli_args.subcmd not in subcmd
    ):
        usage()

    if cli_args.subcmd == "about":
        about()
    elif cli_args.subcmd == "info":
        currency_info()

    elif cli_args.subcmd == "diffi":
        difficulties()

    elif cli_args.subcmd == "net" or cli_args.subcmd == "network":
        if cli_args.contains_switches("sort"):
            set_network_sort_keys(cli_args.get_definition("sort"))
        if cli_args.contains_switches("s"):
            set_network_sort_keys(cli_args.get_definition("s"))
        network_info(cli_args.contains_switches("discover"))

    elif (
        cli_args.subcmd == "issuers"
        and cli_args.subsubcmd
        and int(cli_args.subsubcmd) >= 0
    ):
        list_issuers(int(cli_args.subsubcmd), cli_args.contains_switches("last"))

    elif cli_args.subcmd == "argos":
        argos_info()

    elif cli_args.subcmd == "amount":
        cmd_amount(cli_args)

    elif cli_args.subcmd == "tx" or cli_args.subcmd == "transaction":
        send_transaction(cli_args)

    elif cli_args.subcmd == "cert":
        send_certification(cli_args)

    elif cli_args.subcmd == "generate_auth_file":
        generate_auth_file(cli_args)

    elif cli_args.subcmd == "id" or cli_args.subcmd == "identities":
        id_pubkey_correspondence(cli_args.subsubcmd)

    elif cli_args.subcmd == "wot":
        received_sent_certifications(cli_args.subsubcmd)

    elif cli_args.subcmd == "license":
        display_license()
예제 #14
0
파일: app.py 프로젝트: connectthefuture/hsh
def main():

    c = Command()

    if c.does_not_validate_missing_args():
        print(hsh_usage)
        sys.exit(1)

    if c.is_help_request():  # User requested hsh help information
        print(hsh_help)
        sys.exit(0)
    elif c.is_usage_request():  # User requested hsh usage information
        print(hsh_usage)
        sys.exit(0)
    elif c.is_version_request():  # User requested hsh version information
        version_display_string = app_name + ' ' + major_version + '.' + minor_version + '.' + patch_version
        print(version_display_string)
        sys.exit(0)

    primary_command = c.subcmd.lower()  # make the subcommand case-independent

    if primary_command == "sha1":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.sha1(file)
                    print("SHA1 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "sha224":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.sha224(file)
                    print("SHA224 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "sha256":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.sha256(file)
                    print("SHA256 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "sha384":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.sha384(file)
                    print("SHA384 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "sha512":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.sha512(file)
                    print("SHA512 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "md5":
        if c.argc > 1:
            file_list = c.argv[1:]
            for file in file_list:
                if file_exists(file):
                    hasher = Hasher()
                    sha_hash = hasher.md5(file)
                    print("MD5 (" + file + ") :")
                    print(sha_hash)
                else:
                    sys.stderr.write(
                        file +
                        " does not appear to be an existing file path.\n")
        else:
            sys.stderr.write(
                "You did not include a file in your command.  Please try again.\n"
            )
            sys.exit(1)
    elif primary_command == "check":
        if c.argc == 3:  # primary command + 2 arguments
            hc = HashChecker()
            hc.compare(
                c.argv[1:]
            )  # pass the argument list excluding the primary command
        elif c.argc < 3:
            sys.stderr.write(
                "You did not include a file or hash digest for comparison.  Please try again.\n"
            )
            sys.exit(1)
        elif c.argc > 3:
            sys.stderr.write(
                "Too many arguments.  Please include two arguments for comparison.\n"
            )
            sys.exit(1)
    elif c.argc == 1:  # single file hash digest request with default SHA256 settings
        file = c.arg0
        if file_exists(file):
            hasher = Hasher()
            sha_hash = hasher.sha256(file)
            print("SHA256 (" + file + ") :")
            print(sha_hash)
        else:
            sys.stderr.write(
                c.arg0 +
                " does not appear to be an existing file path. Please try again.\n"
            )
            sys.exit(1)
    elif c.argc == 2:  # exactly two arguments, perform comparison between them by default
        hc = HashChecker()
        hc.compare(
            c.argv
        )  # pass the entire argument list because there is no primary command

    else:
        print(
            "Could not complete the command that you entered.  Please try again."
        )
        sys.exit(1)
def test_commandobj_property_defaults_type():
    set_sys_argv()
    c = Command()
    assert isinstance(c.defaults, dict)
예제 #16
0
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
def test_commandobj_property_defaults_startsempty():
    set_sys_argv()
    c = Command()
    assert len(c.defaults) == 0
def test_commandobj_property_has_args():
    """Test: obj.has_args is defined as True when arguments are present"""
    set_sys_argv()
    c = Command()
    assert c.has_args is False
def test_commandobj_str_method():
    set_sys_argv2()
    c = Command()
    assert c.__str__(
    ) == "< Command object > instantiated from arguments: ['-mops', '-t', 'lastpos']"
def test_commandobj_property_switches():
    """Test: obj.switches property is defined with instantiated Switches object and includes correct strings"""
    set_sys_argv()
    c = Command()
    assert isinstance(c.switches, set)
    assert len(c.switches) == 0
def test_commandobj_property_has_defs():
    """Test obj.has_defs is defined as True when defs are present"""
    set_sys_argv()
    c = Command()
    assert c.has_defs is True
def test_commandobj_property_mops():
    """Test: obj.mops property is defined with instantiated Mops object and includes correct characters"""
    set_sys_argv()
    c = Command()
    assert isinstance(c.mops, set)
    assert len(c.mops) == 0  # should be an empty set
def test_commandobj_property_arguments():
    """Test: obj.arguments property is defined with instantiated Arguments object"""
    set_sys_argv()
    c = Command()
    assert isinstance(c.arguments, list)
    assert c.arguments == sys.argv[1:]       # the obj.arguments list is same as sys.argv[1:]
def test_commandobj_property_definitions():
    """Test: obj.defs property is defined with instantiated Definitions object and includes correct key:value pairs"""
    set_sys_argv()
    c = Command()
    assert isinstance(c.defs, dict)
    assert len(c.defs) == 0
def test_commandobj_property_argc():
    """Test: obj.argc is defined with appropriate argument length"""
    set_sys_argv()
    c = Command()
    assert c.argc == 3
def test_commandobj_property_arg2():
    """Test: obj.arg2 is defined as the third positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arg2 == "--long"
def test_commandobj_property_arg1():
    """Test: obj.arg1 is defined as second positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arg1 == "-name"
def test_commandobj_property_arg3():
    """Test: obj.arg3 is defined as the fourth positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arg3 == "-n"
def test_commandobj_property_arglp():
    """Test: obj.arglp is defined as the last positional argument"""
    set_sys_argv()
    c = Command()
    assert c.arglp == "tests/aaa.txt"
def test_command_default_verbose():
    set_sysargv(test_command_verbose_1)
    c = Command()
    assert c.is_verbose_request() == True