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.iteritems():
			if key.lower() == 'files':
				exceptions = self.file_task.execute(configuration['files'], destination_path)
				if exceptions is not None and len(exceptions) > 0:
					build_filename = 'SublimeProjectMaker_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(exception_iter.next()) + '\n'
					except StopIteration, e:
						pass
					f.write(message)
					f.close()

		return configuration
Пример #2
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.iteritems():
            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(exception_iter.next()) + '\n'
                    except StopIteration, e:
                        pass
                    f.write(message)
                    f.close()

        return configuration
Пример #3
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()
	def __init__(self):
		self.file_task = RemoteFileFetchTask()
		# Add tasks associated with key in JSON.
		self.tasks = dict({
			"files": self.file_task
		})
Пример #5
0
 def __init__(self):
     self.file_task = RemoteFileFetchTask()
     # Add tasks associated with key in JSON.
     self.tasks = dict({"files": self.file_task})