Minor updates to feed to remove deprecated features.
[AddApp.git] / Zero2Bundle / AppRun
bloba2a65af139b256b6ca8eed12b203e309357ad3a6
1 #!/usr/bin/env python
2 import os, sys
3 import findrox; findrox.version(1, 9, 6)
4 from zeroinstall.injector.policy import Policy
5 import rox
6 from rox import g, processes, saving
7 from cStringIO import StringIO
9 zero2bundle_uri = "http://rox.sourceforge.net/2006/interfaces/Zero2Bundle.xml"
11 def try_interface(uri):
12 errors = StringIO()
13 launcher = processes.PipeThroughCommand(
14 ["0launch", "-d", "-g", "--", uri],
15 None, errors)
16 try:
17 launcher.wait()
18 except processes.ChildError, ex:
19 if '(256)' not in str(ex):
20 rox.alert(str(ex))
21 except:
22 rox.report_exception()
23 else:
24 return True
25 return False
27 if len(sys.argv) == 1:
28 from chooser import Chooser
29 m = Chooser()
30 while True:
31 m.show()
32 resp = m.run()
33 if resp != g.RESPONSE_OK:
34 sys.exit(1)
35 m.hide()
36 uri = m.uri.get_text()
37 if try_interface(uri):
38 break
39 m.destroy()
40 elif len(sys.argv) == 2:
41 uri = sys.argv[1]
42 if not try_interface(uri):
43 sys.exit(1)
44 else:
45 rox.alert("Multiple arguments to Zero2Bundle (%s)!" % `sys.argv[1:]`)
46 sys.exit(1)
48 policy = Policy(uri)
49 policy.freshness == 0
50 policy.recalculate()
51 assert policy.ready
53 from bundle import BundleMaker
55 maker = BundleMaker(policy)
56 default_name = os.path.basename(uri)
57 if default_name.endswith('.xml'):
58 default_name = default_name[:-4]
59 box = saving.SaveBox(maker, default_name, 'inode/directory')
60 if maker.icon:
61 image = g.Image()
62 try:
63 # Icon format must be PNG (to avoid attacks)
64 loader = g.gdk.PixbufLoader('png')
65 try:
66 loader.write(file(maker.icon).read())
67 finally:
68 loader.close()
69 icon_pixbuf = loader.get_pixbuf()
70 except Exception, ex:
71 print >>sys.stderr, "Failed to load cached PNG icon: %s" % ex
72 else:
73 image.set_from_pixbuf(icon_pixbuf)
74 box.set_type('inode/directory', image)
75 box.show()
76 rox.mainloop()