Login

Update All Apps to Latest Revision

Author:
ericflo
Posted:
July 1, 2008
Language:
Python
Version:
.96
Score:
6 (after 6 ratings)

A simple script that I have put in my Django applications directory to fetch the latest application code from git and svn.

For example, your directory structure might look like so:

django-apps/
    django-tagging/
    django-pagination/
    django-registration/
    django-threadedcomments/
    django-mptt/
    update_apps.py

Where update_apps.py is the source of this snippet.

To run, simply execute:

python update_apps.py

And the script will iterate through all of your apps and update them to the latest version.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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')
        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'])
        else:
            continue

More like this

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

Comments

kcarnold (on July 1, 2008):

Subversion has an "externals" facility that works well in this situation: simply define all your external apps (even Django itself, perhaps) in svn:externals, then an svn up will pull all the latest versions. (You can also lock a specific revision.)

I think git has something similar, but I don't know how it works.

#

dnordberg (on July 2, 2008):

Thanks! been wanting this for sometime

#

ericflo (on July 2, 2008):

@kcarnold: That's a really great solution when all of your applications are within a subversion project, and we do it that way for the Pinax project. That being said, I like to keep a separate global directory just for Django apps, and this script addresses that particular use case.

#

izibi (on July 16, 2008):

Great snippet, but is it possible to add Mercurial support?

The update command is hg -u pull

#

mikl (on January 2, 2009):

Nice trick, but I'm pretty sure that your env usage is wrong – it's supposed to be something like this:

#!/usr/bin/env python

#

Please login first before commenting.