Skip to content
Snippets Groups Projects
Commit 8546f4a5 authored by anonymous's avatar anonymous
Browse files

changed fallback-filepath

parent 59248287
No related branches found
No related tags found
No related merge requests found
...@@ -111,22 +111,28 @@ def resource_formats(): ...@@ -111,22 +111,28 @@ def resource_formats():
g.parse(urlresponse) g.parse(urlresponse)
# At the moment, there are 143 different file types listed, # At the moment, there are 143 different file types listed,
# if less than 120 are found, something went wrong. # if less than 120 are found, something went wrong.
assert len(set([s for s in g.subjects()])) > 120 if len(set([s for s in g.subjects()])) > 120:
raise ValueError("Not enough subjects")
# Save the content as backup # Save the content as backup
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
urlresponse = urllib2.urlopen(urllib2.Request(format_european_url)) urlresponse = urllib2.urlopen(urllib2.Request(format_european_url))
elif sys.version_info[0] == 3: # >=Python3.1 elif sys.version_info[0] == 3: # >=Python3.1
urlresponse = urllib.request.urlopen(urllib.request.Request(format_european_url)) urlresponse = urllib.request.urlopen(urllib.request.Request(format_european_url))
err_msg = "Could not write to /usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/fileformats.rdf" fallback_filepath = config.get('ckan.odsh.resource_formats_fallback_filepath')
f = open('/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/fileformats.rdf', 'w') if not fallback_filepath:
log.warning("Could not find config setting: 'ckan.odsh.resource_formats_fallback_filepath', using fallback instead.")
fallback_filepath = "/tmp/fileformats.rdf"
err_msg = "Could not write to " + fallback_filepath
f = open(fallback_filepath, 'w')
f.write(urlresponse.read()) f.write(urlresponse.read())
f.close() f.close()
except: except:
log.exception("failed to process resource_formats")
# Something went wrong with trying to get the file formats online, try to use backup instead # Something went wrong with trying to get the file formats online, try to use backup instead
try: try:
g.parse('/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/fileformats.rdf') g.parse(fallback_filepath)
assert len(set([s for s in g.subjects()])) > 120 assert len(set([s for s in g.subjects()])) > 120
log.warning("Could not get file formats from " + format_european_url + ", using fallback instead.") log.info("Could not get file formats from " + format_european_url + ", using fallback instead.")
except: except:
raise Exception(err_msg) raise Exception(err_msg)
file_types = [subj.decode() for subj in g.subjects()] file_types = [subj.decode() for subj in g.subjects()]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment