Beispiel #1
0
    def __init__(self):
        #Create a manager for different instances.
        self.manager = OneServerManager()

        # Load the configurations.
        self.config = ConfigManager()
        self.config.loadConfigFile()
        self.manager.config = self.config

        # Start logging.
        self.log = logging.getLogger('oneserver')
        logHandler = logging.StreamHandler()
        logHandler.setFormatter(
            logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
        self.log.addHandler(logHandler)
        self.log.setLevel(logging.DEBUG)
        # TODO: Add file handler for writing to a file.
        self.manager.log = self.log

        self.log.info('Preparing the OneServer media server to start...')

        # Start plugin loader.
        self.pluginManager = PluginManager()
        self.manager.pluginManager = self.pluginManager
        self.pluginManager.loadEnablePluginList(self.config)
        self.pluginManager.loadPlugins()
        self.pluginManager.enableAdminPlugins()
        self.pluginManager.enableStoragePlugins()
        self.pluginManager.enableUtilityPlugins()

        self.storagePlugins = self.pluginManager.getStoragePlugins()
        self.adminPlugins = self.pluginManager.getAdminPlugins()
        self.utilityPlugins = self.pluginManager.getUtilityPlugins()

        # Start scheduler.
        self.log.debug('Starting task scheduler...')

        self.scheduler = TaskScheduler()
        self.manager.scheduler = self.scheduler
        self.scheduler.startScheduler()

        self.log.debug('Task scheduler started.')

        # Start VFS
        self.log.debug('Starting virtual file system...')

        #TODO: Load loaded Storage plugins into vfs
        self.vfs = VirtualFileSystem()
        plugins = self.storagePlugins

        for plugin in plugins:
            if plugin != None:
                self.log.debug("Loading Storage Plugin : " + plugin)
            self.vfs.loadDataSource(plugin)

        self.log.debug('Virtual file system started.')

        # Start DLNA
        self.log.debug('Preparing DLNA service...')

        self.dlna = DLNAService(self.config)
        self.manager.dlna = self.dlna.dlna

        self.log.debug('DLNA service ready.')

        #Temporary Content Store
        self.log.debug('Creating temporary content store...')

        tcsRoot = tcs.populate([
            "samples/sample.mp4", "samples/sample.mp3", "samples/movie.mp4",
            "samples/sample.jpg"
        ])
        self.manager.rootEntry.addChild(tcsRoot)
        tcsRoot.parent = self.manager.rootEntry

        self.log.debug('Temporary content store ready.')

        # Set the singleton instance.
        OneServer.instance = self
Beispiel #2
0
class TestVirtualFileSystem(unittest.TestCase):
	
	##
	# Basic setup that happens before every test.
	def setUp(self):
		self.vfs = VirtualFileSystem()
		self.plugin = testPlugin()
		self.vfs.loadDataSource(self.plugin)
	
	##
	# Tests __init__
	def test_Init(self):
		#Try the normal constructor
		vfs = VirtualFileSystem()
		
	##
	# Tests checkPath
	def test_checkPath(self):
		with self.assertRaises(ValueError):
			self.vfs.checkPath(None)
		with self.assertRaises(ValueError):
			self.vfs.checkPath("")
		with self.assertRaises(ValueError):
			self.vfs.checkPath("NotAPath")
		self.assertEquals(VirtualFileSystem.FILE, self.vfs.checkPath("/path/to/file"))
		self.assertEquals(VirtualFileSystem.DIR , self.vfs.checkPath("d/path/to/directory"))
			
	##
	# Tests get
	def test_get(self):
		#Check special case outside of plugins
		with self.assertRaises(DirectoryError):
			self.vfs.get("/")
			
		self.vfs.get("/TestPlugin/file1")
		self.assertEquals(self.plugin.getPaths["/TestPlugin/file1"], 1)
		
		with self.assertRaises(EntryNotFoundError):
			self.vfs.get("/TestPlugin/NotHere")
			
		entry = self.vfs.get("/TestPlugin/file1")
		self.assertEquals(self.plugin.files["file1"], entry)
		
	##
	# Tests list
	def test_list(self):
		#Only VFS specific case is listing /
		dirs = self.vfs.list("/")
		self.assertEquals(1, len(dirs))
		self.assertEquals("d/TestPlugin", dirs[0])
		
		#Check it calls the plugin's list
		self.vfs.list("/TestPlugin/dir1")
		self.assertEquals(1, self.plugin.listPaths["/TestPlugin/dir1"])
		
	##
	# Tests put
	def test_put(self):
		with self.assertRaises(ValueError):
			self.vfs.put("ASDASDAS", "NotLoadedPlugin")
			
		self.vfs.put("ASDAS", "TestPlugin")
		self.assertEquals("ASDAS", self.plugin.putItem)
		
	##
	# Tests search
	def test_search(self):
		with self.assertRaises(ValueError):
			self.vfs.search(None)
		with self.assertRaises(ValueError):
			self.vfs.search({})
		
		results = self.vfs.search({"genre": "testData"})
		self.assertEquals(1, len(results))
		self.assertEquals("FOUNDIT", results[0])
	
	##
	# Tests Loading and unloading of data sources
	def test_loadUnload(self):
		#Test unloading our default plugin
		self.vfs.unloadDataSource("TestPlugin")
		self.assertEquals(0, len(self.vfs.dataSources))
		#Test loading a random object
		with self.assertRaises(ValueError):
			self.vfs.loadDataSource("I'm not a plugin!")
		#Test loading our old plugin
		self.vfs.loadDataSource(self.plugin)
		self.assertEquals(1, len(self.vfs.dataSources))
		self.assertEquals(self.plugin, self.vfs.dataSources["TestPlugin"])
		#Load one more plugin
		p = testPlugin()
		p.name = "TotallyDifferentPlugin"
		p.tree = Entry("/"+p.name, "object.container.storageFolder", OneServerManager().rootEntry, [], p.name, "", -1, None)
		self.vfs.loadDataSource(p)
		self.assertEquals(2, len(self.vfs.dataSources))
		self.assertEquals(p, self.vfs.dataSources["TotallyDifferentPlugin"])
Beispiel #3
0
	def setUp(self):
		self.vfs = VirtualFileSystem()
		self.plugin = testPlugin()
		self.vfs.loadDataSource(self.plugin)
Beispiel #4
0
	def test_Init(self):
		#Try the normal constructor
		vfs = VirtualFileSystem()
Beispiel #5
0
	def __init__(self):
		#Create a manager for different instances.
		self.manager = OneServerManager()
		
		# Load the configurations.
		self.config = ConfigManager()
		self.config.loadConfigFile()
		self.manager.config = self.config

		# Start logging.
		self.log = logging.getLogger('oneserver')
		logHandler = logging.StreamHandler()
		logHandler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
		self.log.addHandler(logHandler)
		self.log.setLevel(logging.DEBUG)
		# TODO: Add file handler for writing to a file.
		self.manager.log = self.log

		self.log.info('Preparing the OneServer media server to start...')
		
		# Start plugin loader.
		self.pluginManager = PluginManager()
		self.manager.pluginManager = self.pluginManager
		self.pluginManager.loadEnablePluginList(self.config)
		self.pluginManager.loadPlugins()
		self.pluginManager.enableAdminPlugins()
		self.pluginManager.enableStoragePlugins()
		self.pluginManager.enableUtilityPlugins()

		self.storagePlugins = self.pluginManager.getStoragePlugins()
		self.adminPlugins = self.pluginManager.getAdminPlugins()
		self.utilityPlugins = self.pluginManager.getUtilityPlugins()
		
		# Start scheduler.
		self.log.debug('Starting task scheduler...')

		self.scheduler = TaskScheduler()
		self.manager.scheduler = self.scheduler
		self.scheduler.startScheduler()

		self.log.debug('Task scheduler started.')
		
		# Start VFS
		self.log.debug('Starting virtual file system...')

		#TODO: Load loaded Storage plugins into vfs
		self.vfs = VirtualFileSystem()
		plugins = self.storagePlugins
		
		for plugin in plugins:
			if plugin != None:
				self.log.debug("Loading Storage Plugin : " + plugin)
			self.vfs.loadDataSource(plugin)

		self.log.debug('Virtual file system started.')
		
		# Start DLNA
		self.log.debug('Preparing DLNA service...')

		self.dlna = DLNAService(self.config)
		self.manager.dlna = self.dlna.dlna

		self.log.debug('DLNA service ready.')
		
		#Temporary Content Store
		self.log.debug('Creating temporary content store...')

		tcsRoot = tcs.populate(["samples/sample.mp4","samples/sample.mp3", "samples/movie.mp4", "samples/sample.jpg"])
		self.manager.rootEntry.addChild(tcsRoot)
		tcsRoot.parent = self.manager.rootEntry

		self.log.debug('Temporary content store ready.')

		# Set the singleton instance.
		OneServer.instance = self