Exemple #1
0
 def load_config(self, path='', backup=True):
     path = path or self.config_filepath
     config = tools.load_json(path, backup)
     if config:
         self.config = config or {}
         return config
     return config
Exemple #2
0
	def load(self):
		"""Loads the manifest.
		This function not only reads the manifest but also loads the specified provider and plugins.
		Once they are loaded, the initialize() function is called on each of them (if it exists).
		The provider must have an initialize function.
		"""
		# Load the manifest JSON using the loader in common.tools
		# It strips comments (which are invalid in strict json) before loading the data.
		self.data = load_json(self.path)
		# Get the provider name from the manifest and load the corresponding module
		provider_modname = 'providers.{provider}'.format(provider=self.data['provider'])
		log.debug('Loading provider `{modname}\''.format(modname=provider_modname))
		# Create a modules dict that contains the loaded provider and plugins
		self.modules = {'provider': __import__(provider_modname, fromlist=['providers']),
		                'plugins': [],
		                }
		# Run through all the plugins mentioned in the manifest and load them
		if 'plugins' in self.data:
			for plugin_name, plugin_data in self.data['plugins'].iteritems():
				modname = 'plugins.{plugin}'.format(plugin=plugin_name)
				log.debug('Loading plugin `{modname}\''.format(modname=modname))
				plugin = __import__(modname, fromlist=['plugins'])
				self.modules['plugins'].append(plugin)

		# Run the initialize function on the provider and plugins
		self.modules['provider'].initialize()
		for module in self.modules['plugins']:
			# Plugins are not required to have an initialize function
			init = getattr(module, 'initialize', None)
			if callable(init):
				init()
Exemple #3
0
 def load_credentials(self, path=''):
     path = path or self.config_filepath.replace('settings.json',
                                                 'credentials.json')
     config = tools.load_json(path, backup=False)
     for service, values in config.items() or {}:
         logger.info('Loading credentials for "{}" service'.format(service))
         for k, v in values.items():
             self.config['streamservices'][service][k] = v
     return config
Exemple #4
0
	def schema_validator(self, data, schema_path):
		"""This convenience function is passed around to all the validation functions
		so that they may run a json-schema validation by giving it the data and a path to the schema.

		Args:
			data (dict): Data to validate (normally the manifest data)
			schema_path (str): Path to the json-schema to use for validation
		"""
		import jsonschema
		schema = load_json(schema_path)
		try:
			jsonschema.validate(data, schema)
		except jsonschema.ValidationError as e:
			self.validation_error(e.message, e.path)
Exemple #5
0
 def import_database(self, path=''):
     database = tools.load_json(path)
     tools.merge_dict(self.database, database)
     tools.save_json(
         self.database,
         self.config_filepath.replace('settings.json', 'database.json'))
Exemple #6
0
 def load_database(self, path=''):
     path = path or self.config_filepath.replace('settings.json',
                                                 'database.json')
     self.database = tools.load_json(path) or {}
     return self.database