def read_db(self): output = Message() # First test if XML databasing works. config = { 'output': output, 'db_type': 'xml', } db = DbBase(config, [ HERE + '/testfiles/global-overlays.xml', ]) keys = sorted(db.overlays) self.assertEqual(keys, ['wrobel', 'wrobel-stable']) url = ['rsync://gunnarwrobel.de/wrobel-stable'] self.assertEqual(list(db.overlays['wrobel-stable'].source_uris()), url) # Test JSON databasing after. config['db_type'] = 'json' db = DbBase(config, [ HERE + '/testfiles/global-overlays.json', ]) keys = sorted(db.overlays) self.assertEqual(keys, ['twitch153', 'wrobel-stable']) url = ['git://github.com/twitch153/ebuilds.git'] self.assertEqual(list(db.overlays['twitch153'].source_uris()), url)
def _run(self, number): #config = {'output': Message()} config = BareConfig() # Discuss renaming files to "branch-%d.xml" filename1 = os.path.join(HERE, 'testfiles', 'subpath-%d.xml' % number) # Read, write, re-read, compare os1 = DbBase(config, [filename1]) filename2 = tempfile.mkstemp()[1] os1.write(filename2) os2 = DbBase(config, [filename2]) os.unlink(filename2) self.assertTrue(os1 == os2) # Pass original overlays return os1
def select_db(self): output = Message() config = { 'output': output, 'db_type': 'xml', } db = DbBase(config, [ HERE + '/testfiles/global-overlays.xml', ]) url = ['rsync://gunnarwrobel.de/wrobel-stable'] self.assertEqual(list(db.select('wrobel-stable').source_uris()), url) config['db_type'] = 'json' db = DbBase(config, [ HERE + '/testfiles/global-overlays.json', ]) url = ['git://github.com/twitch153/ebuilds.git'] self.assertEqual(list(db.select('twitch153').source_uris()), url)
def _overlays_bug(self, number): config = BareConfig() filename = os.path.join(HERE, 'testfiles', 'overlays_bug_%d.xml'\ % number) o = DbBase(config, [filename]) for verbose in (True, False): for t in o.list(verbose=verbose): print(t[0].decode('utf-8')) print()
def test(self): archives = [] try: from layman.overlays.modules.tar.tar import TarOverlay archives.append('tar') from layman.overlays.modules.squashfs.squashfs import SquashfsOverlay archives.append('squashfs') except ImportError: pass for archive in archives: xml_text, repo_name, temp_archive_path = getattr( self, "_create_%(archive)s_overlay" % {'archive': archive})() (fd, temp_collection_path) = tempfile.mkstemp() with os.fdopen(fd, 'w') as f: f.write(xml_text) # Make playground directory temp_dir_path = tempfile.mkdtemp() # Make DB from it config = BareConfig() # Necessary for all mountable overlay types layman_inst = LaymanAPI(config=config) db = DbBase(config, [temp_collection_path]) specific_overlay_path = os.path.join(temp_dir_path, repo_name) o = db.select(repo_name) # Actual testcase o.add(temp_dir_path) self.assertTrue(os.path.exists(specific_overlay_path)) # (1/2) Sync with source available o.sync(temp_dir_path) self.assertTrue(os.path.exists(specific_overlay_path)) os.unlink(temp_archive_path) try: # (2/2) Sync with source _not_ available o.sync(temp_dir_path) except: pass self.assertTrue(os.path.exists(specific_overlay_path)) o.delete(temp_dir_path) self.assertFalse(os.path.exists(specific_overlay_path)) # Cleanup os.unlink(temp_collection_path) os.rmdir(temp_dir_path)
def write_db(self): tmpdir = tempfile.mkdtemp(prefix='laymantmp_') test_xml = os.path.join(tmpdir, 'test.xml') test_json = os.path.join(tmpdir, 'test.json') config = BareConfig() a = DbBase(config, [ HERE + '/testfiles/global-overlays.xml', ]) b = DbBase({ 'output': Message(), 'db_type': 'xml' }, [ test_xml, ]) b.overlays['wrobel-stable'] = a.overlays['wrobel-stable'] b.write(test_xml) c = DbBase({ 'output': Message(), 'db_type': 'xml' }, [ test_xml, ]) keys = sorted(c.overlays) self.assertEqual(keys, ['wrobel-stable']) config.set_option('db_type', 'json') a = DbBase(config, [ HERE + '/testfiles/global-overlays.json', ]) b = DbBase({ 'output': Message(), 'db_type': 'json' }, [ test_json, ]) b.overlays['twitch153'] = a.overlays['twitch153'] b.write(test_json) c = DbBase({ 'output': Message(), 'db_type': 'json' }, [ test_json, ]) keys = sorted(c.overlays) self.assertEqual(keys, ['twitch153']) # Clean up: os.unlink(test_xml) os.unlink(test_json) shutil.rmtree(tmpdir)
def list_db(self): output = Message() config = { 'output': output, 'db_type': 'xml', 'svn_command': '/usr/bin/svn', 'rsync_command': '/usr/bin/rsync' } db = DbBase(config, [ HERE + '/testfiles/global-overlays.xml', ]) test_info = ('wrobel\n~~~~~~\nSource : '\ 'https://overlays.gentoo.org/svn/dev/wrobel\nContact : '\ '[email protected]\nType : Subversion; Priority: 10\n'\ 'Quality : experimental\n\nDescription:\n Test\n', 'wrobel-stable\n~~~~~~~~~~~~~\nSource : '\ 'rsync://gunnarwrobel.de/wrobel-stable\nContact : '\ '[email protected]\nType : Rsync; Priority: 50\n'\ 'Quality : experimental\n\nDescription:\n A collection '\ 'of ebuilds from Gunnar Wrobel [[email protected]].\n') info = db.list(verbose=True) for i in range(0, len(info)): self.assertEqual(info[i][0].decode('utf-8'), test_info[i]) print(info[i][0].decode('utf-8')) test_info = ('wrobel [Subversion] '\ '(https://o.g.o/svn/dev/wrobel )', 'wrobel-stable [Rsync ] '\ '(rsync://gunnarwrobel.de/wrobel-stable)') info = db.list(verbose=False, width=80) for i in range(0, len(info)): self.assertEqual(info[i][0].decode('utf-8'), test_info[i]) print(info[i][0].decode('utf-8'))
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)