Reincarnation of Imports
svn: r1500
This commit is contained in:
parent
64f34ccfec
commit
5232d9066d
@ -29,6 +29,7 @@
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import string
|
import string
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -54,8 +55,8 @@ except:
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Initialization function for the module. Called to start the reading
|
# Importing data into the currently open database.
|
||||||
# of data.
|
# Must takes care of renaming media files according to their new IDs.
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def importData(database, filename, callback):
|
def importData(database, filename, callback):
|
||||||
@ -115,20 +116,17 @@ def importData(database, filename, callback):
|
|||||||
|
|
||||||
# Rename media files if they were conflicting with existing ones
|
# Rename media files if they were conflicting with existing ones
|
||||||
ObjectMap = parser.db.getObjectMap()
|
ObjectMap = parser.db.getObjectMap()
|
||||||
MediaFileMapKeys = parser.MediaFileMap.keys()
|
newpath = database.getSavePath()
|
||||||
MediaFileMapKeys.sort()
|
for OldMediaID in parser.MediaFileMap.keys():
|
||||||
MediaFileMapKeys.reverse()
|
|
||||||
for OldMediaID in MediaFileMapKeys:
|
|
||||||
NewMediaID = parser.MediaFileMap[OldMediaID]
|
NewMediaID = parser.MediaFileMap[OldMediaID]
|
||||||
if NewMediaID != OldMediaID:
|
oldfile = ObjectMap[NewMediaID].getPath()
|
||||||
oldfile = ObjectMap[NewMediaID].getPath()
|
oldpath = os.path.dirname(oldfile)
|
||||||
oldpath = os.path.dirname(oldfile)
|
(junk,oldext) = os.path.splitext(os.path.basename(oldfile))
|
||||||
(junk,oldext) = os.path.splitext(os.path.basename(oldfile))
|
oldfile = os.path.join(basefile,OldMediaID+oldext)
|
||||||
oldfile = os.path.join( basefile, OldMediaID + oldext )
|
newfile = os.path.join(newpath,NewMediaID+oldext)
|
||||||
newfile = os.path.join( basefile, NewMediaID + oldext )
|
shutil.copy2(oldfile,newfile)
|
||||||
os.rename(oldfile,newfile)
|
ObjectMap[NewMediaID].setPath(os.path.join(newfile))
|
||||||
ObjectMap[NewMediaID].setPath(os.path.join(oldpath,NewMediaID+oldext))
|
ObjectMap[NewMediaID].setLocal(1)
|
||||||
ObjectMap[NewMediaID].setLocal(1)
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ from intl import gettext as _
|
|||||||
import gtk
|
import gtk
|
||||||
import const
|
import const
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -80,35 +79,7 @@ class ReadNative:
|
|||||||
Utils.destroy_passed_object(self.top)
|
Utils.destroy_passed_object(self.top)
|
||||||
self.show_display()
|
self.show_display()
|
||||||
|
|
||||||
# Create tempdir, if it does not exist, then check for writability
|
dbname = os.path.join(imp_dbpath,const.xmlFile)
|
||||||
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)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
importData(self.db,dbname,self.progress)
|
importData(self.db,dbname,self.progress)
|
||||||
@ -116,25 +87,11 @@ class ReadNative:
|
|||||||
import DisplayTrace
|
import DisplayTrace
|
||||||
DisplayTrace.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.window.destroy()
|
||||||
self.callback(1)
|
self.callback(1)
|
||||||
|
|
||||||
def progress(self,val):
|
def progress(self,val):
|
||||||
self.progress_bar.set_value(val*100.0)
|
self.progress_bar.set_fraction(val)
|
||||||
while gtk.events_pending():
|
while gtk.events_pending():
|
||||||
gtk.mainiteration()
|
gtk.mainiteration()
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ from intl import gettext as _
|
|||||||
import gtk
|
import gtk
|
||||||
import const
|
import const
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import time
|
import time
|
||||||
from QuestionDialog import ErrorDialog, WarningDialog
|
from QuestionDialog import ErrorDialog, WarningDialog
|
||||||
import TarFile
|
import TarFile
|
||||||
@ -118,15 +117,8 @@ class ReadPkg:
|
|||||||
|
|
||||||
# Clean up tempdir after ourselves
|
# Clean up tempdir after ourselves
|
||||||
files = os.listdir(tmpdir_path)
|
files = os.listdir(tmpdir_path)
|
||||||
|
|
||||||
dbdir_path = self.db.getSavePath()
|
|
||||||
for filename in files:
|
for filename in files:
|
||||||
oldfile = os.path.join(tmpdir_path,filename)
|
os.remove(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)
|
os.rmdir(tmpdir_path)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user