diff options
author | Konstantin Ryabitsev <mricon@kernel.org> | 2014-03-12 16:53:05 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <mricon@kernel.org> | 2014-03-12 16:53:05 -0400 |
commit | 084309d4af434180b485e9ff8d6ac78e78605fb0 (patch) | |
tree | 268c764c635f709aabc3914ee050bdf974ca6f03 | |
parent | 3bee9827c3798a124fd5458cba8c836814cced8c (diff) | |
download | grokmirror-pypingou-py_modules.tar.gz |
Fixes so we can still run the commands directlypypingou-py_modules
- Add __name__ == '__main__' bits so we can still test easily
- Move optparser errors where they will actually work
- Restore exit code functionality on grok-pull
-rwxr-xr-x | grokmirror/dumb_pull.py | 12 | ||||
-rwxr-xr-x | grokmirror/fsck.py | 13 | ||||
-rwxr-xr-x | grokmirror/manifest.py | 23 | ||||
-rwxr-xr-x | grokmirror/pull.py | 18 | ||||
-rw-r--r-- | setup.py | 8 |
5 files changed, 48 insertions, 26 deletions
diff --git a/grokmirror/dumb_pull.py b/grokmirror/dumb_pull.py index 72a150c..b42d17e 100755 --- a/grokmirror/dumb_pull.py +++ b/grokmirror/dumb_pull.py @@ -197,13 +197,16 @@ def parse_args(): default=None, help='Put debug logs into this file') - return parser.parse_args() + opts, args = parser.parse_args() + + if not len(args): + parser.error('You must provide at least a path to the repos to pull') + + return opts, args def dumb_pull(args, verbose=False, svn=False, remotes=[], posthook='', logfile=None): - if not len(args): - parser.error('You must provide at least a path to the repos to pull') if not len(remotes): remotes = ['*'] @@ -259,3 +262,6 @@ def command(): return dumb_pull( args, verbose=opts.verbose, svn=opts.svn, remotes=opts.remotes, posthook=opts.posthook, logfile=opts.logfile) + +if __name__ == '__main__': + command() diff --git a/grokmirror/fsck.py b/grokmirror/fsck.py index d73c3a1..bdfad78 100755 --- a/grokmirror/fsck.py +++ b/grokmirror/fsck.py @@ -320,15 +320,17 @@ def parse_args(): parser.add_option('-c', '--config', dest='config', help='Location of fsck.conf') - return parser.parse_args() + opts, args = parser.parse_args() + + if not opts.config: + parser.error('You must provide the path to the config file') + + return opts, args def grok_fsck(config, verbose=False, force=False): from ConfigParser import ConfigParser - if not config: - parser.error('You must provide the path to the config file') - ini = ConfigParser() ini.read(config) @@ -357,8 +359,9 @@ def grok_fsck(config, verbose=False, force=False): def command(): - opts, args = parse_args() return grok_fsck(opts.config, opts.verbose, opts.force) +if __name__ == '__main__': + command() diff --git a/grokmirror/manifest.py b/grokmirror/manifest.py index dec566d..5280511 100755 --- a/grokmirror/manifest.py +++ b/grokmirror/manifest.py @@ -180,20 +180,22 @@ def parse_args(): default=False, help='Be verbose and tell us what you are doing') - return parser.parse_args() + opts, args = parser.parse_args() + + if not opts.manifile: + parser.error('You must provide the path to the manifest file') + if not opts.toplevel: + parser.error('You must provide the toplevel path') + if not len(args) and opts.wait: + parser.error('--wait option only makes sense when dirs are passed') + + return opts, args def grok_manifest(manifile, toplevel, args=[], logfile=None, usenow=False, check_export_ok=False, purge=False, remove=False, pretty=False, ignore=[], wait=False, verbose=False): - if not manifile: - parser.error('You must provide the path to the manifest file') - if not toplevel: - parser.error('You must provide the toplevel path') - if not len(args) and wait: - parser.error('--wait option only makes sense when dirs are passed') - logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() @@ -288,7 +290,10 @@ def command(): opts, args = parse_args() return grok_manifest( - opts.manifile, opts.toplevel, args=args, logfile=opt.logfile, + opts.manifile, opts.toplevel, args=args, logfile=opts.logfile, usenow=opts.usenow, check_export_ok=opts.check_export_ok, purge=opts.purge, remove=opts.remove, pretty=opts.pretty, ignore=opts.ignore, wait=opts.wait, verbose=opts.verbose) + +if __name__ == '__main__': + command() diff --git a/grokmirror/pull.py b/grokmirror/pull.py index e3e411d..8f73981 100755 --- a/grokmirror/pull.py +++ b/grokmirror/pull.py @@ -922,16 +922,19 @@ def parse_args(): parser.add_option('-c', '--config', dest='config', help='Location of repos.conf') - return parser.parse_args() + opts, args = parser.parse_args() + + if not opts.config: + parser.error('You must provide the path to the config file') + + return opts, args def grok_pull(config, verbose=False, force=False, nomtime=False, verify=False, verify_subpath='*', noreuse=False, purge=False, pretty=False): - from ConfigParser import ConfigParser - if not config: - parser.error('You must provide the path to the config file') + from ConfigParser import ConfigParser ini = ConfigParser() ini.read(config) @@ -969,6 +972,11 @@ def command(): opts, args = parse_args() - return grok_pull( + retval = grok_pull( opts.config, opts.verbose, opts.force, opts.nomtime, opts.verify, opts.verify_subpath, opts.noreuse, opts.purge, opts.pretty) + + sys.exit(retval) + +if __name__ == '__main__': + command() @@ -25,10 +25,10 @@ setup( long_description=read('README.rst'), entry_points={ 'console_scripts': [ - "grok-dumb-pull=grokmirror/dumb_pull:command", - "grok-pull=grokmirror/pull:command", - "grok-fsck=grokmirror/fsck:command", - "grok-manifest=grokmirror/manifest:command", + "grok-dumb-pull=grokmirror.dumb_pull:command", + "grok-pull=grokmirror.pull:command", + "grok-fsck=grokmirror.fsck:command", + "grok-manifest=grokmirror.manifest:command", ] } ) |