Skip to content
Closed
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
23 changes: 14 additions & 9 deletions scripts/v.db.droptable/v.db.droptable.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ def main():

gs.message(_("Current attribute table link(s):"))
# silently test first to avoid confusing error messages
nuldev = open(os.devnull, "w")
try:
gs.run_command(
"v.db.connect", flags="p", map=map, quiet=True, stdout=nuldev, stderr=nuldev
)
except CalledModuleError:
gs.message(_("(No database links remaining)"))
else:
gs.run_command("v.db.connect", flags="p", map=map)
with open(os.devnull, "w") as nuldev:
try:
gs.run_command(
"v.db.connect",
flags="p",
map=map,
quiet=True,
stdout=nuldev,
stderr=nuldev,
)
except CalledModuleError:
gs.message(_("(No database links remaining)"))
else:
gs.run_command("v.db.connect", flags="p", map=map)

# write cmd history:
gs.vector_history(map)
Expand Down
5 changes: 4 additions & 1 deletion scripts/v.db.reconnect.all/v.db.reconnect.all.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,7 @@ def main():
if __name__ == "__main__":
options, flags = gs.parser()
nuldev = open(os.devnull, "w")
sys.exit(main())
try:
sys.exit(main())
finally:
nuldev.close()
5 changes: 4 additions & 1 deletion scripts/v.db.univar/v.db.univar.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ def main():
if __name__ == "__main__":
options, flags = gs.parser()
nuldev = open(os.devnull, "w")
main()
try:
main()
finally:
nuldev.close()
1 change: 1 addition & 0 deletions scripts/v.in.e00/v.in.e00.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def main():
gcore.call(["e00conv", filename, e00tmp + ".e00"])
gcore.message(_("...converted to Arc Coverage in current directory"))
gcore.call(["avcimport", e00tmp + ".e00", e00shortname], stderr=nuldev)
nuldev.close()

# SQL name fix:
name = name.replace("-", "_")
Expand Down
7 changes: 3 additions & 4 deletions scripts/v.rast.stats/v.rast.stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
# %end

import sys
import os
import atexit
import grass.script as gs
from grass.script.utils import decode
Expand All @@ -88,16 +87,14 @@ def cleanup():


def main():
global tmp, sqltmp, tmpname, nuldev, vector, rastertmp
global tmp, sqltmp, tmpname, vector, rastertmp
rastertmp = False
# setup temporary files
tmp = gs.tempfile()
sqltmp = tmp + ".sql"
# we need a random name
tmpname = gs.basename(tmp)

nuldev = open(os.devnull, "w")

rasters = options["raster"].split(",")
colprefixes = options["column_prefix"].split(",")
vector = options["map"]
Expand Down Expand Up @@ -296,6 +293,7 @@ def get_nr_of_categories(
for line in p.stdout:
line = decode(line)
cats.append(line.rstrip("\r\n").split(";")[0])
p.stdout.close()
p.wait()

number = len(cats)
Expand Down Expand Up @@ -482,6 +480,7 @@ def perform_stats(

f.write(" WHERE %s=%s;\n" % (fi["key"], vars[0]))
f.write("{0}\n".format(gs.db_commit_transaction(fi["driver"])))
p.stdout.close()
p.wait()


Expand Down
6 changes: 6 additions & 0 deletions scripts/v.report/v.report.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def main():
if cols[catcol] == "-1" or cols[catcol] == "0":
continue
records1.append(cols[:catcol] + [int(cols[catcol])] + cols[(catcol + 1) :])
p.stdout.close()
p.wait()
if p.returncode != 0:
sys.exit(1)
Expand Down Expand Up @@ -162,6 +163,7 @@ def main():
if fields[0] in {"cat", "-1", "0"}:
continue
records2.append([int(fields[0])] + fields[1:])
p.stdout.close()
p.wait()
records2.sort()

Expand All @@ -186,6 +188,7 @@ def main():
field = int(decode(line).rstrip())
if field > 0:
records1.append(field)
p.stdout.close()
p.wait()
records1.sort()
records1 = uniq(records1)
Expand All @@ -206,6 +209,7 @@ def main():
if fields[0] in {"cat", "-1", "0"}:
continue
records3.append([int(fields[0])] + fields[1:])
p.stdout.close()
p.wait()
records3.sort()

Expand Down Expand Up @@ -240,6 +244,8 @@ def main():
for r in records3:
sys.stdout.write(fs.join(map(str, r)) + "\n")

nuldev.close()


if __name__ == "__main__":
options, flags = gs.parser()
Expand Down
Loading