Esempio n. 1
0
class ConfigurationReader:
	""" Reads JSON file configuration and executes associated tasks. """

	def __init__(self):
		self.file_task = RemoteFileFetchTask()
		# Add tasks associated with key in JSON.
		self.tasks = dict({
			"files": self.file_task
		})

	def load_config(self, filepath):
		f = open(filepath)
		configuration = json.loads(f.read())
		f.close()
		return configuration

	def read(self, filepath, destination_path):
		configuration = self.load_config(filepath)
		# Iterate through task list and run associated task.
		for key, value in self.tasks.items():
			if key.lower() == 'files':
				exceptions = self.file_task.execute(configuration['files'], destination_path)
				if exceptions is not None and len(exceptions) > 0:
					build_filename = 'STProjectMaker_build.log'
					message = 'The following problems occured from FileTask:\n'
					exception_iter = iter(exceptions)
					f = open(os.path.join(destination_path, build_filename), "w")
					try:
						message += str(next(exception_iter)) + '\n'
					except StopIteration as e:
						pass
					f.write(message)
					f.close()

		return configuration
Esempio n. 2
0
 def setUp(self):
     """ Python <2.7 psuedo setUpBeforeClass """
     if self.__class__.configuration is None:
         f = open('config_test.json')
         self.__class__.configuration = json.loads(f.read())
         f.close()
     if self.__class__.task is None:
         self.__class__.task = RemoteFileFetchTask()
Esempio n. 3
0
	def __init__(self):
		self.file_task = RemoteFileFetchTask()
		# Add tasks associated with key in JSON.
		self.tasks = dict({
			"files": self.file_task
		})