Merge lp:~ivoks/ubuntu-reports/private-ppa into lp:ubuntu-reports

Proposed by Ante Karamatić on 2013-08-23
Status: Needs review
Proposed branch: lp:~ivoks/ubuntu-reports/private-ppa
Merge into: lp:ubuntu-reports
Diff against target: 144 lines (+45/-9)
2 files modified
server/cloud-archive/version-tracker/ca-versions.py (+8/-1)
server/cloud-archive/version-tracker/gather-versions.py (+37/-8)
To merge this branch: bzr merge lp:~ivoks/ubuntu-reports/private-ppa
Reviewer Review Type Date Requested Status
Ubuntu Reports Dev Team 2013-08-23 Pending
Review via email: mp+181778@code.launchpad.net

Description of the change

This branch adds feautre of inspecting private PPAs. For example:

gather-versions.py -a MyApp -u supersecret grizzly

ca-versions.py -r grizzly -u supersecret

In this example, 'supersecret' is user's Private PPA or a PPA from a private LP team. 'MyApp' is application name that LP library would use to get OAuth token.

In addition, this branch also fixes some PEP8 warnings and errors.

To post a comment you must log in.

Unmerged revisions

105. By Ante Karamatić on 2013-08-23

Add support for private PPA and LP authentication for cloud-archive
set of scripts.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'server/cloud-archive/version-tracker/ca-versions.py'
2--- server/cloud-archive/version-tracker/ca-versions.py 2013-04-30 15:45:47 +0000
3+++ server/cloud-archive/version-tracker/ca-versions.py 2013-08-23 10:35:34 +0000
4@@ -49,7 +49,11 @@
5
6 def load_sets(json_dir, release):
7 # this list determines which pockets to display, and in what order.
8- sets = ['ubuntu', 'staging', 'proposed', 'updates']
9+ if opts.lp_user:
10+ user_set = ('%s-staging' % opts.lp_user)
11+ sets = ['ubuntu', 'staging', 'proposed', 'updates', user_set]
12+ else:
13+ sets = ['ubuntu', 'staging', 'proposed', 'updates']
14 i = 1
15 package_sets = {}
16 for s in sets:
17@@ -142,6 +146,9 @@
18 action='store_true', default=False,
19 help='Ensure Ubuntu pockets do not contain newer '\
20 'packages than what is at least in CA staging.')
21+parser.add_option('-u', '--user', action='store', dest='lp_user',
22+ default=None, type='string',
23+ help='Additional staging PPA owned by this user')
24 (opts, args) = parser.parse_args()
25
26 if not os.path.exists(opts.json_dir):
27
28=== modified file 'server/cloud-archive/version-tracker/gather-versions.py'
29--- server/cloud-archive/version-tracker/gather-versions.py 2013-05-29 17:40:31 +0000
30+++ server/cloud-archive/version-tracker/gather-versions.py 2013-08-23 10:35:34 +0000
31@@ -35,6 +35,12 @@
32 parser.add_option('-o', '--output_dir', action='store', dest='out_dir',
33 default=os.path.join(os.getenv('HOME'), '.ca-versions'),
34 help='Directory to dump JSON (Default: $HOME/.ca-versions)')
35+parser.add_option('-u', '--user', action='store', dest='lp_user',
36+ default=None, type='string',
37+ help='Additional staging PPA owned by this user')
38+parser.add_option('-a', '--auth', action='store', dest='lp_auth',
39+ default=None, type='string',
40+ help='Authenticate against LP as this application')
41 (opts, args) = parser.parse_args()
42
43 if len(args) == 0:
44@@ -53,6 +59,7 @@
45 conn["lp"] = None
46 conn["ubuntu"] = None
47
48+
49 def version_from_packages_url(packages, package):
50 packages = packages.split('\n')
51 loc = 0
52@@ -90,13 +97,15 @@
53
54 return s or p or None
55
56+
57 def versions_from_packages(os_release, pocket, pkgs):
58 url = common.packages_url(os_release, pocket)
59 req = httplib2.Http()
60
61 resp, content = req.request(url, "GET")
62 if resp.status != 200:
63- logging.warn('Could not fetch Packages from %s (%s)' % (url, resp.status))
64+ logging.warn('Could not fetch Packages from %s (%s)' % (url,
65+ resp.status))
66 return {}
67
68 packages = content
69@@ -107,28 +116,37 @@
70
71 return versions
72
73+
74 def init_lp():
75 if not conn['lp']:
76 logging.info("Initializing connection to LP...")
77- conn['lp'] = Launchpad.login_anonymously('openstack', 'production')
78+ if not opts.lp_auth:
79+ conn['lp'] = Launchpad.login_anonymously('openstack', 'production')
80+ else:
81+ conn['lp'] = Launchpad.login_with(opts.lp_auth, 'production')
82 if not conn['ubuntu']:
83 conn['ubuntu'] = conn['lp'].distributions['ubuntu']
84 return conn['lp']
85
86-def query_ca_ppa(ppa='folsom-staging', release='precise'):
87+
88+def query_ppa(lp_user='ubuntu-cloud-archive', ppa='folsom-staging',
89+ release='precise'):
90 init_lp()
91- ppa = conn['lp'].people['ubuntu-cloud-archive'].getPPAByName(name=ppa)
92+ ppa = conn['lp'].people[lp_user].getPPAByName(name=ppa)
93 distro = ppa.distribution.getSeries(name_or_version=release)
94 out = {}
95- for pkg in ppa.getPublishedSources(distro_series=distro, status='Published'):
96+ for pkg in ppa.getPublishedSources(distro_series=distro,
97+ status='Published'):
98 out[pkg.source_package_name] = pkg.source_package_version
99 return out
100
101+
102 def get_ubuntu_pkg_vers(pkg, release):
103 '''
104 get pkg version in ubuntu with pocket priority:
105 (Security > Updates > Release)
106- returns a tuple: (pocket, version) or (None, None) if pkg doesn't exist in Ubuntu.
107+ returns a tuple: (pocket, version) or (None, None) if pkg doesn't exist
108+ in Ubuntu.
109 '''
110 init_lp()
111 archive, partner = conn['ubuntu'].archives
112@@ -158,6 +176,7 @@
113 return None, None
114 return 'release', rel
115
116+
117 def query_ubuntu(pkgs, release):
118 '''return a dict mapping all pkgs to versions in ubuntu for a
119 given release.
120@@ -176,12 +195,22 @@
121 # in other places.
122 logging.info("Querying package list and versions from staging PPA.")
123 staging_ppa = '%s-staging' % os_release
124-staging_versions = query_ca_ppa(ppa=staging_ppa,
125- release=stable_rel)
126+staging_versions = query_ppa(ppa=staging_ppa,
127+ release=stable_rel)
128 f = open(os.path.join(opts.out_dir, '%s_staging_versions' % os_release), 'w+')
129 f.write(json.dumps(staging_versions))
130 f.close()
131
132+if opts.lp_user:
133+ logging.info("Querying package list and versions from user's staging PPA.")
134+ staging_ppa = '%s-staging' % os_release
135+ user_staging_versions = query_ppa(lp_user=str(opts.lp_user), ppa=staging_ppa,
136+ release=stable_rel)
137+ f = open(os.path.join(opts.out_dir, '%s_%s-staging_versions' % (os_release,
138+ opts.lp_user)), 'w+')
139+ f.write(json.dumps(user_staging_versions))
140+ f.close()
141+
142 # with the names of the packages published to the staging ppa, we can determine
143 # what we need to track in ubuntu.
144 logging.info("Querying Ubuntu versions for all packages.")

Subscribers

People subscribed via source and target branches