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
):
56 contents
= file(interface
).read()
57 data
, sign_fn
, key
= signing
.check_signature(interface
)
60 if os
.path
.exists(options
.local
):
61 data
= create
.create_from_local(options
.local
)
62 sign_fn
= signing
.sign_unsigned
66 raise Exception("File '%s' does not exist." % options
.local
)
68 if confirm("Interface file '%s' does not exist. Create it?" % interface
):
69 from create
import create
70 data
= create(interface
)
71 sign_fn
= signing
.sign_unsigned
77 debug("Original data: %s", data
)
78 info("Original signing method: %s", sign_fn
.__name
__)
79 info("Original key: %s", key
)
86 # Validate the input...
90 except validator
.InvalidInterface
, ex
:
91 print "Invalid interface: " + str(ex
)
94 ans
= raw_input("Interface is invalid. (E)dit or (A)bort?").lower()
95 if ans
in ('e', 'edit'):
96 data
= edit
.edit(data
)
97 options
.edit
= False # Don't edit twice
99 if ans
in ('a', 'abort'): sys
.exit(1)
103 sign_fn
= signing
.sign_xml
105 print "Changing key from '%s' to '%s'" % (key
, options
.key
)
109 data
= release
.make_release(data
)
112 data
= merge
.merge(data
, options
.local
)
114 data
= edit
.edit(data
)
117 # Validate the result...
119 validator
.check(data
)
121 except validator
.InvalidInterface
, ex
:
122 print "Invalid interface: " + str(ex
)
125 ans
= raw_input("Interface is invalid. (E)dit or (A)bort?").lower()
126 if ans
in ('e', 'edit'):
127 data
= edit
.edit(data
)
129 if ans
in ('a', 'abort'): sys
.exit(1)
132 if (old_data
== data
and sign_fn
== old_sign_fn
and key
== old_key
) and not force_save
:
133 print "Interface unchanged. Not writing."
137 if not data
.endswith('\n'): data
+= '\n'
138 sign_fn(interface
, data
, key
)
140 print "Wrote", interface