diff options
-rw-r--r-- | layman/db.py | 100 | ||||
-rwxr-xr-x | layman/tests/external.py | 90 |
2 files changed, 91 insertions, 99 deletions
diff --git a/layman/db.py b/layman/db.py index add8fa1..ba7399c 100644 --- a/layman/db.py +++ b/layman/db.py @@ -107,52 +107,7 @@ class DB(DbBase): def add(self, overlay): ''' Add an overlay to the local list of overlays. - - >>> import tempfile - >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_") - >>> write = os.path.join(tmpdir, 'installed.xml') - >>> write2 = os.path.join(tmpdir, 'make.conf') - >>> here = os.path.dirname(os.path.realpath(__file__)) - >>> from layman.config import OptionConfig - >>> myoptions = {'installed' : - ... here + '/tests/testfiles/global-overlays.xml', - ... 'local_list': here + '/tests/testfiles/overlays.xml', - ... 'make_conf' : write2, - ... 'nocheck' : 'yes', - ... 'storage' : tmpdir} - - >>> config = OptionConfig(myoptions) - >>> config.set_option('quietness', 3) - >>> a = DB(config) - >>> config.set_option('installed', write) - >>> b = DB(config) - >>> config['output'].set_colorize(False) - - >>> m = MakeConf(config, b.overlays) - >>> m.path = write2 - >>> success = m.write() - >>> success - True - - # Commented out since it needs network access: - - # >>> b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS - # * Running command "/usr/bin/rsync -rlptDvz --progress --delete --delete-after --timeout=180 --exclude="distfiles/*" --exclude="local/*" --exclude="packages/*" "rsync://gunnarwrobel.de/wrobel-stable/*" "/tmp/file.../wrobel-stable""... - # >>> c = DbBase([write, ], dict()) - # >>> c.overlays.keys() - # ['wrobel-stable'] - - # >>> m = MakeConf(config, b.overlays) - # >>> [i.name for i in m.overlays] #doctest: +ELLIPSIS - # ['wrobel-stable'] - - # >>> os.unlink(write) - >>> os.unlink(write2) - - >>> import shutil - >>> shutil.rmtree(tmpdir) ''' - if overlay.name not in self.overlays.keys(): if not self._check_official(overlay): return False @@ -188,61 +143,8 @@ class DB(DbBase): def delete(self, overlay): ''' - Add an overlay to the local list of overlays. - - >>> import tempfile - >>> tmpdir = tempfile.mkdtemp(prefix="laymantmp_") - >>> write = os.path.join(tmpdir, 'installed.xml') - >>> write2 = os.path.join(tmpdir, 'make.conf') - >>> here = os.path.dirname(os.path.realpath(__file__)) - >>> from layman.config import OptionConfig - >>> myoptions = {'installed' : - ... here + '/tests/testfiles/global-overlays.xml', - ... 'local_list': here + '/tests/testfiles/overlays.xml', - ... 'make_conf' : write2, - ... 'nocheck' : 'yes', - ... 'storage' : tmpdir} - - >>> config = OptionConfig(myoptions) - >>> config.set_option('quietness', 3) - >>> a = DB(config) - >>> config.set_option('installed', write) - >>> b = DB(config) - >>> config['output'].set_colorize(False) - - >>> m = MakeConf(config, b.overlays) - >>> m.path = here + '/tests/testfiles/make.conf' - >>> m.read() - True - - >>> m.path = write2 - >>> m.write() - True - - # >>> b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS - # * Running command "/usr/bin/rsync -rlptDvz --progress --delete --delete-after --timeout=180 --exclude="distfiles/*" --exclude="local/*" --exclude="packages/*" "rsync://gunnarwrobel.de/wrobel-stable/*" "/tmp/file.../wrobel-stable""... - # >>> b.add(a.select('wrobel')) #doctest: +ELLIPSIS - # * Running command "/usr/bin/svn co "https://overlays.gentoo.org/svn/dev/wrobel/" "/tmp/file.../wrobel""... - # >>> c = DbBase([write, ], dict()) - # >>> c.overlays.keys() - # ['wrobel', 'wrobel-stable'] - - # >>> b.delete(b.select('wrobel')) - # >>> c = DbBase([write, ], dict()) - # >>> c.overlays.keys() - # ['wrobel-stable'] - - # >>> m = MakeConf(config, b.overlays) - # >>> [i.name for i in m.overlays] #doctest: +ELLIPSIS - # ['wrobel-stable'] - - # >>> os.unlink(write) - >>> os.unlink(write2) - - >>> import shutil - >>> shutil.rmtree(tmpdir) + Delete an overlay from the local list of overlays. ''' - if overlay.name in self.overlays.keys(): overlay.delete(self.config['storage']) repo_ok = self.repo_conf.delete(overlay) diff --git a/layman/tests/external.py b/layman/tests/external.py index 713923b..f8bcc8c 100755 --- a/layman/tests/external.py +++ b/layman/tests/external.py @@ -118,6 +118,96 @@ class AddDeleteEnableDisableFromConf(unittest.TestCase): shutil.rmtree(tmpdir) +class AddDeleteDB(unittest.TestCase): + 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>foo@example.org</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'], + '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) + + # Tests archive overlay types (squashfs, tar) # http://bugs.gentoo.org/show_bug.cgi?id=304547 class ArchiveAddRemoveSync(unittest.TestCase): |