diff --git a/gitenberg/metadata/pandata.py b/gitenberg/metadata/pandata.py index fa7b683..4d6a5a4 100644 --- a/gitenberg/metadata/pandata.py +++ b/gitenberg/metadata/pandata.py @@ -67,6 +67,7 @@ def __init__(self, datafile): self.metadata = yaml.safe_load( r.content) else: self.metadata = yaml.safe_load(file(datafile, 'r').read()) + self.set_edition_id() def __getattr__(self, name): if name in PANDATA_STRINGFIELDS: @@ -79,11 +80,24 @@ def __getattr__(self, name): return self.metadata.get(name, {}) return self.metadata.get(name, None) + def set_edition_id(self): + # set a (hopefully globally unique) edition identifier + if not self.metadata.has_key('edition_identifiers'): + self.metadata['edition_identifiers'] = {} + base=self.url + if not base: + try: + base = unicode(self.identifiers.keys[0])+':'+unicode(self.identifiers.values[0]) + except: + base = u'repo:' + unicode(self._repo) + self.metadata['edition_identifiers']['edition_id'] = base + '#' + self._edition + def agents(self, agent_type): agents = self.metadata.get(agent_type, []) return agents if agents else [] # the edition should be able to report ebook downloads, which should have format and url attributes + # TODO - fill in URL based on a standard place in repo def downloads(self): return [] @@ -112,7 +126,6 @@ def get_by_isbn(isbn): def get_one_identifier(self, id_name): - print 'in get 1' if self.metadata.get(id_name,''): return get_one(self.metadata[id_name]) if self.identifiers.get(id_name,''): @@ -123,15 +136,14 @@ def get_one_identifier(self, id_name): @property def isbn(self): - print 'in isbn' return self.get_one_identifier('isbn') @property def _edition(self): if self.metadata.get("_edition", ''): - return self.metadata["_edition"] + return unicode(self.metadata["_edition"]) elif self.get_one_identifier('isbn'): - return self.get_one_identifier('isbn') #use first isbn if available + return unicode(self.get_one_identifier('isbn')) #use first isbn if available elif self._repo: return edition_name_from_repo(self._repo) else: @@ -143,4 +155,5 @@ def get_edition_list(self): new_self = Pandata(self) for key in edition.keys(): new_self.metadata[key] = edition[key] + new_self.set_edition_id() yield new_self \ No newline at end of file diff --git a/setup.py b/setup.py index 603793c..08b86cb 100755 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( name='gitenberg.metadata', - version='0.1.9', + version='0.1.10', description="metadata development - formats and machinery for GITenberg", long_description=readme + '\n\n' + history, author="Eric Hellman", diff --git a/tests/test.py b/tests/test.py index 455bb5a..9a93210 100644 --- a/tests/test.py +++ b/tests/test.py @@ -70,6 +70,8 @@ def test_editions(self): self.assertEqual(ed2.publisher, "Recovering the Classics") self.assertEqual(ed2.isbn, "9781111122223") self.assertEqual(ed1.isbn, "") + self.assertEqual(ed1.edition_identifiers['edition_id'], "repo:Space-Viking_20728#default") + self.assertEqual(ed2.edition_identifiers['edition_id'], u'repo:Space-Viking_20728#9781111122223') if __name__ == '__main__':