def run_scipt(cls, name, stdin): from kibitzr.compat import sh logger.debug("Launching script %r", name) try: args = cls.ARGS + [name] return True, sh.Command(cls.EXECUTABLE)(*args, _in=stdin) except sh.ErrorReturnCode as exc: return False, exc
def run_jq(query, text): from kibitzr.compat import sh jq = sh.Command("jq").bake('--monochrome-output', '--raw-output') logger.debug("Running jq query %s against %s", query, text) try: command = jq(query, _in=text) if not command.stderr: success, result = True, command.stdout.decode('utf-8') else: success, result = False, command.stderr.decode('utf-8') except sh.ErrorReturnCode as exc: logger.exception("jq failure") success, result = False, exc.stderr logger.debug("jq transform success: %r, content: %r", success, result) return success, result
def __init__(self, conf, storage_dir=None, style=None): self.storage_dir = storage_dir or self.STORAGE_DIR self.cwd = os.path.join( self.storage_dir, normalize_filename(conf['name']), ) self.target = os.path.join(self.cwd, "content") self.git = sh.Command('git').bake( '--no-pager', _cwd=self.cwd, ) self.ensure_repo_exists() if conf.get('url'): self.commit_msg = f"{conf['name']} at {conf.get('url')}" else: self.commit_msg = conf['name'] self.reporter = ChangesReporter( self.git, self.commit_msg, style, )