def main(srcdir, file_extensions, **kwargs): assert type(file_extensions) == list for root, dirs, files in Path(srcdir).walk(): for f in files: f = Path(root, f) if f.splitext()[-1][1:] in file_extensions: check_file(f, **kwargs)
def compile_all(self): src_files = set() for root, dirs, files in self.src_path.walk(): filter_ = re.compile(self.src_filter) if self.src_filter else None for f in files: path = Path(root, f) if not path.extension() in self.src_extensions: continue if not filter_ or filter_.search(str(path)): src_files.add(path) if src_files: self.compile_(src_files)
def __init__(self, **kwargs): self.__dict__.update(kwargs) self.src_path = Path(self.src_path) self.out_path = Path(self.out_path) self.print = self.print or self.src_filter self.classpath = os.environ["CLASSPATH"] self.src_extensions = self.src_extensions.split(",") try: self.plugin_path = path_resolv.resolve("lib/sketchrewriter.jar") except: self.plugin_path = "" assert self.src_path.exists() and self.out_path.exists()
class Compiler(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) self.src_path = Path(self.src_path) self.out_path = Path(self.out_path) self.print = self.print or self.src_filter self.classpath = os.environ["CLASSPATH"] self.src_extensions = self.src_extensions.split(",") try: self.plugin_path = path_resolv.resolve("lib/sketchrewriter.jar") except: self.plugin_path = "" assert self.src_path.exists() and self.out_path.exists() def clean_dir(self): if self.clean: [self.out_path.subpath(f).remove_tree() for f in self.out_path.listdir()] @staticmethod def print_cmd(cmd): def quote(v): v = re.sub("([\$\'\"])", r"\\\g<1>", v) return "\"%s\"" %(v) if (" " in v) else v print(" ".join([quote(v) for v in cmd])) def run(self, cmd, save_output=None, file_ext="txt"): if self.print: self.print_cmd(cmd) save_output = (self.kwrite or self.vim) if save_output else save_output pipe_output = { "stdout": subprocess.PIPE } if save_output else { } try: proc = subprocess.Popen(cmd, **pipe_output) text = proc.communicate()[0] except Exception, e: proc = namedtuple("anon", "returncode")(1) text = "ERROR RUNNING COMMAND - " + str(e) if proc.returncode != 0: print("=== error compiling ===") if not self.print: self.print_cmd(cmd) if text: print(text) sys.exit(1) elif not save_output: return from tempfile import NamedTemporaryFile tf = NamedTemporaryFile(suffix="." + file_ext, delete=False) tf.write(text) tf.close() if self.kwrite: subprocess.Popen(["kwrite", tf.name], stderr=subprocess.PIPE) elif self.vim: subprocess.Popen(["vim", tf.name]).wait()
#!/usr/bin/env python2.6 # -*- coding: utf-8 -*- # NOTE - this file is mostly for examining compilation results, not for building the project from __future__ import print_function from collections import namedtuple import optparse, os, re, subprocess, sys import path_resolv from path_resolv import Path # setup classpath os.environ["CLASSPATH"] = Path.pathjoin(os.environ["CLASSPATH"], path_resolv.resolve("lib/scala-library.jar"), path_resolv.resolve("lib/scala-compiler.jar")) # reinit with updated classpath path_resolv.resolvers[0] = path_resolv.EnvironPathResolver() class Compiler(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) self.src_path = Path(self.src_path) self.out_path = Path(self.out_path) self.print = self.print or self.src_filter self.classpath = os.environ["CLASSPATH"] self.src_extensions = self.src_extensions.split(",") try: self.plugin_path = path_resolv.resolve("lib/sketchrewriter.jar") except: self.plugin_path = "" assert self.src_path.exists() and self.out_path.exists()
warn("no license") def main(srcdir, file_extensions, **kwargs): assert type(file_extensions) == list for root, dirs, files in Path(srcdir).walk(): for f in files: f = Path(root, f) if f.splitext()[-1][1:] in file_extensions: check_file(f, **kwargs) if __name__ == "__main__": cmdopts = optparse.OptionParser(usage="%prog [options]") cmdopts.add_option("--srcdir", default=Path("."), help="source directory to look through") cmdopts.add_option("--file_extensions", default="java,scala,py,sh", help="comma-sepated list of file extensions") cmdopts.add_option("--show_info", action="store_true", help="show info for command") cmdopts.add_option("--override_ignores", action="store_true", help="ignore \"@code standards ignore [file]\"") options, args = cmdopts.parse_args() options.file_extensions = options.file_extensions.split(",") if not options.show_info: print("use --show_info to show more notices") main(**options.__dict__)