Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed May 31, 2018
1 parent a5721e0 commit eb9539c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions geoportal/c2cgeoportal_geoportal/scaffolds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def _epsg2bbox(srid):
print("Unable to get the bbox")
return None

def fix_executables(output_dir, patterns, in_const_create_template=False):
if os.name == 'posix':
for pattern in (patterns):
if in_const_create_template:
pattern = os.path.join(output_dir, "CONST_create_template", pattern)
else:
pattern = os.path.join(output_dir, pattern)
for file_ in glob.glob(pattern):
subprocess.check_call(["chmod", "+x", file_])

class TemplateCreate(BaseTemplate): # pragma: no cover
_template_dir = "create"
Expand All @@ -157,10 +166,7 @@ def post(self, command, output_dir, vars_):
Overrides the base template class to print the next step.
"""

if os.name == 'posix':
for file_ in ("docker-run", "docker-compose-run", "bin/eval-templates"):
dest = os.path.join(output_dir, file_)
subprocess.check_call(["chmod", "+x", dest])
fix_executables(output_dir, ("docker-run", "docker-compose-run", "bin/*"))

self.out("\nContinue with:")
self.out(colorize(
Expand Down Expand Up @@ -198,10 +204,8 @@ def post(self, command, output_dir, vars_):
after a successful scaffolding rendering.
"""

if os.name == 'posix':
for file_ in ("docker-run", "docker-compose-run", "bin/eval-templates"):
dest = os.path.join(output_dir, "CONST_create_template", file_)
subprocess.check_call(["chmod", "+x", dest])
fix_executables(output_dir, ("docker-run", "docker-compose-run", "bin/*"), True)

self.out(colorize("\nWelcome to c2cgeoportal!", GREEN))

return BaseTemplate.post(self, command, output_dir, vars_)
Expand All @@ -216,13 +220,8 @@ def pre(self, command, output_dir, vars_):
return super().pre(command, output_dir, vars_)

def post(self, command, output_dir, vars_):
if os.name == 'posix':
for glob_ in (
"get-pip-dependencies",
"deploy/hooks/*",
):
for file_ in glob.glob(os.path.join(output_dir, glob_)):
subprocess.check_call(["chmod", "+x", file_])
fix_executables(output_dir, ("get-pip-dependencies", "deploy/hooks/*"))

return super().post(command, output_dir, vars_)


Expand All @@ -236,12 +235,6 @@ def pre(self, command, output_dir, vars_):
return BaseTemplate.pre(self, command, output_dir, vars_)

def post(self, command, output_dir, vars_):
if os.name == 'posix':
for glob_ in (
"get-pip-dependencies",
"deploy/hooks/*",
):
for file_ in glob.glob(os.path.join(output_dir, "CONST_create_template", glob_)):
subprocess.check_call(["chmod", "+x", file_])
fix_executables(output_dir, ("get-pip-dependencies", "deploy/hooks/*"), True)

return BaseTemplate.post(self, command, output_dir, vars_)

0 comments on commit eb9539c

Please sign in to comment.