Beispiel #1
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)
        repos_conf.write()
Beispiel #2
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 #3
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 #4
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 #5
0
 def create_repos_conf(self):
     self.output.info("  Creating layman's repos.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 %(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)
     repos_conf.write()
Beispiel #6
0
class Main(object):
    '''Performs the actions the user selected.
    '''
    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'),
        ]

    def __call__(self):
        self.output.debug(
            "CLI.__call__(): self.config.keys()"
            " %s" % str(self.config.keys()), 6)
        # blank newline  -- no " *"
        self.output.notice('')

        # check for and handle setup-help option
        if self.config.get_option('setup_help'):
            from layman.updater import Main as Updater
            updater = Updater(config=self.config, output=self.output)
            updater.print_instructions()

        # Make fetching the overlay list a default action
        if not 'nofetch' in self.config.keys():
            # Actions that implicitly call the fetch operation before
            fetch_actions = ['sync', 'sync_all', 'list']
            for i in fetch_actions:
                if i in self.config.keys():
                    # Implicitely call fetch, break loop
                    self.Fetch()
                    break

        result = 0

        # Set the umask
        umask = self.config['umask']
        try:
            new_umask = int(umask, 8)
            old_umask = os.umask(new_umask)
        except Exception as error:
            self.output.die('Failed setting to umask "' + umask +
                            '"!\nError was: ' + str(error))

        action_errors = []
        results = []
        act = set([x[0] for x in self.actions])
        k = set([x for x in self.config.keys()])
        a = act.intersection(k)
        self.output.debug('Actions = %s' % str(a), 4)
        for action in self.actions:
            self.output.debug('Checking for action %s' % action[0], 4)

            if action[0] in self.config.keys():
                result += getattr(self, action[1])()
                _errors = self.api.get_errors()
                if _errors:
                    self.output.debug(
                        "CLI: found errors performing "
                        "action %s" % action[0], 2)
                    action_errors.append((action[0], _errors))
                    result = -1  # So it cannot remain 0, i.e. success
            results.append(result)
            self.output.debug(
                'Completed action %s, result %s' % (action[0], result == 0), 4)

        self.output.debug('Checking for action errors', 4)
        if action_errors:
            for action, _errors in action_errors:
                self.output.warn("CLI: Errors occurred processing action"
                                 " %s" % action)
                for _error in _errors:
                    self.output.error(_error)
                self.output.notice("")

        # Reset umask
        os.umask(old_umask)

        if -1 in results:
            sys.exit(FAILURE)
        else:
            sys.exit(SUCCEED)

    def Fetch(self):
        ''' Fetches the overlay listing.
        '''
        self.output.info("Fetching remote list...", 2)
        result = self.api.fetch_remote_list()
        if result:
            self.output.info('Fetch Ok', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result

    def Add(self):
        ''' Adds the selected overlay(s).
        '''
        self.output.info("Adding overlay...", 2)
        selection = decode_selection(self.config['add'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_available()
        self.output.debug('Adding selected overlay(s)', 6)
        result = self.api.add_repos(selection, update_news=True)
        if result:
            self.output.info(
                'Successfully added overlay(s) ' + ', '.join(
                    (x.decode('UTF-8') if isinstance(x, bytes) else x)
                    for x in selection) + '.', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result

    def Readd(self):
        '''Readds the selected overlay(s).
        '''
        self.output.info('Reinstalling overlay(s)...', 2)
        selection = decode_selection(self.config['readd'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        self.output.debug('Reinstalling selected overlay(s)', 6)
        result = self.api.readd_repos(selection, update_news=True)
        if result:
            self.output.info(
                'Successfully reinstalled overlay(s) ' + ', '.join(
                    (x.decode('UTF-8') if isinstance(x, bytes) else x)
                    for x in selection) + '.', 2)
        self.output.notice('')
        return result

    def Sync(self):
        ''' Syncs the selected overlay(s).
        '''
        self.output.info("Syncing selected overlay(s)...", 2)
        # Note api.sync() defaults to printing results
        selection = decode_selection(self.config['sync'])
        if self.config['sync_all'] or ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        self.output.debug('Updating selected overlay(s)', 6)
        result = self.api.sync(selection, update_news=True)
        # blank newline  -- no " *"
        self.output.notice('')
        return result

    def Delete(self):
        ''' Deletes the selected overlay(s).
        '''
        self.output.info('Deleting selected overlay(s)...', 2)
        selection = decode_selection(self.config['delete'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.delete_repos(selection)
        if result:
            self.output.info(
                'Successfully deleted overlay(s) ' + ', '.join(
                    (x.decode('UTF-8') if isinstance(x, bytes) else x)
                    for x in selection) + '.', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result

    def Disable(self):
        '''
        Disable the selected overlay(s).

        @rtype bool
        '''
        self.output.info('Disabling selected overlay(s),...', 2)
        selection = decode_selection(self.config['disable'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.disable_repos(selection)
        if result:
            self.output.info(
                'Successfully disabled overlay(s) ' + ', '.join(
                    (x.decode('UTF-8') if isinstance(x, bytes) else x)
                    for x in selection) + '.', 2)
        self.output.notice('')
        return result

    def Enable(self):
        '''
        Enable the selected overlay(s).

        @rtype bool
        '''
        self.output.info('Enabling the selected overlay(s),...', 2)
        selection = decode_selection(self.config['enable'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.enable_repos(selection)
        if result:
            self.output.info(
                'Successfully enable overlay(s) ' + ', '.join(
                    (x.decode('UTF-8') if isinstance(x, bytes) else x)
                    for x in selection) + '.', 2)
        self.output.notice('')
        return result

    def Info(self):
        ''' Print information about the specified overlay(s).
        '''
        selection = decode_selection(self.config['info'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_available()

        list_printer = ListPrinter(self.config)
        _complain = self.config['nocheck'] or self.config['verbose']

        info = self.api.get_info_str(selection,
                                     local=False,
                                     verbose=True,
                                     width=list_printer.width)
        list_printer.print_shortdict(info, complain=_complain)
        # blank newline  -- no " *"
        self.output.notice('')
        return info != {}

    def ListRemote(self):
        ''' Lists the available overlays.
        '''

        self.output.debug('Printing remote overlays.', 6)
        list_printer = ListPrinter(self.config)

        _complain = self.config['nocheck'] or self.config['verbose']
        info = self.api.get_info_list(local=False,
                                      verbose=self.config['verbose'],
                                      width=list_printer.width)
        list_printer.print_shortlist(info, complain=_complain)
        # blank newline  -- no " *"
        self.output.notice('')

        return info != {}

    def ListLocal(self):
        ''' Lists the local overlays.
        '''
        #print "ListLocal()"
        self.output.debug('Printing installed overlays.', 6)
        list_printer = ListPrinter(self.config)

        info = self.api.get_info_list(verbose=self.config['verbose'],
                                      width=list_printer.width)
        #self.output.debug('CLI: ListLocal() info = %s' % len(info), 4)
        #self.output.debug('\n'.join([ str(x) for x in info]), 4)
        list_printer.print_shortlist(info, complain=True)

        # blank newline  -- no " *"
        self.output.notice('')
        return info != {}
Beispiel #7
0
class Main(object):
    '''Performs the actions the user selected.
    '''

    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'),]

    def __call__(self):
        self.output.debug("CLI.__call__(): self.config.keys()"
            " %s" % str(self.config.keys()), 6)
        # blank newline  -- no " *"
        self.output.notice('')

        # check for and handle setup-help option
        if self.config.get_option('setup_help'):
            from layman.updater import Main as Updater
            updater = Updater(config=self.config, output=self.output)
            updater.print_instructions()

        # Make fetching the overlay list a default action
        if not 'nofetch' in self.config.keys():
            # Actions that implicitly call the fetch operation before
            fetch_actions = ['sync', 'sync_all', 'list']
            for i in fetch_actions:
                if i in self.config.keys():
                    # Implicitely call fetch, break loop
                    self.Fetch()
                    break

        result = 0

        # Set the umask
        umask = self.config['umask']
        try:
            new_umask = int(umask, 8)
            old_umask = os.umask(new_umask)
        except Exception as error:
            self.output.die('Failed setting to umask "' + umask +
                '"!\nError was: ' + str(error))

        action_errors = []
        results = []
        act=set([x[0] for x in self.actions])
        k=set([x for x in self.config.keys()])
        a=act.intersection(k)
        self.output.debug('Actions = %s' % str(a), 4)
        for action in self.actions:
            self.output.debug('Checking for action %s' % action[0], 4)

            if action[0] in self.config.keys():
                result += getattr(self, action[1])()
                _errors = self.api.get_errors()
                if _errors:
                    self.output.debug("CLI: found errors performing "
                        "action %s" % action[0], 2)
                    action_errors.append((action[0], _errors))
                    result = -1  # So it cannot remain 0, i.e. success
            results.append(result)
            self.output.debug('Completed action %s, result %s'
                % (action[0], result==0), 4)

        self.output.debug('Checking for action errors', 4)
        if action_errors:
            for action, _errors in action_errors:
                self.output.warn("CLI: Errors occurred processing action"
                    " %s" % action)
                for _error in _errors:
                    self.output.error(_error)
                self.output.notice("")

        # Reset umask
        os.umask(old_umask)

        if -1 in results:
            sys.exit(FAILURE)
        else:
            sys.exit(SUCCEED)


    def Fetch(self):
        ''' Fetches the overlay listing.
        '''
        self.output.info("Fetching remote list...", 2)
        result = self.api.fetch_remote_list()
        if result:
            self.output.info('Fetch Ok', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result


    def Add(self):
        ''' Adds the selected overlay(s).
        '''
        self.output.info("Adding overlay...", 2)
        selection = decode_selection(self.config['add'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_available()
        self.output.debug('Adding selected overlay(s)', 6)
        result = self.api.add_repos(selection, update_news=True)
        if result:
            self.output.info('Successfully added overlay(s) ' +
                ', '.join((x.decode('UTF-8') if isinstance(x, bytes) else x) for x in selection) +
                '.', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result


    def Readd(self):
        '''Readds the selected overlay(s).
        '''
        self.output.info('Reinstalling overlay(s)...', 2)
        selection = decode_selection(self.config['readd'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        self.output.debug('Reinstalling selected overlay(s)', 6)
        result = self.api.readd_repos(selection, update_news=True)
        if result:
            self.output.info('Successfully reinstalled overlay(s) ' +
                ', '.join((x.decode('UTF-8') if isinstance(x, bytes) else x) for x in selection)
                + '.', 2)
        self.output.notice('')
        return result


    def Sync(self):
        ''' Syncs the selected overlay(s).
        '''
        self.output.info("Syncing selected overlay(s)...", 2)
        # Note api.sync() defaults to printing results
        selection = decode_selection(self.config['sync'])
        if self.config['sync_all'] or ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        self.output.debug('Updating selected overlay(s)', 6)
        result = self.api.sync(selection, update_news=True)
        # blank newline  -- no " *"
        self.output.notice('')
        return result


    def Delete(self):
        ''' Deletes the selected overlay(s).
        '''
        self.output.info('Deleting selected overlay(s)...', 2)
        selection = decode_selection(self.config['delete'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.delete_repos(selection)
        if result:
            self.output.info('Successfully deleted overlay(s) ' +
                ', '.join((x.decode('UTF-8') if isinstance(x, bytes) else x) for x in selection) +
                '.', 2)
        # blank newline  -- no " *"
        self.output.notice('')
        return result


    def Disable(self):
        '''
        Disable the selected overlay(s).

        @rtype bool
        '''
        self.output.info('Disabling selected overlay(s),...', 2)
        selection = decode_selection(self.config['disable'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.disable_repos(selection)
        if result:
            self.output.info('Successfully disabled overlay(s) ' +
                ', '.join((x.decode('UTF-8') if isinstance(x, bytes) else x) for x in selection) +
                '.', 2)
        self.output.notice('')
        return result


    def Enable(self):
        '''
        Enable the selected overlay(s).

        @rtype bool
        '''
        self.output.info('Enabling the selected overlay(s),...', 2)
        selection = decode_selection(self.config['enable'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_installed()
        result = self.api.enable_repos(selection)
        if result:
            self.output.info('Successfully enable overlay(s) ' +
                ', '.join((x.decode('UTF-8') if isinstance(x, bytes) else x) for x in selection) +
                '.', 2)
        self.output.notice('')
        return result


    def Info(self):
        ''' Print information about the specified overlay(s).
        '''
        selection = decode_selection(self.config['info'])
        if ALL_KEYWORD in selection:
            selection = self.api.get_available()

        list_printer = ListPrinter(self.config)
        _complain = self.config['nocheck'] or self.config['verbose']

        info = self.api.get_info_str(selection, local=False,
            verbose=True, width=list_printer.width)
        list_printer.print_shortdict(info, complain=_complain)
        # blank newline  -- no " *"
        self.output.notice('')
        return info != {}


    def ListRemote(self):
        ''' Lists the available overlays.
        '''

        self.output.debug('Printing remote overlays.', 6)
        list_printer = ListPrinter(self.config)

        _complain = self.config['nocheck'] or self.config['verbose']
        info = self.api.get_info_list(local=False,
            verbose=self.config['verbose'], width=list_printer.width)
        list_printer.print_shortlist(info, complain=_complain)
        # blank newline  -- no " *"
        self.output.notice('')

        return info != {}


    def ListLocal(self):
        ''' Lists the local overlays.
        '''
        #print "ListLocal()"
        self.output.debug('Printing installed overlays.', 6)
        list_printer = ListPrinter(self.config)

        info = self.api.get_info_list(verbose=self.config['verbose'],
                                      width=list_printer.width)
        #self.output.debug('CLI: ListLocal() info = %s' % len(info), 4)
        #self.output.debug('\n'.join([ str(x) for x in info]), 4)
        list_printer.print_shortlist(info, complain=True)

        # blank newline  -- no " *"
        self.output.notice('')
        return info != {}