From 9d50b05261b71414efd3644a1a33f9438ee1e4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 8 Jun 2016 10:40:14 +0200 Subject: [PATCH] Add the create template in the update template to track the changes --- .gitignore | 7 +- Makefile | 8 ++- c2cgeoportal/scaffolds/__init__.py | 106 +++++++++++++---------------- travis/create-new-project.sh | 2 +- 4 files changed, 60 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 0550fa4568..e83c020315 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.pyc *.pyo *.class -/c2cgeoportal/static/build +/c2cgeoportal/static/build/ /c2cgeoportal/tests/functional/c2cgeoportal_test.map /c2cgeoportal/tests/functional/test.ini /c2cgeoportal/tests/functional/alembic.ini @@ -16,6 +16,7 @@ /c2cgeoportal/scaffolds/update/+dot+tx/CONST_config_mako /c2cgeoportal/scaffolds/create/+package+/static-ngeo/js/mobile.js_tmpl /c2cgeoportal/scaffolds/create/+package+/templates/mobile.html_tmpl +/c2cgeoportal/scaffolds/update/CONST_create_template/ /c2cgeoportal/version.py /c2cgeoportal.egg-info /doc/administrator/administrate.rst @@ -27,8 +28,8 @@ /doc/integrator/fulltext_search.rst /doc/integrator/print.rst /doc/integrator/upgrade_application.rst -/ngeo -/.build +/ngeo/ +/.build/ /.eggs /.coverage /coverage.xml diff --git a/Makefile b/Makefile index 097c1ecd1d..8365da9bdd 100644 --- a/Makefile +++ b/Makefile @@ -83,7 +83,8 @@ build: $(MAKO_FILES:.mako=) \ $(MO_FILES) \ $(APPS_HTML_FILES) $(APPS_JS_FILES) \ c2cgeoportal/scaffolds/update/+dot+tx/CONST_config_mako \ - c2cgeoportal/scaffolds/update/package.json_tmpl + c2cgeoportal/scaffolds/update/package.json_tmpl \ + c2cgeoportal/scaffolds/update/CONST_create_template/ .PHONY: buildall buildall: build doc tests checks @@ -211,6 +212,11 @@ ngeo/package.json: ngeo c2cgeoportal/scaffolds/update/package.json_tmpl: ngeo/package.json .build/requirements.timestamp c2cgeoportal/scripts/import_ngeo_apps.py .build/venv/bin/import-ngeo-apps --package _ $< $@ +.PRECIOUS: c2cgeoportal/scaffolds/update/CONST_create_template/ +c2cgeoportal/scaffolds/update/CONST_create_template/: c2cgeoportal/scaffolds/create/ + rm -rf $@ || true + cp -r $< $@ + # Templates $(MAKO_FILES:.mako=): .build/venv/bin/c2c-template ${VARS_FILES} diff --git a/c2cgeoportal/scaffolds/__init__.py b/c2cgeoportal/scaffolds/__init__.py index dfee828082..8da82e3468 100644 --- a/c2cgeoportal/scaffolds/__init__.py +++ b/c2cgeoportal/scaffolds/__init__.py @@ -57,6 +57,30 @@ def pre(self, command, output_dir, vars): package logger "root"). """ + self._args_to_vars(command.args, vars) + + self._get_vars(vars, "package", "Get a package name: ") + self._get_vars(vars, "apache_vhost", "The Apache vhost name: ") + self._get_vars( + vars, "srid", + "Spatial Reference System Identifier (e.g. 21781): ", int, + ) + srid = vars["srid"] + extent = self._epsg2bbox(srid) + self._get_vars( + vars, "extent", + "Extent (minx miny maxx maxy): in EPSG: {srid} projection, default is " + "[{bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}]: ".format(srid=srid, bbox=extent) + if extent else + "Extent (minx miny maxx maxy): in EPSG: {srid} projection: ".format(srid=srid) + ) + match = re.match(r"(\d+)[,; ] *(\d+)[,; ] *(\d+)[,; ] *(\d+)", vars["extent"]) + if match is not None: + extent = [match.group(n + 1) for n in range(4)] + vars["extent"] = ",".join(extent) + vars["extent_mapserver"] = " ".join(extent) + vars["extent_viewer"] = json.dumps(extent) + ret = Template.pre(self, command, output_dir, vars) if vars["package"] == "site": @@ -83,43 +107,6 @@ def _args_to_vars(self, args, vars): if m: vars[m.group(1)] = m.group(2) - -class TemplateCreate(BaseTemplate): # pragma: no cover - _template_dir = "create" - summary = "Template used to create a c2cgeoportal project" - - def pre(self, command, output_dir, vars): - """ - Overrides the base template, adding the "srid" variable to - the variables list. - """ - - self._args_to_vars(command.args, vars) - - self._get_vars(vars, "package", "Get a package name: ") - self._get_vars(vars, "apache_vhost", "The Apache vhost name: ") - self._get_vars( - vars, "srid", - "Spatial Reference System Identifier (e.g. 21781): ", int, - ) - srid = vars["srid"] - extent = self._epsg2bbox(srid) - self._get_vars( - vars, "extent", - "Extent (minx miny maxx maxy): in EPSG: {srid} projection, default is " - "[{bbox[0]} {bbox[1]} {bbox[2]} {bbox[3]}]: ".format(srid=srid, bbox=extent) - if extent else - "Extent (minx miny maxx maxy): in EPSG: {srid} projection: ".format(srid=srid) - ) - match = re.match(r"(\d+)[,; ] *(\d+)[,; ] *(\d+)[,; ] *(\d+)", vars["extent"]) - if match is not None: - extent = [match.group(n + 1) for n in range(4)] - vars["extent"] = ", ".join(extent) - vars["extent_mapserver"] = " ".join(extent) - vars["extent_viewer"] = json.dumps(extent) - - return BaseTemplate.pre(self, command, output_dir, vars) - def _get_vars(self, vars, name, prompt, type=None): """ Set an attribute in the vars dict. @@ -138,25 +125,6 @@ def _get_vars(self, vars, name, prompt, type=None): vars[name] = value - def post(self, command, output_dir, vars): - """ - Overrides the base template class to print the next step. - """ - - if os.name == 'posix': - for file in ("post-restore-code", "pre-restore-database.mako"): - dest = os.path.join(output_dir, "deploy/hooks", file) - subprocess.check_call(["chmod", "+x", dest]) - - self.out("\nContinue with:") - self.out(colorize( - ".build/venv/bin/pcreate -s c2cgeoportal_update ../{vars[project]} " - "package={vars[package]} srid={vars[srid]}".format(vars=vars), - GREEN - )) - - return BaseTemplate.post(self, command, output_dir, vars) - def _epsg2bbox(self, srid): try: r = requests.get("http://epsg.io/?format=json&q={}".format(srid)) @@ -177,6 +145,30 @@ def _epsg2bbox(self, srid): return None +class TemplateCreate(BaseTemplate): # pragma: no cover + _template_dir = "create" + summary = "Template used to create a c2cgeoportal project" + + def post(self, command, output_dir, vars): + """ + Overrides the base template class to print the next step. + """ + + if os.name == 'posix': + for file in ("post-restore-code", "pre-restore-database.mako"): + dest = os.path.join(output_dir, "deploy/hooks", file) + subprocess.check_call(["chmod", "+x", dest]) + + self.out("\nContinue with:") + self.out(colorize( + ".build/venv/bin/pcreate -s c2cgeoportal_update ../{vars[project]} " + "package={vars[package]} srid={vars[srid]} extent={vars[extent]}".format(vars=vars), + GREEN + )) + + return BaseTemplate.post(self, command, output_dir, vars) + + class TemplateUpdate(BaseTemplate): # pragma: no cover _template_dir = "update" summary = "Template used to update a c2cgeoportal project" @@ -196,8 +188,6 @@ def pre(self, command, output_dir, vars): if isinstance(value, string_types) \ else value - self._args_to_vars(command.args, vars) - return BaseTemplate.pre(self, command, output_dir, vars) def post(self, command, output_dir, vars): diff --git a/travis/create-new-project.sh b/travis/create-new-project.sh index 3f73e6b703..26d8be68c3 100755 --- a/travis/create-new-project.sh +++ b/travis/create-new-project.sh @@ -1,7 +1,7 @@ #!/bin/bash -ex .build/venv/bin/pcreate -s c2cgeoportal_create /tmp/travis/testgeomapfish package=testgeomapfish srid=21781 apache_vhost=test extent= > /dev/null -.build/venv/bin/pcreate -s c2cgeoportal_update /tmp/travis/testgeomapfish package=testgeomapfish srid=21781 apache_vhost=test > /dev/null # on create +.build/venv/bin/pcreate -s c2cgeoportal_update /tmp/travis/testgeomapfish package=testgeomapfish srid=21781 apache_vhost=test extent= > /dev/null # on create cp travis/build.mk /tmp/travis/testgeomapfish/travis.mk cp travis/vars.yaml /tmp/travis/testgeomapfish/vars_travis.yaml