<s> import sys <EOL> from commandlines import Command <EOL> from hsh . library . hash import Hasher , HashChecker , file_exists <EOL> from hsh . settings import help as hsh_help <EOL> from hsh . settings import usage as hsh_usage <EOL> from hsh . settings import app_name , major_version , minor_version , patch_version <EOL> def main ( ) : <EOL> c = Command ( ) <EOL> if c . does_not_validate_missing_args ( ) : <EOL> print ( hsh_usage ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if c . is_help_request ( ) : <EOL> print ( hsh_help ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif c . is_usage_request ( ) : <EOL> print ( hsh_usage ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif c . is_version_request ( ) : <EOL> version_display_string = app_name + '<STR_LIT:U+0020>' + major_version + '<STR_LIT:.>' + minor_version + '<STR_LIT:.>' + patch_version <EOL> print ( version_display_string ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> primary_command = c . subcmd . lower ( ) <EOL> if primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha1 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha224 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha256 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha384 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha512 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc > <NUM_LIT:1> : <EOL> file_list = c . argv [ <NUM_LIT:1> : ] <EOL> for file in file_list : <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . md5 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( file + "<STR_LIT>" ) <EOL> else : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif primary_command == "<STR_LIT>" : <EOL> if c . argc == <NUM_LIT:3> : <EOL> hc = HashChecker ( ) <EOL> hc . compare ( c . argv [ <NUM_LIT:1> : ] ) <EOL> elif c . argc < <NUM_LIT:3> : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif c . argc > <NUM_LIT:3> : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif c . argc == <NUM_LIT:1> : <EOL> file = c . arg0 <EOL> if file_exists ( file ) : <EOL> hasher = Hasher ( ) <EOL> sha_hash = hasher . sha256 ( file ) <EOL> print ( "<STR_LIT>" + file + "<STR_LIT>" ) <EOL> print ( sha_hash ) <EOL> else : <EOL> sys . stderr . write ( c . arg0 + "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> elif c . argc == <NUM_LIT:2> : <EOL> hc = HashChecker ( ) <EOL> hc . compare ( c . argv ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
