Skip to content

Commit

Permalink
#41: added method for converting the .edtr to .json
Browse files Browse the repository at this point in the history
  • Loading branch information
panterz committed Apr 13, 2016
1 parent e562666 commit 3592724
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/pcapi/utils/pcapi_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def rec2geojson(record):
res["properties"] = record
return res

def updateEditorExtension(record):
"""
updates the editor to be from .edtr to .json
"""
if record["properties"]["editor"].endswith(".edtr"):
record["properties"]["editor"] = record["properties"]["editor"].replace(".edtr", ".json")
return record
return None

def updateIdInGeojson(record):
"""
updates id of each field of the geojson to follow the updated format
Expand Down Expand Up @@ -73,6 +82,13 @@ def upgrade_all_data():
print "Overwriting new version of %s" % f
with open(f,'w') as fp:
json.dump(new_gj,fp)
gj_new_ed_ext = updateEditorExtension(new_gj)
if not gj_new_ed_ext:
print "Ignoring %s which is already converted." % f
else:
print "Overwriting new version of %s" % f
with open(f,'w') as fp:
json.dump(gj_new_ed_ext,fp)

if __name__ == "__main__":
upgrade_all_data()
10 changes: 9 additions & 1 deletion src/test/upgrade_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pcapi.server import application
from pcapi import config
from pcapi.utils.pcapi_upgrade import find_json, updateIdInGeojson
from pcapi.utils.pcapi_upgrade import find_json, updateIdInGeojson, updateEditorExtension

userid = "[email protected]"

Expand All @@ -47,3 +47,11 @@ def test_updateIdInGeojson(self):
new_record = updateIdInGeojson(record)
self.assertEquals(new_record["properties"]["fields"][0]["id"],
record["properties"]["fields"][0]["id"].replace("fieldcontain-", ""))

def test_updateEditorExtension(self):
""" read geojson and check if editor extension has changed"""
gen = find_json(envsys_records_dir)
record = json.load(open(gen.next()))
new_record = updateEditorExtension(record)
self.assertEquals(new_record["properties"]["editor"],
record["properties"]["editor"].replace(".edtr", ".json"))

0 comments on commit 3592724

Please sign in to comment.