From cbd4429cc29a3b66ac9dfcfca17efa6b4ad672fa Mon Sep 17 00:00:00 2001 From: Rashmi Keshava Iyengar Date: Mon, 11 Dec 2017 18:06:40 -0800 Subject: [PATCH 1/2] Fixes to support platform independent URL construction --- publicdata/censusreporter/generator.py | 16 ++++++++++++---- publicdata/censusreporter/url.py | 12 ++++++++---- setup.py | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/publicdata/censusreporter/generator.py b/publicdata/censusreporter/generator.py index 9488ba9..deb085f 100644 --- a/publicdata/censusreporter/generator.py +++ b/publicdata/censusreporter/generator.py @@ -6,6 +6,7 @@ """ +import os import json from itertools import repeat from operator import itemgetter @@ -14,6 +15,10 @@ from publicdata.censusreporter.jsonurl import CensusReporterJsonUrl from rowgenerators import Source +#DEBUG +import inspect +from appurl.url import debug_print +## class CensusReporterSource(Source): """A RowGenerator source that can be registered for Census REporter URLs. @@ -37,7 +42,7 @@ def __init__(self, ref, cache=None, working_dir=None, **kwargs): super().__init__(ref, cache, working_dir, **kwargs) self._source_url = kwargs.get('source_url') - + assert isinstance(ref, CensusReporterJsonUrl) @property @@ -81,9 +86,12 @@ def get_cr_rows(self): :param kwargs: Catchall so dict can be expanded into the signature. :return: """ - - table_id, summary_level, geoid = unquote(self.ref.target_file).split('/') - + #DEBUG + #debug_print(self.ref.target_file, inspect.getframeinfo(inspect.currentframe()).filename, inspect.getframeinfo(inspect.currentframe()).lineno) + ## + + table_id, summary_level, geoid = unquote(self.ref.target_file).split('/') + with open(self.ref.path) as f: data = json.load(f) diff --git a/publicdata/censusreporter/url.py b/publicdata/censusreporter/url.py index 0370e9a..e556a69 100644 --- a/publicdata/censusreporter/url.py +++ b/publicdata/censusreporter/url.py @@ -14,6 +14,10 @@ from appurl import WebUrl, AppUrlError, parse_app_url from publicdata.censusreporter.jsonurl import CensusReporterJsonUrl +#DEBUG +import inspect +from appurl.url import debug_print +## class CensusReporterURL(WebUrl): """A URL for censusreporter tables. @@ -95,9 +99,9 @@ def get_resource(self): if cache: cache.makedirs(dirname(self.cache_key), recreate=True) cache.settext(self.cache_key, json.dumps(data, indent=4)) - - return parse_app_url(cache.getsyspath(self.cache_key), - fragment=[join(*self._parts),None], + + return parse_app_url(cache.getsyspath(self.cache_key), + fragment=["/".join(self._parts),None], ).as_type(CensusReporterJsonUrl) def get_target(self): @@ -187,7 +191,7 @@ def get_resource(self): # The downloaded file doesn't have a .zip extension, so Fiona won't recognize # it as a Shapeilfe ZIP archive. So, just make a link. - p = r.inner.path + p = r.inner.path pz = p+'.zip' if exists(pz): diff --git a/setup.py b/setup.py index 13a6bcb..a8d7d5a 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='publicdata', - version='0.1.4', + version='0.1.5', url='https://github.com/CivicKnowledge/publicdata', license='MIT', author='Eric Busboom', From 8fddc1a460716a3d54a7504c82376c083a0af014 Mon Sep 17 00:00:00 2001 From: Rashmi Keshava Iyengar Date: Tue, 12 Dec 2017 07:11:46 -0800 Subject: [PATCH 2/2] Changes to debug code --- publicdata/censusreporter/generator.py | 11 ++++++----- publicdata/censusreporter/url.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/publicdata/censusreporter/generator.py b/publicdata/censusreporter/generator.py index deb085f..72f1a81 100644 --- a/publicdata/censusreporter/generator.py +++ b/publicdata/censusreporter/generator.py @@ -17,7 +17,7 @@ #DEBUG import inspect -from appurl.url import debug_print +from appurl.util import debug_print ## class CensusReporterSource(Source): @@ -45,6 +45,10 @@ def __init__(self, ref, cache=None, working_dir=None, **kwargs): assert isinstance(ref, CensusReporterJsonUrl) + #DEBUG + #debug_print(self.ref.target_file, inspect.getframeinfo(inspect.currentframe()).filename, inspect.getframeinfo(inspect.currentframe()).lineno) + ## + @property def columns(self): """ Returns columns for the file accessed by accessor. @@ -86,10 +90,7 @@ def get_cr_rows(self): :param kwargs: Catchall so dict can be expanded into the signature. :return: """ - #DEBUG - #debug_print(self.ref.target_file, inspect.getframeinfo(inspect.currentframe()).filename, inspect.getframeinfo(inspect.currentframe()).lineno) - ## - + table_id, summary_level, geoid = unquote(self.ref.target_file).split('/') with open(self.ref.path) as f: diff --git a/publicdata/censusreporter/url.py b/publicdata/censusreporter/url.py index e556a69..ced49ab 100644 --- a/publicdata/censusreporter/url.py +++ b/publicdata/censusreporter/url.py @@ -16,7 +16,7 @@ #DEBUG import inspect -from appurl.url import debug_print +from appurl.util import debug_print ## class CensusReporterURL(WebUrl):