def main(): c = Command() if c.does_not_validate_missing_args(): sys.stderr.write( f"[ufolint] ERROR: Please include one or more UFO directory arguments " f"with your command.{os.linesep}") sys.exit(1) if c.is_help_request(): print(HELP) sys.exit(0) elif c.is_version_request(): print(VERSION) sys.exit(0) elif c.is_usage_request(): print(USAGE) sys.exit(0) for argument in sys.argv: if argument[-4:] == ".ufo": hh = MainRunner(argument) hh.run() # if the script completes without status code 1 SystemExit # being raised, then all tests passed sys.exit(0)
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)
def main(): """Defines the logic for the `ufodiff` command line executable""" c = Command() if c.does_not_validate_missing_args(): stderr( "[ufodiff] ERROR: Please include the appropriate 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) # DELTA + DELTAJSON + DELTAMD sub-commands if c.subcmd in {"delta", "deltajson", "deltamd"}: # argument validation validate_delta_commands_args(c) # create list for UFO filtered analyses as requested by user ufo_directory_list = [] for arg in c.argv: if arg.endswith(".ufo"): ufo_directory_list.append(arg) # flags for type of test is_branch_test = False is_commits_test = False if c.arg2.startswith("commits:"): is_commits_test = True commits_list = c.arg2.split(":") commit_number = commits_list[1] elif c.arg2.startswith("branch:"): is_branch_test = True branch_list = c.arg2.split(":") branch_name = branch_list[1] # else: # pass # TODO: add direct git idiom call support # recursive search for the root of the git repository x 3 levels if not found in working directory verified_gitroot_path = get_git_root_path() # perform the delta analysis on the repository, different object for commits vs branch tests if is_commits_test is True: delta = Delta( verified_gitroot_path, ufo_directory_list, is_commit_test=True, commit_number=commit_number, ) elif is_branch_test is True: delta = Delta( verified_gitroot_path, ufo_directory_list, is_branch_test=True, compare_branch_name=branch_name, ) if c.arg1 == "all": if c.subcmd == "delta": sys.stdout.write(delta.get_stdout_string(write_format="text")) elif c.subcmd == "deltajson": sys.stdout.write(delta.get_stdout_string(write_format="json")) elif c.subcmd == "deltamd": sys.stdout.write( delta.get_stdout_string(write_format="markdown")) # elif c.arg1 == "glyph": # pass # TODO: implement glyph only command handling with 'ufo delta glyph' # elif c.arg1 == "nonglyph": # pass # TODO: implement nonglyph only command handling with 'ufo delta nonglyph' # DIFF SUBCOMMAND elif c.subcmd == "diff": # argument validation validate_diff_commands_args(c) # execute the command try: verified_gitroot_path = get_git_root_path() diff = Diff(verified_gitroot_path, color_diff=True) for diff_string in diff.get_diff_string_generator(c.arg1): stdout(diff_string) except Exception as e: stderr( "[ufodiff] ERROR: Unable to excecute your request. Error returned as: " + os.linesep + str(e)) sys.exit(1) # DIFFNC SUBCOMMAND elif c.subcmd == "diffnc": # argument validations validate_diff_commands_args(c) # execute the command try: verified_gitroot_path = get_git_root_path() diff = Diff(verified_gitroot_path, color_diff=False) for diff_string in diff.get_diff_string_generator(c.arg1): stdout(diff_string) except Exception as e: stderr( "[ufodiff] ERROR: Unable to excecute your request. Error returned as: " + os.linesep + str(e)) sys.exit(1) # # DIFF-FILE SUBCOMMAND # elif c.subcmd == "diff-filter": # user specified file/directory filters on the diff performed # pass # # DIFF-FILENC SUBCOMMAND # elif c.subcmd == "diff-filternc": # pass sys.exit(0)
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))
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 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)
def test_command_default_help_short(): set_sysargv(test_command_help_2) c = Command() assert c.is_help_request() == True
def test_command_default_help_when_nothelp(): set_sysargv(test_command_usage_1) c = Command() assert c.is_help_request() == False
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 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()
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)