def call_asciidoc(src, dst): """Call asciidoc for the given files. Args: src: The source .asciidoc file. dst: The destination .html file, or None to auto-guess. """ print("Calling asciidoc for {}...".format(os.path.basename(src))) if os.name == 'nt': # FIXME this is highly specific to my machine # https://github.com/The-Compiler/qutebrowser/issues/106 args = [r'C:\Python27\python', r'J:\bin\asciidoc-8.6.9\asciidoc.py'] else: args = ['asciidoc'] if dst is not None: args += ['--out-file', dst] args.append(src) try: subprocess.check_call(args) except FileNotFoundError: utils.print_col("asciidoc needs to be installed to use this script!", 'red') sys.exit(1) except (subprocess.CalledProcessError, OSError) as e: utils.print_col(str(e), 'red') sys.exit(1)
def main(colors=False): """Generate html files for the online documentation.""" utils.change_cwd() utils.use_color = colors parser = argparse.ArgumentParser() parser.add_argument('--website', help="Build website into a given " "directory.", nargs=1) parser.add_argument('--asciidoc', help="Full path to python and " "asciidoc.py. If not given, it's searched in PATH.", nargs=2, required=False, metavar=('PYTHON', 'ASCIIDOC')) parser.add_argument('--no-authors', help=argparse.SUPPRESS, action='store_true') args = parser.parse_args() try: os.mkdir('qutebrowser/html/doc') except FileExistsError: pass asciidoc = AsciiDoc(args) try: asciidoc.prepare() except FileNotFoundError: utils.print_col("Could not find asciidoc! Please install it, or use " "the --asciidoc argument to point this script to the " "correct python/asciidoc.py location!", 'red') sys.exit(1) try: asciidoc.build() finally: asciidoc.cleanup()
def check_git(): """Check for uncommited git files..""" if not os.path.isdir(".git"): print("No .git dir, ignoring") print() return False untracked = [] changed = [] gitst = subprocess.check_output(['git', 'status', '--porcelain']) gitst = gitst.decode('UTF-8').strip() for line in gitst.splitlines(): s, name = line.split(maxsplit=1) if s == '??' and name != '.venv/': untracked.append(name) elif s == 'M': changed.append(name) status = True if untracked: status = False utils.print_col("Untracked files:", 'red') print('\n'.join(untracked)) if changed: status = False utils.print_col("Uncommited changes:", 'red') print('\n'.join(changed)) print() return status
def main(): """Regenerate all documentation.""" utils.print_col("Generating asciidoc files...", 'cyan') regenerate_manpage('doc/qutebrowser.1.asciidoc') generate_settings('doc/help/settings.asciidoc') generate_commands('doc/help/commands.asciidoc') regenerate_authors('README.asciidoc') if '--html' in sys.argv: asciidoc2html.main()
def main(colors=False): """Generate html files for the online documentation.""" utils.change_cwd() utils.use_color = colors parser = argparse.ArgumentParser() parser.add_argument('--all', help="Build all documentation into a given " "directory.", nargs=1) parser.add_argument('--asciidoc', help="Full path to python and " "asciidoc.py. If not given, it's searched in PATH.", nargs=2, required=False, metavar=('PYTHON', 'ASCIIDOC')) args = parser.parse_args() asciidoc_files = [ ('FAQ.asciidoc', 'qutebrowser/html/doc/FAQ.html'), ('CHANGELOG.asciidoc', 'qutebrowser/html/doc/CHANGELOG.html'), ('doc/quickstart.asciidoc', 'qutebrowser/html/doc/quickstart.html'), ('doc/userscripts.asciidoc', 'qutebrowser/html/doc/userscripts.html'), ] try: os.mkdir('qutebrowser/html/doc') except FileExistsError: pass try: asciidoc = _get_asciidoc_cmd(args) except FileNotFoundError: utils.print_col("Could not find asciidoc! Please install it, or use " "the --asciidoc argument to point this script to the " "correct python/asciidoc.py location!", 'red') sys.exit(1) if args.all: for root, _dirs, files in os.walk(os.getcwd()): for filename in files: if os.path.splitext(filename)[1] != '.asciidoc': continue src = os.path.join(root, filename) parts = [args.all[0]] dirname = os.path.dirname(src) if dirname: parts.append(os.path.relpath(os.path.dirname(src))) parts.append( os.extsep.join((os.path.splitext(os.path.basename(src))[0], 'html'))) dst = os.path.join(*parts) os.makedirs(os.path.dirname(dst), exist_ok=True) call_asciidoc(asciidoc, src, dst) else: for src in glob.glob('doc/help/*.asciidoc'): name, _ext = os.path.splitext(os.path.basename(src)) dst = 'qutebrowser/html/doc/{}.html'.format(name) asciidoc_files.append((src, dst)) for src, dst in asciidoc_files: call_asciidoc(asciidoc, src, dst)
def main(): """Main entry point.""" exit_status = collections.OrderedDict() exit_status_bool = {} parser = argparse.ArgumentParser(description='Run various checkers.') parser.add_argument('-s', '--setup', help="Run additional setup checks", action='store_true') parser.add_argument('checkers', help="Checkers to run (or 'all')", default='all', nargs='?') args = parser.parse_args() checkers = _get_checkers() groups = ['global'] groups += config.get('DEFAULT', 'targets').split(',') groups.append('setup') for group in groups: print() utils.print_col("==================== {} ====================".format( group), 'yellow') for name, func in checkers[group].items(): utils.print_col("------ {} ------".format(name), 'cyan') if _checker_enabled(args, group, name): status = func() key = '{}_{}'.format(group, name) exit_status[key] = status if name == 'flake8': # pyflakes uses True for errors and False for ok. exit_status_bool[key] = not status elif isinstance(status, bool): exit_status_bool[key] = status else: # sys.exit(0) means no problems -> True, anything != 0 # means problems. exit_status_bool[key] = (status == 0) else: utils.print_col("Checker disabled.", 'blue') print() utils.print_col("Exit status values:", 'yellow') for (k, v) in exit_status.items(): ok = exit_status_bool[k] color = 'green' if ok else 'red' utils.print_col( ' {} - {} ({})'.format(k, 'ok' if ok else 'FAIL', v), color) if all(exit_status_bool): return 0 else: return 1
def main(): """Main entry point.""" utils.change_cwd() read_files = config.read('.run_checks') if not read_files: raise IOError("Could not read config!") exit_status = collections.OrderedDict() exit_status_bool = {} args = _parse_args() checkers = _get_checkers() groups = ['global'] groups += config.get('DEFAULT', 'targets').split(',') groups.append('setup') for group in groups: print() utils.print_col("==================== {} ====================".format( group), 'yellow') for name, func in checkers[group].items(): utils.print_col("------ {} ------".format(name), 'cyan') if _checker_enabled(args, group, name): status = func() key = '{}_{}'.format(group, name) exit_status[key] = status if name == 'flake8': # pyflakes uses True for errors and False for ok. exit_status_bool[key] = not status elif isinstance(status, bool): exit_status_bool[key] = status else: # sys.exit(0) means no problems -> True, anything != 0 # means problems. exit_status_bool[key] = (status == 0) else: utils.print_col("Checker disabled.", 'blue') print() utils.print_col("Exit status values:", 'yellow') for (k, v) in exit_status.items(): ok = exit_status_bool[k] color = 'green' if ok else 'red' utils.print_col( ' {} - {} ({})'.format(k, 'ok' if ok else 'FAIL', v), color) if all(exit_status_bool): return 0 else: return 1
def call_asciidoc(args, src, dst): """Call asciidoc for the given files. Args: args: The asciidoc binary to use, as a list. src: The source .asciidoc file. dst: The destination .html file, or None to auto-guess. """ print("Calling asciidoc for {}...".format(os.path.basename(src))) args = args[:] if dst is not None: args += ['--out-file', dst] args.append(src) try: subprocess.check_call(args) except (subprocess.CalledProcessError, OSError) as e: utils.print_col(str(e), 'red') sys.exit(1)
def check_git(): """Check for uncommitted git files..""" if not os.path.isdir(".git"): print("No .git dir, ignoring") print() return False untracked = [] gitst = subprocess.check_output(["git", "status", "--porcelain"]) gitst = gitst.decode("UTF-8").strip() for line in gitst.splitlines(): s, name = line.split(maxsplit=1) if s == "??" and name != ".venv/": untracked.append(name) status = True if untracked: status = False utils.print_col("Untracked files:", "red") print("\n".join(untracked)) print() return status
def call_asciidoc(src, dst): """Call asciidoc for the given files. Args: src: The source .asciidoc file. dst: The destination .html file, or None to auto-guess. """ utils.print_col("Calling asciidoc for {}...".format( os.path.basename(src)), 'cyan') if os.name == 'nt': # FIXME this is highly specific to my machine args = [r'C:\Python27\python', r'J:\bin\asciidoc-8.6.9\asciidoc.py'] else: args = ['asciidoc'] if dst is not None: args += ['--out-file', dst] args.append(src) try: subprocess.check_call(args) except subprocess.CalledProcessError as e: utils.print_col(str(e), 'red') sys.exit(1)
def call(self, src, dst, *args): """Call asciidoc for the given files. Args: src: The source .asciidoc file. dst: The destination .html file, or None to auto-guess. *args: Additional arguments passed to asciidoc. """ print("Calling asciidoc for {}...".format(os.path.basename(src))) cmdline = self._cmd[:] if dst is not None: cmdline += ['--out-file', dst] cmdline += args cmdline.append(src) try: subprocess.check_call(cmdline, env={'HOME': self._homedir}) self._failed = True except (subprocess.CalledProcessError, OSError) as e: self._failed = True utils.print_col(str(e), 'red') print("Keeping modified sources in {}.".format(self._homedir)) sys.exit(1)
def print_ret(ret): """Print information about an exit status.""" if ret == 0: utils.print_col("success", 'green') elif ret == -signal.SIGSEGV: utils.print_col("segfault", 'red') else: utils.print_col("error {}".format(ret), 'yellow') print()