~revu-hackers/revu/trunk

125 by siretart
new script to fetch keys from launchpad
1
#!/usr/bin/env python
2
3
import RDF
4
import os, os.path, sys
5
import shutil
6
7
#some variables set that somewhere else
8
9
class RevuKeyUpdater:
10
	"""Retrieves Fingerprints from a launchpad group by parsing the group rdf
11
		stores corresponding keys in a new gpg keyring
12
	"""
127.2.2 by revu1
fix paths to new location
13
	def __init__(self, lpgroup = 'ubuntu-universe-contributors', revubase = '/srv/revu1-production'):
125 by siretart
new script to fetch keys from launchpad
14
		" initializes this class"
15
		self.lpgroup = lpgroup
16
		self.keyserver = 'keyserver.ubuntu.com'
17
		self.keyring = "%s/launchpad.gpg" % revubase
18
		self.gpgopts = "--no-options --no-default-keyring "
19
		self.gpgopts += "--secret-keyring %s/secring.gpg" % revubase
20
		self.gpgopts += " --trustdb-name %s/trustdb.gpg" % revubase
21
		self.gpgopts += " --keyring %s" % self.keyring
22
		self.gpgopts += " --keyserver keyserver.ubuntu.com"
140 by Reinhard Tartler
add hint from pkern on #ubuntu-motu
23
		self.gpgopts += " --no-auto-check-trustdb --trust-model always"
125 by siretart
new script to fetch keys from launchpad
24
		self.fingerprints = []
25
26
	def get_fingerprints(self):
27
		"parses fingerprints from the rdf"
28
		model = RDF.Model()
29
		model.load('https://launchpad.net/people/%s/+rdf' % self.lpgroup)
30
		q = RDF.Query("SELECT ?fingerprint WHERE (?any, <http://xmlns.com/wot/0.1/fingerprint>, ?fingerprint )")
31
32
		results = q.execute(model)
33
		for statement in results:
34
			self.fingerprints.append(statement['fingerprint'].literal_value['string'])
35
36
	def do_update(self):
37
		"handles calling gpg for all found fingerprints"
38
		self.get_fingerprints()
39
40
		for fingerprint in self.fingerprints:
41
			# get the keyid from the fingerprint
42
			key = fingerprint[-8:]
43
			os.system("gpg %s --recv-key %s" % (self.gpgopts, key))
44
45
46
if __name__ == '__main__':
127.2.2 by revu1
fix paths to new location
47
	updater = RevuKeyUpdater(revubase='/srv/revu1-production')
125 by siretart
new script to fetch keys from launchpad
48
	updater.do_update()