diff options
Diffstat (limited to 'chimere/utils.py')
-rw-r--r-- | chimere/utils.py | 40 |
1 files changed, 10 insertions, 30 deletions
diff --git a/chimere/utils.py b/chimere/utils.py index 607ec36..7518076 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -210,21 +210,20 @@ class ImportManager(object): try: source = open(source) except IOError as msg: - return (None, msg) + return None, msg except (urllib.error.URLError, AttributeError) as error: - return (None, str(error)) + return None, str(error) if self.importer_instance.zipped: try: files = self.get_files_inside_zip( self.importer_instance.source_file or self.importer_instance.source , suffixes, dest_dir) except zipfile.BadZipfile: - return (None, _("Bad zip file")) + return None, _("Bad zip file") if not files or None in files or [] in files: - return (None, - _("Missing file(s) inside the zip file")) + return None, _("Missing file(s) inside the zip file") source = files[0] if len(suffixes) == 1 else files - return (source, None) + return source, None class KMLManager(ImportManager): @@ -786,11 +785,11 @@ class JsonManager(ImportManager): top = True if not isinstance(filtr, dict): if filtr in item: - yield base_key, item[filtr] + yield filtr, item[filtr] else: for k in filtr: if top: - base_key = k + base_key = filtr[k] if not isinstance(filtr[k], dict): if k in item: yield base_key, item[k] @@ -852,7 +851,6 @@ class JsonManager(ImportManager): new_item, updated_item, _("A key must be associated to \"%s\" in the " "filter.") % k) - default_dct = {'origin': self.importer_instance.origin, 'license': self.importer_instance.license, 'description': ""} @@ -865,9 +863,6 @@ class JsonManager(ImportManager): dct = default_dct.copy() for key, value in self.extract_dict_values(item, filtr): - """ - for k in filtr: - """ if key.startswith('prefix_') or key.startswith('suffix_'): continue if key == 'external_image': @@ -927,7 +922,7 @@ class JsonManager(ImportManager): cls = Marker pl_id = (dct.pop('id') if 'id' in dct else dct['name']) \ - + "-" + str(self.importer_instance.pk) + + "-" + str(self.importer_instance.pk) it, updated, created = self.create_or_update_item(cls, dct, pl_id) if updated: @@ -1033,7 +1028,7 @@ class OSMManager(ImportManager): for way in result.ways: dct = deepcopy(default_dct) dct.update(self._get_attributes(way, filtr)) - pl_id = "OSM-way-{}".format(node.id) + pl_id = "OSM-way-{}".format(way.id) if not way.nodes or len(way.nodes) == 1: # not a real way @@ -1083,22 +1078,7 @@ class OSMManager(ImportManager): - updated items; - error detail on error. """ - - is_file = True if self.importer_instance.source_file else False - if not is_file: - return self.parse_overpass() - source, msg = self.get_source_file( - ['.osm'], extra_url=self.importer_instance.filtr) - if not source: - return (0, 0, msg) - - tree = etree.parse(source) - # only import node or ways - if tree.xpath('count(//way)') and tree.xpath('count(//node)'): - return self.import_ways(tree) - elif tree.xpath('count(//node)'): - return self.import_nodes(tree) - return 0, 0, _("Nothing to import") + return self.parse_overpass() def import_ways(self, tree): from chimere.models import Route |