def create(self, to_create, recipient):
		if self.__job_exist(to_create) == False:
			initial_config = self.server.get_job_config(self.template)
			self.reconfiger = JobReconfiger(initial_config)
			new_configuration = self.reconfiger.reconfig(to_create, recipient)
			self.server.create_job(to_create, new_configuration)
		else:
			print 'Job ' + to_create + ' already exists...'
class Jenkins(jenkins.Jenkins):
	def __init__(self, config=ConfigurationsLoader().get_configurations()):
		self.url = config.url
		self.login = config.login
		self.password = config.password
		self.template = config.template

	def connect(self):
		server = jenkins.Jenkins(self.url, username=self.login, password=self.password)
		self.server = server
		return server

	def delete(self, to_delete):
		if to_delete in self.__get_job_names():
			self.server.delete_job(to_delete)

	def create(self, to_create, recipient):
		if self.__job_exist(to_create) == False:
			initial_config = self.server.get_job_config(self.template)
			self.reconfiger = JobReconfiger(initial_config)
			new_configuration = self.reconfiger.reconfig(to_create, recipient)
			self.server.create_job(to_create, new_configuration)
		else:
			print 'Job ' + to_create + ' already exists...'


	def __get_job_names(self):
		all_existing_jobs = []
		for i in self.server.get_all_jobs():
			all_existing_jobs.append(i['fullname'])
		return all_existing_jobs

	def __job_exist(self, job_name):
		if job_name in self.__get_job_names():
			return True
		else:
			return False

	def build(self, job_to_build):
		if hasattr(self, 'reconfiger'):
		    self.server.build_job(job_to_build, None, self.reconfiger.token)
		else:
			print 'Job you try to build has not been created...'