def project(raw_path): path = FilePath(raw_path) git_dir = path.child(".git") if git_dir.isdir(): return GitPath(git_dir) hg_dir = path.child(".hg") if hg_dir.isdir(): return HgPath(path) return path
def _find_suite(): root = os.environ.get("JSON_SCHEMA_TEST_SUITE") if root is not None: return FilePath(root) root = FilePath(jsonschema.__file__).parent().sibling("json") if not root.isdir(): raise ValueError( ("Can't find the JSON-Schema-Test-Suite directory. " "Set the 'JSON_SCHEMA_TEST_SUITE' environment " "variable or run the tests from alongside a checkout " "of the suite."), ) return root
def _find_suite(): root = os.environ.get("JSON_SCHEMA_TEST_SUITE") if root is not None: return FilePath(root) root = FilePath(jsonschema.__file__).parent().sibling("json") if not root.isdir(): raise ValueError( ( "Can't find the JSON-Schema-Test-Suite directory. " "Set the 'JSON_SCHEMA_TEST_SUITE' environment " "variable or run the tests from alongside a checkout " "of the suite." ), ) return root
def run( paths, output=_I_STILL_HATE_EVERYTHING, recurse=core.flat, sort_by=lambda x: x, ls=core.ls, stdout=stdout, ): """ Project-oriented directory and file information lister. """ if output is _I_STILL_HATE_EVERYTHING: output = core.columnized if stdout.isatty() else core.one_per_line def _sort_by(thing): return not getattr(thing, "_always_sorts_first", False), sort_by(thing) contents = [ path_and_children for path in paths or (project.from_path(FilePath(".")), ) for path_and_children in recurse(path=path, ls=ls) ] for line in output(contents, sort_by=_sort_by): stdout.write(line) stdout.write("\n")
def assets_in_paths(app, segments): """ Select some assets from all of the static paths in the app which match the given segments, and return the available basenames. Useful for getting a list of options for random selections of banners or other images. """ names = [] for path in app.static_paths: root = FilePath(path) fp = root.descendant(segments) # Get some banners, if they exist. if fp.exists(): names.extend([p.basename() for p in fp.children()]) return names
def run( paths, output=_I_STILL_HATE_EVERYTHING, recurse=core.flat, sort_by=None, ls=core.ls, stdout=stdout, ): """ Project-oriented directory and file information lister. """ if output is _I_STILL_HATE_EVERYTHING: output = core.columnized if stdout.isatty() else core.one_per_line if sort_by is None: if output == core.as_tree: def sort_by(thing): return ( thing.parent(), thing.basename().lstrip(string.punctuation).lower(), ) else: def sort_by(thing): return thing def _sort_by(thing): return not getattr(thing, "_always_sorts_first", False), sort_by(thing) contents = [ path_and_children for path in paths or (project.from_path(FilePath(".")), ) for path_and_children in recurse(path=path, ls=ls) ] for line in output(contents, sort_by=_sort_by): stdout.write(line) stdout.write("\n")
def test_it_works(self): self.cycy.interpret( [FilePath(__file__).sibling("example.c").getContent()], ) self.assertEqual(self.stdout.getvalue(), "Hello, world!\n")
def convert(self, value, param, context): return project.from_path(FilePath(value))
def getStatusChangeTime(self): """ Return the archive file's status change time. """ return FilePath(self.zipfile.filename).getStatusChangeTime()
def getModificationTime(self): """ Return the archive file's modification time. """ return FilePath(self.zipfile.filename).getModificationTime()
def getAccessTime(self): """ Return the archive file's last access time. """ return FilePath(self.zipfile.filename).getAccessTime()
def exists(self): """ Returns whether the underlying archive exists. """ return FilePath(self.zipfile.filename).exists()
$ pypy example.py ~/Desktop/haarcascade_frontalface_default.xml """ from time import time import sys from bp.filepath import FilePath from opencv_cffi.core import Color, invert from opencv_cffi.imaging import Camera from opencv_cffi.gui import ESCAPE, Window from opencv_cffi.object_detection import HaarClassifier cascade_filepath = FilePath(sys.argv[1]) classifier = HaarClassifier.from_path(cascade_filepath, canny_pruning=True) def uglify(frame, facetangle): with frame.region_of_interest(facetangle.right_half): invert(frame) def prettify(frame, facetangle): with frame.region_of_interest(facetangle.right_half): prettified = frame.flipped_vertical() with frame.region_of_interest(facetangle.left_half): prettified.write_into(frame)
@app.context_processor def site_config(): d = app.config["DCON_CONFIG"] return {"dcon": d} load_filters(app) wd = None if wd is None: wd = os.getcwd() wd = FilePath(wd) app.debug = True # This default should be sufficient to limp along for starters. app.config["DCON_STATIC_URL"] = "/static/" app.config["DCON_PATH"] = wd app.config["DCON_PASSWORD_FILE"] = wd.child("passwords.dcon") app.config["DCON_UPLOAD_PATH"] = wd.child("uploads") app.config["SECRET_KEY"] = wd.child("secret.key").open("rb").read() app.config["UPLOADS_DEFAULT_DEST"] = app.config["DCON_UPLOAD_PATH"].path app.config["SESSION_PROTECTION"] = None load_config(app)
#!/usr/bin/env python """ A performance benchmark using the example from issue #232: https://github.com/Julian/jsonschema/pull/232 """ from bp.filepath import FilePath from perf import Runner from pyrsistent import m from jsonschema.tests._suite import Collection import jsonschema collection = Collection( path=FilePath(__file__).sibling("issue232"), remotes=m(), name="issue232", validator=jsonschema.Draft7Validator, ) if __name__ == "__main__": collection.benchmark(runner=Runner())
def children(self): return [FilePath(path) for path in self.listdir()]