All pastes #609846 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-09 03:12 UTC
rendered paste body
#!/usr/bin/python

import sys
import os
import deb822

def get_filenames(f):
    base = os.path.dirname(f)
    if f.endswith('.dsc'):
        d = deb822.Dsc(file(f))
    elif f.endswith('.changes'):
        d = deb822.Changes(file(f))
    return [os.path.join(base, elt['name']) for elt in d['Files']] + [f]

def get_distro(files_list):
    "Runs sed on the .diff.gz to find what pbuilder to run."
    ## Assumes that pbuilders are named in the pbuilder-sed , pbuilder-gutsy
    ## style.

    for file in files_list:
        if file.endswith('.changes'):
            changes_file = file.open(file, 'r')
            for line in changes_file.readlines():
                if line.split(';')[0].split()[-1] == True:
                    return line.split(';')[0].split()[-1]

def get_dsc(files_list):
    for file in files_list:
        if file.endswith('.dsc'):
            return file

if len (sys.argv) < 3:
    print "Usage: drsync foo.dsc [OPTIONS...] user@host:/path/to/incomming"
    print "See man rsync(1) for accepted Options"

dest = sys.argv[-1]

files = []
for f in sys.argv[1:-1]:
    files += get_filenames(f)

distro = get_distro(files)

if dest.endswith('/') == False:
    rdsc = dest.split(':')[-1] + '/' + get_dsc(files)
else:
    rdsc = dest.split(':')[-1] + get_dsc(files)

os.execvp('rsync', ['rsync'] + files + [dest])
os.execvp('ssh', ['ssh'] + [dest] + '": pbuilder-' + distro + 'build ' + rdsc)