[Dive4elements-commits] [PATCH] Use os.access instead of try/except open

Wald Commits scm-commit at wald.intevation.org
Wed Feb 13 19:12:15 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1360779094 -3600
# Branch dami
# Node ID b5ac7588cf4d32d88ea9e200c324892699c0454b
# Parent  ee908e4946cde3ed1466fc56b12fb728417c5fba
Use os.access instead of try/except open

diff -r ee908e4946cd -r b5ac7588cf4d flys-backend/contrib/shpimporter/shpimporter.py
--- a/flys-backend/contrib/shpimporter/shpimporter.py	Wed Feb 13 18:35:37 2013 +0100
+++ b/flys-backend/contrib/shpimporter/shpimporter.py	Wed Feb 13 19:11:34 2013 +0100
@@ -231,14 +231,10 @@
         if not config.skip_dgm:
             dgmfilename = os.path.join(
                     config.directory, "..", "DGMs.csv")
-            try:
-                dgmfile = open(dgmfilename, "r")
-                dgmfile.close()
-            except IOError:
-                INFO("Could not find DGM file: %s \n"
+            if not os.access(dgmfilename, os.R_OK):
+                INFO("Could not find or access DGM file: %s \n"
                      "Skipping DGM import." % dgmfilename)
-                dgmfilename=None
-            if dgmfilename:
+            else:
                 INFO("Inserting DGM meta information in 'dem' table.")
                 insertRiverDgm(dbconn_raw, dgmfilename, river_name, config.dry_run)
 


More information about the Dive4elements-commits mailing list