Esempio n. 1
0
    def create_app(self, name, requirements):
        """@type name: str
		@type requirements: L{zeroinstall.injector.requirements.Requirements}
		@rtype: L{App}"""
        validate_name(name)

        apps_dir = basedir.save_config_path(namespaces.config_site, "apps")
        app_dir = os.path.join(apps_dir, name)
        if os.path.isdir(app_dir):
            raise SafeException(
                _("Application '{name}' already exists: {path}").format(
                    name=name, path=app_dir))

        if self.config.handler.dry_run:
            print(
                _("[dry-run] would create directory {path}").format(
                    path=app_dir))
        else:
            os.mkdir(app_dir)

        app = App(self.config, app_dir)
        app.set_requirements(requirements)
        app.set_last_checked()

        return app
Esempio n. 2
0
def save_feed(feed):
    """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
	@since: 0.49"""
    feeds = basedir.save_config_path(config_site, config_prog, 'feeds')

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, 'feed-preferences', None)
    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)

    if feed.last_checked:
        root.setAttribute('last-checked', str(feed.last_checked))

    impls = feed.implementations.values()
    impls.sort()
    for impl in impls:
        if impl.user_stability:
            node = doc.createElementNS(XMLNS_IFACE, 'implementation')
            root.appendChild(node)
            node.setAttribute('user-stability', str(impl.user_stability))
            node.setAttribute('id', impl.id)

    _atomic_save(doc, feeds, feed.url)

    # Keep interfaces/ directory's mtime as a global timestamp to detect
    # if cached solution are stale
    ts = time.time()
    os.utime(basedir.save_cache_path(config_site, 'interfaces'), (ts, ts))
Esempio n. 3
0
def save_interface(interface):
	"""@type interface: L{zeroinstall.injector.model.Interface}"""
	user_overrides = basedir.save_config_path(config_site, config_prog, 'interfaces')

	impl = minidom.getDOMImplementation()
	doc = impl.createDocument(XMLNS_IFACE, 'interface-preferences', None)

	root = doc.documentElement
	root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)
	root.setAttribute('uri', interface.uri)

	if interface.stability_policy:
		root.setAttribute('stability-policy', str(interface.stability_policy))

	for feed in interface.extra_feeds:
		if feed.user_override:
			elem = doc.createElementNS(XMLNS_IFACE, 'feed')
			root.appendChild(elem)
			elem.setAttribute('src', feed.uri)
			if feed.arch:
				elem.setAttribute('arch', feed.arch)
			if feed.site_package:
				elem.setAttribute('is-site-package', 'True')

	_atomic_save(doc, user_overrides, interface.uri)
Esempio n. 4
0
    def save(self):
        from xml.dom import minidom
        import tempfile

        doc = minidom.Document()
        root = doc.createElementNS(XMLNS_TRUST, "trusted-keys")
        root.setAttribute("xmlns", XMLNS_TRUST)
        doc.appendChild(root)

        for fingerprint in self.keys:
            keyelem = doc.createElementNS(XMLNS_TRUST, "key")
            root.appendChild(keyelem)
            keyelem.setAttribute("fingerprint", fingerprint)
            for domain in self.keys[fingerprint]:
                domainelem = doc.createElementNS(XMLNS_TRUST, "domain")
                domainelem.setAttribute("value", domain)
                keyelem.appendChild(domainelem)

        d = basedir.save_config_path(config_site, config_prog)
        fd, tmpname = tempfile.mkstemp(dir=d, prefix="trust-")
        tmp = os.fdopen(fd, "wb")
        doc.writexml(tmp, indent="", addindent="  ", newl="\n")
        tmp.close()

        os.rename(tmpname, os.path.join(d, "trustdb.xml"))
Esempio n. 5
0
    def save(self):
        from xml.dom import minidom
        import tempfile

        doc = minidom.Document()
        root = doc.createElementNS(XMLNS_TRUST, 'trusted-keys')
        root.setAttribute('xmlns', XMLNS_TRUST)
        doc.appendChild(root)

        for fingerprint in self.keys:
            keyelem = doc.createElementNS(XMLNS_TRUST, 'key')
            root.appendChild(keyelem)
            keyelem.setAttribute('fingerprint', fingerprint)
            for domain in self.keys[fingerprint]:
                domainelem = doc.createElementNS(XMLNS_TRUST, 'domain')
                domainelem.setAttribute('value', domain)
                keyelem.appendChild(domainelem)

        d = basedir.save_config_path(config_site, config_prog)
        fd, tmpname = tempfile.mkstemp(dir=d, prefix='trust-')
        tmp = os.fdopen(fd, 'wb')
        doc.writexml(tmp, indent="", addindent="  ", newl="\n")
        tmp.close()

        os.rename(tmpname, os.path.join(d, 'trustdb.xml'))
Esempio n. 6
0
    def save(self):
        d = basedir.save_config_path(config_site, config_prog)
        db_file = os.path.join(d, 'trustdb.xml')
        if self._dry_run:
            print(
                _("[dry-run] would update trust database {file}").format(
                    file=db_file))
            return
        from xml.dom import minidom
        import tempfile

        doc = minidom.Document()
        root = doc.createElementNS(XMLNS_TRUST, 'trusted-keys')
        root.setAttribute('xmlns', XMLNS_TRUST)
        doc.appendChild(root)

        for fingerprint in self.keys:
            keyelem = doc.createElementNS(XMLNS_TRUST, 'key')
            root.appendChild(keyelem)
            keyelem.setAttribute('fingerprint', fingerprint)
            for domain in self.keys[fingerprint]:
                domainelem = doc.createElementNS(XMLNS_TRUST, 'domain')
                domainelem.setAttribute('value', domain)
                keyelem.appendChild(domainelem)

        with tempfile.NamedTemporaryFile(dir=d,
                                         prefix='trust-',
                                         delete=False,
                                         mode='wt') as tmp:
            doc.writexml(tmp,
                         indent="",
                         addindent="  ",
                         newl="\n",
                         encoding='utf-8')
        support.portable_rename(tmp.name, db_file)
Esempio n. 7
0
def save_interface(interface):
    """@type interface: L{zeroinstall.injector.model.Interface}"""
    user_overrides = basedir.save_config_path(config_site, config_prog,
                                              'interfaces')

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, 'interface-preferences', None)

    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)
    root.setAttribute('uri', interface.uri)

    if interface.stability_policy:
        root.setAttribute('stability-policy', str(interface.stability_policy))

    for feed in interface.extra_feeds:
        if feed.user_override:
            elem = doc.createElementNS(XMLNS_IFACE, 'feed')
            root.appendChild(elem)
            elem.setAttribute('src', feed.uri)
            if feed.arch:
                elem.setAttribute('arch', feed.arch)
            if feed.site_package:
                elem.setAttribute('is-site-package', 'True')

    _atomic_save(doc, user_overrides, interface.uri)
Esempio n. 8
0
	def save(self):
		d = basedir.save_config_path(config_site, config_prog)
		db_file = os.path.join(d, 'trustdb.xml')
		if self._dry_run:
			print(_("[dry-run] would update trust database {file}").format(file = db_file))
			return
		from xml.dom import minidom
		import tempfile

		doc = minidom.Document()
		root = doc.createElementNS(XMLNS_TRUST, 'trusted-keys')
		root.setAttribute('xmlns', XMLNS_TRUST)
		doc.appendChild(root)

		for fingerprint in self.keys:
			keyelem = doc.createElementNS(XMLNS_TRUST, 'key')
			root.appendChild(keyelem)
			keyelem.setAttribute('fingerprint', fingerprint)
			for domain in self.keys[fingerprint]:
				domainelem = doc.createElementNS(XMLNS_TRUST, 'domain')
				domainelem.setAttribute('value', domain)
				keyelem.appendChild(domainelem)

		with tempfile.NamedTemporaryFile(dir = d, prefix = 'trust-', delete = False, mode = 'wt') as tmp:
			doc.writexml(tmp, indent = "", addindent = "  ", newl = "\n", encoding = 'utf-8')
		support.portable_rename(tmp.name, db_file)
Esempio n. 9
0
def handle(args):
	cmd.find_config()
	config = cmd.load_config()

	path = join(basedir.save_config_path('0install.net', '0repo'), 'repositories.json')
	if os.path.exists(path):
		with open(path, 'rb') as stream:
			db = json.load(stream)
	else:
		db = {}
	
	existing = db.get(config.REPOSITORY_BASE_URL, None)

	entry = {'type': 'local', 'path': os.getcwd()}

	if existing and existing == entry:
		print("Already registered in {path} (no changes made):\n{base}: {json}".format(
			path = path,
			base = config.REPOSITORY_BASE_URL,
			json = json.dumps(entry)))
		return

	db[config.REPOSITORY_BASE_URL] = entry

	with open(path + '.new', 'wb') as stream:
		json.dump(db, stream)
	os.rename(path + '.new', path)
	
	if existing:
		print("Updated entry in {path} to:".format(path = path))
	else:
		print("Created new entry in {path}:".format(path = path))

	print("{base}: {json}".format(base = config.REPOSITORY_BASE_URL, json = json.dumps(entry)))
Esempio n. 10
0
    def testBadConfig(self):
        path = basedir.save_config_path(namespaces.config_site, namespaces.config_prog)
        glob = os.path.join(path, "global")
        assert not os.path.exists(glob)
        stream = open(glob, "w")
        stream.write("hello!")
        stream.close()

        logger.setLevel(logging.ERROR)
        Driver(requirements=Requirements(foo_iface_uri), config=self.config)
        logger.setLevel(logging.WARN)
Esempio n. 11
0
	def testBadConfig(self):
		path = basedir.save_config_path(namespaces.config_site,
						namespaces.config_prog)
		glob = os.path.join(path, 'global')
		assert not os.path.exists(glob)
		stream = open(glob, 'w')
		stream.write('hello!')
		stream.close()

		logger.setLevel(logging.ERROR)
		Driver(requirements = Requirements(foo_iface_uri), config = self.config)
		logger.setLevel(logging.WARN)
	def testBadConfig(self):
		path = basedir.save_config_path(namespaces.config_site,
						namespaces.config_prog)
		glob = os.path.join(path, 'global')
		assert not os.path.exists(glob)
		stream = file(glob, 'w')
		stream.write('hello!')
		stream.close()

		logger.setLevel(logging.ERROR)
		Policy(foo_iface_uri, config = self.config)
		logger.setLevel(logging.WARN)
Esempio n. 13
0
	def save_config(self):
		"""Write global settings."""
		config = ConfigParser.ConfigParser()
		config.add_section('global')

		config.set('global', 'help_with_testing', self.help_with_testing)
		config.set('global', 'network_use', self.network_use)
		config.set('global', 'freshness', self.freshness)

		path = basedir.save_config_path(config_site, config_prog)
		path = os.path.join(path, 'global')
		config.write(file(path + '.new', 'w'))
		os.rename(path + '.new', path)
Esempio n. 14
0
	def save_globals(self):
               """Write global settings."""
               parser = ConfigParser.ConfigParser()
               parser.add_section('global')

               parser.set('global', 'help_with_testing', self.help_with_testing)
               parser.set('global', 'network_use', self.network_use)
               parser.set('global', 'freshness', self.freshness)

               path = basedir.save_config_path(config_site, config_prog)
               path = os.path.join(path, 'global')
               parser.write(file(path + '.new', 'w'))
               os.rename(path + '.new', path)
Esempio n. 15
0
	def create_app(self, name, requirements):
		validate_name(name)

		apps_dir = basedir.save_config_path(namespaces.config_site, "apps")
		app_dir = os.path.join(apps_dir, name)
		if os.path.isdir(app_dir):
			raise SafeException(_("Application '{name}' already exists: {path}").format(name = name, path = app_dir))
		os.mkdir(app_dir)

		app = App(self.config, app_dir)
		app.set_requirements(requirements)
		app.set_last_checked()

		return app
Esempio n. 16
0
	def save_globals(self):
		"""Write global settings."""
		parser = ConfigParser.ConfigParser()
		parser.add_section('global')

		parser.set('global', 'help_with_testing', self.help_with_testing)
		parser.set('global', 'network_use', self.network_use)
		parser.set('global', 'freshness', self.freshness)
		parser.set('global', 'auto_approve_keys', self.auto_approve_keys)

		path = basedir.save_config_path(config_site, config_prog)
		path = os.path.join(path, 'global')
		parser.write(open(path + '.new', 'w'))
		os.rename(path + '.new', path)
Esempio n. 17
0
	def save_globals(self):
		"""Write global settings."""
		parser = ConfigParser.ConfigParser()
		parser.add_section('global')

		parser.set('global', 'help_with_testing', str(self.help_with_testing))
		parser.set('global', 'network_use', self.network_use)
		parser.set('global', 'freshness', str(self.freshness))
		parser.set('global', 'auto_approve_keys', str(self.auto_approve_keys))

		path = basedir.save_config_path(config_site, config_prog)
		path = os.path.join(path, 'global')
		with open(path + '.new', 'wt') as stream:
			parser.write(stream)
		support.portable_rename(path + '.new', path)
Esempio n. 18
0
    def create_app(self, name, requirements):
        validate_name(name)

        apps_dir = basedir.save_config_path(namespaces.config_site, "apps")
        app_dir = os.path.join(apps_dir, name)
        if os.path.isdir(app_dir):
            raise SafeException(
                _("Application '{name}' already exists: {path}").format(
                    name=name, path=app_dir))
        os.mkdir(app_dir)

        app = App(self.config, app_dir)
        app.set_requirements(requirements)
        app.set_last_checked()

        return app
Esempio n. 19
0
    def save_globals(self):
        """Write global settings."""
        parser = ConfigParser.ConfigParser()
        parser.add_section('global')

        parser.set('global', 'help_with_testing', str(self.help_with_testing))
        parser.set('global', 'network_use', self.network_use)
        parser.set('global', 'freshness', str(self.freshness))
        parser.set('global', 'auto_approve_keys', str(self.auto_approve_keys))
        if self.key_info_server != DEFAULT_KEY_LOOKUP_SERVER:
            parser.set('global', 'key_info_server', str(self.key_info_server))

        path = basedir.save_config_path(config_site, config_prog)
        path = os.path.join(path, 'global')
        with open(path + '.new', 'wt') as stream:
            parser.write(stream)
        support.portable_rename(path + '.new', path)
Esempio n. 20
0
    def setUp(self):
        os.chdir("/")
        self.tmpdir = tempfile.mkdtemp(prefix="0compile-test-")
        self.hello_dir = os.path.join(self.tmpdir, "hello")

        os.environ["HOME"] = self.tmpdir
        reload(basedir)

        config_dir = basedir.save_config_path("0install.net", "injector")
        stream = open(os.path.join(config_dir, "implementation-dirs"), "w")
        for x in stores.stores:
            stream.write(x.dir + "\n")
        stream.close()

        stream = open(os.path.join(config_dir, "global"), "w")
        stream.write("[global]\n" "freshness = -1\n" "help_with_testing = True\n" "network_use = off-line\n")
        stream.close()
Esempio n. 21
0
    def setUp(self):
        os.chdir('/')
        self.tmpdir = tempfile.mkdtemp(prefix='0compile-test-')
        self.hello_dir = os.path.join(self.tmpdir, 'hello')

        os.environ['HOME'] = self.tmpdir
        reload(basedir)

        config_dir = basedir.save_config_path('0install.net', 'injector')
        stream = open(os.path.join(config_dir, 'implementation-dirs'), 'w')
        for x in stores.stores:
            stream.write(x.dir + '\n')
        stream.close()

        stream = open(os.path.join(config_dir, 'global'), 'w')
        stream.write('[global]\n'
                     'freshness = -1\n'
                     'help_with_testing = True\n'
                     'network_use = off-line\n')
        stream.close()
Esempio n. 22
0
def save_interface(interface):
	user_overrides = basedir.save_config_path(config_site, config_prog, 'user_overrides')

	impl = minidom.getDOMImplementation()
	doc = impl.createDocument(XMLNS_IFACE, 'interface-preferences', None)

	root = doc.documentElement
	root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)
	root.setAttribute('uri', interface.uri)

	if interface.stability_policy:
		root.setAttribute('stability-policy', str(interface.stability_policy))

	if interface.last_checked:
		root.setAttribute('last-checked', str(interface.last_checked))

	impls = interface.implementations.values()
	impls.sort()
	for impl in impls:
		_add_impl(root, impl)
	
	for feed in interface.extra_feeds:
		if feed.user_override:
			elem = doc.createElementNS(XMLNS_IFACE, 'feed')
			root.appendChild(elem)
			elem.setAttribute('src', feed.uri)
			if feed.arch:
				elem.setAttribute('arch', feed.arch)

	import tempfile
	tmp_fd, tmp_name = tempfile.mkstemp(dir = user_overrides)
	try:
		tmp_file = os.fdopen(tmp_fd, 'w')
		doc.writexml(tmp_file, addindent = " ", newl = '\n')
		tmp_file.close()
		path = os.path.join(user_overrides, escape(interface.uri))
		os.rename(tmp_name, path)
		os.chmod(path, 0660)
	except:
		os.unlink(tmp_name)
		raise
Esempio n. 23
0
	def create_app(self, name, requirements):
		"""@type name: str
		@type requirements: L{zeroinstall.injector.requirements.Requirements}
		@rtype: L{App}"""
		validate_name(name)

		apps_dir = basedir.save_config_path(namespaces.config_site, "apps")
		app_dir = os.path.join(apps_dir, name)
		if os.path.isdir(app_dir):
			raise SafeException(_("Application '{name}' already exists: {path}").format(name = name, path = app_dir))

		if self.config.handler.dry_run:
			print(_("[dry-run] would create directory {path}").format(path = app_dir))
		else:
			os.mkdir(app_dir)

		app = App(self.config, app_dir)
		app.set_requirements(requirements)
		app.set_last_checked()

		return app
Esempio n. 24
0
def save_interface(interface):
    user_overrides = basedir.save_config_path(config_site, config_prog, "interfaces")

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, "interface-preferences", None)

    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, "xmlns", XMLNS_IFACE)
    root.setAttribute("uri", interface.uri)

    if interface.stability_policy:
        root.setAttribute("stability-policy", str(interface.stability_policy))

    for feed in interface.extra_feeds:
        if feed.user_override:
            elem = doc.createElementNS(XMLNS_IFACE, "feed")
            root.appendChild(elem)
            elem.setAttribute("src", feed.uri)
            if feed.arch:
                elem.setAttribute("arch", feed.arch)

    _atomic_save(doc, user_overrides, interface.uri)
Esempio n. 25
0
def save_feed(feed):
    """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
	@since: 0.49"""
    feeds = basedir.save_config_path(config_site, config_prog, "feeds")

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, "feed-preferences", None)
    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, "xmlns", XMLNS_IFACE)

    if feed.last_checked:
        root.setAttribute("last-checked", str(feed.last_checked))

    impls = feed.implementations.values()
    impls.sort()
    for impl in impls:
        if impl.user_stability:
            node = doc.createElementNS(XMLNS_IFACE, "implementation")
            root.appendChild(node)
            node.setAttribute("user-stability", str(impl.user_stability))
            node.setAttribute("id", impl.id)

    _atomic_save(doc, feeds, feed.url)
Esempio n. 26
0
def handle(args):
    cmd.find_config()
    config = cmd.load_config()

    path = join(basedir.save_config_path('0install.net', '0repo'),
                'repositories.json')
    if os.path.exists(path):
        with open(path, 'rb') as stream:
            db = json.load(stream)
    else:
        db = {}

    existing = db.get(config.REPOSITORY_BASE_URL, None)

    entry = {'type': 'local', 'path': os.getcwd()}

    if existing and existing == entry:
        print(
            "Already registered in {path} (no changes made):\n{base}: {json}".
            format(path=path,
                   base=config.REPOSITORY_BASE_URL,
                   json=json.dumps(entry)))
        return

    db[config.REPOSITORY_BASE_URL] = entry

    with open(path + '.new', 'w') as stream:
        json.dump(db, stream)
    support.portable_rename(path + '.new', path)

    if existing:
        print("Updated entry in {path} to:".format(path=path))
    else:
        print("Created new entry in {path}:".format(path=path))

    print("{base}: {json}".format(base=config.REPOSITORY_BASE_URL,
                                  json=json.dumps(entry)))
Esempio n. 27
0
def save_feed(feed):
	"""Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
	@type feed: L{zeroinstall.injector.model.ZeroInstallFeed}
	@since: 0.49"""
	feeds = basedir.save_config_path(config_site, config_prog, 'feeds')

	impl = minidom.getDOMImplementation()
	doc = impl.createDocument(XMLNS_IFACE, 'feed-preferences', None)
	root = doc.documentElement
	root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)

	if feed.last_checked:
		root.setAttribute('last-checked', str(feed.last_checked))

	impls = list(feed.implementations.values())
	impls.sort()
	for impl in impls:
		if impl.user_stability:
			node = doc.createElementNS(XMLNS_IFACE, 'implementation')
			root.appendChild(node)
			node.setAttribute('user-stability', str(impl.user_stability))
			node.setAttribute('id', impl.id)

	_atomic_save(doc, feeds, feed.url)
Esempio n. 28
0
def save_feed(feed):
    """Save information about a feed. Currently, this is the last_checked time and any user-set stability ratings.
	@type feed: L{zeroinstall.injector.model.ZeroInstallFeed}
	@since: 0.49"""
    feeds = basedir.save_config_path(config_site, config_prog, 'feeds')

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, 'feed-preferences', None)
    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)

    if feed.last_checked:
        root.setAttribute('last-checked', str(feed.last_checked))

    impls = list(feed.implementations.values())
    impls.sort()
    for impl in impls:
        if impl.user_stability:
            node = doc.createElementNS(XMLNS_IFACE, 'implementation')
            root.appendChild(node)
            node.setAttribute('user-stability', str(impl.user_stability))
            node.setAttribute('id', impl.id)

    _atomic_save(doc, feeds, feed.url)