diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f044b7f..b858297 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + - + @@ -36,20 +39,22 @@ - + + - + + - + - + @@ -69,21 +74,21 @@ - - + + - + - + - - + + @@ -91,7 +96,7 @@ - + @@ -103,7 +108,7 @@ - + @@ -112,14 +117,14 @@ - + - - + + - + @@ -128,7 +133,7 @@ - + @@ -140,7 +145,7 @@ - + @@ -152,7 +157,7 @@ - + @@ -165,7 +170,7 @@ - + @@ -206,7 +211,6 @@ @@ -460,7 +465,14 @@ \ No newline at end of file diff --git a/git.py b/git.py index 894737f..34e6f30 100644 --- a/git.py +++ b/git.py @@ -1,6 +1,7 @@ import re import os import ssh +import subprocess class Git(ssh.SSH): @@ -214,9 +215,15 @@ class Git(ssh.SSH): self.get_branch_server() if name in self.remotes.keys(): if branch not in self.branches_server: - return os.popen("git push -u {0} {1}".format(name, branch)).read() + proc = subprocess.Popen("git push -u {0} {1}".format(name, branch), stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.comunicate(timeout=30) + return stdout.decode("utf-8") else: - return os.popen("git push {0} {1}".format(name, branch)).read() + proc = subprocess.Popen("git push {0} {1}".format(name, branch), stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.comunicate(timeout=30) + return stdout.decode("utf-8") else: raise ValueError("Name Abnormal") else: @@ -228,7 +235,10 @@ class Git(ssh.SSH): self.get_branch_server() if name in self.remotes.keys(): if branch in self.branches_server: - return os.popen("git pull {0} {1}".format(name, branch)).read() + proc = subprocess.Popen(["git pull", "{0} {1}".format(name, branch)], shell=True, stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.comunicate(timeout=30) + return stdout.decode("utf-8") else: return "Current Branch '{0}' Not Exist In Server.".format(branch) else: raise ValueError("Remote Error") diff --git a/main.py b/main.py index 0fe3c72..2d543fa 100644 --- a/main.py +++ b/main.py @@ -80,6 +80,19 @@ class Main(window.Window): showinfo(message="Authentication failed.") return + except paramiko.ssh_exception.BadHostKeyException: + self.connection_status["text"] = "Failed" + showinfo(message="Bad HostKey.") + return + except paramiko.ssh_exception.SSHException: + self.connection_status["text"] = "Failed" + showinfo(message="There was any other error connecting or establishing an SSH session.") + return + except paramiko.socket.error: + self.connection_status["text"] = "Failed" + showinfo(message="A socket error occurred while connecting.") + return + self.connection_status["text"] = "Succeed" try: diff --git a/ssh.py b/ssh.py index 3bf1f4f..61a122f 100644 --- a/ssh.py +++ b/ssh.py @@ -2,7 +2,7 @@ import paramiko class SSH(object): - ssh = paramiko.SSHClient(); + ssh = paramiko.SSHClient() def __init__(self, hostname, path, user, passwd=None, ssh_key=False): self.hostname = hostname @@ -38,10 +38,11 @@ class SSH(object): def connect(self, timeout): if self.ssh_key: - self.ssh.connect(hostname=self.hostname, port=22, username=self.user, pkey=self.key, timeout=timeout) + self.ssh.connect(hostname=self.hostname, port=22, username=self.user, pkey=self.key, + timeout=timeout, look_for_keys=True) else: self.ssh.connect(hostname=self.hostname, port=22, username=self.user, password=self.passwd, - timeout=timeout) + timeout=timeout, look_for_keys = True) def __del__(self): self.close()