[Greater-commits] r3872 - trunk/greater-pre-processing

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 6 19:07:59 CET 2012


Author: aheinecke
Date: 2012-03-06 19:07:59 +0100 (Tue, 06 Mar 2012)
New Revision: 3872

Modified:
   trunk/greater-pre-processing/ChangeLog
   trunk/greater-pre-processing/greater-pre-processing.py
Log:
Fix path escaping on Windows. Previously the \ / 
replacement was called on the whole commandline and not
only on the path. This resulted in broken stretch connections.

Fix call to join by sorting the input files differently the
output is now the same as it was intended originally by the
join -n call.


Modified: trunk/greater-pre-processing/ChangeLog
===================================================================
--- trunk/greater-pre-processing/ChangeLog	2012-01-03 10:03:27 UTC (rev 3871)
+++ trunk/greater-pre-processing/ChangeLog	2012-03-06 18:07:59 UTC (rev 3872)
@@ -1,3 +1,11 @@
+2012-03-06  Andre Heinecke <aheinecke at intevation.de>
+
+	* greater-pre-processing.py:
+	 - Fix bug on windows caused by a too generic path modification
+	 causing every backslash (even the ones that were intended) to
+	 be replaced by slashes.
+	 - Fix sort and join of to_id and from_id to correctly work
+	 with newer versions of GNU coreutils
 2011-08-12  Andre Heinecke <aheinecke at intevation.de>
 
 	* upload-catchment.py: - Remove oracle option from the wizzard

Modified: trunk/greater-pre-processing/greater-pre-processing.py
===================================================================
--- trunk/greater-pre-processing/greater-pre-processing.py	2012-01-03 10:03:27 UTC (rev 3871)
+++ trunk/greater-pre-processing/greater-pre-processing.py	2012-03-06 18:07:59 UTC (rev 3872)
@@ -64,6 +64,12 @@
 ./disch_river.shp,rivernet,CATCHMENT,DISCHRIVER
 ./disch_river.shx,rivernet,CATCHMENT,DISCHRIVER"""
 
+def cygwin_path_join(*args):
+    """Convert a Windows path with \ to a cygwin path with /"""
+    if os.name == 'nt':
+        return os.path.join(*args).replace('\\', '/')
+    return os.path.join(*args)
+
 def cygwin_call(command, suppress_output=False, extra_env={}, inputdata=None,
          logfile=None, **kw):
     """Run command as a subprocess in a cygwin shell on windws
@@ -81,10 +87,6 @@
         else:
             command = ["sh.exe", "-c"] + command
 
-        converted_command = []
-        for string in command:
-            converted_command.append(string.replace('\\', '/'))
-        command = converted_command
         extra_env["CYGWIN"] = "nodosfilewarning"
 
     if inputdata is not None:
@@ -479,7 +481,7 @@
     yield(7)
 
     print ' Creating discharges.shp ...'
-    cmds = [ 'gawk -f ' + os.path.join(greater_pre_proc_path,
+    cmds = [ 'gawk -f ' + cygwin_path_join(greater_pre_proc_path,
                 'awk', 'dsd2gen.awk') + ' < ' + catchment['ID'] + \
                 '.dsd > discharges.gen.tmp',\
             'gen2shp discharges points < discharges.gen.tmp']
@@ -491,7 +493,7 @@
 
     print ' Creating rivernet.shp ...'
     cmds = [ 'gawk -v LOG=' + catchment['ID'] + '.log -f ' + \
-                os.path.join(greater_pre_proc_path, 'awk','drn2gen.awk') +' < ' + \
+                cygwin_path_join(greater_pre_proc_path, 'awk','drn2gen.awk') +' < ' + \
                 catchment['ID'] + '.drn > rivernet.gen.tmp',\
             'gen2shp rivernet lines < rivernet.gen.tmp']
     for cmd in cmds:
@@ -501,7 +503,7 @@
     yield(15)
 
     print ' Creating disch_river.shp ...'
-    cmds = [ 'gawk -f ' + os.path.join(greater_pre_proc_path,
+    cmds = [ 'gawk -f ' + cygwin_path_join(greater_pre_proc_path,
             'awk', 'drn_dsd2gen.awk') + " " + catchment['ID'] + '.drn ' + \
             catchment['ID'] + '.dsd > disch_river.gen.tmp',\
             'gen2shp disch_river lines < disch_river.gen.tmp']
@@ -513,7 +515,7 @@
 
     print ' Creating catchbound.shp ...'
     cmds = [ 'sed -e "s/D/E/g" < ' + catchment['ID'] + \
-                '.cbp | gawk -f ' + os.path.join(greater_pre_proc_path,
+                '.cbp | gawk -f ' + cygwin_path_join(greater_pre_proc_path,
                  'awk', 'cbp2gen.awk') + ' > catchbound.gen.tmp',\
             'gen2shp catchbound polygons < catchbound.gen.tmp',\
             'echo "#catchbound,Name" > catchbound.att.tmp',\
@@ -528,23 +530,23 @@
 
     print ' Creating attribute files rivclass.dbf, wwtp.dbf, disch.dbf ' \
           'and river.dbf ...'
-    cmds = [ 'LC_ALL=C gawk -f ' + os.path.join(greater_pre_proc_path,
+    cmds = [ 'LC_ALL=C gawk -f ' + cygwin_path_join(greater_pre_proc_path,
                 'awk', 'topology.awk') +" "+ catchment['ID'] + '.drn', \
-            'LC_COLLATE=C sort -n to_id.tmp > to_id2.tmp', \
-            'LC_COLLATE=C sort -n from_id.tmp > from_id2.tmp', \
+            'LC_COLLATE=C sort -k1b,1 to_id.tmp > to_id2.tmp', \
+            'LC_COLLATE=C sort -k1b,1 from_id.tmp > from_id2.tmp', \
             r'''join to_id2.tmp from_id2.tmp | cut -d " " -f 2,3 | sort -n | sed -e "s/ /,/" > f_t.tmp''',
             r'''gawk --source='BEGIN { FS="," } { printf("%s,%s\n", $2, $1) }' f_t.tmp | sort -n > t_f.tmp''',
             'echo from-tos > f_ts.tmp',
             'gawk -f ' + greater_pre_proc_path + \
                 '/awk/joinup.awk f_t.tmp >> f_ts.tmp',
             'echo to-froms > t_fs.tmp',
-            'gawk -f ' + os.path.join(greater_pre_proc_path,
+            'gawk -f ' + cygwin_path_join(greater_pre_proc_path,
                 'awk', 'joinup.awk') + ' t_f.tmp >> t_fs.tmp',
                 'sed -e "s/$/,/" < ' + catchment['ID'] + '.dsd > ' + \
                 catchment['ID'] + '.dsd.tmp',
             'gawk -v LOG=' + catchment['ID'] + '.log -v OUTVERSION='+ \
                 catchment['OUT-VERSION'] + ' -f ' + \
-                os.path.join(greater_pre_proc_path,
+                cygwin_path_join(greater_pre_proc_path,
                 'awk', 'generateAttTables.awk') + " " +\
                 catchment['ID'] + '.rna ' + catchment['ID'] + '.dsd.tmp ' + \
                 catchment['ID'] + '.lks f_ts.tmp t_fs.tmp'
@@ -556,8 +558,12 @@
                     'river.dbf 2>> ' + catchment['ID'] + '.log')
     elif catchment['OUT-VERSION'] == '2.0':
         # add down1,down2 to river.att
-        cmds.append('"%s" %s > river2.att' % ( sys.executable,
-             os.path.join(greater_pre_proc_path, 'add-downsegments.py'))
+        if os.name == "nt":
+            executable_path = sys.executable.replace("\\", "/")
+        else:
+            executable_path = sys.executable
+        cmds.append('"%s" %s > river2.att' % ( executable_path,
+             cygwin_path_join(greater_pre_proc_path, 'add-downsegments.py'))
         )
         # two additional -I10 for down1, down2
         cmds.append('txt2dbf -d , -I10 -I2 -I1 -I10 -I10 -I10 -I10 -I5 -R12.5 '
@@ -606,9 +612,9 @@
 
     yield(75)
     print ' Creating pics.shp ...'
-    cmds = [ 'gawk -f ' + os.path.join(greater_pre_proc_path,
+    cmds = [ 'gawk -f ' + cygwin_path_join(greater_pre_proc_path,
                 'awk', 'pic2gen.awk') + ' < ' + catchment['ID'] + '.pic > pic.gen.tmp',\
-            'gawk -f ' + os.path.join(greater_pre_proc_path,
+            'gawk -f ' + cygwin_path_join(greater_pre_proc_path,
             'awk', 'pic2att.awk') +' < ' + catchment['ID'] + '.pic > pic.att.tmp', \
             'gen2shp pics points < pic.gen.tmp',
             'dbf2txt pics.dbf | sed -e "s/\t//g" > pics.txt.tmp',
@@ -634,7 +640,7 @@
     yield(90)
 
     print ' Creating Thuban session file (' + catchment['ID'] + '.session) ...'
-    cmds = [ 'cp ' + os.path.join(greater_pre_proc_path, "catchment.thuban") + ' .']
+    cmds = [ 'cp ' + cygwin_path_join(greater_pre_proc_path, "catchment.thuban") + ' .']
     for cmd in cmds:
         if cygwin_call(cmd) != 0:
             raise OSError( '  Error executing ' + cmd)
@@ -883,6 +889,7 @@
             try:
                 oldcwd = os.getcwd()
                 os.chdir(self.catchment_page.catchment_dir)
+                print "Changing to working direcotory : ", self.catchment_page.catchment_dir
                 for progress in do_run():
                     if not dialog.Update(progress):
                         os.chdir(oldcwd)



More information about the Greater-commits mailing list