Skip to content

Commit

Permalink
Merge pull request #3 from griembauer/non_required_env
Browse files Browse the repository at this point in the history
t.geoserver.publish: make the OUTPUTFOLDER env VAR dependent on GEOSERVER_DATAPATH
  • Loading branch information
griembauer authored Dec 7, 2022
2 parents c4cbd5f + 499b604 commit 17c1e47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions t.geoserver.publish/t.geoserver.publish.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ <h2>DESCRIPTION</h2>
<li>GEOSERVER_USER</li>
<li>GEOSERVER_PASSWORD</li>
<li>GEOSERVER_WORKSPACE</li>
<li>OUTPUTFOLDER</li>
</ul>
In case a shared directory between GRASS GIS and GeoServer is possible,
another environment variable can be used to tell GeoServer to publish data
two further environment variables can be used to tell GeoServer to publish data
from this local path instead of uploading the data:
<ul>
<li>GEOSERVER_DATAPATH</li>
<li>OUTPUTFOLDER (path from GRASS GIS to shared directory)</li>
<li>GEOSERVER_DATAPATH (path from GeoServer to shared directory)</li>
</ul>
There are two ways to publish GeoServer layers with <em>t.geoserver.publish</em>:
<p>
Expand Down
18 changes: 11 additions & 7 deletions t.geoserver.publish/t.geoserver.publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def cleanup():
os.remove(rm_file)


def get_env(envname):
def get_env(envname, required=True):
env = os.getenv(envname)
if env is None:
if env is None and required is True:
grass.fatal(_(f"Environment variable {envname} not defined."))
else:
return env
Expand Down Expand Up @@ -295,11 +295,16 @@ def main():
geoserver_user = get_env("GEOSERVER_USER")
geoserver_pw = get_env("GEOSERVER_PASSWORD")
geoserver_workspace = get_env("GEOSERVER_WORKSPACE")
outputfolder = get_env("OUTPUTFOLDER")
# geoserver_datapath can be empty if no shared folder
# between GRASS GIS and GeoServer is allowed, so
# data will be uploaded instead of shared.
geoserver_datapath = os.getenv("GEOSERVER_DATAPATH")
geoserver_datapath = get_env("GEOSERVER_DATAPATH", required=False)
# if no shared folder exists, the OUTPUTFOLDER (where to store the temporary zip)
# does not matter, hence it can be a temp dir
if geoserver_datapath:
outputfolder = get_env("OUTPUTFOLDER")
else:
outputfolder = grass.tempdir()

layer_suffix = 1
layernames = list()
Expand Down Expand Up @@ -395,7 +400,7 @@ def main():
if not geoserver_datapath:
# Case when GRASS GIS and GeoServer don't share a common directory
output_uuid = str(uuid.uuid4())
targetdir_grass = f"{targetdir_grass}/{output_uuid}"
targetdir_grass = os.path.join(targetdir_grass, output_uuid)
if not os.path.isdir(targetdir_grass):
os.makedirs(targetdir_grass)
# if the dir exists and has files, cancel
Expand Down Expand Up @@ -505,8 +510,7 @@ def main():
geoserver_port,
geoserver_auth,
)
rm_dirs.append(targetdir_grass)
rm_files.append(zip_name)
rm_dirs.append(outputfolder)
layernames.append(mosaic_layername)

# style the layer(s)
Expand Down

0 comments on commit 17c1e47

Please sign in to comment.