Beispiel #1
0
    def __call__(self) -> None:
        """See Command.__call__."""
        Command.__call__(self)
        if self.funk and self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)

        if not self.funk_dict:
            raise errors.FunkNotDefinedError(global_=self.global_)

        if self.funk is None:
            log.logger.debug("Prompting to destroy local funk database.")
            prompt = (
                "Remove all local funks defined in this directory? (y/n): ")
            y_or_n = utils.getch(prompt)
            if y_or_n == "y":
                self.funk_dict = {}
                print()
                log.logger.info(
                    "Done. The local funk database has been removed.")
            else:
                return self.abort()
        else:
            self.remove_funk()

        self.commit()
Beispiel #2
0
    def __call__(self):
        super().__call__()
        if not self.funk_dict:
            self.purge_db()
            raise errors.FunkNotDefinedError(global_=self.global_)

        if self.funk is None:
            self.show_search(prefix='')
        elif self.funk[-2:] == '..':
            self.show_search(prefix=self.funk[:-2])
        elif self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)
        else:
            self.show(self.funk)
Beispiel #3
0
    def __call__(self) -> None:
        """See Command.__call__."""
        super().__call__()
        if not self.funk_dict:
            self.purge_db()
            raise errors.FunkNotDefinedError(global_=self.global_)

        if self.funk is None:
            self.show_search(prefix="")
        elif self.funk[-2:] == "..":
            self.show_search(prefix=self.funk[:-2])
        elif self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)
        else:
            self.show(self.funk)
Beispiel #4
0
    def __call__(self):
        super().__call__()
        if self.funk and self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)

        try:
            self.edit_funk()
            log.logger.info('Edited funk "%s".', self.funk)
        except errors.BlankDefinition as e:
            log.logger.info(str(e))
            self.remove_funk()

        self.commit()
Beispiel #5
0
    def show_search(self, prefix):
        """Prints all funks that start with @prefix to stdout."""
        log.logger.debug('Running show command for all defined funks.')
        sorted_funks = sorted([funk for funk in self.funk_dict if funk.startswith(prefix)],
                              key=lambda x: x.lower())

        if not sorted_funks:
            raise errors.FunkNotDefinedError(funk=self.funk)

        for funk in sorted_funks:
            if self.verbose:
                print()
            self.show(funk)
Beispiel #6
0
    def __call__(self):
        super().__call__()
        if self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)

        new_funk = self.args[0]
        if new_funk in self.funk_dict:
            y_or_n = utils.getch('"{}" is already in use. Overwrite? (y/n): '.format(new_funk))
            if y_or_n == 'y':
                print()
            else:
                return self.abort()

        self.funk_dict[new_funk] = self.funk_dict[self.funk]
        self.funk_dict.pop(self.funk)

        msg_fmt = 'Funk "{}" has successfully been renamed to "{}".'
        log.logger.info(msg_fmt.format(self.funk, new_funk))
        self.commit()
Beispiel #7
0
    def __call__(self) -> None:
        """See Command.__call__."""
        super().__call__()
        if self.funk not in self.funk_dict:
            raise errors.FunkNotDefinedError(funk=self.funk)

        new_funk = self.args[0]
        if new_funk in self.funk_dict:
            y_or_n = utils.getch(
                '"{}" is already in use. Overwrite? (y/n): '.format(new_funk))
            if y_or_n == "y":
                print()
            else:
                return self.abort()

        self.funk_dict[new_funk] = self.funk_dict[self.funk]
        self.funk_dict.pop(self.funk)

        log.logger.info(
            'Funk "%s" has successfully been renamed to "%s".',
            self.funk,
            new_funk,
        )
        self.commit()