{"action":"created","comment":{"url":"https://api.github.com/repos/etalab/geozones/pulls/comments/69477245","id":69477245,"diff_hunk":"@@ -75,60 +76,90 @@ def traverse(self):\n                 children.extend(level.children)\n             levels, children = children, []\n \n-    def load(self, workdir, db):\n-        '''Extract territories from a given file for a given level with a given extractor function'''\n+    def load(self, workdir, db, only=None, exclude=None):\n+        '''\n+        Extract territories from a given file for a given level\n+        with a given extractor function.\n+        '''\n         loaded = 0\n         for url, extractor in self.extractors:\n+            if only is not None and extractor.__name__ != only:\n+                continue\n+            if exclude is not None and extractor.__name__ == exclude:\n+                continue\n             loaded += self.process_dataset(workdir, db, url, extractor)\n         success('Loaded {0} zones for level {1}'.format(loaded, self.id))\n         return loaded\n \n     def process_dataset(self, workdir, db, url, extractor):\n-        '''Extract territories from a given file for a given level with a given extractor function'''\n+        '''\n+        Extract territories from a given file for a given level\n+        with a given extractor function.\n+        '''\n         loaded = 0\n         filename = join(workdir, basename(url))\n \n         # Identify the shapefile to avoid multiple file error on GDAL 2\n-\n         with ZipFile(filename) as z:\n             candidates = [n for n in z.namelist() if n.endswith('.shp')]\n+            if len(candidates) > 1:\n+                # Try the exact name of the zip file for arrondissements\n+                # given that the epci shapefile is present too...\n+                for candidate in candidates:\n+                    # Remove useless prefix and suffix.\n+                    guessed_name = filename[len('downloads/'):-len('-shp.zip')]\n+                    if guessed_name in candidate:\n+                        candidates = [candidate]\n+                        break\n             if len(candidates) != 1:\n-                raise ValueError('Unable to find a unique shpaefile into {0}'.format(filename))\n+                raise ValueError((\n+                    'Unable to find a unique shapefile into {0} {1}'\n+                    '').format(filename, candidates))\n             shp = candidates[0]\n \n-        with fiona.open('/{0}'.format(shp), vfs='zip://{0}'.format(filename), encoding='utf8') as collection:\n+        with fiona.open('/{0}'.format(shp),\n+                        vfs='zip://{0}'.format(filename),\n+                        encoding='utf8') as collection:\n             info('Extracting {0} elements from {1} ({2} {3})'.format(\n-                len(collection), basename(filename), collection.driver, to_string(collection.crs)\n+                len(collection), basename(filename), collection.driver,\n+                to_string(collection.crs)\n             ))\n \n             for polygon in collection:\n                 try:\n                     zone = extractor(polygon)\n                     if not zone:\n                         continue\n-                    zone['keys'] = dict((k, v) for k, v in zone.get('keys', {}).items() if v is not None)\n+                    zone['keys'] = dict(\n+                        (k, v) for k, v in zone.get('keys', {}).items()\n+                        if v is not None)\n                     geom = shape(polygon['geometry'])\n                     if extractor.simplify:\n                         geom = geom.simplify(extractor.simplify)\n                     if geom.geom_type == 'Polygon':\n                         geom = MultiPolygon([geom])\n                     elif geom.geom_type != 'MultiPolygon':\n-                        warning('Unsupported geometry type \"{0}\" for \"{1}\"'.format(geom.geom_type, zone['name']))\n+                        warning(('Unsupported geometry type \"{0}\" for \"{1}\"'\n+                                 '').format(geom.geom_type, zone['name']))\n                         continue\n                     zoneid = '/'.join((self.id, zone['code']))\n-                    zone.update(_id=zoneid, level=self.id, geom=geom.__geo_interface__)\n+                    zone.update(\n+                        _id=zoneid, level=self.id, geom=geom.__geo_interface__)\n                     db.find_one_and_replace({'_id': zoneid}, zone, upsert=True)\n                     loaded += 1\n                 except Exception as e:\n-                    error('Error extracting polygon {0}: {1}', polygon['properties'], str(e))\n+                    error('Error extracting polygon {0}: {1}',\n+                          polygon['properties'], str(e))\n \n-        info('Loaded {0} zones for level {1} from file {2}'.format(loaded, self.id, filename))\n+        info(('Loaded {0} zones for level {1} from file {2}'\n+              '').format(loaded, self.id, filename))\n         return loaded\n \n     def build_aggregates(self, db):\n         processed = 0\n         for code, name, zones, properties in self.aggregates:\n-            info('Building aggregate \"{0}\" (level={1}, code={2})'.format(name, self.id, code))\n+            info(('Building aggregate \"{0}\" (level={1}, code={2})'","path":"geo.py","position":155,"original_position":155,"commit_id":"76fdf87b3c37faa0b41e5a07da66311ee2acfcb1","original_commit_id":"76fdf87b3c37faa0b41e5a07da66311ee2acfcb1","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"body":"Same split message and formatting and, if available, remove the format, pass args.","created_at":"2016-07-04T16:21:31Z","updated_at":"2016-07-04T16:21:31Z","html_url":"https://github.com/etalab/geozones/pull/22#discussion_r69477245","pull_request_url":"https://api.github.com/repos/etalab/geozones/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/etalab/geozones/pulls/comments/69477245"},"html":{"href":"https://github.com/etalab/geozones/pull/22#discussion_r69477245"},"pull_request":{"href":"https://api.github.com/repos/etalab/geozones/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/etalab/geozones/pulls/22","id":75280144,"html_url":"https://github.com/etalab/geozones/pull/22","diff_url":"https://github.com/etalab/geozones/pull/22.diff","patch_url":"https://github.com/etalab/geozones/pull/22.patch","issue_url":"https://api.github.com/repos/etalab/geozones/issues/22","number":22,"state":"open","locked":false,"title":"[WiP] Rename French IDs for counties and towns","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"body":"In order to generate user friendly IDs/URLs, we are moving from `county` to `departement` and from `town` to `commune` for French related zones.\r\n\r\nThe aggregate bug has been resolved in the meantime with manual accumulation of geometries.\r\n\r\nRefs opendatateam/udata#499\r\n\r\nWiP because there is still an issue with D(R)OM-(T|C)OM aggregation when loaded within udata.","created_at":"2016-06-27T09:25:42Z","updated_at":"2016-07-04T16:21:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19701e3d5dbc3f0d365aec31b078375b740a5945","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/etalab/geozones/pulls/22/commits","review_comments_url":"https://api.github.com/repos/etalab/geozones/pulls/22/comments","review_comment_url":"https://api.github.com/repos/etalab/geozones/pulls/comments{/number}","comments_url":"https://api.github.com/repos/etalab/geozones/issues/22/comments","statuses_url":"https://api.github.com/repos/etalab/geozones/statuses/76fdf87b3c37faa0b41e5a07da66311ee2acfcb1","head":{"label":"davidbgk:french-names","ref":"french-names","sha":"76fdf87b3c37faa0b41e5a07da66311ee2acfcb1","user":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"repo":{"id":45543608,"name":"geozones","full_name":"davidbgk/geozones","owner":{"login":"davidbgk","id":3556,"avatar_url":"https://avatars.githubusercontent.com/u/3556?v=3","gravatar_id":"","url":"https://api.github.com/users/davidbgk","html_url":"https://github.com/davidbgk","followers_url":"https://api.github.com/users/davidbgk/followers","following_url":"https://api.github.com/users/davidbgk/following{/other_user}","gists_url":"https://api.github.com/users/davidbgk/gists{/gist_id}","starred_url":"https://api.github.com/users/davidbgk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidbgk/subscriptions","organizations_url":"https://api.github.com/users/davidbgk/orgs","repos_url":"https://api.github.com/users/davidbgk/repos","events_url":"https://api.github.com/users/davidbgk/events{/privacy}","received_events_url":"https://api.github.com/users/davidbgk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidbgk/geozones","description":"Simple spatial/administrative referential","fork":true,"url":"https://api.github.com/repos/davidbgk/geozones","forks_url":"https://api.github.com/repos/davidbgk/geozones/forks","keys_url":"https://api.github.com/repos/davidbgk/geozones/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidbgk/geozones/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidbgk/geozones/teams","hooks_url":"https://api.github.com/repos/davidbgk/geozones/hooks","issue_events_url":"https://api.github.com/repos/davidbgk/geozones/issues/events{/number}","events_url":"https://api.github.com/repos/davidbgk/geozones/events","assignees_url":"https://api.github.com/repos/davidbgk/geozones/assignees{/user}","branches_url":"https://api.github.com/repos/davidbgk/geozones/branches{/branch}","tags_url":"https://api.github.com/repos/davidbgk/geozones/tags","blobs_url":"https://api.github.com/repos/davidbgk/geozones/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidbgk/geozones/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidbgk/geozones/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidbgk/geozones/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidbgk/geozones/statuses/{sha}","languages_url":"https://api.github.com/repos/davidbgk/geozones/languages","stargazers_url":"https://api.github.com/repos/davidbgk/geozones/stargazers","contributors_url":"https://api.github.com/repos/davidbgk/geozones/contributors","subscribers_url":"https://api.github.com/repos/davidbgk/geozones/subscribers","subscription_url":"https://api.github.com/repos/davidbgk/geozones/subscription","commits_url":"https://api.github.com/repos/davidbgk/geozones/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidbgk/geozones/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidbgk/geozones/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidbgk/geozones/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidbgk/geozones/contents/{+path}","compare_url":"https://api.github.com/repos/davidbgk/geozones/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidbgk/geozones/merges","archive_url":"https://api.github.com/repos/davidbgk/geozones/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidbgk/geozones/downloads","issues_url":"https://api.github.com/repos/davidbgk/geozones/issues{/number}","pulls_url":"https://api.github.com/repos/davidbgk/geozones/pulls{/number}","milestones_url":"https://api.github.com/repos/davidbgk/geozones/milestones{/number}","notifications_url":"https://api.github.com/repos/davidbgk/geozones/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidbgk/geozones/labels{/name}","releases_url":"https://api.github.com/repos/davidbgk/geozones/releases{/id}","deployments_url":"https://api.github.com/repos/davidbgk/geozones/deployments","created_at":"2015-11-04T14:20:34Z","updated_at":"2016-02-04T09:04:39Z","pushed_at":"2016-07-04T15:36:56Z","git_url":"git://github.com/davidbgk/geozones.git","ssh_url":"git@github.com:davidbgk/geozones.git","clone_url":"https://github.com/davidbgk/geozones.git","svn_url":"https://github.com/davidbgk/geozones","homepage":null,"size":263,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"etalab:master","ref":"master","sha":"a5600eda5998e3e8a51c5572c5a410f244487b81","user":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"repo":{"id":33991469,"name":"geozones","full_name":"etalab/geozones","owner":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/etalab/geozones","description":"Simple spatial/administrative referential","fork":false,"url":"https://api.github.com/repos/etalab/geozones","forks_url":"https://api.github.com/repos/etalab/geozones/forks","keys_url":"https://api.github.com/repos/etalab/geozones/keys{/key_id}","collaborators_url":"https://api.github.com/repos/etalab/geozones/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/etalab/geozones/teams","hooks_url":"https://api.github.com/repos/etalab/geozones/hooks","issue_events_url":"https://api.github.com/repos/etalab/geozones/issues/events{/number}","events_url":"https://api.github.com/repos/etalab/geozones/events","assignees_url":"https://api.github.com/repos/etalab/geozones/assignees{/user}","branches_url":"https://api.github.com/repos/etalab/geozones/branches{/branch}","tags_url":"https://api.github.com/repos/etalab/geozones/tags","blobs_url":"https://api.github.com/repos/etalab/geozones/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/etalab/geozones/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/etalab/geozones/git/refs{/sha}","trees_url":"https://api.github.com/repos/etalab/geozones/git/trees{/sha}","statuses_url":"https://api.github.com/repos/etalab/geozones/statuses/{sha}","languages_url":"https://api.github.com/repos/etalab/geozones/languages","stargazers_url":"https://api.github.com/repos/etalab/geozones/stargazers","contributors_url":"https://api.github.com/repos/etalab/geozones/contributors","subscribers_url":"https://api.github.com/repos/etalab/geozones/subscribers","subscription_url":"https://api.github.com/repos/etalab/geozones/subscription","commits_url":"https://api.github.com/repos/etalab/geozones/commits{/sha}","git_commits_url":"https://api.github.com/repos/etalab/geozones/git/commits{/sha}","comments_url":"https://api.github.com/repos/etalab/geozones/comments{/number}","issue_comment_url":"https://api.github.com/repos/etalab/geozones/issues/comments{/number}","contents_url":"https://api.github.com/repos/etalab/geozones/contents/{+path}","compare_url":"https://api.github.com/repos/etalab/geozones/compare/{base}...{head}","merges_url":"https://api.github.com/repos/etalab/geozones/merges","archive_url":"https://api.github.com/repos/etalab/geozones/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/etalab/geozones/downloads","issues_url":"https://api.github.com/repos/etalab/geozones/issues{/number}","pulls_url":"https://api.github.com/repos/etalab/geozones/pulls{/number}","milestones_url":"https://api.github.com/repos/etalab/geozones/milestones{/number}","notifications_url":"https://api.github.com/repos/etalab/geozones/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/etalab/geozones/labels{/name}","releases_url":"https://api.github.com/repos/etalab/geozones/releases{/id}","deployments_url":"https://api.github.com/repos/etalab/geozones/deployments","created_at":"2015-04-15T12:06:35Z","updated_at":"2016-03-31T07:47:56Z","pushed_at":"2016-07-04T15:36:56Z","git_url":"git://github.com/etalab/geozones.git","ssh_url":"git@github.com:etalab/geozones.git","clone_url":"https://github.com/etalab/geozones.git","svn_url":"https://github.com/etalab/geozones","homepage":null,"size":261,"stargazers_count":17,"watchers_count":17,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":3,"forks":6,"open_issues":3,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/etalab/geozones/pulls/22"},"html":{"href":"https://github.com/etalab/geozones/pull/22"},"issue":{"href":"https://api.github.com/repos/etalab/geozones/issues/22"},"comments":{"href":"https://api.github.com/repos/etalab/geozones/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/etalab/geozones/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/etalab/geozones/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/etalab/geozones/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/etalab/geozones/statuses/76fdf87b3c37faa0b41e5a07da66311ee2acfcb1"}}}}
{"actor":{"display_login":"noirbizarre"}}