예제 #1
0
def main():
    from jinja2 import Environment, FileSystemLoader
    import jinja2.ext
    mvnfile = Path("pom.xml")
    assert mvnfile.exists(), "please run in project root (with ./pom.xml)"
    version = "1.6.4"

    paths = list(modpath.walk_files(["jinja2"]))
    dirs = frozenset(v.parent() for v in paths).union((includepath,))
    env = Environment(loader=FileSystemLoader(list(dirs)),
        trim_blocks=True, extensions=[jinja2.ext.do])
    env.globals.update({"version": version})

    for fname in Path("scripts").walk_files(["jinja2"]):
        output = env.get_template(fname.basename()).render()
        outname = fname.parent().subpath("final", fname.basename().strip(".jinja2"))
        Path(outname).write_if_different(output)
        if "launchers" in fname:
            Path(outname).chmod(0755)
예제 #2
0
def main():
    from jinja2 import Environment, FileSystemLoader
    import jinja2.ext
    mvnfile = Path("pom.xml")
    assert mvnfile.exists(), "please run in project root (with ./pom.xml)"
    version = "1.6.4"

    paths = list(modpath.walk_files(["jinja2"]))
    dirs = frozenset(v.parent() for v in paths).union((includepath, ))
    env = Environment(loader=FileSystemLoader(list(dirs)),
                      trim_blocks=True,
                      extensions=[jinja2.ext.do])
    env.globals.update({"version": version})

    for fname in Path("scripts").walk_files(["jinja2"]):
        output = env.get_template(fname.basename()).render()
        outname = fname.parent().subpath("final",
                                         fname.basename().strip(".jinja2"))
        Path(outname).write_if_different(output)
        if "launchers" in fname:
            Path(outname).chmod(0755)
예제 #3
0
def main(*sketchfiles):
    # make sure sketch-noarch.jar exists
    assembly_file = Path("sketch-noarch.jar")
    if not assembly_file.isfile():
        raise Exception("please run renamer-script to generate sketch-noarch.jar")

    # use all sketch files which are subpaths of directory if they exist
    if not sketchfiles:
        sketchfiles = [v for v in Path(".").walk_files() if v.extension() in ["sk", "skh"]]
    else:
        sketchfiles = [Path(v) for v in sketchfiles]
    # sketchfiles = sketchfiles[:1000]

    # run the Java program
    outpath = Path("function_list.xml")
    outpath.exists() and outpath.unlink()
    #[get_info(v) for v in sketchfiles]
    for coarse_idx in range(0, len(sketchfiles), 100):
        subset = map(str, sketchfiles[coarse_idx:(coarse_idx + 100)])
        SubProc(["java", "-classpath", "sketch-noarch.jar",
            "sketch.compiler.main.other.ParseFunctions"] + subset).start_wait()

    fcns_by_fname = read_info(outpath)
    if couldntfindexception:
        print("(press enter to continue)", end="")
        sys.stdin.readline()
    
    for fname, fcns in fcns_by_fname.items():
        lines = open(fname).readlines()
        for fcn in fcns:
            success = False
            if not (0 <= fcn.line_idx < len(lines)):
                print("line offset not in range, assuming it came from a header file")
                success = True
            elif not str(fcn.name) in lines[fcn.line_idx]:
                print("function name not in line, assuming it came from a header file")
                success = True
            else:
                for err_offset in [0, -1, 1, -2, 2]:
                    if not (0 <= fcn.line_idx + err_offset < len(lines)):
                        continue
                    
                    line = lines[fcn.line_idx + err_offset]
                    if REWR_STR in line:
                        success = True
                        break

                    first_char = FIRST_CHAR.search(line)
                    if not first_char:
                        continue

                    try:
                        lines[fcn.line_idx + err_offset] = try_rewrite(line, first_char.start(), fcn)
                        success = True
                        break
                    except RewriteException, e:
                        print("WARNING / REWRITE EXCEPTION -- %s -- %s:%d"
                            %(fname, e, fcn.line_idx + err_offset))
                        continue
            if not success:
                print("    WARNING -- couldn't perform rewrite on all neighboring lines!")

        Path(fname + ".rewrite").write("".join(lines))
예제 #4
0
def main(*sketchfiles):
    # make sure sketch-noarch.jar exists
    assembly_file = Path("sketch-noarch.jar")
    if not assembly_file.isfile():
        raise Exception(
            "please run renamer-script to generate sketch-noarch.jar")

    # use all sketch files which are subpaths of directory if they exist
    if not sketchfiles:
        sketchfiles = [
            v for v in Path(".").walk_files()
            if v.extension() in ["sk", "skh"]
        ]
    else:
        sketchfiles = [Path(v) for v in sketchfiles]
    # sketchfiles = sketchfiles[:1000]

    # run the Java program
    outpath = Path("function_list.xml")
    outpath.exists() and outpath.unlink()
    #[get_info(v) for v in sketchfiles]
    for coarse_idx in range(0, len(sketchfiles), 100):
        subset = map(str, sketchfiles[coarse_idx:(coarse_idx + 100)])
        SubProc([
            "java", "-classpath", "sketch-noarch.jar",
            "sketch.compiler.main.other.ParseFunctions"
        ] + subset).start_wait()

    fcns_by_fname = read_info(outpath)
    if couldntfindexception:
        print("(press enter to continue)", end="")
        sys.stdin.readline()

    for fname, fcns in fcns_by_fname.items():
        lines = open(fname).readlines()
        for fcn in fcns:
            success = False
            if not (0 <= fcn.line_idx < len(lines)):
                print(
                    "line offset not in range, assuming it came from a header file"
                )
                success = True
            elif not str(fcn.name) in lines[fcn.line_idx]:
                print(
                    "function name not in line, assuming it came from a header file"
                )
                success = True
            else:
                for err_offset in [0, -1, 1, -2, 2]:
                    if not (0 <= fcn.line_idx + err_offset < len(lines)):
                        continue

                    line = lines[fcn.line_idx + err_offset]
                    if REWR_STR in line:
                        success = True
                        break

                    first_char = FIRST_CHAR.search(line)
                    if not first_char:
                        continue

                    try:
                        lines[fcn.line_idx + err_offset] = try_rewrite(
                            line, first_char.start(), fcn)
                        success = True
                        break
                    except RewriteException, e:
                        print("WARNING / REWRITE EXCEPTION -- %s -- %s:%d" %
                              (fname, e, fcn.line_idx + err_offset))
                        continue
            if not success:
                print(
                    "    WARNING -- couldn't perform rewrite on all neighboring lines!"
                )

        Path(fname + ".rewrite").write("".join(lines))