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

Proposed by Ante Karamatić
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 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ć

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
=== modified file 'server/cloud-archive/version-tracker/ca-versions.py'
--- server/cloud-archive/version-tracker/ca-versions.py 2013-04-30 15:45:47 +0000
+++ server/cloud-archive/version-tracker/ca-versions.py 2013-08-23 10:35:34 +0000
@@ -49,7 +49,11 @@
4949
50def load_sets(json_dir, release):50def load_sets(json_dir, release):
51 # this list determines which pockets to display, and in what order.51 # this list determines which pockets to display, and in what order.
52 sets = ['ubuntu', 'staging', 'proposed', 'updates']52 if opts.lp_user:
53 user_set = ('%s-staging' % opts.lp_user)
54 sets = ['ubuntu', 'staging', 'proposed', 'updates', user_set]
55 else:
56 sets = ['ubuntu', 'staging', 'proposed', 'updates']
53 i = 157 i = 1
54 package_sets = {}58 package_sets = {}
55 for s in sets:59 for s in sets:
@@ -142,6 +146,9 @@
142 action='store_true', default=False,146 action='store_true', default=False,
143 help='Ensure Ubuntu pockets do not contain newer '\147 help='Ensure Ubuntu pockets do not contain newer '\
144 'packages than what is at least in CA staging.')148 'packages than what is at least in CA staging.')
149parser.add_option('-u', '--user', action='store', dest='lp_user',
150 default=None, type='string',
151 help='Additional staging PPA owned by this user')
145(opts, args) = parser.parse_args()152(opts, args) = parser.parse_args()
146153
147if not os.path.exists(opts.json_dir):154if not os.path.exists(opts.json_dir):
148155
=== modified file 'server/cloud-archive/version-tracker/gather-versions.py'
--- server/cloud-archive/version-tracker/gather-versions.py 2013-05-29 17:40:31 +0000
+++ server/cloud-archive/version-tracker/gather-versions.py 2013-08-23 10:35:34 +0000
@@ -35,6 +35,12 @@
35parser.add_option('-o', '--output_dir', action='store', dest='out_dir',35parser.add_option('-o', '--output_dir', action='store', dest='out_dir',
36 default=os.path.join(os.getenv('HOME'), '.ca-versions'),36 default=os.path.join(os.getenv('HOME'), '.ca-versions'),
37 help='Directory to dump JSON (Default: $HOME/.ca-versions)')37 help='Directory to dump JSON (Default: $HOME/.ca-versions)')
38parser.add_option('-u', '--user', action='store', dest='lp_user',
39 default=None, type='string',
40 help='Additional staging PPA owned by this user')
41parser.add_option('-a', '--auth', action='store', dest='lp_auth',
42 default=None, type='string',
43 help='Authenticate against LP as this application')
38(opts, args) = parser.parse_args()44(opts, args) = parser.parse_args()
3945
40if len(args) == 0:46if len(args) == 0:
@@ -53,6 +59,7 @@
53conn["lp"] = None59conn["lp"] = None
54conn["ubuntu"] = None60conn["ubuntu"] = None
5561
62
56def version_from_packages_url(packages, package):63def version_from_packages_url(packages, package):
57 packages = packages.split('\n')64 packages = packages.split('\n')
58 loc = 065 loc = 0
@@ -90,13 +97,15 @@
9097
91 return s or p or None98 return s or p or None
9299
100
93def versions_from_packages(os_release, pocket, pkgs):101def versions_from_packages(os_release, pocket, pkgs):
94 url = common.packages_url(os_release, pocket)102 url = common.packages_url(os_release, pocket)
95 req = httplib2.Http()103 req = httplib2.Http()
96104
97 resp, content = req.request(url, "GET")105 resp, content = req.request(url, "GET")
98 if resp.status != 200:106 if resp.status != 200:
99 logging.warn('Could not fetch Packages from %s (%s)' % (url, resp.status))107 logging.warn('Could not fetch Packages from %s (%s)' % (url,
108 resp.status))
100 return {}109 return {}
101110
102 packages = content111 packages = content
@@ -107,28 +116,37 @@
107116
108 return versions117 return versions
109118
119
110def init_lp():120def init_lp():
111 if not conn['lp']:121 if not conn['lp']:
112 logging.info("Initializing connection to LP...")122 logging.info("Initializing connection to LP...")
113 conn['lp'] = Launchpad.login_anonymously('openstack', 'production')123 if not opts.lp_auth:
124 conn['lp'] = Launchpad.login_anonymously('openstack', 'production')
125 else:
126 conn['lp'] = Launchpad.login_with(opts.lp_auth, 'production')
114 if not conn['ubuntu']:127 if not conn['ubuntu']:
115 conn['ubuntu'] = conn['lp'].distributions['ubuntu']128 conn['ubuntu'] = conn['lp'].distributions['ubuntu']
116 return conn['lp']129 return conn['lp']
117130
118def query_ca_ppa(ppa='folsom-staging', release='precise'):131
132def query_ppa(lp_user='ubuntu-cloud-archive', ppa='folsom-staging',
133 release='precise'):
119 init_lp()134 init_lp()
120 ppa = conn['lp'].people['ubuntu-cloud-archive'].getPPAByName(name=ppa)135 ppa = conn['lp'].people[lp_user].getPPAByName(name=ppa)
121 distro = ppa.distribution.getSeries(name_or_version=release)136 distro = ppa.distribution.getSeries(name_or_version=release)
122 out = {}137 out = {}
123 for pkg in ppa.getPublishedSources(distro_series=distro, status='Published'):138 for pkg in ppa.getPublishedSources(distro_series=distro,
139 status='Published'):
124 out[pkg.source_package_name] = pkg.source_package_version140 out[pkg.source_package_name] = pkg.source_package_version
125 return out141 return out
126142
143
127def get_ubuntu_pkg_vers(pkg, release):144def get_ubuntu_pkg_vers(pkg, release):
128 '''145 '''
129 get pkg version in ubuntu with pocket priority:146 get pkg version in ubuntu with pocket priority:
130 (Security > Updates > Release)147 (Security > Updates > Release)
131 returns a tuple: (pocket, version) or (None, None) if pkg doesn't exist in Ubuntu.148 returns a tuple: (pocket, version) or (None, None) if pkg doesn't exist
149 in Ubuntu.
132 '''150 '''
133 init_lp()151 init_lp()
134 archive, partner = conn['ubuntu'].archives152 archive, partner = conn['ubuntu'].archives
@@ -158,6 +176,7 @@
158 return None, None176 return None, None
159 return 'release', rel177 return 'release', rel
160178
179
161def query_ubuntu(pkgs, release):180def query_ubuntu(pkgs, release):
162 '''return a dict mapping all pkgs to versions in ubuntu for a181 '''return a dict mapping all pkgs to versions in ubuntu for a
163 given release.182 given release.
@@ -176,12 +195,22 @@
176# in other places.195# in other places.
177logging.info("Querying package list and versions from staging PPA.")196logging.info("Querying package list and versions from staging PPA.")
178staging_ppa = '%s-staging' % os_release197staging_ppa = '%s-staging' % os_release
179staging_versions = query_ca_ppa(ppa=staging_ppa,198staging_versions = query_ppa(ppa=staging_ppa,
180 release=stable_rel)199 release=stable_rel)
181f = open(os.path.join(opts.out_dir, '%s_staging_versions' % os_release), 'w+')200f = open(os.path.join(opts.out_dir, '%s_staging_versions' % os_release), 'w+')
182f.write(json.dumps(staging_versions))201f.write(json.dumps(staging_versions))
183f.close()202f.close()
184203
204if opts.lp_user:
205 logging.info("Querying package list and versions from user's staging PPA.")
206 staging_ppa = '%s-staging' % os_release
207 user_staging_versions = query_ppa(lp_user=str(opts.lp_user), ppa=staging_ppa,
208 release=stable_rel)
209 f = open(os.path.join(opts.out_dir, '%s_%s-staging_versions' % (os_release,
210 opts.lp_user)), 'w+')
211 f.write(json.dumps(user_staging_versions))
212 f.close()
213
185# with the names of the packages published to the staging ppa, we can determine214# with the names of the packages published to the staging ppa, we can determine
186# what we need to track in ubuntu.215# what we need to track in ubuntu.
187logging.info("Querying Ubuntu versions for all packages.")216logging.info("Querying Ubuntu versions for all packages.")

Subscribers

People subscribed via source and target branches