[a70355]: AppRun Maximize Restore History

Download this file

AppRun    70 lines (63 with data), 1.6 kB

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

zero2bundle_uri = "http://rox.sourceforge.net/2006/interfaces/Zero2Bundle.xml"

def try_interface(uri):
	errors = StringIO()
	try:
		sels = get_selections_gui(uri, ["--download-only"])
	except:
		rox.report_exception()
	else:	
		return sels
	return False

if len(sys.argv) == 1:
	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()
		sels = try_interface(uri)
		if sels:
			break
	m.destroy()
elif len(sys.argv) == 2:
	uri = sys.argv[1]
	sels = try_interface(uri)
	if not sels:
		sys.exit(1)
else:
	rox.alert("Multiple arguments to Zero2Bundle (%s)!" % `sys.argv[1:]`)
	sys.exit(1)

print sels

from bundle import BundleMaker

maker = BundleMaker(sels)
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()