<commit_before>from bookhelper import on_no_errors
from bookhelper.cmds import publish, versionize, status, create, importer


class Starter(object):

    command_mapping = {
        "publish": publish.PublishAction,
        "versionize": versionize.VersionizeAction,
        "status": status.StatusAction,
        "create": create.CreateAction,
        "import": importer.ImportAction,
    }

    def __init__(self, conf):
        self.errors = []
        self.conf = conf
        self.action = self.get_action()

    def start(self):
        self.action.validate()
        self.errors += self.action.errors
        res = "FAILED"
        if not self.errors:
            res = self.run_cmd()
        if not self.errors:
            if not res:
                res = "SUCCESS"
        return res

    @on_no_errors
    def get_action(self):
        Action = self.command_mapping[self.conf.cmd]
        return Action(self.conf)

    def run_cmd(self):
        if self.conf.queued:
            # ugly, but ...
            # celeryapp expects "--sqlitedb" in  sys.argv
            import sys
            sys.argv.append('--db-path=%s' % (self.conf.tmp_path))
            #sys.exit(str(sys.argv))
            from bookhelper.celeryapp import async_action
            task = async_action.delay(self.action)
            return task.id
        else:
            res = self.action.run()
            self.errors += self.action.errors
            return res
<commit_msg>dbpath for celery<commit_after>from bookhelper import on_no_errors
from bookhelper.cmds import publish, versionize, status, create, importer


class Starter(object):

    command_mapping = {
        "publish": publish.PublishAction,
        "versionize": versionize.VersionizeAction,
        "status": status.StatusAction,
        "create": create.CreateAction,
        "import": importer.ImportAction,
    }

    def __init__(self, conf):
        self.errors = []
        self.conf = conf
        self.action = self.get_action()

    def start(self):
        self.action.validate()
        self.errors += self.action.errors
        res = "FAILED"
        if not self.errors:
            res = self.run_cmd()
        if not self.errors:
            if not res:
                res = "SUCCESS"
        return res

    @on_no_errors
    def get_action(self):
        Action = self.command_mapping[self.conf.cmd]
        return Action(self.conf)

    def run_cmd(self):
        import sys
        sys.argv.append('--db-path=%s' % (self.conf.tmp_path))
        #sys.exit(str(sys.argv))
        if self.conf.queued:
            from bookhelper.celeryapp import async_action
            task = async_action.delay(self.action)
            return task.id
        else:
            res = self.action.run()
            self.errors += self.action.errors
            return res

{'fraction_non_alphanumeric': 0.10368011323425336, 'fraction_numerical': 0.0, 'mean_word_length': 1.9024640657084189, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5177376', 'n_tokens_mistral': 817, 'n_tokens_neox': 802, 'n_words': 181}