def read_info(fname): all = bindery.parse(fname.read()).vector info = [v for v in all.xml_children if v.xml_type == "element"] def setImplements(fcns): for fcn in fcns: fcn.name = str(fcn.nameStr) fcn.impl = getattr(fcn, "implName", None) fcn.impl = (str(fcn.impl) if fcn.impl else fcn.impl) fcn.line_idx = int(str(fcn.lineNum)) - 1 fcn.is_generator = str(fcn.isGenerator) == "true" for fcn in fcns: fcn.is_toplevel = getattr(fcn, "is_toplevel", False) or bool( fcn.impl) if fcn.impl: try: get_singleton(v for v in fcns if v.name == fcn.impl).is_toplevel = True except GetSingletonEmptyException: global couldntfindexception couldntfindexception = True print("couldn't find function %s for file %s" % (fcn.impl, fcn.srcFile)) return fcns return dict(list(info).equiv_classes( lambda a: Path(str(a.srcFile)))).map_values(setImplements)
def run_osc_commit(name, tmppath, commit_msg): repopath = Path("home:gatoatigrado1/%s" % (name)) skip = False if Path("home:gatoatigrado1").exists(): with ExecuteIn(Path("home:gatoatigrado1")): skip = list(SubProc(["osc", "status"]).exec_lines()) == [] if not skip: try: SubProc(["osc", "co", "home:gatoatigrado1", name]).start_wait() except OSError: print("\n\n\nosc not found in path; install with 'sudo zypper -n in osc'", file=sys.stderr) else: print("skipping already checked out source.") [v.copy(repopath.subpath(v.basename())) for v in tmppath.files()] with ExecuteIn(repopath): SubProc(["osc", "add"] + [v for v in Path(".").listdir() if v != ".osc"]).start_wait() SubProc(["osc", "commit"] + (["-m", commit_msg] if commit_msg else [])).start_wait()
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)
def run_osc_commit(name, tmppath, commit_msg): repopath = Path("home:gatoatigrado1/%s" % (name)) skip = False if Path("home:gatoatigrado1").exists(): with ExecuteIn(Path("home:gatoatigrado1")): skip = list(SubProc(["osc", "status"]).exec_lines()) == [] if not skip: try: SubProc(["osc", "co", "home:gatoatigrado1", name]).start_wait() except OSError: print( "\n\n\nosc not found in path; install with 'sudo zypper -n in osc'", file=sys.stderr) else: print("skipping already checked out source.") [v.copy(repopath.subpath(v.basename())) for v in tmppath.files()] with ExecuteIn(repopath): SubProc(["osc", "add"] + [v for v in Path(".").listdir() if v != ".osc"]).start_wait() SubProc(["osc", "commit"] + (["-m", commit_msg] if commit_msg else [])).start_wait()
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)
def main(name, version, proj_path, conf_path, no_inc_release, tmpdir, run_local_install, osc_commit, commit_msg, upload_to_cobol, additional_path): proj_path, conf_path, tmpdir = Path(proj_path), Path(conf_path), Path( tmpdir) assert proj_path.subpath( ".hg").isdir(), "please run in base directory (with .hg)" check_modified() version = get_sketch_version(proj_path) if version is None else version # NOTE -- need to use gz instead of lzma for Debian compatibility sourcefile = "%s_%s.orig.tar.gz" % (name, version) release_number_v = get_release_version(conf_path, no_inc_release) tmppath = tmpdir.subpath("%s-%s" % (name, version)) if tmppath.exists(): print("temporary directory exists; delete it? ", end="") sys.stdout.flush() if "y" in raw_input(): tmppath.rmtree() tmppath.makedirs() srcpath = tmppath.subpath("%s-%s" % (name, version)) proj_path.copytree(srcpath) pathmap = { "debian.control": srcpath.subpath("debian/control"), "debian.rules": srcpath.subpath("debian/rules"), "debian.changelog": srcpath.subpath("debian/changelog") } with ExecuteIn(srcpath): assert (Path(".") != proj_path) SubProc(["zsh", "-c", r"rm -rf $(hg stat -uin) .hg*"]).start_wait() files = [conf_path.subpath("%s.spec.jinja2" % (name))] nondsc_files = [v for v in files if not "dsc" in v] dsc_files = [v for v in files if "dsc" in v] with ExecuteIn(conf_path): run_jinja2(nondsc_files, tmppath, name, version, sourcefile, release_number_v, pathmap) if additional_path: additional_path = Path(additional_path) final_path = srcpath.subpath(additional_path.basename()) final_path.rmtree() additional_path.copytree(final_path) with ExecuteIn(tmppath): SubProc(["tar", "cfa", sourcefile, srcpath.basename()]).start_wait() srcpath.rmtree() with ExecuteIn(conf_path): run_jinja2(dsc_files, tmppath, name, version, sourcefile, release_number_v, pathmap) with ExecuteIn(tmppath): if run_local_install: SubProc(["build"]).start_wait() if osc_commit: run_osc_commit(name, tmppath, commit_msg) if upload_to_cobol: with ExecuteIn(tmpdir): if osc_commit: repopath.parent().rmtree() tar_name = sourcefile.replace("lzma", "tar") SubProc(["tar", "cfa", tar_name, tmppath.basename()]).start_wait() SubProc([ "scp", tar_name, "[email protected]:public_html/temp" ])
# Copyright 2009 University of California, Berkeley # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain a # copy of the License at http://www.apache.org/licenses/LICENSE-2.0 . from __future__ import division, print_function from collections import namedtuple try: from gatoatigrado_lib import (ExecuteIn, Path, SubProc, dict, get_singleton, list, memoize_file, pprint, process_jinja2, set, sort) except: raise ImportError("please install gatoatigrado's utility library from " "bitbucket.org/gatoatigrado/gatoatigrado_lib") modpath = Path(__file__).parent() includepath = modpath.subpath("includes") 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})
def main(name, version, proj_path, conf_path, no_inc_release, tmpdir, run_local_install, osc_commit, commit_msg, upload_to_cobol, additional_path): proj_path, conf_path, tmpdir = Path(proj_path), Path(conf_path), Path(tmpdir) assert proj_path.subpath(".hg").isdir(), "please run in base directory (with .hg)" check_modified() version = get_sketch_version(proj_path) if version is None else version # NOTE -- need to use gz instead of lzma for Debian compatibility sourcefile = "%s_%s.orig.tar.gz" % (name, version) release_number_v = get_release_version(conf_path, no_inc_release) tmppath = tmpdir.subpath("%s-%s" % (name, version)) if tmppath.exists(): print("temporary directory exists; delete it? ", end="") sys.stdout.flush() if "y" in raw_input(): tmppath.rmtree() tmppath.makedirs() srcpath = tmppath.subpath("%s-%s" % (name, version)) proj_path.copytree(srcpath) pathmap = { "debian.control": srcpath.subpath("debian/control"), "debian.rules": srcpath.subpath("debian/rules"), "debian.changelog": srcpath.subpath("debian/changelog") } with ExecuteIn(srcpath): assert (Path(".") != proj_path) SubProc(["zsh", "-c", r"rm -rf $(hg stat -uin) .hg*"]).start_wait() files = [conf_path.subpath("%s.spec.jinja2" % (name))] nondsc_files = [v for v in files if not "dsc" in v] dsc_files = [v for v in files if "dsc" in v] with ExecuteIn(conf_path): run_jinja2(nondsc_files, tmppath, name, version, sourcefile, release_number_v, pathmap) if additional_path: additional_path = Path(additional_path) final_path = srcpath.subpath(additional_path.basename()) final_path.rmtree() additional_path.copytree(final_path) with ExecuteIn(tmppath): SubProc(["tar", "cfa", sourcefile, srcpath.basename()]).start_wait() srcpath.rmtree() with ExecuteIn(conf_path): run_jinja2(dsc_files, tmppath, name, version, sourcefile, release_number_v, pathmap) with ExecuteIn(tmppath): if run_local_install: SubProc(["build"]).start_wait() if osc_commit: run_osc_commit(name, tmppath, commit_msg) if upload_to_cobol: with ExecuteIn(tmpdir): if osc_commit: repopath.parent().rmtree() tar_name = sourcefile.replace("lzma", "tar") SubProc(["tar", "cfa", tar_name, tmppath.basename()]).start_wait() SubProc(["scp", tar_name, "[email protected]:public_html/temp"])
"--showphase": "--debug-show-phase", "--branchamnt": "--bnd-branch-amnt", "--main_names": "--sem-main-names", "--heapsize": "--bnd-heap-size", "--reorderEncoding": "--slv-reorder-encoding", "--vectorszGuess": "--par-vectorsz-guess", "--inbits": "--bnd-inbits", "--cex": "--debug-cex", "--sem-main-names": "--sem-main-names", "--outputcode": "--sem-main-names", "--intbits": "--bnd-intbits", "--cbits": "--bnd-cbits", "--keepasserts": "--fe-keep-asserts" } files = Path('.').walk_files(['sk']) def print_pragmas(): lines = [line.strip() for file in files for line in open(file).readlines()] lines = [ v.lstrip('pragma options ') for v in lines if v.startswith('pragma options ') and v.endswith(';') ] result = defaultdict(lambda: 0) for flag in [v.strip() for line in lines for v in flagre.findall(line)]: result[flag] += 1 print("=== flags and counts ===") result = dict(result) pprint(result)
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain a # copy of the License at http://www.apache.org/licenses/LICENSE-2.0 . from __future__ import division, print_function from collections import namedtuple try: from gatoatigrado_lib import (ExecuteIn, Path, SubProc, dict, get_singleton, list, memoize_file, pprint, process_jinja2, set, sort) except: raise ImportError("please install gatoatigrado's utility library from " "bitbucket.org/gatoatigrado/gatoatigrado_lib") modpath = Path(__file__).parent() includepath = modpath.subpath("includes") 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])
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))
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))