2 from zeroinstall
.injector
import gpg
3 from optparse
import OptionParser
6 from logging
import info
, debug
11 parser
= OptionParser(usage
="usage: %prog [options] interface")
12 parser
.add_option("-k", "--key", help="key to use for signing")
13 parser
.add_option("-e", "--edit", help="edit with $EDITOR", action
='store_true')
14 parser
.add_option("-l", "--local", help="create feed from local interface")
15 parser
.add_option("-r", "--release", help="set versions and dates", action
='store_true')
16 parser
.add_option("-x", "--xmlsign", help="add an XML signature block", action
='store_true')
17 parser
.add_option("-v", "--verbose", help="more verbose output", action
='count')
18 parser
.add_option("-V", "--version", help="display version information", action
='store_true')
20 (options
, args
) = parser
.parse_args()
25 print "0publish (zero-install) " + version
26 print "Copyright (C) 2005 Thomas Leonard"
27 print "This program comes with ABSOLUTELY NO WARRANTY,"
28 print "to the extent permitted by law."
29 print "You may redistribute copies of this program"
30 print "under the terms of the GNU General Public License."
31 print "For more information about these matters, see the file named COPYING."
36 logger
= logging
.getLogger()
37 if options
.verbose
== 1:
38 logger
.setLevel(logging
.INFO
)
40 logger
.setLevel(logging
.DEBUG
)
49 ans
= raw_input(q
+ " [Y/N] ").lower()
50 if ans
in ('y', 'yes'): return True
51 if ans
in ('n', 'no'): return False
53 # Load or create the starting data...
55 if os
.path
.exists(interface
):
57 raise Exception("Can't use --local; file '%s' already exists!" % interface
)
58 contents
= file(interface
).read()
59 data
, sign_fn
, key
= signing
.check_signature(interface
)
62 if os
.path
.exists(options
.local
):
63 data
= create
.create_from_local(options
.local
)
64 sign_fn
= signing
.sign_unsigned
68 raise Exception("File '%s' does not exist." % options
.local
)
70 if confirm("Interface file '%s' does not exist. Create it?" % interface
):
71 from create
import create
72 data
= create(interface
)
73 sign_fn
= signing
.sign_unsigned
79 debug("Original data: %s", data
)
80 info("Original signing method: %s", sign_fn
.__name
__)
81 info("Original key: %s", key
)
88 # Validate the input...
92 except validator
.InvalidInterface
, ex
:
93 print "Invalid interface: " + str(ex
)
96 ans
= raw_input("Interface is invalid. (E)dit or (A)bort?").lower()
97 if ans
in ('e', 'edit'):
98 data
= edit
.edit(data
)
99 options
.edit
= False # Don't edit twice
101 if ans
in ('a', 'abort'): sys
.exit(1)
105 sign_fn
= signing
.sign_xml
107 print "Changing key from '%s' to '%s'" % (key
, options
.key
)
111 data
= release
.make_release(data
)
113 data
= edit
.edit(data
)
116 # Validate the result...
118 validator
.check(data
)
120 except validator
.InvalidInterface
, ex
:
121 print "Invalid interface: " + str(ex
)
124 ans
= raw_input("Interface is invalid. (E)dit or (A)bort?").lower()
125 if ans
in ('e', 'edit'):
126 data
= edit
.edit(data
)
128 if ans
in ('a', 'abort'): sys
.exit(1)
131 if (old_data
== data
and sign_fn
== old_sign_fn
and key
== old_key
) and not force_save
:
132 print "Interface unchanged. Not writing."
136 if not data
.endswith('\n'): data
+= '\n'
137 sign_fn(interface
, data
, key
)
139 print "Wrote", interface