Mercurial > hg > MakeItSo
comparison makeitso/python_package/{{package}}/{{main}}.py @ 251:b4a3e8bbe095
py 3 + version bump
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Fri, 31 Mar 2017 18:16:36 -0700 |
| parents | ab726b2f3143 |
| children |
comparison
equal
deleted
inserted
replaced
| 250:3840a2c5bc4f | 251:b4a3e8bbe095 |
|---|---|
| 25 os.execl(sys.executable, *args) | 25 os.execl(sys.executable, *args) |
| 26 | 26 |
| 27 # module globals | 27 # module globals |
| 28 __all__ = ['main', 'Parser'] | 28 __all__ = ['main', 'Parser'] |
| 29 here = os.path.dirname(os.path.realpath(__file__)) | 29 here = os.path.dirname(os.path.realpath(__file__)) |
| 30 string = (str, unicode) | 30 |
| 31 try: | |
| 32 # python 2 | |
| 33 string = (str, unicode) | |
| 34 except NameError: | |
| 35 # python 3 | |
| 36 string = (str, ) | |
| 37 | |
| 31 | 38 |
| 32 def ensure_dir(directory): | 39 def ensure_dir(directory): |
| 33 """ensure a directory exists""" | 40 """ensure a directory exists""" |
| 34 if os.path.exists(directory): | 41 if os.path.exists(directory): |
| 35 if not os.path.isdir(directory): | 42 if not os.path.isdir(directory): |
| 39 return directory | 46 return directory |
| 40 | 47 |
| 41 | 48 |
| 42 class Parser(argparse.ArgumentParser): | 49 class Parser(argparse.ArgumentParser): |
| 43 """CLI option parser""" | 50 """CLI option parser""" |
| 51 | |
| 44 def __init__(self, **kwargs): | 52 def __init__(self, **kwargs): |
| 45 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) | 53 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) |
| 46 kwargs.setdefault('description', __doc__) | 54 kwargs.setdefault('description', __doc__) |
| 47 argparse.ArgumentParser.__init__(self, **kwargs) | 55 argparse.ArgumentParser.__init__(self, **kwargs) |
| 48 self.add_argument('--monitor', dest='monitor', | 56 self.add_argument('--monitor', dest='monitor', |
| 57 return options | 65 return options |
| 58 | 66 |
| 59 def validate(self, options): | 67 def validate(self, options): |
| 60 """validate options""" | 68 """validate options""" |
| 61 | 69 |
| 70 | |
| 62 def main(args=sys.argv[1:]): | 71 def main(args=sys.argv[1:]): |
| 63 """CLI""" | 72 """CLI""" |
| 64 | 73 |
| 65 # parse command line options | 74 # parse command line options |
| 66 parser = Parser() | 75 parser = Parser() |
| 73 else: | 82 else: |
| 74 break | 83 break |
| 75 except KeyboardInterrupt: | 84 except KeyboardInterrupt: |
| 76 pass | 85 pass |
| 77 | 86 |
| 87 | |
| 78 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 79 main() | 89 main() |
| 80 | 90 |
