Beispiel #1
0
    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)
Beispiel #2
0
def init_layman(config=None):
    '''Returns the initialized ``LaymanAPI``.

    :param config: the layman's configuration to use (optional)
    '''
    if config is None: config = BareConfig(read_configfile=True, quietness=1)
    return LaymanAPI(config)
Beispiel #3
0
    def create_repos_conf(self):
        self.output.info("  Creating layman's repos.conf file")

        if os.path.isdir(self.config['repos_conf']):
            msg = '  create_repos_conf() error: %s is a directory and will\n'\
                  '  not be written to.' % self.config['repos_conf']
            self.output.error(msg)
            return None

        conf_dir = os.path.dirname(self.config['repos_conf'])

        if not os.path.isdir(conf_dir):
            try:
                os.mkdir(conf_dir)
            except OSError as e:
                self.output.error('  create_repos_conf() error creating %s: '\
                                  % conf_dir)
                self.output.error('  "%s"' % e)
                return None

        layman_inst = LaymanAPI(config=self.config)
        overlays = {}
        for ovl in layman_inst.get_installed():
            overlays[ovl] = layman_inst._get_installed_db().select(ovl)
        # create layman's %(repos_conf) so layman
        # can write the overlays to it.
        open(self.config['repos_conf'], 'w').close()
        from layman.config_modules.reposconf.reposconf import ConfigHandler
        repos_conf = ConfigHandler(self.config, overlays, rebuild=True)
        repos_conf.write()
Beispiel #4
0
 def __init__(self, config=None):
     self.config = config
     if self.config:
         reload_config(self.config)
     self.layman_inst = LaymanAPI(config=self.config)
     self.output = self.config.get_option('output')
     self.overlay = {}
     self.overlays = []
     self.overlays_available = self.layman_inst.get_available()
     self.supported_types = list(self.layman_inst.supported_types())
Beispiel #5
0
 def create_make_conf(self):
     self.output.info("  Creating layman's make.conf file")
     layman_inst = LaymanAPI(config=self.config)
     overlays = {}
     for ovl in layman_inst.get_installed():
         overlays[ovl] = layman_inst._get_installed_db().select(ovl)
     # create layman's %(storage)s/make.conf
     # so portage won't error
     from layman.config_modules.makeconf.makeconf import ConfigHandler
     maker = ConfigHandler(self.config, overlays)
     maker.write()
Beispiel #6
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)
Beispiel #7
0
    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
Beispiel #8
0
 def __init__(self, config):
     self.config = config
     self.output = config['output']
     self.api = LaymanAPI(config, report_errors=False, output=config.output)
     # Given in order of precedence
     self.actions = [
         ('fetch', 'Fetch'),
         ('add', 'Add'),
         ('sync', 'Sync'),
         ('info', 'Info'),
         ('sync_all', 'Sync'),
         ('readd', 'Readd'),
         ('delete', 'Delete'),
         ('disable', 'Disable'),
         ('enable', 'Enable'),
         ('list', 'ListRemote'),
         ('list_local', 'ListLocal'),
     ]
Beispiel #9
0
    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)