Unpack archives to tmp dir.
[zeroinstall.git] / trust.py
blob9aabc75c65295e4299090d3ca27af0b36d333d43
1 import os
3 import basedir
4 from namespaces import config_site, config_prog
6 class TrustDB:
7 keys = None
9 def __init__(self):
10 self.keys = None
12 def is_trusted(self, key):
13 self.ensure_uptodate()
14 return key in self.keys
16 def trust_key(self, key):
17 self.ensure_uptodate()
18 self.keys[key] = True
19 self.save()
21 def untrust_key(self, key):
22 self.ensure_uptodate()
23 del self.keys[key]
24 self.save()
26 def save(self):
27 d = basedir.save_config_path(config_site, config_prog)
28 # XXX
29 f = file(os.path.join(d, 'trust'), 'w')
30 for key in self.keys:
31 print >>f, key
32 f.close()
34 def ensure_uptodate(self):
35 trust = basedir.load_first_config(config_site, config_prog,
36 'trust')
37 # This is a bit inefficient...
38 self.keys = {}
39 if trust:
40 #print "Loading trust from", trust_db
41 for key in file(trust).read().split('\n'):
42 self.keys[key] = True
44 # Singleton
45 trust_db = TrustDB()