diff options
| author | eroen | 2013-11-15 18:12:45 +0100 |
|---|---|---|
| committer | eroen | 2013-11-16 00:50:07 +0100 |
| commit | 198ab420df7fd1be17d8f4e92ba0e31c8478c627 (patch) | |
| tree | f5a2af6a56c118766dca2f39167a7352d7190d52 /ga_wrapper | |
| parent | 13bd2785dd487af09fe5f871c312f248de27b399 (diff) | |
| download | git-annex-wrapper-198ab420df7fd1be17d8f4e92ba0e31c8478c627.tar.gz git-annex-wrapper-198ab420df7fd1be17d8f4e92ba0e31c8478c627.tar.bz2 git-annex-wrapper-198ab420df7fd1be17d8f4e92ba0e31c8478c627.tar.xz | |
initial wget wrapper
Diffstat (limited to 'ga_wrapper')
| -rw-r--r-- | ga_wrapper/wrapper.py | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/ga_wrapper/wrapper.py b/ga_wrapper/wrapper.py index baf7648..a246a68 100644 --- a/ga_wrapper/wrapper.py +++ b/ga_wrapper/wrapper.py @@ -6,6 +6,8 @@ purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. ''' +import argparse +import os.path import sys import subprocess @@ -17,8 +19,40 @@ def fallthrough(args): def wget_wrapper(args): print('emulating wget for ', ' '.join(args)) - status = 0 - raise(Exception('Not implemented')) + if args[0].endswith('wget'): + args = args[1:] + + parser = argparse.ArgumentParser() + parser.add_argument('src') + parser.add_argument('-O') + parser.add_argument('-t') + parser.add_argument('-T') + parser.add_argument('--passive-ftp', action='store_true') + + wgetargs = parser.parse_args(args) + src = wgetargs.src + out = wgetargs.O + (repo, outfile) = os.path.split(out) + + print('source: ', src) + print('repo: ', repo) + print('outfile: ', outfile) + + os.chdir(repo) + proc = subprocess.Popen(['git', 'annex', 'whereis', outfile], + stdout=subprocess.PIPE) + (stdoutdata, _) = proc.communicate() + print('\n'.join(stdoutdata.decode().split())) + + if not 'ok' in stdoutdata.decode().split(): + raise(Exception()) + + proc = subprocess.Popen(['git', 'annex', 'get', outfile], + stdout=subprocess.PIPE) + (stdoutdata, _) = proc.communicate() + print('\n'.join(stdoutdata.decode().split())) + status = proc.returncode + return status @@ -27,11 +61,12 @@ def generic_wrapper(): if len(args) <= 1: raise(Exception()) if args[0].endswith('git-annex-wrapper'): - del(args[0]) + args = args[1:] if args[0].endswith('wget'): try: status = wget_wrapper(args) - except Exception: + except Exception as exc: + print(exc) print('Emulation failed, doing real call') status = fallthrough(args) else: |
