示例#1
0
	def push(self, username=None, password=None):
		if not self.repo_is_defined:
			error("No Git repository found for the current directory.")
			self.repo.git.push()
			return
		try:
			pexpect.spawnu('git push')
		except:
			try:
				self.repo.git.push()
				print("Push was successful")
			except Exception as e:
				error("Git push failed!")
				print(type(e))
			return
		try:
			g.logfile_read = sys.stdout
			if not username: username = ''
			if not password: password = ''
			while True:
				i = g.expect([u'Username for .*', u'Password for .*', pexpect.EOF])
				if(i == 0):
					g.send(username+'\n')
				elif(i == 1):
					# Python 2
					# g.send(codecs.decode(password, 'base64')+'\n')
					# End Python 2
	       			# Python 3
					g.send(str(codecs.decode(password.encode(), 'base64'), 'utf-8')+'\n')
					# End Python 3
				else:
					break
		except:
			print("Notice: Auto-credentials currently not operational")
		'''
示例#2
0
	def push(self, username=None, password=None):
		username = self.conf_parser.get('main', 'git_username')
		password = self.conf_parser.get('main', 'git_password')
		if not self.repo_is_defined:
			if not (self.repo_exists()):
				error("No Git repository found for the current directory.")
				return
		try:
			g = pexpect.spawnu('git push')
		except:
			try:
				self.repo.git.push()
				print("Push was successful")
			except Exception as e:
				error("Git push failed!")
				print(type(e))
			return
		try:
			g.logfile_read = sys.stdout
			while True:
				i = g.expect([u'Username for .*', u'Password for .*', pexpect.EOF])
				if(i == 0):
					g.send(username+'\n')
				elif(i == 1):
					# Python 2
					# g.send(codecs.decode(password, 'base64')+'\n')
					# End Python 2
					# Python 3
					g.send(str(codecs.decode(password.encode(), 'base64'), 'utf-8')+'\n')
					# End Python 3
				else:
					break
		except Exception as e:
			print("Notice: Auto-credentials currently not operational")
		'''
示例#3
0
	def repo_exists(self, repo_directory=os.getcwd()):
		while repo_directory and repo_directory != "" and not (os.path.isdir(repo_directory + "/.git")):
			repo_directory = repo_directory.split(os.sep)[:-1]
			repo_directory = (os.sep).join(repo_directory)
		if not repo_directory or repo_directory == "":
			error("No Git repository found for the current directory.")
			return False
		else:
			self.repo_directory = repo_directory
			return True
示例#4
0
	def repo_exists(self, repo_directory=os.getcwd()):
		while repo_directory and repo_directory != "" and not (os.path.isdir(repo_directory + os.sep+".git")):
			repo_directory = repo_directory.split(os.sep)[:-1]
			repo_directory = (os.sep).join(repo_directory)
		if not repo_directory or repo_directory == "":
			error("No Git repository found for the current directory.")
			return False
		else:
			self.repo_directory = repo_directory
			self.initialize_repo()
			return True
示例#5
0
	def commit(self, message):
		if not self.repo_is_defined:
			error("No Git repository found for the current directory.")
			return
		message.rstrip(' ')
		self.repo.index.commit("Translations updated for " + message)
示例#6
0
	def add_file(self, file_name):
		if not self.repo_is_defined:
			error("No Git repository found for the current directory.")
			return
		self.repo.git.add(file_name)