[e696bf]: AppRun  Maximize  Restore  History

Download this file

80 lines (74 with data), 1.9 kB

#!/usr/bin/env python
import os, sys
import findrox; findrox.version(1, 9, 6)
from zeroinstall.injector.policy import Policy
import rox
from rox import g, processes, saving
from cStringIO import StringIO

def try_interface(uri):
	errors = StringIO()
	launcher = processes.PipeThroughCommand(
		["0launch", "-d", "--", uri],
		None, errors)
	try:
		launcher.wait()
	except processes.ChildError, ex:
		if '(256)' not in str(ex):
			rox.alert(str(ex))
	except:
		rox.report_exception()
	else:	
		return True
	return False

if len(sys.argv) == 1:
	# By default, create a bundle for ourselves
	uri = 'http://rox.sourceforge.net/2006/interfaces/Zero2Bundle.xml'
	if not try_interface(uri):
		sys.exit(1)
elif sys.argv[1] == '--prompt':
	from chooser import Chooser
	m = Chooser()
	while True:
		m.show()
		resp = m.run()
		if resp != g.RESPONSE_OK:
			sys.exit(1)
		m.hide()
		uri = m.uri.get_text()
		if try_interface(uri):
			break
	m.destroy()
elif len(sys.argv) == 2:
	uri = sys.argv[1]
	if not try_interface(uri):
		sys.exit(1)
else:
	rox.alert("Multiple arguments to Zero2Bundle (%s)!" % `sys.argv[1:]`)
	sys.exit(1)

policy = Policy(uri)
policy.freshness == 0
policy.recalculate()
assert policy.ready

from bundle import BundleMaker

maker = BundleMaker(policy)
default_name = os.path.basename(uri)
if default_name.endswith('.xml'):
	default_name = default_name[:-4]
box = saving.SaveBox(maker, default_name, 'inode/directory')
if maker.icon:
	image = g.Image()
	try:
		# Icon format must be PNG (to avoid attacks)
		loader = g.gdk.PixbufLoader('png')
		try:
			loader.write(file(maker.icon).read())
		finally:
			loader.close()
		icon_pixbuf = loader.get_pixbuf()
	except Exception, ex:
		print >>sys.stderr, "Failed to load cached PNG icon: %s" % ex
	else:
		image.set_from_pixbuf(icon_pixbuf)
		box.set_type('inode/directory', image)
box.show()
rox.mainloop()

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks