From 37ef7aebcc8a7985136a64c6564fde745d1edd64 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Tue, 6 May 2003 15:16:04 +0000 Subject: [PATCH] Reincarnation of Imports svn: r1500 --- src/ReadXML.py | 28 +++++++++++------------ src/plugins/ReadNative.py | 47 ++------------------------------------- src/plugins/ReadPkg.py | 10 +-------- 3 files changed, 16 insertions(+), 69 deletions(-) diff --git a/src/ReadXML.py b/src/ReadXML.py index 21e002988..2374af91d 100644 --- a/src/ReadXML.py +++ b/src/ReadXML.py @@ -29,6 +29,7 @@ #------------------------------------------------------------------------- import string import os +import shutil from xml.parsers.expat import ExpatError #------------------------------------------------------------------------- @@ -54,8 +55,8 @@ except: #------------------------------------------------------------------------- # -# Initialization function for the module. Called to start the reading -# of data. +# Importing data into the currently open database. +# Must takes care of renaming media files according to their new IDs. # #------------------------------------------------------------------------- def importData(database, filename, callback): @@ -115,20 +116,17 @@ def importData(database, filename, callback): # Rename media files if they were conflicting with existing ones ObjectMap = parser.db.getObjectMap() - MediaFileMapKeys = parser.MediaFileMap.keys() - MediaFileMapKeys.sort() - MediaFileMapKeys.reverse() - for OldMediaID in MediaFileMapKeys: + newpath = database.getSavePath() + for OldMediaID in parser.MediaFileMap.keys(): NewMediaID = parser.MediaFileMap[OldMediaID] - if NewMediaID != OldMediaID: - oldfile = ObjectMap[NewMediaID].getPath() - oldpath = os.path.dirname(oldfile) - (junk,oldext) = os.path.splitext(os.path.basename(oldfile)) - oldfile = os.path.join( basefile, OldMediaID + oldext ) - newfile = os.path.join( basefile, NewMediaID + oldext ) - os.rename(oldfile,newfile) - ObjectMap[NewMediaID].setPath(os.path.join(oldpath,NewMediaID+oldext)) - ObjectMap[NewMediaID].setLocal(1) + oldfile = ObjectMap[NewMediaID].getPath() + oldpath = os.path.dirname(oldfile) + (junk,oldext) = os.path.splitext(os.path.basename(oldfile)) + oldfile = os.path.join(basefile,OldMediaID+oldext) + newfile = os.path.join(newpath,NewMediaID+oldext) + shutil.copy2(oldfile,newfile) + ObjectMap[NewMediaID].setPath(os.path.join(newfile)) + ObjectMap[NewMediaID].setLocal(1) return 1 diff --git a/src/plugins/ReadNative.py b/src/plugins/ReadNative.py index 849adf304..88337c2fc 100644 --- a/src/plugins/ReadNative.py +++ b/src/plugins/ReadNative.py @@ -30,7 +30,6 @@ from intl import gettext as _ import gtk import const import os -import shutil #------------------------------------------------------------------------- # @@ -80,35 +79,7 @@ class ReadNative: Utils.destroy_passed_object(self.top) self.show_display() - # Create tempdir, if it does not exist, then check for writability - tmpdir_path = os.path.expanduser("~/.gramps/tmp" ) - if not os.path.isdir(tmpdir_path): - try: - os.mkdir(tmpdir_path,0700) - except: - ErrorDialog( _("Could not create temporary directory %s") % - tmpdir_path ) - return - elif not os.access(tmpdir_path,os.W_OK): - ErrorDialog( _("Temporary directory %s is not writable") % tmpdir_path ) - return - else: # tempdir exists and writable -- clean it up if not empty - files = os.listdir(tmpdir_path) ; - for filename in files: - os.remove( os.path.join(tmpdir_path,filename) ) - - # Copy all files from imp_dbpath to tmpdir_path - files = os.listdir(imp_dbpath) - for filename in files: - oldfile = os.path.join(imp_dbpath,filename) - newfile = os.path.join(tmpdir_path,filename) - try: - shutil.copy2( oldfile, newfile ) - except: - # These are .* files, and dirs under database dir -- ignore them - pass - - dbname = os.path.join(tmpdir_path,const.xmlFile) + dbname = os.path.join(imp_dbpath,const.xmlFile) try: importData(self.db,dbname,self.progress) @@ -116,25 +87,11 @@ class ReadNative: import DisplayTrace DisplayTrace.DisplayTrace() - # Clean up tempdir after ourselves - files = os.listdir(tmpdir_path) - - dbdir_path = self.db.getSavePath() - for filename in files: - oldfile = os.path.join(tmpdir_path,filename) - newfile = os.path.join(dbdir_path,filename) - if filename not in [const.xmlFile,const.xmlFile+'.bak']: - shutil.copy2( oldfile, newfile ) - - os.remove( oldfile ) - - os.rmdir(tmpdir_path) - self.window.destroy() self.callback(1) def progress(self,val): - self.progress_bar.set_value(val*100.0) + self.progress_bar.set_fraction(val) while gtk.events_pending(): gtk.mainiteration() diff --git a/src/plugins/ReadPkg.py b/src/plugins/ReadPkg.py index 576c64127..71c166c62 100644 --- a/src/plugins/ReadPkg.py +++ b/src/plugins/ReadPkg.py @@ -30,7 +30,6 @@ from intl import gettext as _ import gtk import const import os -import shutil import time from QuestionDialog import ErrorDialog, WarningDialog import TarFile @@ -118,15 +117,8 @@ class ReadPkg: # Clean up tempdir after ourselves files = os.listdir(tmpdir_path) - - dbdir_path = self.db.getSavePath() for filename in files: - oldfile = os.path.join(tmpdir_path,filename) - newfile = os.path.join(dbdir_path,filename) - if filename not in [const.xmlFile,const.xmlFile+'.bak']: - shutil.copy2( oldfile, newfile ) - - os.remove( oldfile ) + os.remove(os.path.join(tmpdir_path,filename)) os.rmdir(tmpdir_path)