From 198ab420df7fd1be17d8f4e92ba0e31c8478c627 Mon Sep 17 00:00:00 2001 From: eroen Date: Fri, 15 Nov 2013 18:12:45 +0100 Subject: initial wget wrapper --- bin/git-annex-wrapper | 4 ++-- ga_wrapper/wrapper.py | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bin/git-annex-wrapper b/bin/git-annex-wrapper index eddaf0f..1f45588 100755 --- a/bin/git-annex-wrapper +++ b/bin/git-annex-wrapper @@ -11,7 +11,7 @@ from ga_wrapper import wrapper def main(): - wrapper.generic_wrapper() + return wrapper.generic_wrapper() if __name__ == '__main__': - main() + exit(main()) 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: -- cgit v1.2.1