Skip to content

Instantly share code, notes, and snippets.

@SirVer
Created April 20, 2014 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirVer/11122037 to your computer and use it in GitHub Desktop.
Save SirVer/11122037 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
import os.path
from subprocess import Popen, PIPE, STDOUT
from colorama import Fore, Back, Style
from shell_grunt import WorkItem, Executor
import sys
class BuildWidelands(WorkItem):
name = "Building widelands"
command = lambda selp, paths: ["ninja", "-k", "5"]
output_file = "/tmp/wl_errors.log"
output_stream = "/tmp/wl_errors_stream.log"
cwd="../widelands.build"
start_delay = 1.2
@staticmethod
def path_matcher(fn):
extension = os.path.splitext(fn)[-1].lower()
if extension in [".cc", ".h", ".pyx"]:
# files = [ l.strip() for l in open("files.txt") ]
# if "test/richtext" in fn or "src/graphic/text" in fn:
# launch("Building everything in test/richtext", ["scons", "-C", "test/richtext", "-j5"], "/tmp/rt_errors.log")
if "src/" in fn:
return True
# launch("Building everything in test/richtext", ["scons", "-C", "test/richtext", "-j5"], "/tmp/rt_errors.log")
return False
class Ctags(WorkItem):
name = "ctags"
command = lambda self, paths: ["ctags", "--fields=+l", "-R", "src"]
start_delay = 0.1
path_matcher = staticmethod(lambda fn: any(ext in fn for ext in ['.cc', '.h']))
report_launch = lambda self: True
report_finish = lambda self: True
class RebuildCtrlPCache(WorkItem):
name = "Rebuilding CtrlP cache"
command = lambda self, paths: ["find", "-E", ".", "-type", "f",
"-and", "-not", "-iname", "*.png",
"-and", "-not", "-iname", "*.jpg",
"-and", "-not", "-iname", "*.mo",
"-and", "-not", "-iregex", r".*\.bzr\/.*",
"-and", "-not", "-iregex", r".*\.bzr-repo\/.*",
"-and", "-not", "-iregex", r".*binary\/.*",
]
output_file = "/Users/sirver/.cache/ctrlp/%Users%sirver%Desktop%Programming%cpp%widelands%bzr_repo.txt"
start_delay = .5
path_matcher = staticmethod(lambda fn: True)
report_launch = lambda self: True
_paths_to_check = set()
class StyleChecker(WorkItem):
name = "Checking Style"
output_file = "/tmp/wl_style_errors.log"
start_delay = 6
def report_launch(self): True
def report_finish(self):
if open(self.output_file, "r").read():
sys.stdout.write(Fore.YELLOW + "-> Has Style warnings." + Fore.RESET + "\n")
sys.stdout.flush()
@staticmethod
def path_matcher(fn):
extension = os.path.splitext(fn)[-1].lower()
return extension in [".cc", ".h", ".pyx"]
def command(self, paths):
_paths_to_check.update(paths)
d = {}
for p in _paths_to_check:
d[p] = Popen(["cmake/codecheck/CodeCheck.py", p], stderr=STDOUT, stdout=PIPE, cwd=self.cwd)
## Remove paths that do not have any style warnings again.
for p in d:
d[p].wait()
if not d[p].stdout.read():
_paths_to_check.remove(p)
if not _paths_to_check:
return ["true"]
return ["cmake/codecheck/CodeCheck.py"] + sorted(_paths_to_check)
if __name__ == "__main__":
executor = Executor()
executor.add_item(Ctags)
executor.add_item(StyleChecker)
executor.add_item(BuildWidelands)
executor.add_item(RebuildCtrlPCache)
executor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment