extracted wordfile detection code to function
authorSteven Tobin <steventtobin (at) gmail.com>
Mon, 8 Sep 2014 01:37:57 +0000 (11:37 +1000)
committerSteven Tobin <steventtobin (at) gmail.com>
Mon, 8 Sep 2014 01:37:57 +0000 (11:37 +1000)
xkcdpass/xkcd_password.py

index deb537dca8edf6d840379ca29347e76bc2302822..96530fc6d0751af06e7ae4f614f380655a196d84 100755 (executable)
@@ -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,
git clone https://git.99rst.org/PROJECT