Created
September 19, 2010 05:36
-
-
Save jobscry/586432 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 | |
from optparse import OptionParser | |
import os | |
import sys | |
__version__ = '1.1' | |
__author__ = 'Joe Vasquez <joe.vasquez@gmail.com>' | |
if __name__ == '__main__': | |
parser = OptionParser(version=__version__) | |
parser.add_option("-s", "--start_dir", type="string", dest="start_dir", | |
help="Which directory to start from, default is CWD") | |
(options, args) = parser.parse_args() | |
if options.start_dir: | |
cwd = options.start_dir | |
try: | |
os.chdir(cwd) | |
except OSError: | |
parser.error('start directory does not exist!') | |
else: | |
cwd = os.getcwd() | |
sys.stdout.write(u'\nstarting in %s\n'%cwd) | |
dirs = os.listdir(cwd) | |
sys.stdout.write(u'found %s directories\n'%len(dirs)) | |
for directory in dirs: | |
path = os.path.join(cwd, directory) | |
sys.stdout.write('\n--------------------------------------------\n') | |
sys.stdout.write(u'looking in %s\n'%directory) | |
try: | |
contents = os.listdir(path) | |
if u'.git' in contents: | |
sys.stdout.write('it is a git repo\n') | |
os.chdir(path) | |
sys.stdout.write(u'changed dir to %s\n'%directory) | |
sys.stdout.write('pulling\n') | |
os.system('git pull') | |
elif u'.svn' in contents: | |
sys.stdout.write('it is a svn repo\n') | |
os.chdir(path) | |
sys.stdout.write(u'changed dir to %s\n'%directory) | |
sys.stdout.write('upping\n') | |
os.system('svn up') | |
else: | |
sys.stdout.write(u'not a repo\n') | |
except OSError: | |
sys.stdout.write('not a directory!\n') | |
sys.stdout.write('\n--------------------------------------------\n') | |
sys.stdout.write(u'returning to %s\n\n'%cwd) | |
os.chdir(cwd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment