Login

Update All Apps to Latest Revision

Author:
izibi
Posted:
July 18, 2008
Language:
Python
Version:
.96
Score:
3 (after 3 ratings)

This snippet is based on #844 and updates all apps in the current directory using hg, svn, git or bzr.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

ericflo (on July 18, 2008):

Cool! It would be nice if it detected if you had each VCS on your system, too. I wonder if that's easy.

#

dedaluz (on July 30, 2008):

What about searching for apps in subdirs? Let's say I have:

/home/python/lib/

with some apps, and

/home/python/lib/django-apps/

with apps related to Django. And I want to update all my apps under my lib dir.

#

izibi (on August 5, 2008):

@dedaluz The script uses the current path (.) so you can do something like this:

cd /home/python/lib
python /path/to/update.py

Or do I misunderstand your problem?

#

Please login first before commenting.