From a1384931644cad04c856e20a70cc505136521f5b Mon Sep 17 00:00:00 2001 From: Bridget Almas Date: Tue, 26 Apr 2016 06:50:36 -0400 Subject: [PATCH] Release 0.0.4 - #21 don't add texts to inventory if they don't have cites - #23 fix cache handling on command line - Bump version --- capitains_nautilus/cmd.py | 4 ++-- capitains_nautilus/inventory/local.py | 11 +++++++++-- setup.py | 2 +- tests/inventory/test_local.py | 11 ++++++++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/capitains_nautilus/cmd.py b/capitains_nautilus/cmd.py index 58e57dc..aed54c8 100644 --- a/capitains_nautilus/cmd.py +++ b/capitains_nautilus/cmd.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from capitains_nautilus.flask_ext import FlaskNautilus +from capitains_nautilus.flask_ext import FlaskNautilus, WerkzeugCacheWrapper from werkzeug.contrib.cache import FileSystemCache, RedisCache, NullCache from flask import Flask from flask_cache import Cache @@ -45,7 +45,7 @@ def _commandline(repositories, FlaskNautilus( app=app, resources=repositories, - parser_cache=nautilus_cache, + parser_cache=WerkzeugCacheWrapper(nautilus_cache), http_cache=Cache(config={'CACHE_TYPE': cache_type}), logger=None ) diff --git a/capitains_nautilus/inventory/local.py b/capitains_nautilus/inventory/local.py index fe1969b..65c6270 100644 --- a/capitains_nautilus/inventory/local.py +++ b/capitains_nautilus/inventory/local.py @@ -120,7 +120,8 @@ def parse(self, resource, cache=True, verbose=True): work.urn = URN(work.xml.get("urn")) self.inventory.textgroups[str(textgroup.urn)].works[str(work.urn)] = work - for __text__ in self.inventory.textgroups[str(textgroup.urn)].works[str(work.urn)].texts.values(): + for __textkey__ in self.inventory.textgroups[str(textgroup.urn)].works[str(work.urn)].texts: + __text__ = self.inventory.textgroups[str(textgroup.urn)].works[str(work.urn)].texts[__textkey__] __text__.path = "{directory}/{textgroup}.{work}.{version}.xml".format( directory=os.path.dirname(__subcts__), textgroup=__text__.urn.textgroup, @@ -148,9 +149,14 @@ def parse(self, resource, cache=True, verbose=True): )) __text__.citation = cites[-1] self.logger.info("%s has been parsed ", __text__.path) + if (__text__.citation): + self.__texts__.append(__text__) + else: + self.logger.error("%s has no passages", __text__.path) except Exception: self.logger.error("%s does not accept parsing at some level (most probably citation) ", __text__.path) - self.__texts__.append(__text__) + else: + self.logger.error("%s is not present", __text__.path) except Exception: self.logger.error("Error parsing %s ", __cts__) @@ -208,6 +214,7 @@ def getCapabilities(self, urn=None, page=None, limit=None, inventory=None, lang= for text in self.__texts__ if (lang is None or (lang is not None and lang == text.lang)) and (urn is None or (urn is not None and text.urn.upTo(__PART) == urn)) and + (text.citation is not None) and (category not in ["edition", "translation"] or (category in ["edition", "translation"] and category.lower() == text.subtype.lower())) ] if pagination: diff --git a/setup.py b/setup.py index 61080d6..1a1a43e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='capitains_nautilus', - version="0.0.3", + version="0.0.4", description='Resolver for Capitains Guidelines Repository', url='http://github.com/Capitains/nautilus', author='Thibault Clerice', diff --git a/tests/inventory/test_local.py b/tests/inventory/test_local.py index b24e5e7..edb6df4 100644 --- a/tests/inventory/test_local.py +++ b/tests/inventory/test_local.py @@ -97,4 +97,13 @@ def test_get_capabilities(self): self.assertEqual( len(Repository.getCapabilities(urn="urn:cts:farsiLit:hafez.divan.perseus-eng1")[0]), 1, "Complete URN filtering works" - ) \ No newline at end of file + ) + def test_get_capabilities_nocites(self): + """ Check Get Capabilities latinLit data""" + Repository = XMLFolderResolver( + ["./tests/test_data/latinLit"] + ) + self.assertEqual( + len(Repository.getCapabilities(urn="urn:cts:latinLit:stoa0045.stoa008.perseus-lat2")[0]), 0, + "Texts without citations were ignored" + )