[Rapier-commits] r158 - trunk/src

This list send mail when a change occurs on the subversion repository rapier-commits at garage.maemo.org
Sat Dec 1 18:31:03 EET 2007


Author: pamadio
Date: 2007-12-01 18:31:03 +0200 (Sat, 01 Dec 2007)
New Revision: 158

Modified:
   trunk/src/rapier
   trunk/src/swordutils.py
Log:
[PATCH] Refactor handling of the SWMgr and data_path

Modified: trunk/src/rapier
===================================================================
--- trunk/src/rapier	2007-12-01 16:29:43 UTC (rev 157)
+++ trunk/src/rapier	2007-12-01 16:31:03 UTC (rev 158)
@@ -81,8 +81,8 @@
         swordutils.debug('------------------------------------------------')
         swordutils.debug('Rapier starts')
         hildon.Program.__init__(self)
-        self.mgr=Sword.SWMgr()
         self.gconf=gconf.client_get_default()
+        self.reload_manager()
         self.mainWindow = hildon.Window()
         self.mainWindow.connect("destroy",self.application_quit)
         self.mainWindow.connect("key-press-event",self.on_key_press)
@@ -153,7 +153,20 @@
         
         self.gconf.set_string("/apps/osso/rapier/bookmarks/start",position)
 
+    def reload_manager(self):
+        self.mgr = self.get_manager()
 
+    def get_manager(self, *args):
+        data_path = self.get_data_path()
+        mgr = Sword.SWMgr(*args)
+        if data_path:
+            mgr.prefixPath = data_path
+            mgr.configPath = "%s/mods.d" % data_path
+            mgr.augmentModules(data_path)
+        return mgr
+
+    def get_data_path(self):
+        return self.gconf.get_string("/apps/osso/rapier/data_path")
         
     def get_defaultModule(self):
         return self.gconf.get_string('/apps/osso/rapier/modules/default')
@@ -657,10 +670,11 @@
                                   selectedModule)
 
         if self.prefSelectedSwordDataPath!=self.mgr.prefixPath:
-            print "Let s move stuff to ",self.prefSelectedSwordDataPath
-            swordutils.change_DataPath(self.mgr.prefixPath,\
-                                       self.prefSelectedSwordDataPath)
-            self.mgr=Sword.SWMgr()
+            print "Changing data path to ",self.prefSelectedSwordDataPath
+            swordutils.set_DataPath(self.prefSelectedSwordDataPath)
+            self.gconf.set_string('/apps/osso/rapier/data_path',
+                                 self.prefSelectedSwordDataPath)
+            self.reload_manager()
 
         #Debug
         self.gconf.set_bool('/apps/osso/rapier/debug/enabled',\
@@ -835,6 +849,7 @@
     def mgModRemoteRefresh_b_clicked(self,widget):
         args={}
         args['osso_context']=self.osso_context
+        args['data_path'] = self.get_data_path()
         
         newJob=aJob(self.jobCounter,"remote_modules_list",args)
         self.putJob(newJob)
@@ -900,6 +915,7 @@
         args['idx_remove']=idx_to_remove
         args['remote']=self.remoteModules
         args['osso_context']=self.osso_context
+        args['data_path'] = self.get_data_path()
         newJob=aJob(self.jobCounter,'module_management',args)
         self.putJob(newJob)
         self.waitForModuleManagementFlag=True
@@ -1113,7 +1129,7 @@
         print snt
         
 
-        self.mgr=Sword.SWMgr()
+        self.reload_manager()
         self.refresh_module_list()
         self.refillPrefModuleList()
         
@@ -1268,7 +1284,7 @@
        vk=Sword.VerseKey()
        markup=Sword.MarkupFilterMgr(Sword.FMT_PLAIN)
        markup.thisown=False
-       mgr=Sword.SWMgr(markup)
+       mgr=self.get_manager(markup)
        mod=mgr.getModule(self.selected_module)
        if not mod:
           return
@@ -1607,7 +1623,7 @@
         out=[]
         markup=Sword.MarkupFilterMgr(Sword.FMT_PLAIN)
         markup.thisown=False
-        mgr=Sword.SWMgr(markup)
+        mgr=self.get_manager(markup)
         mod=mgr.getModule(args['module'])
         res=mod.doSearch(args['filter'],-4)
         for n in range(res.Count()):
@@ -1617,13 +1633,17 @@
 
 
     def remote_modules_list(self,args):
-        tmp=swordutils.InstallMgr(osso_context=args['osso_context'])
+        data_path = args['data_path']
+        tmp=swordutils.InstallMgr(dataPath=data_path,
+                                  osso_context=args['osso_context'])
         return tmp.get_remote_modules_list()
 
     def module_management(self,args):
         #print "args=",args
         problems=False
-        instmgr=swordutils.InstallMgr(osso_context=args['osso_context'])
+        data_path = args['data_path']
+        instmgr=swordutils.InstallMgr(dataPath=data_path,
+                                      osso_context=args['osso_context'])
         for mod in args['mod_remove']:
             swordutils.debug("let s remove '%s'"%mod)
             if not instmgr.remove_module(mod):
@@ -1636,8 +1656,8 @@
             swordutils.debug("let's install %s"%mod)
             swordutils.debug("dataPath=%s"%remoteM['DataPath'])
             swordutils.debug("conf file=%s"%remoteM['conf_file_name'])
-            if not instmgr.install_module(\
-                remoteM['DataPath'],remoteM['conf_file_name']):
+            if not instmgr.install_module(remoteM['DataPath'],
+                                          remoteM['conf_file_name']):
                 swordutils.debug("Installing %s failed"%mod) 
                 problems=True
             else:

Modified: trunk/src/swordutils.py
===================================================================
--- trunk/src/swordutils.py	2007-12-01 16:29:43 UTC (rev 157)
+++ trunk/src/swordutils.py	2007-12-01 16:31:03 UTC (rev 158)
@@ -62,33 +62,19 @@
     sword_conf.close()
     return content
 
-def get_DataPath():
-    sword_mgr=Sword.SWMgr()
-    return sword_mgr.prefixPath
-
 def set_DataPath(value):
-    sword_mgr=Sword.SWMgr()
-    sword_conf_path=sword_mgr.globalConfPath
+    sword_conf_path = "%s/sword.conf" % value
 
     uri=gnomevfs.URI(sword_conf_path)
     try:
-        sword_conf=gnomevfs.Handle(uri,open_mode=gnomevfs.OPEN_WRITE)
+        sword_conf=gnomevfs.create(uri,open_mode=gnomevfs.OPEN_WRITE)
     except gnomevfs.Error,fault:
-        print "ouuups, probelm setting conf:",fault
+        print "ouuups, probelm setting conf to %s: %s" % (uri, fault)
         return fault
     
     sword_conf.write("[Install]\nDataPath=%s"%value)
     sword_conf.close()
 
-def change_DataPath(src,dst):
-    src_uri=gnomevfs.URI(src)
-    dst_uri=gnomevfs.URI(dst)
-    gnomevfs.xfer_uri_list([src_uri],[dst_uri],\
-                           gnomevfs.XFER_RECURSIVE,\
-                           gnomevfs.XFER_ERROR_MODE_ABORT,\
-                           gnomevfs.XFER_OVERWRITE_ACTION_REPLACE_ALL)
-    set_DataPath(dst)
-    
 def has_clucene_index(modName):
     mgr=Sword.SWMgr()
     a=mgr.getModule(modName)
@@ -101,11 +87,12 @@
     of remote Sword modules.
     """
 
-    def __init__(self,location='ftp://crosswire.org/pub/sword/raw',\
+    def __init__(self,dataPath,location='ftp://crosswire.org/pub/sword/raw',\
                  osso_context=False):
         self.mgr=Sword.SWMgr()
         self.rep_location=location
-        self.tmpDir=get_DataPath()+"tmp"
+        self.data_path = dataPath
+        self.tmpDir=dataPath+"/tmp"
         self.osso_context=osso_context
         if not os.path.isdir(self.tmpDir):
             os.mkdir(self.tmpDir)
@@ -199,10 +186,10 @@
         tmp_mod_uri=gnomevfs.URI(tmp_mod)
 
 
-        dst_conf=self.mgr.prefixPath+"/mods.d/"+conf_file
-        dst_conf_uri=gnomevfs.URI(dst_conf)
-        dst_module=self.mgr.prefixPath+"/"+dataPath
-        dst_module_uri=gnomevfs.URI(dst_module)
+        dst_conf = self.data_path+"/mods.d/"+conf_file
+        dst_conf_uri = gnomevfs.URI(dst_conf)
+        dst_module = self.data_path+"/"+dataPath
+        dst_module_uri = gnomevfs.URI(dst_module)
 
         #print "dst_conf='%s'"%dst_conf
         #print "dst_module='%s'"%dst_module



More information about the Rapier-commits mailing list