From: Steven Tobin Date: Mon, 8 Sep 2014 01:37:57 +0000 (+1000) Subject: extracted wordfile detection code to function X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=c508a587d22ca8fa28767ba18329960fadb18b95;p=redacted-XKCD-password-generator.git extracted wordfile detection code to function --- diff --git a/xkcdpass/xkcd_password.py b/xkcdpass/xkcd_password.py index deb537d..96530fc 100755 --- a/xkcdpass/xkcd_password.py +++ b/xkcdpass/xkcd_password.py @@ -87,26 +87,29 @@ def validate_options(parser, options, args): sys.stderr.write("Could not open the specified word file.\n") sys.exit(1) else: - static_default = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'static', - 'default.txt') - common_word_files = ["/usr/share/cracklib/cracklib-small", - static_default, - "/usr/dict/words", - "/usr/share/dict/words"] - - for wfile in common_word_files: - if os.path.exists(wfile): - options.wordfile = wfile - break + options.wordfile = locate_wordfile() - if options.wordfile is None: + if not options.wordfile: sys.stderr.write("Could not find a word file, or word file does " "not exist.\n") sys.exit(1) +def locate_wordfile(): + static_default = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'static', + 'default.txt') + common_word_files = ["/usr/share/cracklib/cracklib-small", + static_default, + "/usr/dict/words", + "/usr/share/dict/words"] + + for wfile in common_word_files: + if os.path.exists(wfile): + return wfile + + def generate_wordlist(wordfile=None, min_length=5, max_length=9,