From 1eedbdce2b8de0435089e2c93fa2386c1548af5d Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 14 Mar 2019 01:06:15 +0800 Subject: [PATCH] Windows Fixed. --- .idea/workspace.xml | 218 ++++++++++++++------------------------------ change.py | 67 +++++++------- git.py | 2 +- keygen.py | 16 ++-- main.py | 16 ++-- sshtool.py | 4 +- 6 files changed, 123 insertions(+), 200 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f044b7f..daf9ac4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,12 @@ + + + + + - - - + + + - - + - + - + - - + + @@ -495,9 +446,6 @@ - - - + + + - - + + + + + - + - - + + - - + + - - - - - - - - - - - - - - - - - - + @@ -565,27 +501,24 @@ - + - - + + - - - - - + + - - + + @@ -594,33 +527,20 @@ - - + + - - + - - - - - - - - - - - - - + + - diff --git a/change.py b/change.py index 1c12985..0b64382 100644 --- a/change.py +++ b/change.py @@ -25,6 +25,7 @@ class Changes(window.Window): self.list.bind("<>",self.show_change) self.current_index = None self.broad = broad + self.list_bak = [] def draw_widgets(self): self.list.grid(row=0, column=0) @@ -67,45 +68,47 @@ class Changes(window.Window): def show_change(self, *args): - self.current_index = self.list.curselection()[0] - if self.discard_status[self.current_index]: - self.discard['text'] = 'Discard' - else: - self.discard['text'] = 'Add' + if len(self.list_bak) > 0: + self.current_index = self.list.curselection()[0] + if self.discard_status[self.current_index]: + self.discard['text'] = 'Discard' + else: + self.discard['text'] = 'Add' - stdout = os.popen("git diff --cached {0}".format(self.change_files[self.current_index])).read() - self.text.delete('1.0', END) - self.text.insert(INSERT,self.change_files[self.current_index]+"\n","TITLE") - self.text.insert(INSERT, "-----------------------------------------------\n","TITLE") - if_data = False - lines = [] - str = "" - for char in stdout: - if char is not '\n': - str += char - else: - lines.append(str) - str = "" - for line in lines: - if line[0] is '@': - if_data = True - if line[0] is '+' and if_data: - self.text.insert(INSERT,line+"\n","ADD") - elif line[0] is '-' and if_data: - self.text.insert(INSERT, line + "\n", "DEL") - elif line[0] is '@': - self.text.insert(INSERT, line + "\n", "INFO") - else: - if if_data: - self.text.insert(INSERT, line + "\n","DATA") + stdout = os.popen("git diff --cached {0}".format(self.change_files[self.current_index])).read() + self.text.delete('1.0', END) + self.text.insert(INSERT,self.change_files[self.current_index]+"\n","TITLE") + self.text.insert(INSERT, "-----------------------------------------------\n","TITLE") + if_data = False + lines = [] + str = "" + for char in stdout: + if char is not '\n': + str += char else: - self.text.insert(INSERT, line + "\n","TITLE") + lines.append(str) + str = "" + for line in lines: + if line[0] is '@': + if_data = True + if line[0] is '+' and if_data: + self.text.insert(INSERT,line+"\n","ADD") + elif line[0] is '-' and if_data: + self.text.insert(INSERT, line + "\n", "DEL") + elif line[0] is '@': + self.text.insert(INSERT, line + "\n", "INFO") + else: + if if_data: + self.text.insert(INSERT, line + "\n","DATA") + else: + self.text.insert(INSERT, line + "\n","TITLE") - self.text.see(END) + self.text.see(END) def set_list(self, list): for item in list: self.list.insert(END, item) + self.list_bak =list ret_code = re.compile(r"[:]") tmp_ret = ret_code.split(item) self.change_files.append(tmp_ret[1]) diff --git a/git.py b/git.py index 894737f..22557a5 100644 --- a/git.py +++ b/git.py @@ -228,7 +228,7 @@ 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() + return os.popen("git pull --allow-unrelated-histories {0} {1}".format(name, branch)).read() else: return "Current Branch '{0}' Not Exist In Server.".format(branch) else: raise ValueError("Remote Error") diff --git a/keygen.py b/keygen.py index 47b03c4..1618a40 100644 --- a/keygen.py +++ b/keygen.py @@ -10,8 +10,8 @@ class Key(ssh.SSH): self.connect(5) self.pub_key = None self.keygen = None - self.local_path = "/Users/huyibing/" - self.public_key_path = self.local_path+".ssh/id_rsa.pub" + self.local_path = os.path.expanduser('~') + self.public_key_path = os.path.join(self.local_path, '.ssh', 'id_rsa.pub') self.public_key = None def add_key(self): @@ -20,14 +20,14 @@ class Key(ssh.SSH): @staticmethod def create_key(): - if os.path.exists(os.path.join(os.environ["HOME"],".ssh","id_rsa.pub")): - os.remove(os.path.join(os.environ["HOME"],".ssh","id_rsa.pub")) - os.remove(os.path.join(os.environ["HOME"], ".ssh", "id_rsa")) + if os.path.exists(os.path.join(os.path.expanduser('~'),".ssh","id_rsa.pub")): + os.remove(os.path.join(os.path.expanduser('~'),".ssh","id_rsa.pub")) + os.remove(os.path.join(os.path.expanduser('~'), ".ssh", "id_rsa")) - print("Key Path:","{0}".format(os.path.join(os.environ["HOME"],".ssh","id_rsa"))) + print("Key Path:","{0}".format(os.path.join(os.path.expanduser('~'),".ssh","id_rsa"))) ret_code = subprocess.Popen(["ssh-keygen", "-b 4096","-N ''", "-q", - "-f {0}".format(os.path.join(os.environ["HOME"],".ssh","id_rsa")), - ], shell=True, + "-f {0}".format(os.path.join(os.path.expanduser('~'),".ssh","id_rsa")), + ], shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE) stdout, stderr = ret_code.communicate(input=b"\ny\n") return stdout.decode("utf-8") diff --git a/main.py b/main.py index 0fe3c72..843c21a 100644 --- a/main.py +++ b/main.py @@ -18,14 +18,14 @@ class Main(window.Window): master.title("GitEasy") self.style.configure("M.MButton",) self.connect = None - self.hostname_label = Label(self, width=8) + self.hostname_label = Label(self, width=10) self.user_name_label = Label(self, width=12) self.password_label = Label(self, width=8) self.connection_status = Label(self, width=8) self.hostname = Entry(self, width=15) self.user_name = Entry(self, width=15) self.password = Entry(self, width=15, show="*") - self.list_projects = Button(self, width=12) + self.list_projects = Button(self, width=13) self.fix_project = Button(self, width=12) self.create_project = Button(self, width=12) self.broad = Text(self, width=85, height=30) @@ -35,13 +35,13 @@ class Main(window.Window): self.set_local = Button(self, width=12) self.add_remote = Button(self, width=12) self.list_remote = Button(self, width=12) - self.clone_project = Button(self, width=12) + self.clone_project = Button(self, width=13) self.project_status = Button(self, width=12) self.pull = Button(self, width=12) self.push = Button(self, width=12) self.add = Button(self, width=12) self.commit = Button(self, width=12) - self.save = Button(self, width=12) + self.save = Button(self, width=15) self.ssh_tools = Button(self, width=12) self.info = None self.save_info = None @@ -49,11 +49,11 @@ class Main(window.Window): self.git = None self.draw_widget() - if os.path.exists(os.path.join(os.environ['HOME'],"save_data.json")): + if os.path.exists(os.path.join(os.path.expanduser('~'),"save_data.json")): self.get_save_data() def get_save_data(self): - save_file = open(os.path.join(os.environ['HOME'],"save_data.json"),"r") + save_file = open(os.path.join(os.path.expanduser('~'),"save_data.json"),"r") json_data = save_file.readline() save_infos = json.loads(json_data) self.save_info = save_infos[0] @@ -323,12 +323,12 @@ class Main(window.Window): save_info["fix_project"] = self.git.fix_name save_infos.append(save_info) json_info = json.dumps(save_infos) - save_file = open(os.path.join(os.environ['HOME'],"save_data.json"),"w") + save_file = open(os.path.join(os.path.expanduser('~'),"save_data.json"),"w") save_file.write(json_info) save_file.close() self.broad.insert(INSERT, "--------------------------\n") self.broad.insert(INSERT, "Data Information Saved\n") - self.broad.insert(INSERT, "Path: "+os.path.join(os.environ['HOME'],"save_data.json")) + self.broad.insert(INSERT, "Path: "+os.path.join(os.path.expanduser('~'), "save_data.json")) self.broad.see(END) else: raise AttributeError("Please Connect And Set Local Path First.") diff --git a/sshtool.py b/sshtool.py index 0bc1e20..7b3b158 100644 --- a/sshtool.py +++ b/sshtool.py @@ -33,8 +33,8 @@ class SSH_Tools(window.Window,Key): self.broad.see(END) def do_check_key(self): - ret_code = subprocess.Popen("ssh -T {0}@{1}".format(self.user, self.hostname), - shell=True, + ret_code = subprocess.Popen("ssh -o StrictHostKeyChecking=no -T {0}@{1}".format(self.user, self.hostname), + shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE ) stdout, stderr = ret_code.communicate(input=b"\x03")