def __init__(self, repos, resourcedir, **kwargs): # FIXME: document what kwargs could be (particularly 'combineresources') self.repos = repos self.resourcedir = resourcedir from ferenda.manager import DEFAULT_CONFIG defaults = dict(DEFAULT_CONFIG) defaults.update(DocumentRepository.get_default_options()) defaults.update(kwargs) self.config = LayeredConfig(Defaults(defaults)) # the below call to setup_logger alters the logging level of # the root logger, which can't be good practice. Also, we # should probably not log to the root logger, but rather to # ferenda.resources. # # from ferenda.manager import setup_logger # self.log = setup_logger() self.log = logging.getLogger("ferenda.resources") # FIXME: How should we set up a global loadpath from the # individual repos? loadpaths = [ResourceLoader.make_loadpath(repo) for repo in repos] loadpath = ["."] # cwd always has priority -- makes sense? for subpath in loadpaths: for p in subpath: if p not in loadpath: loadpath.append(p) self.resourceloader = ResourceLoader(*loadpath)
def test_loadpath(self): self.assertEqual( ResourceLoader.make_loadpath(self), [ "test/res", # from test.testResourceLoader.SubTestCase "ferenda/res" # from ferenda.compat.unittest.TestCase ])
def __init__(self, repos, inifile=None, **kwargs): self.repos = repos self.log = logging.getLogger("wsgi") # FIXME: Cut-n-paste of the method in Resources.__init__ loadpaths = [ResourceLoader.make_loadpath(repo) for repo in repos] loadpath = ["."] # cwd always has priority -- makes sense? for subpath in loadpaths: for p in subpath: if p not in loadpath: loadpath.append(p) self.resourceloader = ResourceLoader(*loadpath) # FIXME: need to specify documentroot? defaults = DocumentRepository.get_default_options() if inifile: assert os.path.exists( inifile), "INI file %s doesn't exist (relative to %s)" % ( inifile, os.getcwd()) # NB: If both inifile and kwargs are specified, the latter # will take precedence. I think this is the expected # behaviour. self.config = LayeredConfig(Defaults(defaults), INIFile(inifile), Defaults(kwargs), cascade=True)
def __init__(self, repos, inifile=None, **kwargs): self.repos = repos self.log = logging.getLogger("wsgi") # FIXME: Cut-n-paste of the method in Resources.__init__ loadpaths = [ResourceLoader.make_loadpath(repo) for repo in repos] loadpath = ["."] # cwd always has priority -- makes sense? for subpath in loadpaths: for p in subpath: if p not in loadpath: loadpath.append(p) self.resourceloader = ResourceLoader(*loadpath) # FIXME: need to specify documentroot? defaults = DocumentRepository.get_default_options() if inifile: assert os.path.exists( inifile), "INI file %s doesn't exist (relative to %s)" % (inifile, os.getcwd()) # NB: If both inifile and kwargs are specified, the latter # will take precedence. I think this is the expected # behaviour. self.config = LayeredConfig(Defaults(defaults), INIFile(inifile), Defaults(kwargs), cascade=True)
def sameas_minter(self): # make a resourceloader that only loads resource from # superclasses, not this actual class. This'll make it # look in ferenda/sources/legal/se/res, not lagen/nu/res. loadpath = ResourceLoader.make_loadpath(self) if "lagen/nu/" in loadpath[0]: loadpath = loadpath[1:] rl = ResourceLoader(*loadpath) spacefile = rl.filename("uri/swedishlegalsource.space.ttl") # print("sameas: Loading URISpace from %s" % spacefile) self.log.debug("Loading URISpace from %s" % spacefile) with open(spacefile) as space: cfg = Graph().parse(space, format="turtle") # slugs contains space:abbrSlug, but space contains # urispace:abbrSlug... We do a little translation src = URIRef("http://rinfo.lagrummet.se/sys/uri/space#abbrSlug") dst = URIRef("https://lagen.nu/sys/uri/space#abbrSlug") for (s, p, o) in cfg: if o == src: # print("Translating %s %s :abbrSlug" % (s.n3(), p.n3())) cfg.remove((s, p, o)) cfg.add((s, p, dst)) elif s == dst: # print("Translating :abbrSlug %s %s" % (p.n3(), o.n3())) cfg.remove((s, p, o)) cfg.add((dst, p, o)) slugsfile = self.resourceloader.filename("uri/swedishlegalsource.slugs.ttl") # self.log.debug("sameas: Loading slugs from %s" % slugsfile) with open(slugsfile) as slugs: cfg.parse(slugs, format="turtle") COIN = Namespace("http://purl.org/court/def/2009/coin#") # select correct URI for the URISpace definition by # finding a single coin:URISpace object spaceuri = cfg.value(predicate=RDF.type, object=COIN.URISpace) return URIMinter(cfg, spaceuri)
def __init__(self, repos, resourcedir, **kwargs): # FIXME: document what kwargs could be (particularly 'combineresources') self.repos = repos self.resourcedir = resourcedir defaults = DocumentRepository.get_default_options() defaults.update(kwargs) self.config = LayeredConfig(Defaults(defaults)) # the below call to setup_logger alters the logging level of # the root logger, which can't be good practice. Also, we # should probably not log to the root logger, but rather to # ferenda.resources. # # from ferenda.manager import setup_logger # self.log = setup_logger() self.log = logging.getLogger("ferenda.resources") # FIXME: How should we set up a global loadpath from the # individual repos? loadpaths = [ResourceLoader.make_loadpath(repo) for repo in repos] loadpath = ["."] # cwd always has priority -- makes sense? for subpath in loadpaths: for p in subpath: if p not in loadpath: loadpath.append(p) self.resourceloader = ResourceLoader(*loadpath)
def test_loadpath(self): self.assertEqual(ResourceLoader.make_loadpath(self), ["test/res", # from test.testResourceLoader.SubTestCase "ferenda/res" # from ferenda.compat.unittest.TestCase ])