Created
January 24, 2016 21:37
-
-
Save Fi5t/271569dd3d995d20631d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: UTF-8 -*- | |
__author__ = 'Fi5t' | |
from Tkinter import * | |
import subprocess | |
import io | |
import sys | |
import ConfigParser | |
def executeCmd(cmd): | |
return subprocess.check_output(cmd.split(" ")) | |
def getBranches(): | |
cmd = "git --git-dir %s/.git branch" % sys.argv[1] | |
return executeCmd(cmd) | |
def callback(): | |
parser = ConfigParser.ConfigParser() | |
configPath = "%s/.git/config" % sys.argv[1] | |
with open(configPath) as gitConfig: | |
content = gitConfig.read().replace('\t', '') | |
parser.readfp(io.BytesIO(content)) | |
parser.set('gitflow "branch"', 'develop', branchValue.get()) | |
with open(configPath, "w+") as gitConfig: | |
for section in parser.sections(): | |
sectionLine = "[%s]\n" % section | |
gitConfig.write(sectionLine) | |
for option in parser.options(section): | |
optionLine = "\t%s = %s\n" % (option, parser.get(section, option)) | |
gitConfig.write(optionLine) | |
root.destroy() | |
def rootWindowConfig(): | |
root.wm_title("Select branch") | |
root.minsize(width=300, height=100) | |
if len(sys.argv) == 2: | |
branches = map(lambda x: x.strip(), getBranches().split("\n")[:-1]) | |
root = Tk() | |
rootWindowConfig() | |
branchValue = StringVar() | |
for branch in branches: | |
if branch.startswith("*"): | |
branch = branch.replace("*", "").strip() | |
branchValue.set(branch) | |
radiobutton = Radiobutton(root, text=branch, variable=branchValue, value=branch).pack(anchor=W) | |
button = Button(root, text="Apply", command=callback, width=20).pack() | |
root.lift() | |
root.call('wm', 'attributes', '.', '-topmost', True) | |
root.after_idle(root.call, 'wm', 'attributes', '.', '-topmost', False) | |
root.mainloop() | |
else: | |
print "Error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment