Modify main code for packaging
authorLowe Thiderman <redacted>
Tue, 27 May 2014 22:16:44 +0000 (00:16 +0200)
committerLowe Thiderman <redacted>
Tue, 27 May 2014 22:16:44 +0000 (00:16 +0200)
Add main() function that setuptools can use as an executable entry point.

Also pass the `parser` variable to `validate_options()`. Since the parser is
now created within the function scope of `main()` it cannot be seen by
`validate_options()` anymore.

xkcdpass/xkcd_password.py

index 45530b22587c5864784cc6733e0b40b61a1693d4..76aeeb0bce5411bd3f7098d9202b11a040874236 100755 (executable)
@@ -57,7 +57,7 @@ if sys.version[0] == "3":
     raw_input = input
 
 
-def validate_options(options, args):
+def validate_options(parser, options, args):
     """
     Given a set of command line options, performs various validation checks
     """
@@ -214,8 +214,7 @@ def generate_xkcdpassword(wordlist,
     return passwd
 
 
-if __name__ == '__main__':
-
+def main():
     count = 1
     usage = "usage: %prog [options]"
     parser = optparse.OptionParser(usage)
@@ -252,7 +251,7 @@ if __name__ == '__main__':
                       help="separator character between words")
 
     (options, args) = parser.parse_args()
-    validate_options(options, args)
+    validate_options(parser, options, args)
 
     my_wordlist = generate_wordlist(wordfile=options.wordfile,
                                     min_length=options.min_length,
@@ -272,3 +271,7 @@ if __name__ == '__main__':
                                     acrostic=options.acrostic,
                                     delim=options.delim))
         count -= 1
+
+
+if __name__ == '__main__':
+    main()
git clone https://git.99rst.org/PROJECT