/
git_gui.py
107 lines (78 loc) · 2.83 KB
/
git_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python2.7
import sys
import string
import base64
import webbrowser
from Tkinter import Tk
from tkFileDialog import askopenfilename
from githubpy import github
from bs4 import BeautifulSoup
import urllib2
def gitall():
'''
print "For using this app, you need to have Github auth token."
raw_input("Press Enter to get your token")
webbrowser.open("https://help.github.com/articles/creating-an-access-token-for-command-line-use/#creating-a-token",new=2)
token = raw_input("Enter/paste your token : ")
#print "\nNow, that you have your auth token, from next execution simply comment out first 3 lines of code and paste your token in program itself, save and enjoy.\nYou should find the source-code here:/usr/local/lib/python2.7/dist-packages/gitgui/git_gui.py"
'''
token = '33aa***************************************0570f' #Github auth token for authorisation
gh = github.GitHub(access_token=token)
username = str(gh.user.get()['login'])
root = Tk()
root.withdraw()
root.resizable(width=800, height=400)
root.filename = askopenfilename()
filename = str(root.filename)
filename_rev = filename[::-1]
str_file =''
for i in range(30):
if filename_rev[i] == "/":
break
else:
str_file = str_file + filename_rev[i]
file_name = str_file[::-1]
commit_message = raw_input("Enter your commit Message : ")
with open(filename) as f:
file_content = f.read()
flag1 = 1
j = 0
list = gh.user.repos.get()
while (j<=3):
repo_name = raw_input("Enter the repo, you want your code to be pushed: ")
for dictionary in list:
if str(repo_name) != str(dictionary['name']):
flag1 = 0
else:
flag1 = 1
j = 5
break
if flag1 == 0:
print "I think, you have forgotten your repo names, have a look here, and try again."
for dictionary in list:
print dictionary['name']
j += 1
if j == 3:
print "Number of trails exceeded, Aborting."
sys.exit(1)
break
link = "https://github.com/" + username + "/" + str(repo_name)
url = urllib2.urlopen(link)
soup = BeautifulSoup(url)
con = soup.find_all("a",{"class" : "js-directory-link"})
count = len(con)
flag2 = 0
for title in con:
if str(file_name) == str(title.text):
flag2 = 1
print "You are trying to push a file, which is already there on your remote. This feature is not in this module. Please try later and push a file which is not alrady pushed. Aborting."
break
if (flag1==1 and flag2==0):
encoded_file = base64.b64encode(file_content)
gh = github.GitHub(access_token=token)
username = str(gh.user.get()['login'])
gh.repos(username)(repo_name)('contents')(file_name).put(path=file_content,message=commit_message,content=encoded_file)
print ("\nFile '%s' with commit message : '%s' pushed into your repo :'%s'" %(file_name, commit_message, repo_name))
raw_input("\nPress Enter to exit :)")
if __name__ == "__main__":
gitall()