diff Generic/durusdatabase.py @ 5:6502bfdaa84d

update import durus database
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sat, 06 Nov 2010 21:30:33 +0100
parents 2ac1551ad2ab
children 0359329a1c26
line wrap: on
line diff
--- a/Generic/durusdatabase.py	Sun Oct 31 23:12:06 2010 +0100
+++ b/Generic/durusdatabase.py	Sat Nov 06 21:30:33 2010 +0100
@@ -21,9 +21,12 @@
 
 # Modules
 import os.path
+import time
 # Durus Modules
 from durus.file_storage import FileStorage
 from durus.connection import Connection
+# pyArq Presupuestos Modules
+from Generic import utils
 
 class DurusFile(object):
     def __init__(self, file, new):
@@ -44,3 +47,32 @@
         self.__root["budget"] = budget
         self.__connection.commit()
 
+class Read(object):
+    def __init__(self, filename=None, budget=None):
+        self.__budget = budget
+        self.__filename = filename
+        self.__cancel = False
+
+    def cancel(self):
+        """def cancel(self)
+        
+        It do nothing
+        """
+        # TODO: Cancel reading Durus database.
+        self.__cancel = True
+        
+    def readFile(self, budget=None, filename=None, interface=None):
+        if not filename is None:
+            self.__filename = filename
+        if self.__filename is None or self.__cancel == True:
+            return None
+        if not os.path.exists(self.__filename):
+            return None
+        print utils.mapping(_("Loading file: $1:"), (self.__filename,))
+        _time = time.time()
+        _durus_file = DurusFile(self.__filename, False)
+        self.__budget = _durus_file.getBudget()
+        _durus_file.close()
+        print utils.mapping(_("Loadig time: $1 seconds"),
+             (("%.2f" %(time.time()-_time)),))
+        return self.__budget