Exemplo n.º 1
0
	def OnCheck(self, event):
		# close eventually existing previous instance
		self.list.ClearInstance()
		self.SetStatusBarText()

		try:
			# create trees
			fstree = FilesystemTree(self.rootDir, self.preferences.includes, \
				[ os.path.sep + self.metaName ] + self.preferences.excludes)
			fstree.open()
			dbtree = DatabaseTree(self.dbFile, self.sigFile)
			dbtree.open()
			memtree = MemoryTree()
			memtree.open()
		except MyException as e:
			e.showDialog('Checking ' + self.rootDir)
			return

		try:
			# create progress dialog
			progressDialog = FileProcessingProgressDialog(self, 'Checking ' + self.rootDir)
			progressDialog.Show()
			stats = fstree.getNodeStatistics()
			progressDialog.Init(stats.getNodeCount(), stats.getNodeSize())

			# execute task
			fstree.registerHandlers(progressDialog.SignalNewFile, \
				progressDialog.SignalBytesDone)
			fstree.diff(dbtree, memtree)
			memtree.commit()
			fstree.unRegisterHandlers()
		except UserCancelledException:
			progressDialog.SignalFinished()
			return
		except MyException as e:
			progressDialog.Destroy()
			e.showDialog('Checking ' + self.rootDir)
			return

		# signal that we have returned from calculation, either
		# after it is done or after progressDialog signalled that the
		# user stopped the calcuation using the cancel button
		progressDialog.SignalFinished()

		self.list.SetInstance(Instance(self.preferences, memtree, dbtree, fstree))
		self.list.readonly = False

		self.SetStatusBarText('Checked ' + str(stats))
Exemplo n.º 2
0
	def Import(self):
		# do not care about previous content: reset meta directory and database files
		if os.path.exists(self.metaDir):
			if os.path.exists(self.dbFile):
				os.remove(self.dbFile)
			if os.path.exists(self.sigFile):
				os.remove(self.sigFile)
			if os.path.exists(self.preferencesFile):
				os.remove(self.preferencesFile)
		else:
			os.mkdir(self.metaDir)
		# if on windows platform, hide directory
		if platform.system() == 'Windows':
			os.system('attrib +h "' + self.metaDir + '"')
		self.preferences = Preferences()
		preferencesDialog = PreferencesDialog(self, self.preferences)
		preferencesDialog.ShowModal()
		self.preferences.save(self.preferencesFile)

		try:
			# create trees
			fstree = FilesystemTree(self.rootDir, self.preferences.includes, \
				[ os.path.sep + self.metaName ] + self.preferences.excludes)
			fstree.open()
			dbtree = DatabaseTree(self.dbFile, self.sigFile)
			dbtree.open()
		except MyException as e:
			e.showDialog('Importing ' + self.rootDir)
			return

		try:
			# create progress dialog
			progressDialog = FileProcessingProgressDialog(self, 'Importing ' + self.rootDir)
			progressDialog.Show()
			stats = fstree.getNodeStatistics()
			progressDialog.Init(stats.getNodeCount(), stats.getNodeSize())

			# execute task
			fstree.registerHandlers(progressDialog.SignalNewFile, \
				progressDialog.SignalBytesDone)
			fstree.copyTo(dbtree)
			dbtree.commit()
			fstree.unRegisterHandlers()
		except UserCancelledException:
			progressDialog.SignalFinished()
			return
		except MyException as e:
			progressDialog.Destroy()
			e.showDialog('Importing ' + self.rootDir)
			return

		# signal that we have returned from calculation, either
		# after it is done or after progressDialog signalled that the
		# user stopped the calculation using the cancel button
		progressDialog.SignalFinished()

		self.list.SetInstance(Instance(self.preferences, dbtree, None, None))
		fstree.close()
		self.list.readonly = True

		self.SetStatusBarText('Imported ' + str(stats))