~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/link-external-sourcecode

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-06-01 00:05:40 UTC
  • mfrom: (8357.5.17 buildout2)
  • Revision ID: launchpad@pqm.canonical.com-20090601000540-ffe3v50mzjzoa05h
[r=flacoste,jml][ui=none] Begin to use buildout for developing and
        deploying launchpad. Explanatory email to follow;
        see also doc/buildout.txt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
def gen_missing_files(source, destination):
37
37
    """Generate info on every file in source not in destination.
38
38
 
39
 
    Yields `(source, destination, broken)` tuples, where `broken`
40
 
    means that the destination is a broken symbolic link.
 
39
    Yields `(source, destination)` tuples.
41
40
    """
42
41
    for name in listdir(source):
43
42
        destination_file = join(destination, name)
44
43
        if not exists(destination_file):
45
44
            source_file = join(source, name)
46
 
            yield source_file, destination_file, islink(destination_file)
 
45
            yield source_file, destination_file,
 
46
 
 
47
 
 
48
def link(source, destination):
 
49
    """Symlink source to destination.
 
50
 
 
51
    Assumes destination is missing or broken.
 
52
    """
 
53
    try:
 
54
        if islink(destination):
 
55
            unlink(destination)
 
56
        symlink(source, destination)
 
57
    except OSError, error:
 
58
        stderr.write(
 
59
            '  Error linking %s: %s\n' % (basename(destination), error))
 
60
    else:
 
61
        if options.verbose:
 
62
            stdout.write('%s -> %s\n' % (
 
63
                    sep.join(destination.rsplit(sep, 3)[-3:]), source))
47
64
 
48
65
 
49
66
if __name__ == '__main__':
98
115
        realpath(join(options.parent, 'sourcecode')),
99
116
        abspath(join(options.target, 'sourcecode')))
100
117
 
101
 
    for target, link, broken in missing_files:
102
 
        try:
103
 
            if broken:
104
 
                unlink(link)
105
 
            symlink(target, link)
106
 
        except OSError, error:
107
 
            stderr.write(
108
 
                '  Error linking %s: %s\n' % (basename(link), error))
109
 
        else:
110
 
            if options.verbose:
111
 
                stdout.write('%s -> %s\n' % (
112
 
                        sep.join(link.rsplit(sep, 3)[-3:]), target))
 
118
    for source, destination in missing_files:
 
119
        link(source, destination)
113
120
 
 
121
    for folder_name in ('eggs', 'download-cache'):
 
122
        source = join(options.parent, folder_name)
 
123
        destination = join(options.target, folder_name)
 
124
        if not exists(destination):
 
125
            link(source, destination)
114
126
 
115
127
# End