1
2
3
4
5
6
7
8
9
10
11
12
13
14 from conary import callbacks
15 from conary import conaryclient
16 from conary import trove
17 from conary.conarycfg import selectSignatureKey
18 from conary.conaryclient import cmdline
19 from conary.deps import deps
20 from conary.lib import log
21 from conary.lib.openpgpfile import KeyNotFound
22 from conary.updatecmd import parseTroveSpec
23 from conary.repository import errors
24
26
28 if need != 0:
29 self._message("Signing trove (%d of %d)..."
30 % (got, need))
31
32 -def signTroves(cfg, specStrList, recurse = False, callback = None):
33 troveStr = ""
34 jobList = []
35 trv = []
36 client = conaryclient.ConaryClient(cfg)
37 repos = client.getRepos()
38
39 if callback is None:
40 if cfg.quiet:
41 callback = callbacks.SignatureCallback()
42 else:
43 callback = SignatureCallback()
44
45 for specStr in specStrList:
46 name, versionStr, flavor = parseTroveSpec(specStr)
47
48 try:
49 trvList = repos.findTrove([ cfg.buildLabel ],
50 (name, versionStr, flavor), cfg.flavor)
51 except errors.TroveNotFound, e:
52 log.error(str(e))
53 return
54
55 for trvInfo in trvList:
56 troveStr += "%s=%s[%s]\n" % (trvInfo[0], trvInfo[1].asString(),
57 deps.formatFlavor(trvInfo[2]))
58
59 jobList.append((trvInfo[0], (None, None), (trvInfo[1], trvInfo[2]),
60 True))
61
62 if cfg.interactive:
63 print troveStr
64 print "Total: %d troves" % len(jobList)
65 answer = cmdline.askYn('Are you sure you want to digitally sign these troves [y/N]?', default=False)
66 if not answer:
67 return
68
69
70
71 cs = repos.createChangeSet(jobList, withFiles = True,
72 withFileContents = False, recurse = recurse)
73
74 totalNum = len([ x for x in cs.iterNewTroveList() ])
75 misfires = []
76
77 for i, trvCs in enumerate(cs.iterNewTroveList()):
78 trv = trove.Trove(trvCs)
79 callback.signTrove(i + 1, totalNum)
80
81 label = trv.getVersion().branch().label()
82 signatureKey = selectSignatureKey(cfg, label.asString())
83
84 if not signatureKey:
85 if not cfg.quiet:
86 print "\nNo key is defined for label %s" % label
87 return
88
89 continue
90
91 try:
92 trv.getDigitalSignature(signatureKey)
93 if not cfg.quiet:
94 print "\nTrove: %s=%s[%s] is already signed by key: %s" \
95 % (trv.getName(), trv.getVersion(),
96 deps.formatFlavor(trv.getFlavor()),
97 cfg.signatureKey)
98 continue
99 except KeyNotFound:
100 pass
101
102 try:
103 trv.addDigitalSignature(signatureKey)
104 except KeyNotFound:
105 print "\nKey:", signatureKey, "is not in your keyring."
106 return
107
108 try:
109 repos.addDigitalSignature(trv.getName(), trv.getVersion(),
110 trv.getFlavor(),
111 trv.getDigitalSignature(signatureKey))
112 except (errors.AlreadySignedError, KeyNotFound):
113 misfires.append(trv.getName())
114
115 if misfires:
116 raise errors.DigitalSignatureError('The following troves could not be signed: %s' % str(misfires))
117