mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Better Python script support; update samples.json
This commit is contained in:
47
samples/Python/python2.script!
Normal file
47
samples/Python/python2.script!
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def main():
|
||||
|
||||
# usage string
|
||||
usage = 'usage: gitall command'
|
||||
|
||||
# command check
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit(usage)
|
||||
|
||||
command = 'git ' + ' '.join(sys.argv[1:])
|
||||
printDelimiter()
|
||||
print 'Running command:', command
|
||||
|
||||
# get a list of git directories in the specified parent
|
||||
gitDirectories = getSubdirectories('.', isGitDirectory)
|
||||
|
||||
for gitDirectory in gitDirectories:
|
||||
os.chdir(gitDirectory)
|
||||
printDelimiter()
|
||||
print 'Current respository location:', os.getcwd()
|
||||
os.system(command)
|
||||
|
||||
printDelimiter()
|
||||
|
||||
def getSubdirectories(directory, filter = None):
|
||||
directory = os.path.abspath(directory)
|
||||
subdirectories = os.walk(directory).next()[1]
|
||||
if filter is None:
|
||||
return [directory + '/' + i for i in subdirectories]
|
||||
else:
|
||||
return [directory + '/' + i for i in subdirectories if filter(directory + '/' + i)]
|
||||
|
||||
def isGitDirectory(directory):
|
||||
return os.path.isdir(directory + '/.git/')
|
||||
|
||||
def printDelimiter():
|
||||
print '\033[91m'
|
||||
print ('#' * 80)
|
||||
print '\033[0m'
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user