Login

Update applications

Author:
alem0lars
Posted:
July 19, 2010
Language:
Python
Version:
1.2
Tags:
update applications svn git baazar mercurial repositories
Score:
2 (after 2 ratings)

This snippet is based on 928.

I've added the support to update a custom folder, using shell arguments.

It requires the argparse module.

You can install it with: pip install argparse

Usage:

Updates repositories in the specified <folder path>

The default is the ./ folder

update_repos --path <folder path>

List available options

update_repos -h

Alessandro Molari

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python


import os.path
import argparse
import sys
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__":
    parser = argparse.ArgumentParser(description = "Updates a collection of Subversion/Git/Mercurial/Bazaar working copies, including subdirectories")
    parser.add_argument("--path", default = "./", help = "Directory to be updated (maybe the parent dir). (Default: current folder)")
    args = parser.parse_args()
    path = os.path.abspath(args.path)
    if os.path.isdir(path):
        update(path)
        print ">>> DONE: Successfully updated %s" % (os.path.basename(path),)
        sys.exit(0)
    else:
        print ">>> ERROR: %s is not a valid directory" % (os.path.basename(path),)
        sys.exit(1)

More like this

  1. Serve static media files from app/media subdirectory by adamlofts 6 years, 7 months ago
  2. Single Django App behind multiple Apache Proxies by chadmaine 7 years, 10 months ago
  3. Dynamic import from an installed app by Archatas 5 years, 11 months ago
  4. Analogue template filter to removetags that also removes the content of the tag by piquadrat 4 years, 3 months ago
  5. Install Django on TextDrive by SuperJared 7 years, 11 months ago

Comments

Please login first before commenting.