[Greater-commits] r3772 - branches/3.0.0-all-models/greater-pre-processing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 4 17:04:20 CEST 2011


Author: aheinecke
Date: 2011-10-04 17:04:19 +0200 (Tue, 04 Oct 2011)
New Revision: 3772

Modified:
   branches/3.0.0-all-models/greater-pre-processing/greater-pre-processing.py
Log:
Backup old catchment files


Modified: branches/3.0.0-all-models/greater-pre-processing/greater-pre-processing.py
===================================================================
--- branches/3.0.0-all-models/greater-pre-processing/greater-pre-processing.py	2011-10-04 15:03:52 UTC (rev 3771)
+++ branches/3.0.0-all-models/greater-pre-processing/greater-pre-processing.py	2011-10-04 15:04:19 UTC (rev 3772)
@@ -26,6 +26,35 @@
 usage_str = 'greater-pre-processing [check|help|run|run-without-cleanup|clean]'
 greater_pre_proc_path = os.path.abspath(os.path.dirname(sys.argv[0]))
 
+# Static definition of what file contians which objects for the
+# Upload
+OUTPUT_FILES="""\
+#PATH,NAME,OBJ_TYPE,OBJ_SUB_TYPE
+#
+# CATCHBOUND
+#
+./catchbound.dbf,rivernet,CATCHMENT,CATCHBOUND
+./catchbound.shp,rivernet,CATCHMENT,CATCHBOUND
+./catchbound.shx,rivernet,CATCHMENT,CATCHBOUND
+#
+# RIVERNET
+#
+./rivernet.dbf,rivernet,CATCHMENT,RIVERNET
+./rivernet.shp,rivernet,CATCHMENT,RIVERNET
+./rivernet.shx,rivernet,CATCHMENT,RIVERNET
+#
+# DISCHARGES
+#
+./discharges.dbf,rivernet,CATCHMENT,DISCHARGES
+./discharges.shp,rivernet,CATCHMENT,DISCHARGES
+./discharges.shx,rivernet,CATCHMENT,DISCHARGES
+#
+# DISCH_RIVER
+#
+./disch_river.dbf,rivernet,CATCHMENT,DISCHRIVER
+./disch_river.shp,rivernet,CATCHMENT,DISCHRIVER
+./disch_river.shx,rivernet,CATCHMENT,DISCHRIVER"""
+
 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
@@ -94,7 +123,7 @@
 
     for k in [ 'ID', 'NAME', 'DESCRIPTION', 'IN-VERSION', 'OUT-VERSION' ]:
         if not catchment.has_key(k):
-            raise ValueError("Error in catchment.desc: missing", k)
+            raise ValueError("Error in catchment.desc: missing %s" % k)
             return 2
 
     for c in  catchment['ID']:
@@ -876,8 +905,20 @@
     """ Tages a CatchmentPage and writes the description for
         uploading into the catchments.desc
     """
-    pass
+    cdir = catchment_page.catchment_dir
+    cfile = os.path.join(cdir, "catchment.desc")
+    with open(cfile, "w") as fptr:
+        fptr.write("ID=%s\n" % catchment_page.text_ID.GetValue())
+        fptr.write("NAME=%s\n" % catchment_page.text_NAME.GetValue())
+        fptr.write("DESCRIPTION=%s\n" % catchment_page.text_DESCRIPTION.GetValue())
+        fptr.write("GISFILELIST=./upload.list")
+        fptr.write("STRECH_TAB=./river2.att")
+        fptr.write("DISCH_TAB=./disch.att")
 
+    upfile = os.path.join(cdir, "catchment.desc")
+    with open(upfile, "w") as fptr:
+        upfile.write(OUTPUT_FILES)
+
 def write_desc(catchment_page):
     """ Tages a CatchmentPage and writes the description into the
         catchment.desc
@@ -894,42 +935,36 @@
         fptr.write("OUT-VERSION=%s\n" % "2.0")
     return cfile
 
-
-#    def DoUpload(self):
-#        """Do the upload."""
-#        dialog = wx.wxProgressDialog("Uploading Catchment",
-#                                     "Uploading Catchment",
-#                                     100,
-#                                     self.wizard,
-#                                     wx.wxPD_CAN_ABORT
-#                                     | wx.wxPD_AUTO_HIDE
-#                                     | wx.wxPD_ELAPSED_TIME
-#                                     | wx.wxPD_ESTIMATED_TIME
-#                                     | wx.wxPD_REMAINING_TIME)
-#        try:
-#            try:
-#                for progress in do_upload(self.db_page.GetDBInfo(),
-#                                          db=self.db_page.GetDBType()):
-#                    if not dialog.Update(progress):
-#                        return False
-#                return True
-#            except:
-#                raise
-#                wx.wxMessageBox("An error occurred:\n%s"
-#                                % str(sys.exc_info()[1]),
-#                                "Error Uploading Catchment")
-#        finally:
-#            dialog.Destroy()
-
-
 if __name__ == '__main__':
     # Run the wizard.  If the wizard is cancelled, exit with status 1.
 
     app = PreProcessingApp(0)
-    success = app.RunWizard()
-    if not success:
-        sys.exit(1)
 
+    # Make a backup of the old catchment.desc
+    try:
+        old_catchment = os.path.join(self.wizard.catchment_page.catchment_dir,
+                "catchment.desc")
+        if os.path.isfile(old_catchment):
+            shutil.copyfile(old_catchment, old_catchment.replace(
+                "catchment.desc", "catchment.desc.bkp"))
+    except:
+        print "Error creating backup: ", str(sys.exc_info()[1])
+
+    def restore_backup():
+        try:
+            shutil.move(old_catchment.replace(
+                "catchment.desc", "catchment.desc.bkp"), old_catchment)
+        except:
+            print "Error restoring backup: ", str(sys.exc_info()[1])
+
+    try:
+        success = app.RunWizard()
+        if not success:
+            restore_backup()
+            sys.exit(1)
+    except:
+        restore_backup()
+
 # Old console version main
 #if __name__ == '__main__':
 #    import sys



More information about the Greater-commits mailing list