#!/usr/bin/python # dcmd - Expand .dsc and .changes file references in any command line # Copyright (C) 2007 Romain Francoise # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # Usage: # # dcmd replaces any reference to a .dsc or .changes file in the command # line with the list of files in its 'Files' section, plus the # .dsc/.changes file itself. # # elegiac$ dcmd scp -C /tmp/1/dasher_4.4.2-1.dsc romain@yeast:/tmp # dasher_4.4.2.orig.tar.gz 100% 8728KB 4.3MB/s 00:02 # dasher_4.4.2-1.diff.gz 100% 5231 5.1KB/s 00:00 # dasher_4.4.2-1.dsc 100% 1259 1.2KB/s 00:00 # elegiac$ # # You can also call it as 'dscp' (with a symlink for example) in which # case it'll simply call scp: # # elegiac$ dscp -C /tmp/1/dasher_4.4.2-1.dsc romain@yeast:/tmp # dasher_4.4.2.orig.tar.gz 100% 8728KB 4.3MB/s 00:02 # dasher_4.4.2-1.diff.gz 100% 5231 5.1KB/s 00:00 # dasher_4.4.2-1.dsc 100% 1259 1.2KB/s 00:00 # elegiac$ import sys, os try: import deb822 except ImportError: print "Error: deb822 module not found, please install 'python-deb822'." sys.exit(1) def maybe_expand_arg(f): if f.endswith('.dsc') and os.path.exists(f): d = deb822.Dsc(file(f)) elif f.endswith('.changes') and os.path.exists(f): d = deb822.Changes(file(f)) else: return [f] base = os.path.dirname(f) return [os.path.join(base, elt['name']) for elt in d['Files']] + [f] if len(sys.argv) < 2: print "No command given, nothing to do" sys.exit(1) # Check if we were called as dcmd, dscp, or something else. name = os.path.basename(sys.argv[0]) if name == 'dcmd': cmd = [] else: # dscp => scp. Yes, this is slightly evil. cmd = [name[1:]] arglist = sys.argv[1:] for arg in arglist: cmd += maybe_expand_arg(arg) os.execvp(cmd[0], cmd)