Example #1
0
    def get_source(self):
        '''
        Prompts user for possible overlay source
        information such as type, url, and branch
        and then appends the values to the overlay
        being created.
        '''
        ovl_type = None

        if self.auto_complete:
            source_amount = 1
        else:
            msg = 'How many different sources, protocols, or mirrors exist '\
                  'for this overlay?: '
            source_amount = int(get_input(msg))

        self.overlay['source'] = []

        for i in range(1, source_amount + 1):
            sources = []
            correct = False
            extra = ''
            if source_amount > 1:
                extra = '[%(i)s]\'s' % {'i': str(i)}

            msg = 'Define source%(extra)s URL: ' % {'extra': extra}
            sources.append(get_input(msg))

            ovl_type = self.guess_overlay_type(sources[0])
            if ovl_type:
                msg = 'Is "%(type)s" the correct overlay type?: '\
                    % ({'type': ovl_type})
                correct = get_ans(msg)
            while not ovl_type or not correct:
                msg = 'Please provide overlay type: '
                ovl_type = self.check_overlay_type(\
                            get_input(msg, color='yellow'))
                correct = True

            sources.append(ovl_type)
            if 'branch' in self.required:
                msg = 'Define source%(extra)s branch (if applicable): '\
                      % {'extra': extra}
                sources.append(get_input(msg))
            else:
                sources.append('')

            if self.auto_complete:
                sources = self._set_additional_info(sources)
                for source in sources:
                    self.overlay['source'].append(source)
            else:
                self.overlay['source'].append(sources)
        self.output.notice('')
Example #2
0
    def get_source(self):
        '''
        Prompts user for possible overlay source
        information such as type, url, and branch
        and then appends the values to the overlay
        being created.
        '''
        ovl_type = None

        if self.auto_complete:
            source_amount = 1
        else:
            msg = 'How many different sources, protocols, or mirrors exist '\
                  'for this overlay?: '
            source_amount = int(get_input(msg))

        self.overlay['source'] = []

        for i in range(1, source_amount + 1):
            sources = []
            correct = False
            extra = ''
            if source_amount > 1:
                extra = '[%(i)s]\'s' % {'i': str(i)}

            msg = 'Define source%(extra)s URL: ' % {'extra': extra}
            sources.append(get_input(msg))

            ovl_type = self.guess_overlay_type(sources[0])
            if ovl_type:
                msg = 'Is "%(type)s" the correct overlay type?: '\
                    % ({'type': ovl_type})
                correct = get_ans(msg)
            while not ovl_type or not correct:
                msg = 'Please provide overlay type: '
                ovl_type = self.check_overlay_type(\
                            get_input(msg, color='yellow'))
                correct = True

            sources.append(ovl_type)
            if 'branch' in self.required:
                msg = 'Define source%(extra)s branch (if applicable): '\
                      % {'extra': extra}
                sources.append(get_input(msg))
            else:
                sources.append('')

            if self.auto_complete:
                sources = self._set_additional_info(sources)
                for source in sources:
                    self.overlay['source'].append(source)
            else:
                self.overlay['source'].append(sources)
        self.output.notice('')
Example #3
0
 def update_required(self):
     """
     Prompts user for optional components and updates
     the required components accordingly.
     """
     for possible in POSSIBLE_COMPONENTS:
         if possible not in self.required:
             msg = "Include %(comp)s for this overlay? [y/n]: " % ({"comp": possible})
             if (possible in "homepage" or possible in "feed") and self.auto_complete:
                 available = False
             else:
                 available = get_ans(msg)
             if available:
                 self.required.append(possible)
Example #4
0
 def update_required(self):
     '''
     Prompts user for optional components and updates
     the required components accordingly.
     '''
     for possible in POSSIBLE_COMPONENTS:
         if possible not in self.required:
             msg = 'Include %(comp)s for this overlay? [y/n]: '\
                     % ({'comp': possible})
             if ((possible in 'homepage' or possible in 'feed') and
                 self.auto_complete):
                 available = False
             else:
                 available = get_ans(msg)
             if available:
                 self.required.append(possible)
Example #5
0
 def update_required(self):
     '''
     Prompts user for optional components and updates
     the required components accordingly.
     '''
     for possible in POSSIBLE_COMPONENTS:
         if possible not in self.required:
             msg = 'Include %(comp)s for this overlay? [y/n]: '\
                     % ({'comp': possible})
             if ((possible in 'homepage' or possible in 'feed')
                     and self.auto_complete):
                 available = False
             else:
                 available = get_ans(msg)
             if available:
                 self.required.append(possible)
Example #6
0
File: db.py Project: wking/layman
    def _check_official(self, overlay):
        '''
        Prompt user to see if they want to install unofficial overlays.

        @params overlay: layman.overlays.Overlay object.
        @rtype bool: reflect the user's decision to install overlay.
        '''
        if self.config['check_official'] and not overlay.status == 'official':
            msg = 'Overlay "%(repo)s" is not an official. Continue install?'\
                  ' [y/n]: ' % {'repo': overlay.name}
            if not get_ans(msg, color='green'):
                msg = 'layman will not add "%(repo)s", due to user\'s'\
                      ' decision\nto not install unofficial overlays.'\
                      % {'repo': overlay.name}
                hint = 'Hint: To remove this check, set "check_official"'\
                       ' to "No"\nin your layman.cfg.'
                self.output.warn(msg)
                self.output.notice('')
                self.output.warn(hint)
                return False
            else:
                return True
        return True
Example #7
0
    def _check_official(self, overlay):
        '''
        Prompt user to see if they want to install unofficial overlays.

        @params overlay: layman.overlays.Overlay object.
        @rtype bool: reflect the user's decision to install overlay.
        '''
        if self.config['check_official'] and not overlay.status == 'official':
            msg = 'Overlay "%(repo)s" is not official. Continue installing?'\
                  ' [y/n]: ' % {'repo': overlay.name}
            if not get_ans(msg, color='green'):
                msg = 'layman will not add "%(repo)s", due to user\'s'\
                      ' decision\nto not install unofficial overlays.'\
                      % {'repo': overlay.name}
                hint = 'Hint: To remove this check, set "check_official"'\
                       ' to "No"\nin your layman.cfg.'
                self.output.warn(msg)
                self.output.notice('')
                self.output.warn(hint)
                return False
            else:
                return True
        return True
Example #8
0
    def sync(self, repos, output_results=True, update_news=False):
        """syncs the specified repo(s) specified by repos

        @type repos: list of strings or string
        @param repos: ['repo-id1', ...] or 'repo-id'
        @param output_results: bool, defaults to True
        @param update_news: bool, defaults to False
        @rtype bool or {'repo-id': bool,...}
        """
        self.output.debug(
            "API.sync(); repos to sync = %s" % ', '.join(
                (x.decode() if isinstance(x, bytes) else x) for x in repos), 5)
        fatals = []
        warnings = []
        success = []
        repos = self._check_repo_type(repos, "sync")
        db = self._get_installed_db()
        rdb = self._get_remote_db()

        self.output.debug("API.sync(); starting ovl loop", 5)
        for ovl in repos:
            update_url = False
            self.output.debug("API.sync(); starting ovl = %s" % ovl, 5)
            try:
                #self.output.debug("API.sync(); selecting %s, db = %s" % (ovl, str(db)), 5)
                odb = db.select(ovl)
                self.output.debug("API.sync(); %s now selected" % ovl, 5)
            except UnknownOverlayException as error:
                #self.output.debug("API.sync(); UnknownOverlayException selecting %s" %ovl, 5)
                #self._error(str(error))
                fatals.append((
                    ovl,
                    'Failed to select overlay "%(repo)s".\nError was: %(error)s'
                    % {
                        'repo': ovl,
                        'err': error
                    }))
                self.output.debug(
                    "API.sync(); UnknownOverlayException "
                    "selecting %(repo)s.   continuing to next ovl..." %
                    {'repo': ovl}, 5)
                continue

            try:
                self.output.debug(
                    "API.sync(); try: self._get_remote_db().select(ovl)", 5)
                ordb = rdb.select(ovl)
            except UnknownOverlayException:
                message = 'Overlay "%(repo)s" could not be found in the remote '\
                        'lists.\nPlease check if it has been renamed and '\
                        're-add if necessary.' % {'repo': ovl}
                warnings.append((ovl, message))
                (diff_type, update_url) = (False, False)
            else:
                self.output.debug(
                    "API.sync(); else: self._get_remote_db().select(ovl)", 5)

                (diff_type, type_msg) = self._verify_overlay_type(odb, ordb)
                (update_url, url_msg,
                 available_srcs) = self._verify_overlay_source(odb, ordb)

                try:
                    if diff_type:
                        self.output.debug(
                            "API.sync(); starting API.readd_repos(ovl)", 5)
                        warnings.append((ovl, type_msg))
                        self.readd_repos(ovl)
                        success.append(
                            (ovl,
                             'Successfully readded overlay "' + ovl + '".'))
                    else:
                        if update_url:
                            self.output.debug(
                                "API.sync() starting db.update(ovl)", 5)
                            warnings.append((ovl, url_msg))
                            update_success = db.update(ordb, available_srcs)
                            if not update_success:
                                msg = 'Failed to update source URL for overlay'\
                                      '"%(ovl)s". Re-add overlay? [y/n]'\
                                      % {'ovl': ovl}
                                if get_ans(msg, color='yellow'):
                                    self.readd_repos(ovl)
                except Exception as error:
                    self.output.warn(
                        'Failed to perform overlay type or url updates', 2)
                    self.output.warn('    for Overlay: %s' % ovl, 2)
                    self.output.warn('    Error was: %s' % str(error))
                    continue

            try:
                self.output.debug("API.sync(); starting db.sync(ovl)", 5)
                db.sync(ovl)
                success.append(
                    (ovl, 'Successfully synchronized overlay "' + ovl + '".'))
            except Exception as error:
                fatals.append(
                    (ovl,
                     'Failed to sync overlay "%(repo)s".\nError was: %(err)s' %
                     {
                         'repo': ovl,
                         'err': error
                     }))

        if output_results:
            if success:
                message = '\nSucceeded:\n------\n'
                for ovl, result in success:
                    message += result + '\n'
                self.output.info(message, 3)

            if warnings:
                message = '\nWarnings:\n------\n'
                for ovl, result in warnings:
                    message += result + '\n'
                self.output.warn(message, 2)

            if fatals:
                message = '\nErrors:\n------\n'
                for ovl, result in fatals:
                    message += result + '\n'
                self.output.error(message)

        self.sync_results = (success, warnings, fatals)

        if update_news:
            self.update_news(repos)

        return fatals == []
Example #9
0
    def sync(self, repos, output_results=True, update_news=False):
        """syncs the specified repo(s) specified by repos

        @type repos: list of strings or string
        @param repos: ['repo-id1', ...] or 'repo-id'
        @param output_results: bool, defaults to True
        @param update_news: bool, defaults to False
        @rtype bool or {'repo-id': bool,...}
        """
        self.output.debug("API.sync(); repos to sync = %s" % ', '.join((x.decode() if isinstance(x, bytes) else x) for x in repos), 5)
        fatals = []
        warnings = []
        success  = []
        repos = self._check_repo_type(repos, "sync")
        db = self._get_installed_db()

        self.output.debug("API.sync(); starting ovl loop", 5)
        for ovl in repos:
            update_url = False
            self.output.debug("API.sync(); starting ovl = %s" %ovl, 5)
            try:
                #self.output.debug("API.sync(); selecting %s, db = %s" % (ovl, str(db)), 5)
                odb = db.select(ovl)
                self.output.debug("API.sync(); %s now selected" %ovl, 5)
            except UnknownOverlayException as error:
                #self.output.debug("API.sync(); UnknownOverlayException selecting %s" %ovl, 5)
                #self._error(str(error))
                fatals.append((ovl,
                    'Failed to select overlay "%(repo)s".\nError was: %(error)s'
                     % {'repo': ovl, 'err': error}))
                self.output.debug("API.sync(); UnknownOverlayException "
                    "selecting %(repo)s.   continuing to next ovl..."
                    % {'repo': ovl}, 5)
                continue

            try:
                self.output.debug("API.sync(); try: self._get_remote_db().select(ovl)", 5)
                ordb = self._get_remote_db().select(ovl)
            except UnknownOverlayException:
                message = 'Overlay "%(repo)s" could not be found in the remote '\
                        'lists.\nPlease check if it has been renamed and '\
                        're-add if necessary.' % {'repo': ovl}
                warnings.append((ovl, message))
                (diff_type, update_url) = (False, False)
            else:
                self.output.debug("API.sync(); else: self._get_remote_db().select(ovl)", 5)

                (diff_type, type_msg) = self._verify_overlay_type(odb, ordb)
                (update_url, url_msg, available_srcs) = self._verify_overlay_source(odb, ordb)

                try:
                    if diff_type:
                        self.output.debug("API.sync(); starting API.readd_repos(ovl)", 5)
                        warnings.append((ovl, type_msg))
                        self.readd_repos(ovl)
                        success.append((ovl, 'Successfully readded overlay "' + ovl + '".'))
                    else:
                        if update_url:
                            self.output.debug("API.sync() starting db.update(ovl)", 5)
                            warnings.append((ovl, url_msg))
                            update_success = db.update(ordb, available_srcs)
                            if not update_success:
                                msg = 'Failed to update source URL for overlay'\
                                      '"%(ovl)s". Re-add overlay? [y/n]'\
                                      % {'ovl': ovl}
                                if get_ans(msg, color='yellow'):
                                    self.readd_repos(ovl)
                except Exception as error:
                    self.output.warn('Failed to perform overlay type or url updates', 2)
                    self.output.warn('    for Overlay: %s' % ovl, 2)
                    self.output.warn('    Error was: %s' % str(error))
                    continue

            try:
                    self.output.debug("API.sync(); starting db.sync(ovl)", 5)
                    db.sync(ovl)
                    success.append((ovl,'Successfully synchronized overlay "' + ovl + '".'))
            except Exception as error:
                fatals.append((ovl,
                    'Failed to sync overlay "%(repo)s".\nError was: %(err)s'
                    % {'repo': ovl, 'err': error}))

        if output_results:
            if success:
                message = '\nSucceeded:\n------\n'
                for ovl, result in success:
                    message += result + '\n'
                self.output.info(message, 3)

            if warnings:
                message = '\nWarnings:\n------\n'
                for ovl, result in warnings:
                    message += result + '\n'
                self.output.warn(message, 2)

            if fatals:
                message = '\nErrors:\n------\n'
                for ovl, result in fatals:
                    message += result + '\n'
                self.output.error(message)

        self.sync_results = (success, warnings, fatals)

        if update_news:
            self.update_news(repos)

        return fatals == []
Example #10
0
    def get_source(self):
        """
        Prompts user for possible overlay source
        information such as type, url, and branch
        and then appends the values to the overlay
        being created.
        """
        ovl_type = None

        if self.auto_complete:
            source_amount = 1
        else:
            msg = "How many different sources, protocols, or mirrors exist " "for this overlay?: "
            source_amount = int(get_input(msg))

        self.overlay["source"] = []

        for i in range(1, source_amount + 1):
            sources = []
            correct = False
            if source_amount > 1:
                msg = "Define source[%(i)s]'s URL: " % ({"i": str(i)})
                sources.append(get_input(msg))

                ovl_type = self.guess_overlay_type(sources[0])
                if ovl_type:
                    msg = 'Is "%(type)s" the correct overlay type?: ' % ({"type": ovl_type})
                    correct = get_ans(msg)
                while not ovl_type or not correct:
                    msg = "Please provide overlay type: "
                    ovl_type = self.check_overlay_type(get_input(msg, color="yellow"))
                    correct = True

                sources.append(ovl_type)
                if "branch" in self.required:
                    msg = "Define source[%(i)s]'s branch (if applicable): " % ({"i": str(i)})
                    sources.append(get_input(msg))
                else:
                    sources.append("")
            else:
                sources.append(get_input("Define source URL: "))

                ovl_type = self.guess_overlay_type(sources[0])
                if ovl_type:
                    msg = "Is %(type)s the correct overlay type?: " % ({"type": ovl_type})
                    correct = get_ans(msg)
                while not ovl_type or not correct:
                    msg = "Please provide overlay type: "
                    ovl_type = self.check_overlay_type(get_input(msg, color="yellow"))
                    correct = True

                sources.append(ovl_type)
                if "branch" in self.required:
                    msg = "Define source branch (if applicable): "
                    sources.append(get_input(msg))
                else:
                    sources.append("")
            if self.auto_complete:
                sources = self._set_additional_info(sources)
                for source in sources:
                    self.overlay["source"].append(source)
            else:
                self.overlay["source"].append(sources)
        self.output.notice("")