Editing is now supported.
[0publish.git] / 0publish
blobebb0809606c99239ff388b49ccf8dee3461a6511
1 #!/usr/bin/env python
2 from zeroinstall.injector import gpg
3 from optparse import OptionParser
4 import os, sys
5 import signing
7 version = '0.1'
9 parser = OptionParser(usage="usage: %prog [options] interface")
10 parser.add_option("-k", "--key", help="key to use for signing")
11 parser.add_option("-e", "--edit", help="edit with $EDITOR", action='store_true')
12 parser.add_option("-x", "--xmlsign", help="add an XML signature block", action='store_true')
13 parser.add_option("-V", "--version", help="display version information", action='store_true')
15 (options, args) = parser.parse_args()
17 if options.version:
18 print "0publish (zero-install) " + version
19 print "Copyright (C) 2005 Thomas Leonard"
20 print "This program comes with ABSOLUTELY NO WARRANTY,"
21 print "to the extent permitted by law."
22 print "You may redistribute copies of this program"
23 print "under the terms of the GNU General Public License."
24 print "For more information about these matters, see the file named COPYING."
25 sys.exit(0)
27 if len(args) != 1:
28 parser.print_help()
29 sys.exit(1)
30 interface = args[0]
32 def confirm(q):
33 while True:
34 ans = raw_input(q + " [Y/N] ").lower()
35 if ans in ('y', 'yes'): return True
36 if ans in ('n', 'no'): return False
38 # Load or create the starting data...
40 if os.path.exists(interface):
41 contents = file(interface).read()
42 data, sign_fn, key = signing.check_signature(interface)
43 else:
44 if confirm("Interface file '%s' does not exist. Create it?" % interface):
45 from create import create
46 data = create(interface)
47 sign_fn = signing.sign_unsigned
48 key = None
49 else:
50 sys.exit(1)
52 # Process it...
53 if options.xmlsign:
54 sign_fn = signing.sign_xml
55 if options.key:
56 print "Changing key from '%s' to '%s'" % (key, options.key)
57 key = options.key
58 if options.edit:
59 import edit
60 data = edit.edit(data)
62 print "Data", data
63 print "Sign", sign_fn
64 print "Key", key
66 # Validate the result...
68 # Write it back out
69 sign_fn(interface, data, key)