def init(args): folder = _cfg("storage_folder") sharding_level = _cfgi("sharding") for i in range(64 ** sharding_level): try: os.mkdir(os.path.join(folder, int2base(i, 64))) except OSError as e: print(e)
def run(self, timeout=_cfgi("max_processing_time")): if not self.args: self.args = self.command.split() thread = threading.Thread(target=self._target) thread.start() thread.join(timeout) if thread.is_alive(): print("Terminating process") self.process.terminate() thread.join() self.exited = True self.returncode = self.process.returncode
# Copy images, preprocess some JS files for folder in copy: for f in list(os.walk(folder))[0][2]: outputpath = os.path.join(app.static_folder, os.path.basename(f)) inputpath = os.path.join(folder, f) if inputpath in preprocess: with open(inputpath) as r: # Using Jinja here is overkill output = r.read() output = output.replace("{{ protocol }}", _cfg("protocol")) output = output.replace("{{ domain }}", _cfg("domain")) with open(outputpath, "w") as w: w.write(output) w.flush() else: copyfile(inputpath, outputpath) @app.before_first_request def compile_first(): prepare() @app.before_request def compile_if_debug(): if app.debug: prepare() if __name__ == '__main__': app.run(host=_cfg("debug-host"), port=_cfgi('debug-port'), debug=True)
from mediacrush.app import app from mediacrush.config import _cfg, _cfgi import os app.static_folder = os.path.join(os.getcwd(), "static") if __name__ == '__main__': app.run(host=_cfg("debug-host"), port=_cfgi('debug-port'), debug=True)
def shard(path): sharding_level = _cfgi("sharding") return os.path.join(path[:sharding_level], path)