Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the create template in the update template to track the changes #2296

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
106 changes: 48 additions & 58 deletions c2cgeoportal/scaffolds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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.
Expand All @@ -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))
Expand All @@ -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"
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion travis/create-new-project.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down