Beispiel #1
0
	def _synchronize(self, on_load=True, autoclose=False):
		""" Synchronize data.

		Attr:
			on_load: if true only read data.
			autoclose: close progress dialog after sync (if no errors)
		"""
		use_dropbox = (self._appconfig.get('sync', 'use_dropbox') and
				dbsync.is_available())
		if not use_dropbox:
			last_sync_file = self._appconfig.get('files', 'last_sync_file')
			if not last_sync_file:
				dlg = wx.FileDialog(self.wnd,
						_("Please select sync file."),
						defaultDir=self._appconfig.get('files', 'last_dir', ''),
						defaultFile=self._appconfig.get('files', 'last_file',
								'GTD_SYNC.zip'),
						style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
				if dlg.ShowModal() == wx.ID_OK:
					last_sync_file = dlg.GetPath()
				dlg.Destroy()
				if last_sync_file:
					self._appconfig.set('files', 'last_sync_file', last_sync_file)
			if not last_sync_file:
				return
		dlg = DlgSyncProggress(self.wnd)
		dlg.run()
		try:
			if use_dropbox:
				dbsync.sync(load_only=on_load)
			else:
				sync.sync(last_sync_file, load_only=on_load)
		except sync.SyncLockedError:
			msgbox = wx.MessageDialog(dlg.wnd, _("Sync file is locked."),
					_("wxGTD"), wx.OK | wx.ICON_HAND)
			msgbox.ShowModal()
			msgbox.Destroy()
			dlg.update(100, _("Sync file is locked."))
			autoclose = False
		except sync.OtherSyncError as err:
			_LOG.exception('FrameMain._on_menu_file_sync error: %r',
					str(err))
			msgdlg = wx.lib.dialogs.ScrolledMessageDialog(self.wnd,
					str(err), _("Synchronisation error"))
			msgdlg.ShowModal()
			msgdlg.Destroy()
			dlg.update(100, _("Error: ") + str(err))
			autoclose = False
		dlg.mark_finished(2 if autoclose else -1)
Beispiel #2
0
def _sync(config, load_only):
	last_sync_file = config.get('files', 'last_sync_file')
	if last_sync_file:
		from wxgtd.model import sync
		sync.sync(last_sync_file, load_only, notify_cb=_log_sync_cb)