예제 #1
0
	def testSitePackages(self):
		# The old system (0install < 1.9):
		# - 0compile stores implementations to ~/.cache, and 
		# - adds to extra_feeds
		#
		# The middle system (0install 1.9..1.12)
		# - 0compile stores implementations to ~/.local/0install.net/site-packages
		#   but using an obsolete escaping scheme, and
		# - modern 0install finds them via extra_feeds
		#
		# The new system (0install >= 1.13):
		# - 0compile stores implementations to ~/.local/0install.net/site-packages, and
		# - 0install finds them automatically

		# For backwards compatibility, 0install >= 1.9:
		# - writes discovered feeds to extra_feeds
		# - skips such entries in extra_feeds when loading

		expected_escape = 'section__prog_5f_1.xml'

		meta_dir = basedir.save_data_path('0install.net', 'site-packages',
						   'http', 'example.com', expected_escape, '1.0', '0install')
		feed = os.path.join(meta_dir, 'feed.xml')
		shutil.copyfile(os.path.join(mydir, 'Local.xml'), feed)

		# Check that we find the feed without us having to register it
		iface = self.config.iface_cache.get_interface('http://example.com/section/prog_1.xml')
		self.assertEqual(1, len(iface.extra_feeds))
		site_feed, = iface.extra_feeds
		self.assertEqual(True, site_feed.site_package)

		# Check that we write it out, so that older 0installs can find it
		writer.save_interface(iface)

		config_file = basedir.load_first_config('0install.net', 'injector',
							'interfaces', 'http:##example.com#section#prog_1.xml')
		with open(config_file, 'rb') as s:
			doc = qdom.parse(s)

		feed_node = None
		for item in doc.childNodes:
			if item.name == 'feed':
				feed_node = item
		self.assertEqual('True', feed_node.getAttribute('is-site-package'))

		# Check we ignore this element
		iface.reset()
		self.assertEqual([], iface.extra_feeds)
		reader.update_user_overrides(iface)
		self.assertEqual([], iface.extra_feeds)

		# Check feeds are automatically removed again
		reader.update_from_cache(iface, iface_cache = self.config.iface_cache)
		self.assertEqual(1, len(iface.extra_feeds))
		shutil.rmtree(basedir.load_first_data('0install.net', 'site-packages',
							'http', 'example.com', expected_escape))

		reader.update_from_cache(iface, iface_cache = self.config.iface_cache)
		self.assertEqual(0, len(iface.extra_feeds))
예제 #2
0
	def testSitePackages(self):
		# The old system (0install < 1.9):
		# - 0compile stores implementations to ~/.cache, and 
		# - adds to extra_feeds
		# The new system (0install >= 1.9):
		# - 0compile stores implementations to ~/.local/0install.net/site-packages, and
		# - 0install finds them automatically

		# For backwards compatibility, 0install >= 1.9:
		# - writes discovered feeds to extra_feeds
		# - skips such entries in extra_feeds when loading

		meta_dir = basedir.save_data_path('0install.net', 'site-packages',
						   'http:##example.com#prog.xml', '1.0', '0install')
		feed = os.path.join(meta_dir, 'feed.xml')
		shutil.copyfile(os.path.join(mydir, 'Local.xml'), feed)

		# Check that we find the feed without us having to register it
		iface = self.config.iface_cache.get_interface('http://example.com/prog.xml')
		self.assertEqual(1, len(iface.extra_feeds))
		site_feed, = iface.extra_feeds
		self.assertEqual(True, site_feed.site_package)

		# Check that we write it out, so that older 0installs can find it
		writer.save_interface(iface)

		config_file = basedir.load_first_config('0install.net', 'injector',
							'interfaces', 'http:##example.com#prog.xml')
		with open(config_file, 'rb') as s:
			doc = qdom.parse(s)

		feed_node = None
		for item in doc.childNodes:
			if item.name == 'feed':
				feed_node = item
		self.assertEqual('True', feed_node.getAttribute('site-package'))

		# Check we ignore this element
		iface.reset()
		self.assertEqual([], iface.extra_feeds)
		reader.update_user_overrides(iface)
		self.assertEqual([], iface.extra_feeds)

		# Check feeds are automatically removed again
		reader.update_from_cache(iface, iface_cache = self.config.iface_cache)
		self.assertEqual(1, len(iface.extra_feeds))
		shutil.rmtree(basedir.load_first_data('0install.net', 'site-packages',
							'http:##example.com#prog.xml'))

		reader.update_from_cache(iface, iface_cache = self.config.iface_cache)
		self.assertEqual(0, len(iface.extra_feeds))
예제 #3
0
	def compile_and_register(self, sels, forced_iface_uri = None):
		"""If forced_iface_uri, register as an implementation of this interface,
		ignoring the any <feed-for>, etc."""

		buildenv = BuildEnv(need_config = False)
		buildenv.config.set('compile', 'interface', sels.interface)
		buildenv.config.set('compile', 'selections', 'selections.xml')
		
		# Download any required packages now, so we can use the GUI to request confirmation, etc
		download_missing = sels.download_missing(self.config, include_packages = True)
		if download_missing:
			yield download_missing
			tasks.check(download_missing)

		tmpdir = tempfile.mkdtemp(prefix = '0compile-')
		try:
			os.chdir(tmpdir)

			# Write configuration for build...

			buildenv.save()

			sel_file = open('selections.xml', 'w')
			try:
				doc = sels.toDOM()
				doc.writexml(sel_file)
				sel_file.write('\n')
			finally:
				sel_file.close()

			# Do the build...

			build = self.spawn_build(buildenv.iface_name)
			if build:
				yield build
				tasks.check(build)

			# Register the result...
			dom = minidom.parse(buildenv.local_iface_file)

			feed_for_elem, = dom.getElementsByTagNameNS(namespaces.XMLNS_IFACE, 'feed-for')
			claimed_iface = feed_for_elem.getAttribute('interface')

			if forced_iface_uri is not None:
				if forced_iface_uri != claimed_iface:
					self.note("WARNING: registering as feed for {forced}, though feed claims to be for {claimed}".format(
						forced = forced_iface_uri,
						claimed = claimed_iface))
			else:
				forced_iface_uri = claimed_iface		# (the top-level interface being built)

			version = sels.selections[sels.interface].version

			site_package_versions_dir = basedir.save_data_path('0install.net', 'site-packages',
						*model.escape_interface_uri(forced_iface_uri))
			leaf =  '%s-%s' % (version, uname[4])
			site_package_dir = os.path.join(site_package_versions_dir, leaf)
			self.note("Storing build in %s" % site_package_dir)

			# 1. Copy new version in under a temporary name. Names starting with '.' are ignored by 0install.
			tmp_distdir = os.path.join(site_package_versions_dir, '.new-' + leaf)
			shutil.copytree(buildenv.distdir, tmp_distdir, symlinks = True)

			# 2. Rename the previous build to .old-VERSION (deleting that if it already existed)
			if os.path.exists(site_package_dir):
				self.note("(moving previous build out of the way)")
				previous_build_dir = os.path.join(site_package_versions_dir, '.old-' + leaf)
				if os.path.exists(previous_build_dir):
					shutil.rmtree(previous_build_dir)
				os.rename(site_package_dir, previous_build_dir)
			else:
				previous_build_dir = None

			# 3. Rename the new version immediately after renaming away the old one to minimise time when there's
			# no version.
			os.rename(tmp_distdir, site_package_dir)

			# 4. Delete the old version.
			if previous_build_dir:
				self.note("(deleting previous build)")
				shutil.rmtree(previous_build_dir)

			local_feed = os.path.join(site_package_dir, '0install', 'feed.xml')
			assert os.path.exists(local_feed), "Feed %s not found!" % local_feed

			# Reload - our 0install will detect the new feed automatically
			iface = self.config.iface_cache.get_interface(forced_iface_uri)
			reader.update_from_cache(iface, iface_cache = self.config.iface_cache)
			self.config.iface_cache.get_feed(local_feed, force = True)

			# Write it out - 0install will add the feed so that older 0install versions can find it
			writer.save_interface(iface)
		except:
			self.note("\nBuild failed: leaving build directory %s for inspection...\n" % tmpdir)
			raise
		else:
			# Can't delete current directory on Windows, so move to parent first
			os.chdir(os.path.join(tmpdir, os.path.pardir))

			ro_rmtree(tmpdir)
예제 #4
0
    def compile_and_register(self, sels, forced_iface_uri=None):
        """If forced_iface_uri, register as an implementation of this interface,
		ignoring the any <feed-for>, etc."""

        buildenv = BuildEnv(need_config=False)
        buildenv.config.set('compile', 'interface', sels.interface)
        buildenv.config.set('compile', 'selections', 'selections.xml')

        # Download any required packages now, so we can use the GUI to request confirmation, etc
        download_missing = sels.download_missing(self.config,
                                                 include_packages=True)
        if download_missing:
            yield download_missing
            tasks.check(download_missing)

        tmpdir = tempfile.mkdtemp(prefix='0compile-')
        try:
            os.chdir(tmpdir)

            # Write configuration for build...

            buildenv.save()

            sel_file = open('selections.xml', 'w')
            try:
                doc = sels.toDOM()
                doc.writexml(sel_file)
                sel_file.write('\n')
            finally:
                sel_file.close()

            # Do the build...

            build = self.spawn_build(buildenv.iface_name)
            if build:
                yield build
                tasks.check(build)

            # Register the result...
            dom = minidom.parse(buildenv.local_iface_file)

            feed_for_elem, = dom.getElementsByTagNameNS(
                namespaces.XMLNS_IFACE, 'feed-for')
            claimed_iface = feed_for_elem.getAttribute('interface')

            if forced_iface_uri is not None:
                if forced_iface_uri != claimed_iface:
                    self.note(
                        "WARNING: registering as feed for {forced}, though feed claims to be for {claimed}"
                        .format(forced=forced_iface_uri,
                                claimed=claimed_iface))
            else:
                forced_iface_uri = claimed_iface  # (the top-level interface being built)

            version = sels.selections[sels.interface].version

            site_package_versions_dir = basedir.save_data_path(
                '0install.net', 'site-packages',
                *model.escape_interface_uri(forced_iface_uri))
            leaf = '%s-%s' % (version, build_target_machine_type)
            site_package_dir = os.path.join(site_package_versions_dir, leaf)
            self.note("Storing build in %s" % site_package_dir)

            # 1. Copy new version in under a temporary name. Names starting with '.' are ignored by 0install.
            tmp_distdir = os.path.join(site_package_versions_dir,
                                       '.new-' + leaf)
            shutil.copytree(buildenv.distdir, tmp_distdir, symlinks=True)

            # 2. Rename the previous build to .old-VERSION (deleting that if it already existed)
            if os.path.exists(site_package_dir):
                self.note("(moving previous build out of the way)")
                previous_build_dir = os.path.join(site_package_versions_dir,
                                                  '.old-' + leaf)
                if os.path.exists(previous_build_dir):
                    shutil.rmtree(previous_build_dir)
                os.rename(site_package_dir, previous_build_dir)
            else:
                previous_build_dir = None

            # 3. Rename the new version immediately after renaming away the old one to minimise time when there's
            # no version.
            os.rename(tmp_distdir, site_package_dir)

            # 4. Delete the old version.
            if previous_build_dir:
                self.note("(deleting previous build)")
                shutil.rmtree(previous_build_dir)

            local_feed = os.path.join(site_package_dir, '0install', 'feed.xml')
            assert os.path.exists(
                local_feed), "Feed %s not found!" % local_feed

            # Reload - our 0install will detect the new feed automatically
            iface = self.config.iface_cache.get_interface(forced_iface_uri)
            reader.update_from_cache(iface,
                                     iface_cache=self.config.iface_cache)
            self.config.iface_cache.get_feed(local_feed, force=True)

            # Write it out - 0install will add the feed so that older 0install versions can find it
            writer.save_interface(iface)

            seen_key = (forced_iface_uri, sels.selections[sels.interface].id)
            assert seen_key not in self.seen, seen_key
            self.seen[seen_key] = site_package_dir
        except:
            self.note(
                "\nBuild failed: leaving build directory %s for inspection...\n"
                % tmpdir)
            raise
        else:
            # Can't delete current directory on Windows, so move to parent first
            os.chdir(os.path.join(tmpdir, os.path.pardir))

            ro_rmtree(tmpdir)