Exemple #1
0
    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)
Exemple #2
0
 def select_db(self):
     output = Message()
     config = {'output': output,
               'db_type': 'xml_db',}
     db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
     url = ['rsync://gunnarwrobel.de/wrobel-stable']
     self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
Exemple #3
0
    def __init__(self, config):

        self.config = config
        self.output = config['output']

        self.path = config['installed']
        self.output.debug("DB.__init__(): config['installed'] = %s" % self.path, 3)

        if config['nocheck']:
            ignore = 2
        else:
            ignore = 1


        DbBase.__init__(self,
                          config,
                          paths=[config['installed'], ],
                          ignore=ignore,
                          )

        self.repo_conf = RepoConfManager(self.config, self.overlays)

        self.output.debug('DB handler initiated', 6)

        # check and handle the name change
        if not os.access(self.config['installed'], os.F_OK) and \
            os.access(self.config['local_list'], os.F_OK):
                self.output.die("Please run layman-updater, "
                    "then run layman again")
Exemple #4
0
    def list_db(self):
        output = Message()
        config = {
                  'output': output,
                  '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'))
Exemple #5
0
    def __init__(self, config):

        self.config = config
        self.output = config['output']

        self.path = config['installed']
        self.output.debug(
            "DB.__init__(): config['installed'] = %s" % self.path, 3)

        if config['nocheck']:
            ignore = 2
        else:
            ignore = 1

        DbBase.__init__(
            self,
            config,
            paths=[
                config['installed'],
            ],
            ignore=ignore,
            allow_missing=True,
        )

        self.repo_conf = RepoConfManager(self.config, self.overlays)

        self.output.debug('DB handler initiated', 6)

        # check and handle the name change
        if not os.access(self.config['installed'], os.F_OK) and \
            os.access(self.config['local_list'], os.F_OK):
            self.output.die("Please run layman-updater, "
                            "then run layman again")
Exemple #6
0
 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]
             print
Exemple #7
0
    def test(self):
        repo_name = 'tar-test-overlay'
        tar_source_path = os.path.join(HERE, 'testfiles', 'layman-test.tar.bz2')

        # Duplicate test tarball (so we have it deletable for later)
        (_, 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_collection_path) = tempfile.mkstemp()
        f = os.fdopen(fd, 'w')
        f.write(xml_text)
        f.close()

        # Make playground directory
        temp_dir_path = tempfile.mkdtemp()

        # Make DB from it
        #config = {'output': Message(), 'tar_command':'/bin/tar'}
        config = BareConfig()
        db = DbBase(config, [temp_collection_path])

        specific_overlay_path = os.path.join(temp_dir_path, repo_name)
        o = db.select('tar-test-overlay')

        # 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_tarball_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)
Exemple #8
0
 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()
Exemple #9
0
    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)
Exemple #10
0
    def __init__(self, config, ignore_init_read_errors=False):

        self.config = config
        self.output = config['output']
        self.detached_urls = []
        self.signed_urls = []
        self.proxies = config.proxies

        self.urls = [
            i.strip() for i in config['overlays'].split('\n') if len(i)
        ]

        if GPG_ENABLED:
            self.get_gpg_urls()
        else:
            self.output.debug(
                'RemoteDB.__init__(), NOT GPG_ENABLED, '
                'bypassing...', 2)

        # add up the lists to load for display, etc.
        # unsigned overlay lists
        paths = [self.filepath(i) + '.xml' for i in self.urls]
        # detach-signed lists
        paths.extend(
            [self.filepath(i[0]) + '.xml' for i in self.detached_urls])
        # single file signed, compressed, clearsigned
        paths.extend([self.filepath(i) + '.xml' for i in self.signed_urls])

        self.output.debug(
            'RemoteDB.__init__(), url lists= \nself.urls: '
            '%s\nself.detached_urls: %s\nself.signed_urls: %s' %
            (str(self.urls), str(self.detached_urls), str(self.signed_urls)),
            2)

        self.output.debug(
            'RemoteDB.__init__(), paths to load = %s' % str(paths), 2)
        if config['nocheck']:
            ignore = 2
        else:
            ignore = 0

        #quiet = int(config['quietness']) < 3

        DbBase.__init__(self,
                        config,
                        paths=paths,
                        ignore=ignore,
                        ignore_init_read_errors=ignore_init_read_errors)

        self.gpg = None
        self.gpg_config = None
Exemple #11
0
    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)
Exemple #12
0
    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)
Exemple #13
0
    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)
Exemple #14
0
    def _run(self, number):
        #config = {'output': Message()}
        config = BareConfig()
        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
Exemple #15
0
    def write_db(self):
        tmpdir = tempfile.mkdtemp(prefix='laymantmp_')
        test_xml = os.path.join(tmpdir, 'test.xml')
        config = BareConfig()
        a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
        b = DbBase({'output': Message()}, [test_xml,])

        b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']
        b.write(test_xml)

        c = DbBase({'output': Message()}, [test_xml,])
        keys = sorted(c.overlays)
        self.assertEqual(keys, ['wrobel-stable'])

        # Clean up:
        os.unlink(test_xml)
        shutil.rmtree(tmpdir)
Exemple #16
0
    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
Exemple #17
0
    def __init__(self, config, ignore_init_read_errors=False):

        self.config = config
        self.output = config['output']
        self.detached_urls = []
        self.signed_urls = []
        self.proxies = config.proxies
        
        self.urls  = [i.strip()
            for i in config['overlays'].split('\n') if len(i)]

        if GPG_ENABLED:
            self.get_gpg_urls()
        else:
            self.output.debug('RemoteDB.__init__(), NOT GPG_ENABLED, '
                'bypassing...', 2)

        # add up the lists to load for display, etc.
        # unsigned overlay lists
        paths = [self.filepath(i) + '.xml' for i in self.urls]
        # detach-signed lists
        paths.extend([self.filepath(i[0]) + '.xml' for i in self.detached_urls])
        # single file signed, compressed, clearsigned
        paths.extend([self.filepath(i) + '.xml' for i in self.signed_urls])

        self.output.debug('RemoteDB.__init__(), url lists= \nself.urls: '
            '%s\nself.detached_urls: %s\nself.signed_urls: %s'
            % (str(self.urls), str(self.detached_urls), str(self.signed_urls)),
            2)

        self.output.debug('RemoteDB.__init__(), paths to load = %s' %str(paths),
            2)
        if config['nocheck']:
            ignore = 2
        else:
            ignore = 0

        #quiet = int(config['quietness']) < 3

        DbBase.__init__(self, config, paths=paths, ignore=ignore,
            ignore_init_read_errors=ignore_init_read_errors)

        self.gpg = None
        self.gpg_config = None
Exemple #18
0
    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'))
Exemple #19
0
    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)
Exemple #20
0
    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)
Exemple #21
0
    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)