示例#1
0
	def LoadAnnouncementFilesIntoTheDatabase():
		announcements = []

		announcementsPath = Settings.GetAnnouncementWatchPath()
		entries = os.listdir( announcementsPath )
		files = [];
		for entry in entries:
			# We can't do anything with undecodable filenames because we can't even join the paths (to move the file to the invalid directory) without getting an UnicodeDecodeError...
			# "Undecodable filenames will still be returned as string objects."
			# http://stackoverflow.com/questions/3409381/how-to-handle-undecodable-filenames-in-python
			if not isinstance( entry, unicode ):
				continue
			
			filePath = os.path.join( announcementsPath, entry )
			if os.path.isfile( filePath ):
				modificationTime = os.path.getmtime( filePath )
				item = modificationTime, filePath # Add as a tuple.
				files.append( item )

		files.sort()
		for item in files:
			path = item[ 1 ] # First element is the modification time, second is the path.
			releaseInfo = AnnouncementWatcher.ProcessAnnouncementFile( path )
			if releaseInfo is not None:
				announcements.append( releaseInfo ) 

		return announcements
示例#2
0
	def __init__( self ):
		MyGlobals.Logger.info( "Starting announcement directory watcher." )

		# "When you call observer.schedule() path should be str properly encoded to what the file system is, not unicode"
		# https://github.com/gorakhargosh/watchdog/issues/157#issuecomment-16584053
		path = Settings.GetAnnouncementWatchPath().encode( sys.getfilesystemencoding() )

		eventHandler = MyWatchdogEventHandler()
		self.Observer = Observer()
		self.Observer.schedule( eventHandler, path, recursive = False )
		self.Observer.start()