diff Gtk/importFiebdc.py @ 4:4e976a99efb9

update ImportPriceDatabase
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Sun, 31 Oct 2010 23:12:06 +0100
parents 2ac1551ad2ab
children 6502bfdaa84d
line wrap: on
line diff
--- a/Gtk/importFiebdc.py	Sun Oct 31 21:01:48 2010 +0100
+++ b/Gtk/importFiebdc.py	Sun Oct 31 23:12:06 2010 +0100
@@ -30,8 +30,10 @@
 import threading
 gobject.threads_init()
 
+# pyArq-Presupuestos Modules
 from Generic import utils
 from Generic import globals
+from Generic import durusdatabase
 import gui
 
 class FileSelectionWindow(object):
@@ -40,8 +42,8 @@
     Description:
         Class to show the selection file window
     Constructor:
-        importFiebdc.FileSelectionWindow(mainWindow, readFileMethod,
-        budget, arg_List, cancelMethod)
+        importFiebdc.FileSelectionWindow(mainWindow, readFileMethod, budget,
+            filename, cancelMethod, filetype)
     Ancestry:
     +-- object
       +-- FileSelectionWindow
@@ -50,6 +52,7 @@
         "__readFileMethod": Method to read the selected file
         "__budget": Budget object
         "__filename": "file"
+        "__filetype": "budget" or "database"
         "__cancelMethod": Method to cancel the read method
         "__file": The selected file
         "__window": The selection file window
@@ -64,15 +67,16 @@
     """
 
     def __init__(self, mainWindow, readFileMethod, budget, filename,
-                 cancelMethod):
+                 cancelMethod, filetype):
         """def __init__(self, mainWindow, readFileMethod, budget,
-                        filename, cancelMethod)
+                        filename, cancelMethod, filetype)
         
         mainWindow: gui.MainWindow object
         readFileMethod: Method to read the selected file
         budget: base.Budget object
         filename: "file"
         cancelMethod: Method to cancel the read method
+        fileytpe: "budget" or "database"
         Sets the init atributes, creates the file selection window
         Connects the events:
             * clicked ok button: _openFile
@@ -84,6 +88,7 @@
         self.__readFileMethod = readFileMethod
         self.__budget = budget
         self.__filename = filename
+        self.__filetype = filetype
         self.__cancelMethod = cancelMethod
         self.__file = None
         self.__window = gtk.FileChooserDialog(title=_("Open File"),
@@ -105,7 +110,7 @@
 
         _emptyPage = gui.EmptyPage(self.__mainWindow, self.__readFileMethod,
                                    self.__budget, self.__filename,
-                                   self.__cancelMethod)
+                                   self.__cancelMethod, self.__filetype)
         self.__mainWindow.getNotebook().append_page(_emptyPage.widget,
                                                     _emptyPage.title)
         self.__mainWindow.getPageList().append(_emptyPage)
@@ -370,7 +375,7 @@
         Thread class to read a file without freeze the gui
     Constructor:
         importFiebdc.Thread(page, mainWindow,
-                            readFileMethod, arg_tuple, cancelMethod)
+                     readFileMethod, budget, filename, cancelMethod, filetype)
     Ancestry:
     +--threading.Thread
       +-- importFiebdc.Thread
@@ -378,8 +383,10 @@
         "__page": The page instanca that launch the thread
         "__mainWindow": gui.MainWindow instance
         "__readFileMethod": Method to read the selected file
-        "__arg_tuple": ("file", base.Budget())
+        "__budget
+        "__filename": "file"
         "__cancelMethod": Method to cancel the read method
+        "__filetype": "budget" or "database"
         "__cancel": Boolean value, True: the thread is stoped
     Methods:
         __init__(self, page, mainWindow,
@@ -390,7 +397,7 @@
     """
 
     def __init__(self, page, mainWindow,
-        readFileMethod, budget, filename, cancelMethod):
+        readFileMethod, budget, filename, cancelMethod, filetype):
         """def __init__(self, page, mainWindow,
                         readFileMethod, budget, filename, cancelMethod)
         
@@ -400,6 +407,7 @@
         budget: base.Budget object
         filename: "file"
         cancelMethod: Method to cancel the read method
+        feletype: "budget" or "basedate"
         Sets the instance atributes.
         """
         super(Thread, self).__init__()
@@ -409,6 +417,7 @@
         self.__budget = budget
         self.__filename = filename
         self.__cancelMethod = cancelMethod
+        self.__filetype = filetype
         self.__cancel = False
 
     def run(self):
@@ -424,7 +433,24 @@
             _mainWindow = self.__mainWindow
             _mainWindow._addBudget(_result)
             self.__page.closeWindow()
+
+            if self.__filetype == "basedate":
+                self.saveDurusDatabase()
         self.clear()
+        
+    def saveDurusDatabase(self):
+        _path = globals.getHomePath("DURUS-DATABASE")
+        _file_whit_path_bc3 = self.__budget.filename
+        _filename_bc3 = _file_whit_path_bc3.split("/")[-1]
+        _filename = _filename_bc3.split(".")[-2]
+        _file = _path + _filename + ".durus"
+        print utils.mapping(_("Saving file: $1"), (_file,))
+        _time = time.time()
+        _durus_file = durusdatabase.DurusFile(_file,True)
+        _durus_file.setBudget(self.__budget)
+        _durus_file.close()
+        print utils.mapping(_("Saving time: $1 seconds"),
+              (("%.2f" %(time.time()-_time) ),))
 
     def cancel(self):
         """cancel(self)