def handle_options(args): """Handle commandline options. """ random_sources = get_random_sources().keys() wordlist_names = get_wordlist_names() defaults = get_config_dict() parser = argparse.ArgumentParser( description="Create a passphrase", epilog="Wordlists are stored in %s" % WORDLISTS_DIR ) parser.add_argument( '-n', '--num', default=6, type=int, help='number of words to concatenate. Default: 6') cap_group = parser.add_mutually_exclusive_group() cap_group.add_argument( '-c', '--caps', action='store_true', help='Capitalize words. This is the default.') cap_group.add_argument( '--no-caps', action='store_false', dest='caps', help='Turn off capitalization.') parser.add_argument( '-s', '--specials', default=0, type=int, metavar='NUM', help="Insert NUM special chars into generated word.") parser.add_argument( '-d', '--delimiter', default='', help="Separate words by DELIMITER. Empty string by default.") parser.add_argument( '-r', '--randomsource', default='system', choices=random_sources, metavar="SOURCE", help=( "Get randomness from this source. Possible values: `%s'. " "Default: system" % "', `".join(sorted(random_sources)))) parser.add_argument( '-w', '--wordlist', default='en_securedrop', choices=wordlist_names, metavar="NAME", help=( "Use words from this wordlist. Possible values: `%s'. " "Wordlists are stored in the folder displayed below. " "Default: en_securedrop" % "', `".join(wordlist_names))) parser.add_argument( 'infile', nargs='?', metavar='INFILE', default=None, type=argparse.FileType('r'), help="Input wordlist. `-' will read from stdin.", ) parser.add_argument( '--version', action='store_true', help='output version information and exit.', ) parser.set_defaults(**defaults) args = parser.parse_args(args) return args
def handle_options(args): """Handle commandline options. """ plugins = get_random_sources() random_sources = plugins.keys() wordlist_names = get_wordlist_names() defaults = get_config_dict() parser = argparse.ArgumentParser( description="Create a passphrase", epilog="Wordlists are stored in %s" % WORDLISTS_DIR ) parser.add_argument( '-n', '--num', default=6, type=int, help='number of words to concatenate. Default: 6') cap_group = parser.add_mutually_exclusive_group() cap_group.add_argument( '-c', '--caps', action='store_true', help='Capitalize words. This is the default.') cap_group.add_argument( '--no-caps', action='store_false', dest='caps', help='Turn off capitalization.') parser.add_argument( '-s', '--specials', default=0, type=int, metavar='NUM', help="Insert NUM special chars into generated word.") parser.add_argument( '-d', '--delimiter', default='', help="Separate words by DELIMITER. Empty string by default.") parser.add_argument( '-r', '--randomsource', default='system', choices=random_sources, metavar="SOURCE", help=( "Get randomness from this source. Possible values: `%s'. " "Default: system" % "', `".join(sorted(random_sources)))) parser.add_argument( '-w', '--wordlist', default='en_eff', choices=wordlist_names, metavar="NAME", help=( "Use words from this wordlist. Possible values: `%s'. " "Wordlists are stored in the folder displayed below. " "Default: en_eff" % "', `".join(wordlist_names))) realdice_group = parser.add_argument_group( "Arguments related to `realdice' randomsource", ) realdice_group.add_argument( '--dice-sides', default=6, type=int, metavar="N", help='Number of sides of dice. Default: 6' ) parser.add_argument( 'infile', nargs='?', metavar='INFILE', default=None, type=argparse.FileType('r'), help="Input wordlist. `-' will read from stdin.", ) parser.add_argument( '-v', '--verbose', action='count', help='Be verbose. Use several times for increased verbosity.') parser.add_argument( '--version', action='store_true', help='output version information and exit.', ) for plugin in plugins.values(): if hasattr(plugin, "update_argparser"): parser = plugin.update_argparser(parser) parser.set_defaults(**defaults) args = parser.parse_args(args) return args
def test_get_wordlist_names_requires_dot(self, wordlists_dir): # we only recognize wordlist files with dot in name wordlists_dir.join("file_without_dot-in-name").write("a\nb\n") assert get_wordlist_names() == []
def test_get_wordlist_names_requires_underscore(self, wordlists_dir): # we only recognize wordlist files with underscore in name wordlists_dir.join("file-without-underscore.txt").write("a\nb\n") assert get_wordlist_names() == []
def test_get_wordlist_names_files_only(self, wordlists_dir): # non-files are ignored when looking for wordlist names sub_dir = wordlists_dir.mkdir('subdir') # a subdir sub_dir.join("somfile_name.txt").write("Some\ntext") # and a file in assert get_wordlist_names() == []
def test_get_wordlist_names(self, wordlists_dir): # we can get wordlist names also if directory is empty. wlist_path = wordlists_dir.join('wordlist_my_en.txt') wlist_path.write("some\nirrelevant\nwords") assert get_wordlist_names() == ['my_en']
def test_get_wordlist_names_requires_dot(self, wordlists_dir): # we only recognize wordlist files with dot in name wordlists_dir.join("file_without_dot-in-name").write("a\nb\n") assert get_wordlist_names() == []
def test_get_wordlist_names_requires_underscore(self, wordlists_dir): # we only recognize wordlist files with underscore in name wordlists_dir.join("file-without-underscore.txt").write("a\nb\n") assert get_wordlist_names() == []
def test_get_wordlist_names_files_only(self, wordlists_dir): # non-files are ignored when looking for wordlist names sub_dir = wordlists_dir.mkdir('subdir') # a subdir sub_dir.join("somfile_name.txt").write("Some\ntext") # and a file in assert get_wordlist_names() == []
def test_get_wordlist_names(self, wordlists_dir): # we can get wordlist names also if directory is empty. wlist_path = wordlists_dir.join('wordlist_my_en.txt') wlist_path.write("some\nirrelevant\nwords") assert get_wordlist_names() == ['my_en']
def handle_options(args): """Handle commandline options. """ plugins = get_random_sources() random_sources = plugins.keys() wordlist_names = get_wordlist_names() defaults = get_config_dict() parser = argparse.ArgumentParser( description="Create a passphrase", epilog="Wordlists are stored in %s" % get_wordlists_dir() ) parser.add_argument( '-n', '--num', default=6, type=int, help='number of words to concatenate. Default: 6') cap_group = parser.add_mutually_exclusive_group() cap_group.add_argument( '-c', '--caps', action='store_true', help='Capitalize words. This is the default.') cap_group.add_argument( '--no-caps', action='store_false', dest='caps', help='Turn off capitalization.') parser.add_argument( '-s', '--specials', default=0, type=int, metavar='NUM', help="Insert NUM special chars into generated word.") parser.add_argument( '-d', '--delimiter', default='', help="Separate words by DELIMITER. Empty string by default.") parser.add_argument( '-r', '--randomsource', default='system', choices=random_sources, metavar="SOURCE", help=( "Get randomness from this source. Possible values: `%s'. " "Default: system" % "', `".join(sorted(random_sources)))) parser.add_argument( '-w', '--wordlist', default='en_eff', choices=wordlist_names, metavar="NAME", help=( "Use words from this wordlist. Possible values: `%s'. " "Wordlists are stored in the folder displayed below. " "Default: en_eff" % "', `".join(wordlist_names))) realdice_group = parser.add_argument_group( "Arguments related to `realdice' randomsource", ) realdice_group.add_argument( '--dice-sides', default=6, type=int, metavar="N", help='Number of sides of dice. Default: 6' ) parser.add_argument( 'infile', nargs='?', metavar='INFILE', default=None, help="Input wordlist. `-' will read from stdin.", ) parser.add_argument( '-v', '--verbose', action='count', help='Be verbose. Use several times for increased verbosity.') parser.add_argument( '--version', action='store_true', help='output version information and exit.', ) for plugin in plugins.values(): if hasattr(plugin, "update_argparser"): parser = plugin.update_argparser(parser) parser.set_defaults(**defaults) args = parser.parse_args(args) return args