~gz/hydrazine/use_bzr_config_email_561211

« back to all changes in this revision

Viewing changes to lp-promote-ppa

  • Committer: Max Bowsher
  • Date: 2010-09-03 01:57:55 UTC
  • mfrom: (76.1.3 lp-promote-ppa)
  • Revision ID: maxb@f2s.com-20100903015755-s3nxga5eidwryhx1
[r=mbp] New command, lp-promote-ppa.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
USAGE = """\
 
4
usage: %prog SOURCE-PPA DESTINATION-PPA
 
5
 
 
6
A PPA should be expressed as PERSON/PPA-NAME - e.g. bzr/proposed or bzr/ppa
 
7
 
 
8
Finds all sources that have successfully built in one PPA, and copies them into
 
9
another, only if the destination does not already contain the same or greater
 
10
version."""
 
11
 
 
12
import itertools
 
13
import optparse
 
14
import os
 
15
import sys
 
16
import time
 
17
import urllib2
 
18
 
 
19
import apt_pkg; apt_pkg.init()
 
20
 
 
21
import hydrazine
 
22
 
 
23
 
 
24
def promote(lp, archive_from, archive_to):
 
25
    from_team, from_ppa = archive_from.split('/')
 
26
    to_team, to_ppa = archive_to.split('/')
 
27
    sourcepub_elts = []
 
28
 
 
29
    destination_sourcepubs = {}
 
30
    
 
31
    print "Querying destination PPA..."
 
32
    to_archive = lp.people[to_team].getPPAByName(name=to_ppa)
 
33
    dest_sources = list(itertools.chain(
 
34
        to_archive.getPublishedSources(status="Published"),
 
35
        to_archive.getPublishedSources(status="Pending"),
 
36
        ))
 
37
    buildsumm = to_archive.getBuildSummariesForSourceIds(source_ids=[x.self_link.split('/')[-1] for x in dest_sources])
 
38
    for spph in dest_sources:
 
39
        value = spph.self_link.split('/')[-1]
 
40
        package = spph.source_package_name
 
41
        version = spph.source_package_version
 
42
        series = spph.distro_series_link.split('/')[-1]
 
43
        status = spph.status
 
44
        buildstate = buildsumm[value]['status']
 
45
        print value, package, series, version, status, buildstate
 
46
        destination_sourcepubs[package, series] = version
 
47
 
 
48
    print "Querying source PPA..."
 
49
    from_archive = lp.people[from_team].getPPAByName(name=from_ppa)
 
50
    src_sources = from_archive.getPublishedSources(status="Published")
 
51
    buildsumm = from_archive.getBuildSummariesForSourceIds(source_ids=[x.self_link.split('/')[-1] for x in src_sources])
 
52
    for spph in src_sources:
 
53
        value = spph.self_link.split('/')[-1]
 
54
        package = spph.source_package_name
 
55
        version = spph.source_package_version
 
56
        series = spph.distro_series_link.split('/')[-1]
 
57
        status = spph.status
 
58
        buildstate = buildsumm[value]['status']
 
59
        dest_version = destination_sourcepubs.get((package, series))
 
60
        note = ""
 
61
        if buildstate != 'FULLYBUILT':
 
62
            pass
 
63
        elif dest_version is None:
 
64
            sourcepub_elts.append((package, version, series))
 
65
            note = "*** REQUESTING PROMOTION (NEW) ***"
 
66
        else:
 
67
            c = apt_pkg.version_compare(version, dest_version)
 
68
            if c > 0:
 
69
                sourcepub_elts.append((package, version, series))
 
70
                note = "*** REQUESTING PROMOTION ***"
 
71
            elif c < 0:
 
72
                note = "*** NEWER IN DESTINATION ***"
 
73
        print value, package, series, version, status, buildstate, note
 
74
 
 
75
    for name, version, series in sourcepub_elts:
 
76
        print "syncSource(%s, %s, %s)..." % (name, version, series)
 
77
        to_archive.syncSource(from_archive=from_archive, include_binaries=True,
 
78
                source_name=name, to_pocket="Release", to_series=series,
 
79
                version=version)
 
80
 
 
81
 
 
82
def main():
 
83
    parser = optparse.OptionParser(USAGE)
 
84
    opts, args = parser.parse_args()
 
85
    if len(args) != 2:
 
86
        parser.error("incorrect number of arguments: %d required, %d given"
 
87
                % (2, len(args)))
 
88
    from_archive, to_archive = args
 
89
    lp = hydrazine.create_session()
 
90
    promote(lp, from_archive, to_archive)
 
91
 
 
92
 
 
93
if __name__ == '__main__':
 
94
    main()