Diff of /bundle.py [6f07ed] .. [e696bf] Maximize Restore

  Switch to side-by-side view

--- a/bundle.py
+++ b/bundle.py
@@ -6,23 +6,22 @@
 import tempfile, shutil
 from zeroinstall.injector.model import EnvironmentBinding
 from zeroinstall.injector.iface_cache import iface_cache
-import __main__
 
-def iface_to_dir_name(iface_uri):
+zero2bundle_uri = "http://rox.sourceforge.net/2006/interfaces/Zero2Bundle"
+
+def iface_to_dir_name(iface):
 	"""Pick a directory name for this interface's implementation."""
-	feed = iface_cache.get_feed(iface_uri)
-	assert feed
-	return feed.get_name().replace(' ', '_').replace('/', '-')
+	return iface.get_name().replace(' ', '_').replace('/', '-')
 
 class BundleMaker(saving.Saveable):
-	def __init__(self, sels):
-		assert sels
+	def __init__(self, policy):
+		assert policy.ready
 
-		self.sels = sels
-		iface = iface_cache.get_interface(sels.interface)
+		self.policy = policy
+		iface = self.policy.get_interface(policy.root)
 		self.icon = iface_cache.get_icon_path(iface)
 
-		self.impl = sels.selections[sels.interface]
+		self.impl = self.policy.implementation[iface]
 		if hasattr(self.impl, 'main'):
 			self.main = self.impl.main
 		else:
@@ -34,8 +33,12 @@
 
 	def save_to_file(self, path):
 		os.mkdir(path)
-		iface_uri = self.sels.interface
-		assert "'" not in iface_uri
+		assert "'" not in self.policy.root
+		if self.policy.root == 'http://rox.sourceforge.net/2005/interfaces/AddApp':
+			# Funky special case: Zero2Bundle behaves differently when run through AppRun
+			options = '--prompt'
+		else:
+			options = ''
 
 		apprun = os.fdopen(os.open(os.path.join(path, 'AppRun'), os.O_CREAT | os.O_WRONLY, 0777), 'w')
 		apprun.write("""#!/bin/sh
@@ -43,23 +46,25 @@
 APP_DIR=`dirname "$0"`
 """)
 
+		iface = self.policy.get_interface(self.policy.root)
+			
 		# Copy each implementation into the bundle and set any
 		# environment variables required to find it
 		bindings = []
-		for needed_iface, impl in self.sels.selections.iteritems():
+		for needed_iface in self.policy.implementation:
+			impl = self.policy.implementation[needed_iface]
 			impl_copy = os.path.join(path, iface_to_dir_name(needed_iface))
 			assert impl
-			assert impl.digests, "No digest for %s" % (impl)	# TODO: --no-local?
-			shutil.copytree(iface_cache.stores.lookup_any(impl.digests), impl_copy)
+			shutil.copytree(self.policy.get_implementation_path(impl), impl_copy)
 
-			for dep in impl.dependencies:
+			for dep in impl.dependencies.values():
 				for b in dep.bindings:
 					bindings.append((dep, b))
 
 		for (dep, binding) in bindings:
+			dep_iface = self.policy.get_interface(dep.interface)
 			if isinstance(b, EnvironmentBinding):
-				dep_name = os.path.join(iface_to_dir_name(dep.interface), b.insert)
-				# XXX: mode?
+				dep_name = os.path.join(iface_to_dir_name(dep_iface), b.insert)
 				apprun.write("""
 if [ "x$%s" = x ]; then
   %s="$APP_DIR/%s"
@@ -68,32 +73,27 @@
 fi
 export %s
 """ % (b.name, b.name, dep_name, b.name, dep_name, b.name, b.name))
+				dep_impl = self.policy.get_implementation(dep_iface)
 			else:
 				print >>sys.stderr, "Warning: unknown binding type " + b
 		
-		root_impl = self.sels.selections[self.sels.interface]
+		root_iface = self.policy.get_interface(self.policy.root)
+		root_impl = self.policy.get_implementation(root_iface)
 
-		impl_apprun = os.path.join(iface_to_dir_name(self.sels.interface), root_impl.main)
-		apprun.write('exec "$APP_DIR/%s" "$@"\n' % impl_apprun)
+		impl_apprun = os.path.join(iface_to_dir_name(root_iface), root_impl.main)
+		apprun.write('exec "$APP_DIR/%s"\n' % impl_apprun)
 
 		apprun.close()
 
 		if self.icon:
 			shutil.copyfile(self.icon, os.path.join(path, '.DirIcon'))
 
-		impl_path = iface_cache.stores.lookup_any(root_impl.digests)
-		assert impl_path
-		applet_run = os.path.join(impl_path, os.path.dirname(root_impl.main), 'AppletRun')
-		if os.path.exists(applet_run):
+		if self.is_applet(root_iface):
 			os.symlink('AppRun', os.path.join(path, 'AppletRun'))
 
 		appinfo = os.path.join(os.path.dirname(impl_apprun), 'AppInfo.xml')
 		if os.path.exists(os.path.join(path, appinfo)):
 			os.symlink(appinfo, os.path.join(path, 'AppInfo.xml'))
-
-		help = os.path.join(os.path.dirname(impl_apprun), 'Help')
-		if os.path.exists(os.path.join(path, help)):
-			os.symlink(help, os.path.join(path, 'Help'))
 
 	def add_item(self, menu, option, labels):
 		doc = menu.ownerDocument
@@ -118,3 +118,10 @@
 		item = parent.ownerDocument.createElement(name)
 		parent.appendChild(item)
 		return item
+
+	def is_applet(self, iface):
+		impl_path = self.policy.get_implementation_path(self.impl)
+		assert impl_path
+
+		applet_run = os.path.join(impl_path, os.path.dirname(self.main), 'AppletRun')
+		return os.path.exists(applet_run)