diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0a8c8cc..e9f1654 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,15 @@ + + + + + - + + @@ -41,30 +47,33 @@ + - + - + - + - + + - + + @@ -74,21 +83,56 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -96,8 +140,8 @@ - - + + @@ -105,26 +149,14 @@ - - - - - - - - - - - - - - + + - + @@ -133,7 +165,7 @@ - + @@ -145,8 +177,8 @@ - - + + @@ -157,30 +189,10 @@ - - + + - - - - - - - - - - - - - - - - - - - - @@ -213,12 +225,15 @@ @@ -349,6 +364,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -589,43 +596,108 @@ - + - - + + - - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branchmanager.py b/branchmanager.py index 867bed8..03c5c04 100644 --- a/branchmanager.py +++ b/branchmanager.py @@ -78,13 +78,20 @@ class Branch(window.Window): def do_merge_list(self): stdout = os.popen("git branch --merged").read() + proc = subprocess.Popen("git branch --merged", shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=3) self.text.insert(INSERT, "-----------------------------------\n") self.text.insert(INSERT, "Merged Branches\n") - self.text.insert(INSERT, stdout + "\n") + self.text.insert(INSERT, stdout.decode("utf-8") + "\n") self.text.insert(INSERT, "-----------------------------------\n") self.text.insert(INSERT, "Unmerged Branches\n") - stdout = os.popen("git branch --no-merged").read() - self.text.insert(INSERT, stdout + "\n") + proc = subprocess.Popen("git branch --no-merged", shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=3) + self.text.insert(INSERT, stdout.decode("utf-8") + "\n") self.text.see(END) def do_list(self): diff --git a/change.py b/change.py index 0b64382..4278da4 100644 --- a/change.py +++ b/change.py @@ -49,7 +49,7 @@ class Changes(window.Window): def discard_change(self): if self.current_index is not None: if self.discard_status[self.current_index]: - os.popen("git checkout -- {0}".format(self.change_files[self.current_index])) + os.popen("git reset {0}".format(self.change_files[self.current_index])) self.discard_status[self.current_index] = False self.discard['text'] = 'Add' else: diff --git a/git.py b/git.py index 23df201..63ec976 100644 --- a/git.py +++ b/git.py @@ -122,6 +122,8 @@ class Git(ssh.SSH): readme.close() cmd = "git add *" os.popen(cmd) + cmd = "git commit --message=\"Initial Commit.\"" + os.popen(cmd) # self.add_remote("origin") else: raise AttributeError("Set Local & Fix Project First.") @@ -179,7 +181,6 @@ class Git(ssh.SSH): self.remotes[name] = {"name": name, "url": "ssh://{0}@{1}:{2}/{3}.git".format(self.user, self.hostname, self.base_path[1], self.fix_name)} - self.if_get_remote = True return stdout else: @@ -215,9 +216,17 @@ 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), shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(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), shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=30) + return stdout.decode("utf-8") else: raise ValueError("Name Abnormal") else: @@ -231,7 +240,7 @@ class Git(ssh.SSH): if branch in self.branches_server: proc = subprocess.Popen(["git pull", "{0} {1}".format(name, branch)], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) - stdout, stderr = proc.comunicate(timeout=30) + stdout, stderr = proc.communicate(timeout=30) return stdout.decode("utf-8") else: return "Current Branch '{0}' Not Exist In Server.".format(branch) else: @@ -277,8 +286,11 @@ class Git(ssh.SSH): def commit_local(self, message): if self.if_set_local and self.if_fix_local and self.if_base_init: if self.base_path[0]: - stdout = os.popen("git commit --message=\"{0}\"".format(message)).read() - return stdout + proc = subprocess.Popen("git commit --message=\"{0}\"".format(message), shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=12) + return stdout.decode("utf-8") else: raise UnboundLocalError("Init Base First") else: @@ -286,8 +298,11 @@ class Git(ssh.SSH): def add(self): if self.if_set_local and self.if_fix_local and self.if_base_init: - stdout = os.popen("git add *").read() - return stdout + proc = subprocess.Popen("git add -A", shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=8) + return stdout.decode("utf-8") else: raise AttributeError("Set Local & Fix Local & Base Init First.") @@ -337,11 +352,26 @@ class Git(ssh.SSH): def status(self): if self.fix_name and self.if_fix_local and self.if_base_init: - stdout = os.popen("git status").read() - return stdout + proc = subprocess.Popen("git status", shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + stdout, stderr = proc.communicate(timeout=8) + return stdout.decode("utf-8") + else: raise AttributeError("Fix Project & Base Init & Fix Local First.") + def set_ignore(self): + if os.path.exists(os.path.join(self.local_path, self.fix_name, ".gitignore")): + pass + else: + proc = subprocess.Popen("touch .gitignore", shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE) + + stdout, stderr = proc.communicate(timeout=3) + + def list_branch(self): if self.if_get_branches: for project in self.projects.items(): diff --git a/gitignore.py b/gitignore.py new file mode 100644 index 0000000..764f42c --- /dev/null +++ b/gitignore.py @@ -0,0 +1,92 @@ +from tkinter import * +from tkinter.ttk import * +from tkinter.messagebox import * +import os +from keygen import * +import window +from info import Info +from main import default_pwd + + +class Gitignore(window.Window): + def __init__(self, master = None): + self.master = master + super().__init__(master) + master.title("Git Ignore Manager") + super().set_width(800) + super().set_position(350, 200) + + super().apply() + self.list = Listbox(self, width=18, height=30) + self.list.bind("<>", self.select_file) + self.add_btn = Button(self) + self.text = Text(self, width=75, height=35) + self.save_btn = Button(self) + self.pwd = default_pwd + + + gitign_file = open(".gitignore","r") + gitign_lines = gitign_file.readlines() + self.gitign_text = "" + if len(gitign_lines) == 0: + self.gitign_text = "# ----Git Ignore File----\n" + else: + for line in gitign_lines: + self.gitign_text += line + gitign_file.close() + + self.draw_widgets() + self.files = [] + self.set_list() + self.current_index = None + + def select_file(self, *args): + if len(self.files) > 0: + self.current_index = self.list.curselection()[0] + + def add_file(self): + if self.current_index is not None: + file_data = open(os.path.join(sys._MEIPASS, self.files[self.current_index]),"r") + for line in file_data.readlines(): + self.text.insert(INSERT, line) + file_data.close() + self.text.insert(INSERT, "\n# ----PART_END----\n\n\n") + self.text.see(END) + else: + showinfo(message="Select one .gitignore file first.") + + def set_list(self): + files = os.listdir(os.path.join(sys._MEIPASS)) + for file in files: + file_info = os.path.splitext(file) + if file_info[1] == ".gitignore": + self.files.append(file) + self.files.sort() + for file in self.files: + file_info = os.path.splitext(file) + self.list.insert(END, file_info[0]) + + + def do_save(self): + self.gitign_text = self.text.get(1.0, END) + gitign_file = open(".gitignore", "w") + gitign_file.write(self.gitign_text) + gitign_file.close() + showinfo(message="File Saved") + + + + def draw_widgets(self): + self.save_btn["text"] = "Save" + self.add_btn["text"] = "Add" + self.save_btn["command"] = self.do_save + self.add_btn["command"] = self.add_file + self.save_btn.grid(row=1, column=1, sticky=E) + self.add_btn.grid(row=1, column=0, sticky=E) + self.text.grid(row=0, column=1) + self.list.grid(row=0, column=0) + self.text.insert(INSERT, self.gitign_text) + +if __name__ == "__main__": + gitign = Gitignore(Tk()) + gitign.mainloop() \ No newline at end of file diff --git a/keygen.py b/keygen.py index 1618a40..63a09b1 100644 --- a/keygen.py +++ b/keygen.py @@ -28,8 +28,12 @@ class Key(ssh.SSH): ret_code = subprocess.Popen(["ssh-keygen", "-b 4096","-N ''", "-q", "-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") + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + try: + stdout, stderr = ret_code.communicate(input=b"\ny\n", timeout=8) + except subprocess.TimeoutExpired: + ret_code.kill() + stdout, stderr = ret_code.communicate() return stdout.decode("utf-8") def get_key(self): diff --git a/main.py b/main.py index e8cd229..cfcf855 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,10 @@ from info import * from change import * from sshtool import * from branchmanager import * +from gitignore import * import paramiko +default_pwd = os.getcwd() class Main(window.Window): def __init__(self, master=None): @@ -43,6 +45,7 @@ class Main(window.Window): self.commit = Button(self, width=12) self.save = Button(self, width=15) self.ssh_tools = Button(self, width=12) + self.gitignore = Button(self, width=12) self.info = None self.save_info = None @@ -386,6 +389,13 @@ class Main(window.Window): else: showinfo(message="Connect and Fix Local Project First") + def start_git_ignore(self): + if self.git is not None and self.git.if_fix_local: + self.git.set_ignore() + self.gitignore_interface = Gitignore(master=Tk()) + else: + showinfo(message="Connect and Fix Local Project First") + def draw_widget(self): self.hostname_label["text"] = "Hostname: " self.hostname_label.grid(row=0, column=0, sticky=W) @@ -440,6 +450,10 @@ class Main(window.Window): # self.list_remote["command"] = self.do_list_remote # self.list_remote.grid(row=4, column=1) + self.gitignore["text"] = "Git Ignore" + self.gitignore["command"] = self.start_git_ignore + self.gitignore.grid(row=4, column=1) + self.pull["text"] = "Pull" self.pull["command"] = self.do_pull self.pull.grid(row=3, column=0) @@ -452,9 +466,6 @@ class Main(window.Window): self.add["command"] = self.do_add self.add.grid(row=4, column=0) - self.commit["text"] = "Commit" - self.commit["command"] = self.do_commit - self.commit.grid(row=4, column=1) self.save["text"] = "Save Information" self.save["command"] = self.do_save diff --git a/ssh.py b/ssh.py index 61a122f..e0cd189 100644 --- a/ssh.py +++ b/ssh.py @@ -22,9 +22,7 @@ class SSH(object): self.ssh.close() def run(self, cmd): - print("CMD:", cmd) stdin, stdout, stderr = self.ssh.exec_command(cmd) - stdout = list(stdout) stderr = list(stderr) return stdout, stderr diff --git a/sshtool.py b/sshtool.py index 7b3b158..79998c6 100644 --- a/sshtool.py +++ b/sshtool.py @@ -35,9 +35,14 @@ class SSH_Tools(window.Window,Key): def do_check_key(self): 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") + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + try: + stdout, stderr = ret_code.communicate(input=b"\x03", timeout=8) + ret_code.send_signal(subprocess.CTRL_C_EVENT) + except subprocess.TimeoutExpired: + ret_code.kill() + stdout, stderr = ret_code.communicate() self.broad.insert(INSERT, "--------------------------\n") self.broad.insert(INSERT, "{0}\n".format(stdout.decode("utf-8"))) self.broad.see(END)