Code for low-level database copy; sometimes corrupted, not sure why
svn: r23416
This commit is contained in:
parent
bdf9f42477
commit
9ef373651f
@ -287,7 +287,7 @@ class CLIDbManager(object):
|
|||||||
"""
|
"""
|
||||||
print(_('Import finished...'))
|
print(_('Import finished...'))
|
||||||
|
|
||||||
def create_new_db_cli(self, title=None):
|
def create_new_db_cli(self, title=None, create_db=True):
|
||||||
"""
|
"""
|
||||||
Create a new database.
|
Create a new database.
|
||||||
"""
|
"""
|
||||||
@ -304,6 +304,7 @@ class CLIDbManager(object):
|
|||||||
name_file.write(title)
|
name_file.write(title)
|
||||||
name_file.close()
|
name_file.close()
|
||||||
|
|
||||||
|
if create_db:
|
||||||
# write the version number into metadata
|
# write the version number into metadata
|
||||||
newdb = DbBsddb()
|
newdb = DbBsddb()
|
||||||
newdb.write_version(new_path)
|
newdb.write_version(new_path)
|
||||||
|
@ -36,6 +36,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import copy
|
import copy
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
@ -258,6 +259,7 @@ class DbManager(CLIDbManager):
|
|||||||
self.rename.set_sensitive(True)
|
self.rename.set_sensitive(True)
|
||||||
self.copy.set_sensitive(True)
|
self.copy.set_sensitive(True)
|
||||||
self.remove.set_sensitive(True)
|
self.remove.set_sensitive(True)
|
||||||
|
self.new.set_sensitive(True)
|
||||||
|
|
||||||
def __build_interface(self):
|
def __build_interface(self):
|
||||||
"""
|
"""
|
||||||
@ -425,6 +427,10 @@ class DbManager(CLIDbManager):
|
|||||||
self.connect.set_sensitive(False)
|
self.connect.set_sensitive(False)
|
||||||
self.rename.set_sensitive(False)
|
self.rename.set_sensitive(False)
|
||||||
self.copy.set_sensitive(False)
|
self.copy.set_sensitive(False)
|
||||||
|
self.rcs.set_sensitive(False)
|
||||||
|
self.repair.set_sensitive(False)
|
||||||
|
self.remove.set_sensitive(False)
|
||||||
|
self.new.set_sensitive(False)
|
||||||
|
|
||||||
def __change_name(self, renderer_sel, path, new_text):
|
def __change_name(self, renderer_sel, path, new_text):
|
||||||
"""
|
"""
|
||||||
@ -644,25 +650,21 @@ class DbManager(CLIDbManager):
|
|||||||
"""
|
"""
|
||||||
Copy the database through low-level file copies.
|
Copy the database through low-level file copies.
|
||||||
"""
|
"""
|
||||||
self.copy.set_sensitive(False)
|
|
||||||
# First, get the selected tree:
|
# First, get the selected tree:
|
||||||
store, node = self.selection.get_selected()
|
store, node = self.selection.get_selected()
|
||||||
path = self.model.get_path(node)
|
# New title:
|
||||||
# Next, copy the files
|
date_string = time.strftime("%d %b %Y %H:%M:%S", time.gmtime())
|
||||||
dirname = store[node][PATH_COL]
|
title = _("%s (copy, %s)") % (store[node][NAME_COL], date_string)
|
||||||
try:
|
# Create the row and directory, awaits user edit of title:
|
||||||
dir_path, title = self._create_new_db(title=_("%s (copy)") % store[node][NAME_COL])
|
(new_dir, title) = self._create_new_db(title, create_db=False)
|
||||||
except (OSError, IOError) as msg:
|
# Copy the files:
|
||||||
DbManager.ERROR(_("Could not create Family Tree"),
|
name_file = store[node][FILE_COL]
|
||||||
str(msg))
|
old_dir = os.path.dirname(name_file)
|
||||||
#scroll to new position
|
for filename in os.listdir(old_dir):
|
||||||
store, node = self.selection.get_selected()
|
if filename == "name.txt":
|
||||||
tree_path = store.get_path(node)
|
continue
|
||||||
self.dblist.scroll_to_cell(tree_path, None, False, 0.5, 0.5)
|
old_file = os.path.abspath(os.path.join(old_dir, filename))
|
||||||
# Finally, allow user to edit the copied name:
|
shutil.copy2(old_file, new_dir)
|
||||||
self.name_renderer.set_property('editable', True)
|
|
||||||
self.dblist.set_cursor(tree_path, self.column, True)
|
|
||||||
self.copy.set_sensitive(True)
|
|
||||||
|
|
||||||
def __repair_db(self, obj):
|
def __repair_db(self, obj):
|
||||||
"""
|
"""
|
||||||
@ -763,11 +765,11 @@ class DbManager(CLIDbManager):
|
|||||||
str(msg))
|
str(msg))
|
||||||
self.new.set_sensitive(True)
|
self.new.set_sensitive(True)
|
||||||
|
|
||||||
def _create_new_db(self, title=None):
|
def _create_new_db(self, title=None, create_db=True):
|
||||||
"""
|
"""
|
||||||
Create a new database, append to model
|
Create a new database, append to model
|
||||||
"""
|
"""
|
||||||
new_path, title = self.create_new_db_cli(title)
|
new_path, title = self.create_new_db_cli(title, create_db)
|
||||||
path_name = os.path.join(new_path, NAME_FILE)
|
path_name = os.path.join(new_path, NAME_FILE)
|
||||||
(tval, last) = time_val(new_path)
|
(tval, last) = time_val(new_path)
|
||||||
node = self.model.append(None, [title, new_path, path_name,
|
node = self.model.append(None, [title, new_path, path_name,
|
||||||
|
Loading…
Reference in New Issue
Block a user