<s> from conary import callbacks <EOL> from conary import conaryclient <EOL> from conary import trove <EOL> from conary . conarycfg import selectSignatureKey <EOL> from conary . conaryclient import cmdline <EOL> from conary . deps import deps <EOL> from conary . lib import log <EOL> from conary . lib . openpgpfile import KeyNotFound <EOL> from conary . cmds . updatecmd import parseTroveSpec <EOL> from conary . repository import errors <EOL> class SignatureCallback ( callbacks . SignatureCallback , callbacks . LineOutput ) : <EOL> def signTrove ( self , got , need ) : <EOL> if need != <NUM_LIT:0> : <EOL> self . _message ( "<STR_LIT>" <EOL> % ( got , need ) ) <EOL> def signTroves ( cfg , specStrList , recurse = False , callback = None ) : <EOL> troveStr = "<STR_LIT>" <EOL> jobList = [ ] <EOL> trv = [ ] <EOL> client = conaryclient . ConaryClient ( cfg ) <EOL> repos = client . getRepos ( ) <EOL> if callback is None : <EOL> if cfg . quiet : <EOL> callback = callbacks . SignatureCallback ( ) <EOL> else : <EOL> callback = SignatureCallback ( ) <EOL> for specStr in specStrList : <EOL> name , versionStr , flavor = parseTroveSpec ( specStr ) <EOL> try : <EOL> trvList = repos . findTrove ( [ cfg . buildLabel ] , <EOL> ( name , versionStr , flavor ) , cfg . flavor ) <EOL> except errors . TroveNotFound , e : <EOL> log . error ( str ( e ) ) <EOL> return <EOL> for trvInfo in trvList : <EOL> troveStr += "<STR_LIT>" % ( trvInfo [ <NUM_LIT:0> ] , trvInfo [ <NUM_LIT:1> ] . asString ( ) , <EOL> deps . formatFlavor ( trvInfo [ <NUM_LIT:2> ] ) ) <EOL> jobList . append ( ( trvInfo [ <NUM_LIT:0> ] , ( None , None ) , ( trvInfo [ <NUM_LIT:1> ] , trvInfo [ <NUM_LIT:2> ] ) , <EOL> True ) ) <EOL> if cfg . interactive : <EOL> print troveStr <EOL> print "<STR_LIT>" % len ( jobList ) <EOL> answer = cmdline . askYn ( '<STR_LIT>' , default = False ) <EOL> if not answer : <EOL> return <EOL> cs = repos . createChangeSet ( jobList , withFiles = True , <EOL> withFileContents = False , recurse = recurse ) <EOL> totalNum = len ( [ x for x in cs . iterNewTroveList ( ) ] ) <EOL> misfires = [ ] <EOL> for i , trvCs in enumerate ( cs . iterNewTroveList ( ) ) : <EOL> trv = trove . Trove ( trvCs ) <EOL> callback . signTrove ( i + <NUM_LIT:1> , totalNum ) <EOL> label = trv . getVersion ( ) . branch ( ) . label ( ) <EOL> signatureKey = selectSignatureKey ( cfg , label . asString ( ) ) <EOL> if not signatureKey : <EOL> if not cfg . quiet : <EOL> print "<STR_LIT>" % label <EOL> return <EOL> continue <EOL> keyCache = trove . openpgpkey . getKeyCache ( ) <EOL> key = keyCache . getPublicKey ( signatureKey ) <EOL> signatureKey = key . getFingerprint ( ) <EOL> try : <EOL> trv . getDigitalSignature ( signatureKey ) <EOL> if not cfg . quiet : <EOL> print "<STR_LIT>" % ( trv . getName ( ) , trv . getVersion ( ) , <EOL> deps . formatFlavor ( trv . getFlavor ( ) ) , <EOL> cfg . signatureKey ) <EOL> continue <EOL> except KeyNotFound : <EOL> pass <EOL> try : <EOL> trv . addDigitalSignature ( signatureKey ) <EOL> except KeyNotFound : <EOL> print "<STR_LIT>" , signatureKey , "<STR_LIT>" <EOL> return <EOL> try : <EOL> repos . addDigitalSignature ( trv . getName ( ) , trv . getVersion ( ) , <EOL> trv . getFlavor ( ) , <EOL> trv . getDigitalSignature ( signatureKey ) ) <EOL> except ( errors . AlreadySignedError , KeyNotFound ) , e : <EOL> misfires . append ( ( trv . getName ( ) , str ( e ) ) ) <EOL> if misfires : <EOL> troves = [ x [ <NUM_LIT:0> ] for x in misfires ] <EOL> errs = set ( x [ <NUM_LIT:1> ] for x in misfires ) <EOL> raise errors . DigitalSignatureError ( '<STR_LIT>' % ( troves , list ( errs ) ) ) </s>
