File: debdeltas_publisher

package info (click to toggle)
debdelta 0.59
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 952 kB
  • sloc: python: 5,510; perl: 1,398; sh: 965; xml: 727; ansic: 215; makefile: 112; awk: 21
file content (74 lines) | stat: -rwxr-xr-x 2,397 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python

" debdeltas  publisher "

import os, sys, subprocess, ConfigParser, copy


# -a is -rlptgoD  (no -H,-A,-X)
rsync_base=['rsync', '-ax', '--no-motd', '--timeout=600',  '--contimeout=600']


def publish(rsync_args, basedir, rsync_destination, files=[]):
    """ rsync basedir to a remote destination 
       rsync_args is the list of args 
       files is the list of files , if relative paths, relative to basedir;
         but if no file is given , then publish all, and add --delete to arguments"""
    
    # rsync gives a special meaning to paths ending in '/'
    if basedir[-1] != '/':
        basedir+='/'
    if rsync_destination[-1] != '/':
        rsync_destination+='/'
    
    assert os.path.isdir(basedir) and os.path.isabs(basedir)
    
    if len(files)<1:
        r=subprocess.call(rsync_args + ['--delete', basedir, rsync_destination ], cwd=basedir)
    else:
        args=[]
        l=len(basedir)
        for f in files:
            if os.path.isabs(f):
                assert os.path.isfile(f)
                if f[:l] == basedir:
                    args.append(f[l:])
                else:
                    raise Exception(' cannot publish this file ' +repr(f))
            else:
                assert os.path.isfile(os.path.join(basedir,f))
                args.append(f)
        r=subprocess.call(rsync_args +  ['-R' ] + args + [ rsync_destination ], cwd=basedir)
    return r


if __name__ == '__main__':
    config=ConfigParser.SafeConfigParser()
    assert os.path.isfile(sys.argv[1])
    config.read(sys.argv[1])
    assert config.has_section("'server'")
    assert config.has_section("'publisher'")
    
    home=''
    if config.has_option("'server'",'home'):
        home=eval(config.get("'server'",'home'))
    
    def gets(s):
        return eval(config.get("'server'", s), {'home':home})
    def getp(s):
        return eval(config.get("'publisher'", s), {'home':home})
    
    basedir=gets('deltas_www_dir')
    
    rsync_args=copy.copy(rsync_base)
    
    if  config.has_option("'publisher'", "rsync_password_file"):
        rsync_password_file = getp("rsync_password_file")
        rsync_args += ['--password-file', rsync_password_file]
    
    rsync_destination = getp( "rsync_destination")
    
    args=sys.argv[2:]
    #TODO parse command arguments such as --delete
    
    publish(rsync_args, basedir, rsync_destination, args)