Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mhucka committed Dec 14, 2020
2 parents 587543e + ee5da69 commit 874d821
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change log for Zowie
====================

Version 1.0.5
--------------

Fixed issue #1: PDF files that have no parent records are not necessarily an error. Print warnings, not errors, for those cases.


Version 1.0.4
--------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[metadata]
name = zowie
version = 1.0.4
version = 1.0.5
description = Write Zotero select links into article PDF files
author = Michael Hucka
author_email = [email protected]
Expand Down
11 changes: 7 additions & 4 deletions zowie/main_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,15 @@ def _do_main_work(self):
inform(f'Will process {pluralized("PDF file", self._files, True)}'
+ f' using {pluralized("method", self.methods)}'
+ f' [cyan2]{", ".join(self.methods)}[/].')
num_targets = len(self._files)
if len(self._files) > 10000:
inform("(That's a huge number of files – this will take a long time.)")
elif len(self._files) > 1000:
inform("(That's a lot of files – this will take some time.)")

for pdffile in self._files:
(record, error) = self._zotero.record_for_file(pdffile)
if error:
alert(error)
(record, failure) = self._zotero.record_for_file(pdffile)
if failure:
warn(failure)
continue
for method in self._writers:
method.write_link(pdffile, record.link)
17 changes: 13 additions & 4 deletions zowie/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ def record_for_file(self, file):
'''Returns a ZoteroRecord corresponding to the given local PDF file.'''
f = antiformat(file)
if not path.exists(file):
# The file should always exist, because of how the list of files is
# gathered, so something is wrong but we don't know what. Give up.
raise ValueError(f'File not found: {f}')

# Zotero stores content in the subdirectory like .../storage/N743ZXDF.
# The item key is the alphanumeric directory name.
# Given the key, there's no way to know whether the record is in a user
# library or a group library, so we have to iterate over the options.
itemkey = path.basename(path.dirname(file))
# We don't know whether it's a user library or a group library, so
# we have to iterate over the options.
record = None
for library in self._libraries:
try:
Expand All @@ -152,10 +157,14 @@ def record_for_file(self, file):
if not record:
if __debug__: log(f'could not find a record for item key "{itemkey}"')
return (None, f'Unable to retrieve Zotero record for {f}')

# If the PDF isn't associated with a bib record, it won't have a parent.
parentkey = self.parent_key(record, file)
if not parentkey:
if __debug__: log(f'could not get parent key for {f}')
return (None, f'Zotero record lacks parent entry for {f}')
if __debug__: log(f'file not associated with a parent record: {f}')
return (None, f'File lacks a parent Zotero record: {f}')

# We have an item record and a parent. We are happy campers.
if __debug__: log(f'{parentkey} is parent of {itemkey} for {f}')
r = ZoteroRecord(key = itemkey, parent_key = parentkey, file = file,
link = self.item_link(record, file), record = record)
Expand Down

0 comments on commit 874d821

Please sign in to comment.