Skip to content

Commit

Permalink
Fix bug importing librarylink.site
Browse files Browse the repository at this point in the history
  • Loading branch information
uogbuji committed Nov 13, 2019
1 parent af1ad47 commit dbe768a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
13 changes: 6 additions & 7 deletions pylib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ def all_sites(sitemap_url='http://library.link/harvest/sitemap.xml', plus_list=N
>>> denversite.host
'link.denverlibrary.org'
'''
global CACHEDIR
import requests
try:
from cachecontrol import CacheControl
from cachecontrol.caches.file_cache import FileCache
CACHEDIR = '.web_cache'
cachedir = getattr(all_sites, 'cachedir', '@UNKNOWN')
except ImportError:
cachedir = None
pass

#FIXME: Avoid accumulating all the nodes, which will require improvements to xml.treesequence
Expand All @@ -168,8 +168,10 @@ def sink(accumulator):
nodes = []

ts = xmliter.sender(('sitemapindex', 'sitemap'), sink(nodes))
if hasattr (all_sites, 'cachedir'):
sess = CacheControl(requests.Session(), cache=FileCache(all_sites.cachedir))
if cachedir == '@UNKNOWN':
sess = CacheControl(requests.Session(), cache=FileCache('.web_cache'))
elif cachedir:
sess = CacheControl(requests.Session(), cache=FileCache(cachedir))
else:
sess = CacheControl(requests.Session())
result = sess.get(sitemap_url)
Expand All @@ -183,6 +185,3 @@ def sink(accumulator):
nodes.append(s)
yield from nodes


if CACHEDIR: all_sites.cachedir = '.web_cache'

2 changes: 0 additions & 2 deletions pylib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from itertools import *
import collections.abc

CACHEDIR = None

from versa.driver import memory
from versa import I, VERSA_BASEIRI, ORIGIN, RELATIONSHIP, TARGET, ATTRIBUTES
from versa.reader import rdfalite
Expand Down
2 changes: 1 addition & 1 deletion pylib/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#http://legacy.python.org/dev/peps/pep-0440/
version_info = ('0', '5', '0')
version_info = ('0', '5', '1')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
liblink_resource_summary "http://link.houstonlibrary.org/portal/Half-of-a-yellow-sun-Chimamanda-Ngozi/n7KqqbZFJuM/"
'''

LONGDESC_CTYPE = 'text/markdown',
LONGDESC_CTYPE = 'text/markdown'

setup(
name=PROJECT_NAME,
Expand Down

0 comments on commit dbe768a

Please sign in to comment.