3 # Using the public key defined in testkey.py, sign all *.pyc files in
4 # the listed directories.
7 from allmydata.Crypto.Hash import MD5
9 import marshal, compileall
13 for dir in sys.argv[1:]:
14 dir=os.path.join(dir, '')
15 compileall.compile_dir(dir)
16 filelist=filelist + glob.glob(dir + '*.pyc')
18 print "Usage: sign.py dir1 dir2 dir3 ..."
19 print " All *.pyc files in the listed directories will be signed,"
20 print "leaving the signatures in *.pys files."
24 print "No *.pyc files found"
28 input=open(file, 'rb')
30 os.unlink(file[:-4]+'.pys') # Delete any existing signed file
31 except os.error, tuple:
32 if (tuple[0]==2): pass # Ignore 'file not found' error
33 else: raise os.error, tuple
34 output=open(file[:-4]+'.pys', 'wb')
36 hash=MD5.new(data).digest() # Compute hash of the code object
38 signature=key.sign(hash, K) # Sign the hash value
39 marshal.dump(signature, output) # Save signature to the file
40 output.write(data) # Copy code object to signed file
43 print os.path.basename(file)+ ' processed.'