Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 46 additions & 35 deletions show_status
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

# @desc Tired of having to go into each sub dir to find out whether or
# not you did a git commit? Tire no more, just use this!
Expand All @@ -9,8 +9,8 @@
# Grab some libraries
import sys
import os
import glob
import commands
import pathlib
import subprocess
from optparse import OptionParser

# Setup some stuff
Expand All @@ -19,20 +19,20 @@ gitted = False
mini = True

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'

def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'

def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''

parser = OptionParser(description="\
Show Status is awesome. If you tell it a directory to look in, it'll scan \
Expand Down Expand Up @@ -62,6 +62,14 @@ parser.add_option("-r", "--remote",
help = "Set the remote name (remotename:branchname)"
)

parser.add_option("-R", "--recursive",
action = "store",
dest = "recursive",
default = 1,
help = "Depth of recursion",
type = int
)

parser.add_option("--push",
action = "store_true",
dest = "push",
Expand Down Expand Up @@ -99,17 +107,21 @@ if __name__ == "__main__":
sys.stdout.write('Scanning sub directories of %s\n' %options.dirname)

# See whats here
for infile in glob.glob( os.path.join(options.dirname, '*') ):
globRegex = ''
for recursion in range(options.recursive):
globRegex += '*/'

for infile in pathlib.Path(options.dirname).glob(globRegex):

#is there a .git file
if os.path.exists( os.path.join(infile, ".git") ):
if os.path.isdir(infile) and os.path.exists( os.path.join(infile, ".git") ):

#Yay, we found one!
gitted = True

# OK, contains a .git file. Let's descend into it
# and ask git for a status
out = commands.getoutput('cd '+ infile + '; git status')
out = subprocess.getoutput('cd '+ str(infile) + '; git status')

# Mini?
if False == options.verbose:
Expand All @@ -119,46 +131,46 @@ if __name__ == "__main__":
branch = out[j+10:k];
branchColor = bcolors.WARNING;

if branch == 'master':
branchColor = bcolors.OKGREEN
if branch == 'master':
branchColor = bcolors.OKGREEN

branch = "[ " + branchColor + branch.ljust(15) + bcolors.ENDC + " ]"
branch = "[ " + branchColor + branch.ljust(15) + bcolors.ENDC + " ]"

if -1 != out.find('nothing'):
if -1 != out.find('nothing'):
result = bcolors.OKGREEN + "No Changes" + bcolors.ENDC

# Pull from the remote
if False != options.pull:
push = commands.getoutput(
'cd '+ infile +
push = subprocess.getoutput(
'cd '+ str(infile) +
'; git pull '+
' '.join(options.remote.split(":"))
)
result = result + " (Pulled) \n" + push

# Push to the remote
if False != options.push:
push = commands.getoutput(
'cd '+ infile +
push = subprocess.getoutput(
'cd '+ str(infile) +
'; git push '+
' '.join(options.remote.split(":"))
)
result = result + " (Pushed) \n" + push

else:
result = bcolors.FAIL + "Changes" + bcolors.ENDC
else:
result = bcolors.FAIL + "Changes" + bcolors.ENDC

# Write to screen
sys.stdout.write("-- " + bcolors.OKBLUE + infile.ljust(55) + bcolors.ENDC + branch + " : " + result +"\n")
sys.stdout.write("-- " + bcolors.OKBLUE + str(infile).ljust(55) + bcolors.ENDC + branch + " : " + result +"\n")

else:
#Print some repo details
sys.stdout.write("\n---------------- "+ infile +" -----------------\n")
sys.stdout.write("\n---------------- "+ str(infile) +" -----------------\n")
sys.stdout.write(out)
sys.stdout.write("\n---------------- "+ infile +" -----------------\n")
sys.stdout.write("\n---------------- "+ str(infile) +" -----------------\n")

# Come out of the dir and into the next
commands.getoutput('cd ../')
subprocess.getoutput('cd ../')



Expand All @@ -167,4 +179,3 @@ if __name__ == "__main__":
show_error("Error: None of those sub directories had a .git file.\n")

sys.stdout.write("Done\n")