mirate logs by spawing a child python process

No progress text, only pulsebar
This commit is contained in:
Dimitur Kirov 2006-04-07 22:57:27 +00:00
parent 8c56beac9b
commit 52d01323ce
4 changed files with 59 additions and 108 deletions

View File

@ -1481,52 +1481,26 @@ class ProgressDialog:
in the textview'''
self.xml = gtk.glade.XML(GTKGUI_GLADE, 'progress_dialog', APP)
self.dialog = self.xml.get_widget('progress_dialog')
self.messages_queue = messages_queue
self.label = self.xml.get_widget('label')
self.label.set_markup('<big>' + during_text + '</big>')
self.progressbar = self.xml.get_widget('progressbar')
self.textview = self.xml.get_widget('textview')
self.textview_buffer = self.textview.get_buffer()
end_iter = self.textview_buffer.get_end_iter()
self.textview_buffer.create_mark('end', end_iter, False)
self.dialog.set_title(title_text)
self.dialog.set_default_size(450, 500)
self.dialog.set_default_size(450, 250)
self.dialog.show_all()
self.xml.signal_autoconnect(self)
self.update_progressbar_timeout_id = gobject.timeout_add(100,
self.update_progressbar)
self.read_from_queue_id = gobject.timeout_add(200,
self.read_from_queue_and_update_textview)
def update_progressbar(self):
self.progressbar.pulse()
return True # loop forever
def read_from_queue_and_update_textview(self):
while not self.messages_queue.empty():
message = self.messages_queue.get()
end_iter = self.textview_buffer.get_end_iter()
self.textview_buffer.insert(end_iter, message + '\n')
self.textview.scroll_to_mark(self.textview_buffer.get_mark('end'), 0,
True, 0, 1)
return True # loop for ever
def update_progressbar(self):
if self.dialog:
self.progressbar.pulse()
return True # loop forever
return False
def on_progress_dialog_delete_event(self, widget, event):
return True # WM's X button or Escape key should not destroy the window
def done(self, done_text):
'''whatever we were doing is done (either we problems or not),
make close button sensitive and show the done_text in label'''
self.xml.get_widget('close_button').set_sensitive(True)
self.label.set_markup('<big>' + done_text + '</big>')
gobject.source_remove(self.update_progressbar_timeout_id)
gobject.source_remove(self.read_from_queue_id)
self.read_from_queue_and_update_textview()
self.progressbar.set_fraction(1)
class SoundChooserDialog:
def __init__(self, path_to_snd_file = ''):

View File

@ -149,6 +149,19 @@ import config
GTKGUI_GLADE = 'gtkgui.glade'
class MigrateCommand(nslookup.IdleCommand):
def __init__(self, on_result):
nslookup.IdleCommand.__init__(self, on_result)
self.commandtimeout = 10
def _compose_command_args(self):
return ['python', 'migrate_logs_to_dot9_db.py', 'dont_wait']
def _return_result(self):
print self.result
if self.result_handler:
self.result_handler(self.result)
self.result_handler = None
class GlibIdleQueue(idlequeue.IdleQueue):
'''
@ -1868,39 +1881,30 @@ if __name__ == '__main__':
gtkgui_helpers.possibly_set_gajim_as_xmpp_handler()
# Migrate old logs if we have such olds logs
from common import logger
LOG_DB_PATH = logger.LOG_DB_PATH
if not os.path.exists(LOG_DB_PATH):
from common import migrate_logs_to_dot9_db
import migrate_logs_to_dot9_db
if os.path.isdir(migrate_logs_to_dot9_db.PATH_TO_LOGS_BASE_DIR):
import Queue
q = Queue.Queue(100)
m = migrate_logs_to_dot9_db.Migration()
dialog = dialogs.ProgressDialog(_('Migrating Logs...'),
_('Please wait while logs are being migrated...'), q)
t = threading.Thread(target = m.migrate, args = (q,))
t.start()
id = gobject.timeout_add(500, wait_migration, m)
# In 1 seconds, we test if migration began
gobject.timeout_add(1000, test_migration, m)
gtk.main()
if not m.DONE:
# stop test_migration handler
gobject.source_remove(id)
# destroy the migration window
def on_result(*arg):
dialog.dialog.destroy()
# Force GTK to really destroy the window
while gtk.events_pending():
gtk.main_iteration(False)
# We can't use a SQLite object in another thread than the one in
# which it was created, so create a new Migration instance
del m
m = migrate_logs_to_dot9_db.Migration()
m.migrate()
# Init logger values (self.con/cur, jid_already_in)
gajim.logger.init_vars()
check_paths.check_and_possibly_create_paths()
Interface()
gtk.main()
dialog.dialog = None
gobject.source_remove(dialog.update_progressbar_timeout_id)
gajim.logger.init_vars()
check_paths.check_and_possibly_create_paths()
Interface()
m = MigrateCommand(on_result)
m.set_idlequeue(GlibIdleQueue())
m.start()
gtk.main()
else:
check_paths.check_and_possibly_create_paths()
Interface()
gtk.main()

View File

@ -18062,42 +18062,6 @@ Maybe I'll refactor later</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkProgressBar" id="progressbar">
<property name="visible">True</property>

View File

@ -27,10 +27,15 @@ import sre
import sys
import time
import signal
import logger
import i18n
from common import logger
from common import i18n
_ = i18n._
from helpers import from_one_line, decode_string
try:
PREFERRED_ENCODING = sys.getpreferredencoding()
except:
PREFERRED_ENCODING = 'utf-8'
from common.helpers import from_one_line, decode_string
signal.signal(signal.SIGINT, signal.SIG_DFL) # ^C exits the application
@ -48,6 +53,8 @@ else:
PATH_TO_LOGS_BASE_DIR = os.path.expanduser('~/.gajim/logs')
PATH_TO_DB = os.path.expanduser('~/.gajim/logs.db') # database is called logs.db
class Migration:
def __init__(self):
self.constants = logger.Constants()
@ -115,11 +122,11 @@ class Migration:
jid_type = self.constants.JID_NORMAL_TYPE
#Type of log
typ = _('normal')
s = _('Processing %s of type %s') % (jid.encode('utf-8'), typ)
s = _('Processing %s of type %s') % (jid, typ)
if self.queue:
self.queue.put(s)
self.queue.put(s.encode(PREFERRED_ENCODING))
else:
print s
print s.encode(PREFERRED_ENCODING)
JID_ID = None
f = open(path_to_text_file, 'r')
@ -243,12 +250,14 @@ Thank you''' % (os.path.dirname(PATH_TO_LOGS_BASE_DIR), PATH_TO_LOGS_BASE_DIR)
self.DONE = True
if __name__ == '__main__':
print 'IMPORTNANT: PLEASE READ http://trac.gajim.org/wiki/MigrateLogToDot9DB'
print 'Migration will start in 40 seconds unless you press Ctrl+C'
time.sleep(40) # give the user time to act
print
print 'Starting Logs Migration'
print '======================='
print 'Please do NOT run Gajim until this script is over'
# magic argumen 'dont_wait' tells us that script is run from Gajim
if len(sys.argv) < 2 or sys.argv[1] != 'dont_wait':
print 'IMPORTNANT: PLEASE READ http://trac.gajim.org/wiki/MigrateLogToDot9DB'
print 'Migration will start in 40 seconds unless you press Ctrl+C'
time.sleep(40) # give the user time to act
print
print 'Starting Logs Migration'
print '======================='
print 'Please do NOT run Gajim until this script is over'
m = Migration()
m.migrate()