#!/usr/env/python
import os
import os.path
from subprocess import call
if __name__ == "__main__":
apps_dir = os.path.abspath('.')
for app_name in os.listdir(apps_dir):
app_dir = os.path.abspath(os.path.join(apps_dir, app_name))
git_path = os.path.join(app_dir, '.git')
svn_path = os.path.join(app_dir, '.svn')
hg_path = os.path.join(app_dir, '.hg')
bzr_path = os.path.join(app_dir, '.bzr')
if os.path.lexists(svn_path):
print "Updating svn %s" % app_dir
os.chdir(app_dir)
call(['svn', 'update'])
elif os.path.lexists(git_path):
print "Updating git %s" % app_dir
os.chdir(app_dir)
call(['git', 'pull'])
elif os.path.lexists(hg_path):
print "Updating hg %s" % app_dir
os.chdir(app_dir)
call(['hg', 'pull', '-u'])
if os.path.lexists(bzr_path):
print "Updating bzr %s" % app_dir
os.chdir(app_dir)
call(['bzr', 'update'])
else:
continue
Comments
Cool! It would be nice if it detected if you had each VCS on your system, too. I wonder if that's easy.
#
What about searching for apps in subdirs? Let's say I have:
with some apps, and
with apps related to Django. And I want to update all my apps under my lib dir.
#
@dedaluz The script uses the current path (
.) so you can do something like this:Or do I misunderstand your problem?
#
I just wanted to update my entire tree of python modules (under a VCS) with just one command instead of walking each subdir and updating them one by one. For instance, I have several subdirs (and even subsubdirs) under my python/lib folder, just to keep things organized.
Just take a look at #928. Perhaps it doesn't make sense but it works pretty well for me.
Anyway, thanks; both to you and Eric for sharing your code.
#