Login

Update All Apps to Latest Revision

Author:
dedaluz
Posted:
July 30, 2008
Language:
Python
Version:
.96
Score:
0 (after 0 ratings)

This snippet is based on #844 and #892 and updates all apps in the current directory using hg, svn, git or bzr. Including subdirectories not under version control (subfolders to keep your stuff organized).

For example:

python/lib/
    django-trunk/
    django-0.96/
    pydelicious/
    (...)
    django-apps/
        django-tagging/
        django-pagination/
        django-registration/
        django-threadedcomments/
        django-mptt/
    (...)

The script will iterate through all of your apps (in the current dir and also recursively in subdirs NOT under version control) and update them to the latest version.

To run, simply execute:

python update_apps.py

in the desired parent folder.

Just in case it could be useful: In my case I'm using MAC OS X. I have a folder full of miscellaneous scripts under my HOMEDIR, with this content:

/Users/Dedaluz/bin/update_apps.py
/Users/Dedaluz/bin/update_apps  (this is a bash script)

The update_apps script contains simply:

#!/bin/bash
python /Users/Dedaluz/bin/update_apps.py

Then I put this folder in my path, so in my /HOMEDIR/.bash_profile I add this line

export PATH=$PATH:$HOME/bin

And I just can update from any parent folder just going there and typing: update_apps

 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
32
33
34
35
36
37
38
#!/usr/env/python
import os
import os.path
from subprocess import call
    
def update(apps_dir):
    """Updates a collection of Subversion/Git/Mercurial/Bazaar working copies, including subdirectories"""
    for app_name in os.listdir(apps_dir):
        app_dir = os.path.abspath(os.path.join(apps_dir, app_name))
        if os.path.isdir(app_dir):
            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'])
            elif os.path.lexists(bzr_path):
                print "Updating bzr %s" % app_dir
                os.chdir(app_dir)
                call(['bzr', 'update'])     
            else:
                update(app_dir)
        else:
            continue
    return None
    
if __name__ == "__main__":
    update(os.path.abspath('.'))

More like this

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

Comments

dedaluz (on July 30, 2008):

I think it could be useful to make it accept parameters like:

update_apps ..
update apps ./some-dir/

#

Please login first before commenting.