2020
2121import json
2222
23+ from colored import fg , bg , attr
2324
2425# Global vars
2526argopts = {}
2627
27-
28- # Class for terminal Color
29- class tcolor :
30- DEFAULT = "\033 [0m"
31- BOLD = "\033 [1m"
32- RED = "\033 [0;1;31;40m"
33- GREEN = "\033 [0;1;32;40m"
34- BLUE = "\033 [0;1;36;40m"
35- ORANGE = "\033 [0;1;33;40m"
36- MAGENTA = "\033 [0;1;35;40m"
37- RESET = "\033 [2J\033 [H"
38- BELL = "\a "
28+ #Load custom parameters from ~/mygitcheck.py
29+ configfile = expanduser ('~/mygitcheck.py' )
30+ if os .path .exists (configfile ):
31+ sys .path .append (expanduser ('~' ))
32+ import mygitcheck as userconf
33+
34+ # Try to load colorthemme
35+ if hasattr (userconf , 'colortheme' ):
36+ colortheme = userconf .colortheme
37+ else :
38+ # Default theme
39+ defaultcolor = attr ('reset' ) + fg ('white' )
40+ colortheme = {
41+ 'default' : defaultcolor ,
42+ 'prjchanged' : attr ('reset' ) + attr ('bold' ) + fg ('deep_pink_1a' ),
43+ 'prjremote' : attr ('reverse' ) + fg ('light_cyan' ),
44+ 'prjname' : attr ('reset' ) + fg ('chartreuse_1' ),
45+ 'reponame' : attr ('reset' ) + fg ('light_goldenrod_2b' ),
46+ 'branchname' : defaultcolor ,
47+ 'fileupdated' : attr ('reset' ) + fg ('light_goldenrod_2b' ),
48+ 'remoteto' : attr ('reset' ) + fg ('deep_sky_blue_3b' ),
49+ 'committo' : attr ('reset' ) + fg ('violet' ),
50+ 'commitinfo' : attr ('reset' ) + fg ('deep_sky_blue_3b' ),
51+ 'commitstate' : attr ('reset' ) + fg ('deep_pink_1a' ),
52+ 'bell' : "\a " ,
53+ 'reset' : "\033 [2J\033 [H"
54+ }
3955
4056
4157class html :
@@ -105,11 +121,11 @@ def checkRepository(rep, branch):
105121 actionNeeded = actionNeeded or (count > 0 )
106122 if count > 0 :
107123 topush += " %s%s%s[%sTo Push:%s%s]" % (
108- tcolor . ORANGE ,
124+ colortheme [ 'reponame' ] ,
109125 r ,
110- tcolor . DEFAULT ,
111- tcolor . BLUE ,
112- tcolor . DEFAULT ,
126+ colortheme [ 'default' ] ,
127+ colortheme [ 'remoteto' ] ,
128+ colortheme [ 'default' ] ,
113129 count
114130 )
115131 html .topush += '<b style="color:black">%s</b>[<b style="color:blue">To Push:</b><b style="color:black">%s</b>]' % (
@@ -123,11 +139,11 @@ def checkRepository(rep, branch):
123139 actionNeeded = actionNeeded or (count > 0 )
124140 if count > 0 :
125141 topull += " %s%s%s[%sTo Pull:%s%s]" % (
126- tcolor . ORANGE ,
142+ colortheme [ 'reponame' ] ,
127143 r ,
128- tcolor . DEFAULT ,
129- tcolor . BLUE ,
130- tcolor . DEFAULT ,
144+ colortheme [ 'default' ] ,
145+ colortheme [ 'remoteto' ] ,
146+ colortheme [ 'default' ] ,
131147 count
132148 )
133149 html .topull += '<b style="color:black">%s</b>[<b style="color:blue">To Pull:</b><b style="color:black">%s</b>]' % (
@@ -153,24 +169,22 @@ def checkRepository(rep, branch):
153169 repname = rep
154170
155171 if ischange :
156- color = tcolor . BOLD + tcolor . RED
172+ prjname = "%s%s%s" % ( colortheme [ 'prjchanged' ], repname , colortheme [ 'default' ])
157173 html .prjname = '<b style="color:red">%s</b>' % (repname )
158174 elif not hasremotes :
159- color = tcolor . BOLD + tcolor . MAGENTA
175+ prjname = "%s%s%s" % ( colortheme [ 'prjremote' ], repname , colortheme [ 'default' ])
160176 html .prjname = '<b style="color:magenta">%s</b>' % (repname )
161177 else :
162- color = tcolor . DEFAULT + tcolor . GREEN
178+ prjname = "%s%s%s" % ( colortheme [ 'prjname' ], repname , colortheme [ 'default' ])
163179 html .prjname = '<b style="color:green">%s</b>' % (repname )
164180
165181 # Print result
166- prjname = "%s%s%s" % (color , repname , tcolor .DEFAULT )
167-
168182 if len (changes ) > 0 :
169- strlocal = "%sLocal%s[" % (tcolor . ORANGE , tcolor . DEFAULT )
183+ strlocal = "%sLocal%s[" % (colortheme [ 'reponame' ], colortheme [ 'default' ] )
170184 lenFilesChnaged = len (getLocalFilesChange (rep ))
171185 strlocal += "%sTo Commit:%s%s" % (
172- tcolor . BLUE ,
173- tcolor . DEFAULT ,
186+ colortheme [ 'remoteto' ] ,
187+ colortheme [ 'default' ] ,
174188 lenFilesChnaged
175189 )
176190 html .strlocal = '<b style="color:orange"> Local</b><b style="color:black">['
@@ -187,7 +201,8 @@ def checkRepository(rep, branch):
187201 html .msg += "<li>%s/%s %s %s %s</li>\n " % (html .prjname , branch , html .strlocal , html .topush , html .topull )
188202
189203 else :
190- print ("%(prjname)s/%(branch)s %(strlocal)s%(topush)s%(topull)s" % locals ())
204+ cbranch = "%s%s" % (colortheme ['branchname' ], branch )
205+ print ("%(prjname)s/%(cbranch)s %(strlocal)s%(topush)s%(topull)s" % locals ())
191206
192207 if argopts .get ('verbose' , False ):
193208 if ischange > 0 :
@@ -197,11 +212,11 @@ def checkRepository(rep, branch):
197212 html .msg += '<ul><li><b>Local</b></li></ul>\n <ul>\n '
198213 for c in changes :
199214 filename = " |--%s%s%s %s%s" % (
200- tcolor . MAGENTA ,
215+ colortheme [ 'commitstate' ] ,
201216 c [0 ],
202- tcolor . ORANGE ,
217+ colortheme [ 'fileupdated' ] ,
203218 c [1 ],
204- tcolor . DEFAULT )
219+ colortheme [ 'default' ] )
205220 html .msg += '<li> <b style="color:orange">[To Commit] </b>%s</li>\n ' % c [1 ]
206221 if not argopts .get ('email' , False ): print (filename )
207222 html .msg += '</ul>\n '
@@ -215,11 +230,11 @@ def checkRepository(rep, branch):
215230 if not argopts .get ('email' , False ): print (rname )
216231 for commit in commits :
217232 pcommit = " |--%s[To Push]%s %s%s%s" % (
218- tcolor . MAGENTA ,
219- tcolor . DEFAULT ,
220- tcolor . BLUE ,
233+ colortheme [ 'committo' ] ,
234+ colortheme [ 'default' ] ,
235+ colortheme [ 'commitinfo' ] ,
221236 commit ,
222- tcolor . DEFAULT )
237+ colortheme [ 'default' ] )
223238 html .msg += '<li><b style="color:blue">[To Push] </b>%s</li>\n ' % commit
224239 if not argopts .get ('email' , False ): print (pcommit )
225240 html .msg += '</ul>\n '
@@ -234,11 +249,11 @@ def checkRepository(rep, branch):
234249 if not argopts .get ('email' , False ): print (rname )
235250 for commit in commits :
236251 pcommit = " |--%s[To Pull]%s %s%s%s" % (
237- tcolor . MAGENTA ,
238- tcolor . DEFAULT ,
239- tcolor . BLUE ,
252+ colortheme [ 'committo' ] ,
253+ colortheme [ 'default' ] ,
254+ colortheme [ 'commitinfo' ] ,
240255 commit ,
241- tcolor . DEFAULT )
256+ colortheme [ 'default' ] )
242257 html .msg += '<li><b style="color:blue">[To Pull] </b>%s</li>\n ' % commit
243258 if not argopts .get ('email' , False ): print (pcommit )
244259 html .msg += '</ul>\n '
@@ -347,7 +362,7 @@ def gitcheck():
347362 updateRemote (r )
348363
349364 if argopts .get ('watchInterval' , 0 ) > 0 :
350- print (tcolor . RESET )
365+ print (colortheme [ 'reset' ] )
351366
352367 showDebug ("Processing repositories... please wait." )
353368 for r in repo :
@@ -362,7 +377,7 @@ def gitcheck():
362377 html .msg += "</ul>\n <p>Report created on %s</p>\n " % html .timestamp
363378
364379 if actionNeeded and argopts .get ('bellOnActionNeeded' , False ):
365- print (tcolor . BELL )
380+ print (colortheme [ 'bell' ] )
366381
367382
368383def sendReport (content ):
@@ -423,13 +438,13 @@ def initEmailConfig():
423438 json .dump (config , fp = open (filename , 'w' ), indent = 4 )
424439 print ('Please, modify config file located here : %s' % filename )
425440
441+
426442def readDefaultConfig ():
427443 filename = expanduser ('~/.gitcheck' )
428444 if os .path .exists (filename ):
429445 pass
430446
431447
432-
433448def usage ():
434449 print ("Usage: %s [OPTIONS]" % (sys .argv [0 ]))
435450 print ("Check multiple git repository in one pass" )
0 commit comments