def load_backup(self) -> Optional[str]: if config.local_copy_dir is None: return None try: res = resource_string(self.local_copy_fn) if isinstance(res, bytes): return res.decode('utf-8') return res except IOError as ex: log.warning( "Caught an exception trying to load local backup for {} via {}: {}" .format(self.url, self.local_copy_fn, ex)) return None
def plumbing(fn: str) -> Plumbing: """ Create a new plumbing instance by parsing yaml from the filename. :param fn: A filename containing the pipeline. :return: A plumbing object This uses the resource framework to locate the yaml file which means that pipelines can be shipped as plugins. """ pid = os.path.splitext(fn)[0] ystr = resource_string(fn) if ystr is None: raise PipeException("Plumbing not found: %s" % fn) pipeline = yaml.safe_load(ystr) return Plumbing(pipeline=pipeline, pid=pid)
def plumbing(fn): """ Create a new plumbing instance by parsing yaml from the filename. :param fn: A filename containing the pipeline. :return: A plumbing object This uses the resource framework to locate the yaml file which means that pipelines can be shipped as plugins. """ id = os.path.splitext(fn)[0] ystr = resource_string(fn) if ystr is None: raise PipeException("Plumbing not found: %s" % fn) pipeline = yaml.safe_load(ystr) return Plumbing(pipeline=pipeline, id=id)
def test_resource_string(self): assert(resource_string("missing") is None) assert(resource_string("missing", "gone") is None) assert(resource_string('test/data/empty.txt') == 'empty') assert(resource_string('empty.txt', 'test/data') == 'empty') tmp = tempfile.NamedTemporaryFile('w').name with open(tmp, "w") as fd: fd.write("test") try: assert(resource_string(tmp) == "test") (d, fn) = os.path.split(tmp) assert(resource_string(fn, d) == "test") except IOError, ex: raise ex
def test_resource_string(self): assert(resource_string("missing") is None) assert(resource_string("missing", "gone") is None) assert(resource_string('test/data/empty.txt') == six.b('empty')) assert(resource_string('empty.txt', 'test/data') == six.b('empty')) tmp = tempfile.NamedTemporaryFile('w').name with open(tmp, "w") as fd: fd.write("test") try: print(resource_string(tmp)) assert(resource_string(tmp) == 'test') (d, fn) = os.path.split(tmp) assert(resource_string(fn, d) == 'test') except IOError as ex: raise ex finally: try: os.unlink(tmp) except Exception: pass
def favicon_ico(self): cherrypy.response.headers['Content-Type'] = 'image/x-icon' return resource_string('favicon.ico', "site/static/icons")
def favicon_ico(self): """Returns the pyff icon (the alchemic symbol for sublimation). """ cherrypy.response.headers['Content-Type'] = 'image/x-icon' return resource_string('favicon.ico', "site/static/icons")