def test(self): tmpdir = tempfile.mkdtemp(prefix='laymantmp_') makeconf = os.path.join(tmpdir, 'make.conf') reposconf = os.path.join(tmpdir, 'repos.conf') make_txt =\ 'PORTDIR_OVERLAY="\n'\ '$PORTDIR_OVERLAY"' # Create the .conf files so layman doesn't # complain. with fileopen(makeconf, 'w') as f: f.write(make_txt) with fileopen(reposconf, 'w') as f: f.write('') my_opts = { 'installed': HERE + '/testfiles/global-overlays.xml', 'make_conf': makeconf, 'nocheck': 'yes', 'storage': tmpdir, 'repos_conf': reposconf, 'conf_type': ['make.conf', 'repos.conf'], } config = OptionConfig(my_opts) config.set_option('quietness', 3) a = DB(config) config['output'].set_colorize(False) conf = RepoConfManager(config, a.overlays) # Set up our success tracker. success = [] # Add all the overlays in global_overlays.xml. for overlay in a.overlays.keys(): conf_success = conf.add(a.overlays[overlay]) if conf_success == False: success.append(False) else: success.append(True) # Disable one overlay. self.assertTrue(conf.disable(a.overlays['wrobel'])) # Enable disabled overlay. self.assertTrue(conf.enable(a.overlays['wrobel'])) # Delete all the overlays in global_overlays.xml. for overlay in a.overlays.keys(): self.assertTrue(conf.delete(a.overlays[overlay])) # Clean up. os.unlink(makeconf) os.unlink(reposconf) shutil.rmtree(tmpdir)
def test(self): tmpdir = tempfile.mkdtemp(prefix='laymantmp_') cache = os.path.join(tmpdir, 'cache') my_opts = { 'overlays': ['file://' + HERE + '/testfiles/global-overlays.xml'], 'cache': cache, 'nocheck': 'yes', 'proxy': None } config = OptionConfig(my_opts) db = RemoteDB(config) self.assertEqual(db.cache(), (True, True)) db_xml = fileopen(db.filepath(config['overlays']) + '.xml') test_line = ' A collection of ebuilds from Gunnar Wrobel '\ '[[email protected]].\n' self.assertEqual(db_xml.readlines()[19], test_line) for line in db_xml.readlines(): print(line, end='') db_xml.close() keys = sorted(db.overlays) self.assertEqual(keys, ['wrobel', 'wrobel-stable']) shutil.rmtree(tmpdir)
def __call__(self): self.args_parser() options = None if self.args.config: options = { 'config': self.args.config, } self.config = OptionConfig(options=options, root=self.root) # fix the config path defaults = self.config.get_defaults() defaults['config'] = defaults['config'] \ % {'configdir': defaults['configdir']} self.config.update_defaults({'config': defaults['config']}) self.config.read_config(defaults) layman_inst = LaymanAPI(config=self.config) self.output = layman_inst.output if self.args.setup_help: self.print_instructions() elif not self.check_is_new(self.args.rebuild): self.rename_check() if self.args.migrate_db: self.migrate_database(self.args.migrate_db)
def make_OptionConfig(self): my_opts = { 'overlays': ["http://www.gentoo-overlays.org/repositories.xml"] } new_defaults = {'configdir': '/etc/test-dir'} a = OptionConfig(options=my_opts, defaults=new_defaults) # Test components of the OptionConfig class: assertEqual(a['overlays'], self.test_url) assertEqual(a['configdir'], my_opts['configdir']) assertEqual(sorted(a), self.test_keys)
def __call__(self, overlay_package=None, path=None): if not overlay_package: self.args_parser() options = {} for key in vars(self.args): options[key] = vars(self.args)[key] self.config = OptionConfig(options=options) reload_config(self.config) self.auto_complete = False self.list_info = self.config.get_option('list_autocomplete') self.no_extra = self.config.get_option('no_extra') self.sudo = self.config.get_option('sudo') if self.list_info: self.list_templates() if self.args.set_autocomplete: if 'ALL' in self.args.set_autocomplete: self.templates = AUTOCOMPLETE_TEMPLATE.keys() self.auto_complete = True else: self.templates = self.args.set_autocomplete self.auto_complete = True msg = 'How many overlays would you like to create?: ' for x in range(1, int(get_input(msg)) + 1): self.output.notice('') self.output.info('Overlay #%(x)s: ' % ({'x': str(x)})) self.output.info('~~~~~~~~~~~~~') self.required = copy.deepcopy(COMPONENT_DEFAULTS) if not self.no_extra: self.output.notice('') self.update_required() self.output.notice('') self.get_overlay_components() ovl = Overlay.Overlay(config=self.config, ovl_dict=self.overlay, ignore=1) self.overlays.append((self.overlay['name'], ovl)) else: ovl_name, ovl = overlay_package self.overlays.append((ovl_name, ovl)) result = self.write(path) return result
def _get_layman_api(self): ''' Initializes layman api. @rtype layman.api.LaymanAPI instance ''' # Make it so that we aren't initializing the # LaymanAPI instance if it already exists and # if the current storage location hasn't been # changed for the new repository. self.storage = self.repo.location.replace(self.repo.name, '') if self._layman and self.storage in self.current_storage: return self._layman config = BareConfig() configdir = {'configdir': config.get_option('configdir')} self.message = Message(out=sys.stdout, err=sys.stderr) self.current_storage = self.storage options = { 'config': config.get_option('config') % (configdir), 'quiet': self.settings.get('PORTAGE_QUIET'), 'quietness': config.get_option('quietness'), 'overlay_defs': config.get_option('overlay_defs') % (configdir), 'output': self.message, 'nocolor': self.settings.get('NOCOLOR'), 'root': self.settings.get('EROOT'), 'storage': self.current_storage, 'verbose': self.settings.get('PORTAGE_VERBOSE'), 'width': self.settings.get('COLUMNWIDTH'), } self.config = OptionConfig(options=options, root=options['root']) # Reloads config to read custom overlay # xml files. reload_config(self.config) layman_api = LaymanAPI(self.config, report_errors=True, output=self.config['output']) self._layman = layman_api return layman_api
def test(self): tmpdir = tempfile.mkdtemp(prefix='laymantmp_') cache = os.path.join(tmpdir, 'cache') my_opts = { 'overlays': ['file://'\ + HERE + '/testfiles/global-overlays.xml'], 'db_type': 'xml', 'cache': cache, 'nocheck': 'yes', 'proxy': None, 'quietness': 3 } config = OptionConfig(my_opts) api = LaymanAPI(config) self.assertTrue(api.fetch_remote_list()) filename = api._get_remote_db().filepath(config['overlays']) + '.xml' with fileopen(filename, 'r') as b: description = b.readlines()[19] self.assertEqual(description, ' A collection of ebuilds from '\ 'Gunnar Wrobel [[email protected]].\n') for line in b.readlines(): print(line, end='') # Check if we get available overlays. available = api.get_available() self.assertEqual(available, ['wrobel', 'wrobel-stable']) # Test the info of an overlay. info = api.get_info_str(['wrobel'], verbose=True, local=False) test_info = 'wrobel\n~~~~~~\nSource : https://overlays.gentoo.org'\ '/svn/dev/wrobel\nContact : [email protected]\nType '\ ': Subversion; Priority: 10\nQuality : experimental\n\n'\ 'Description:\n Test\n' info = info['wrobel'][0].decode('utf-8') self.assertEqual(info, test_info) os.unlink(filename) shutil.rmtree(tmpdir)
def test(self): temp_dir_path = tempfile.mkdtemp() my_opts = { 'overlays': ['file://'\ + HERE + '/testfiles/global-overlays.xml'], 'nocheck': 'yes', 'proxy': None, 'quietness': 3, } config = OptionConfig(my_opts) ovl_dict = { 'name': 'wrobel', 'description': ['Test'], 'owner': [{ 'name': 'nobody', 'email': '*****@*****.**' }], 'status': 'official', 'source': [['https://overlays.gentoo.org/svn/dev/wrobel', 'svn', '']], 'priority': '10', } a = Overlay(config=config, ovl_dict=ovl_dict, ignore=config['ignore']) ovl = (ovl_dict['name'], a) path = temp_dir_path + '/overlay.xml' create_overlay_xml = Interactive(config=config) create_overlay_xml(overlay_package=ovl, path=path) self.assertTrue(os.path.exists(path)) with fileopen(path, 'r') as xml: test_line = ' <source type="svn">'\ 'https://overlays.gentoo.org/svn/dev/wrobel</source>\n' self.assertTrue(test_line in xml.readlines()) for line in xml.readlines(): print(line, end='') shutil.rmtree(temp_dir_path)
def test(self): repo_name = 'tar_test_overlay' temp_dir_path = tempfile.mkdtemp(prefix='laymantmp_') db_file = os.path.join(temp_dir_path, 'installed.xml') make_conf = os.path.join(temp_dir_path, 'make.conf') repo_conf = os.path.join(temp_dir_path, 'repos.conf') tar_source_path = os.path.join(HERE, 'testfiles', 'layman-test.tar.bz2') (_, temp_tarball_path) = tempfile.mkstemp() shutil.copyfile(tar_source_path, temp_tarball_path) # Write overlay collection XML xml_text = '''\ <?xml version="1.0" encoding="UTF-8"?> <repositories xmlns="" version="1.0"> <repo quality="experimental" status="unofficial"> <name>%(repo_name)s</name> <description>XXXXXXXXXXX</description> <owner> <email>[email protected]</email> </owner> <source type="tar">file://%(temp_tarball_url)s</source> </repo> </repositories> '''\ % { 'temp_tarball_url': urllib.pathname2url(temp_tarball_path), 'repo_name': repo_name } (fd, temp_xml_path) = tempfile.mkstemp() my_opts = { 'installed': temp_xml_path, 'conf_type': ['make.conf', 'repos.conf'], 'db_type': 'xml', 'nocheck': 'yes', 'make_conf': make_conf, 'repos_conf': repo_conf, 'storage': temp_dir_path, 'check_official': False } with os.fdopen(fd, 'w') as f: f.write(xml_text) with fileopen(make_conf, 'w') as f: f.write('PORTDIR_OVERLAY="$PORTDIR_OVERLAY"\n') with fileopen(repo_conf, 'w') as f: f.write('') config = OptionConfig(options=my_opts) config.set_option('quietness', 3) a = DB(config) config.set_option('installed', db_file) # Add an overlay to a fresh DB file. b = DB(config) b.add(a.select(repo_name)) # Make sure it's actually installed. specific_overlay_path = os.path.join(temp_dir_path, repo_name) self.assertTrue(os.path.exists(specific_overlay_path)) # Check the DbBase to ensure that it's reading the installed.xml. c = DbBase(config, paths=[ db_file, ]) self.assertEqual(list(c.overlays), ['tar_test_overlay']) # Make sure the configs have been written to correctly. conf = RepoConfManager(config, b.overlays) self.assertEqual(list(conf.overlays), ['tar_test_overlay']) # Delete the overlay from the second DB. b.delete(b.select(repo_name)) self.assertEqual(b.overlays, {}) # Ensure the installed.xml has been cleaned properly. c = DbBase(config, paths=[ db_file, ]) self.assertEqual(c.overlays, {}) conf = RepoConfManager(config, b.overlays) self.assertEqual(conf.overlays, {}) # Clean up. os.unlink(temp_xml_path) os.unlink(temp_tarball_path) shutil.rmtree(temp_dir_path)