bin/clone_deps.py
branchstable
changeset 6304 228921b064c3
child 7896 4c954e1e73ef
equal deleted inserted replaced
6303:1aad5389c013 6304:228921b064c3
       
     1 #!/usr/bin/python
       
     2 import os
       
     3 import sys
       
     4 from subprocess import call, Popen, PIPE
       
     5 try:
       
     6     from mercurial.dispatch import dispatch as hg_call
       
     7 except ImportError:
       
     8     print '-' * 20
       
     9     print "mercurial module is not reachable from this Python interpreter"
       
    10     print "trying from command line ..."
       
    11     tryhg = os.system('hg --version')
       
    12     if tryhg:
       
    13         print 'mercurial seems to unavailable, please install it'
       
    14         raise
       
    15     print 'found it, ok'
       
    16     print '-' * 20
       
    17     def hg_call(args):
       
    18         call(['hg'] + args)
       
    19 from urllib import urlopen
       
    20 from os import path as osp, pardir
       
    21 from os.path import normpath, join, dirname
       
    22 
       
    23 BASE_URL = 'http://www.logilab.org/hg/'
       
    24 
       
    25 to_clone = ['fyzz', 'yams', 'rql',
       
    26             'logilab/common', 'logilab/constraint', 'logilab/database',
       
    27             'logilab/devtools', 'logilab/mtconverter',
       
    28             'cubes/blog', 'cubes/calendar', 'cubes/card', 'cubes/comment',
       
    29             'cubes/datafeed', 'cubes/email', 'cubes/file', 'cubes/folder',
       
    30             'cubes/forgotpwd', 'cubes/keyword', 'cubes/link',
       
    31             'cubes/mailinglist', 'cubes/nosylist', 'cubes/person',
       
    32             'cubes/preview', 'cubes/registration', 'cubes/rememberme',
       
    33             'cubes/tag', 'cubes/vcsfile', 'cubes/zone']
       
    34 
       
    35 # a couple of functions to be used to explore available
       
    36 # repositories and cubes
       
    37 def list_repos(repos_root):
       
    38     assert repos_root.startswith('http://')
       
    39     hgwebdir_repos = (repo.strip()
       
    40                       for repo in urlopen(repos_root + '?style=raw').readlines()
       
    41                       if repo.strip())
       
    42     prefix = osp.commonprefix(hgwebdir_repos)
       
    43     return (repo[len(prefix):].strip('/')
       
    44             for repo in hgwebdir_repos)
       
    45 
       
    46 def list_all_cubes(base_url=BASE_URL):
       
    47     all_repos = list_repos(base_url)
       
    48     #search for cubes
       
    49     for repo in all_repos:
       
    50         if repo.startswith('cubes'):
       
    51             to_clone.append(repo)
       
    52 
       
    53 def get_latest_debian_tag(path):
       
    54     proc = Popen(['hg', '-R', path, 'tags'], stdout=PIPE)
       
    55     out, _err = proc.communicate()
       
    56     for line in out.splitlines():
       
    57         if 'debian-version' in line:
       
    58             return line.split()[0]
       
    59 
       
    60 def main():
       
    61     if len(sys.argv) == 1:
       
    62         base_url = BASE_URL
       
    63     elif len(sys.argv) == 2:
       
    64         base_url = sys.argv[1]
       
    65     else:
       
    66         print >> sys.stderr, 'usage %s [base_url]' %  sys.argv[0]
       
    67         sys.exit(1)
       
    68     print len(to_clone), 'repositories will be cloned'
       
    69     base_dir = normpath(join(dirname(__file__), pardir, pardir))
       
    70     os.chdir(base_dir)
       
    71     not_updated = []
       
    72     for repo in to_clone:
       
    73         url = base_url + repo
       
    74         if '/' not in repo:
       
    75             target_path = repo
       
    76         else:
       
    77             assert repo.count('/') == 1, repo
       
    78             directory, repo = repo.split('/')
       
    79             if not osp.isdir(directory):
       
    80                 os.mkdir(directory)
       
    81                 open(join(directory, '__init__.py'), 'w').close()
       
    82             target_path = osp.join(directory, repo)
       
    83         if osp.exists(target_path):
       
    84             print target_path, 'seems already cloned. Skipping it.'
       
    85         else:
       
    86             hg_call(['clone', '-U', url, target_path])
       
    87             tag = get_latest_debian_tag(target_path)
       
    88             if tag:
       
    89                 print 'updating to', tag
       
    90                 hg_call(['update', '-R', target_path, tag])
       
    91             else:
       
    92                 not_updated.append(target_path)
       
    93     print """
       
    94 CubicWeb dependencies and standard set of cubes have been fetched and
       
    95 update to the latest stable version.
       
    96 
       
    97 You should ensure your PYTHONPATH contains `%(basedir)s`.
       
    98 You might want to read the environment configuration section of the documentation
       
    99 at http://docs.cubicweb.org/admin/setup.html#environment-configuration
       
   100 
       
   101 You can find more cubes at http://www.cubicweb.org.
       
   102 Clone them from `%(baseurl)scubes/` into the `%(basedir)s%(sep)scubes%(sep)s` directory.
       
   103 
       
   104 To get started you may read http://docs.cubicweb.org/tutorials/base/index.html.
       
   105 """ % {'basedir': os.getcwd(), 'baseurl': base_url, 'sep': os.sep}
       
   106     if not_updated:
       
   107         print >> sys.stderr, 'WARNING: The following repositories were not updated (no debian tag found):'
       
   108         for path in not_updated:
       
   109             print >> sys.stderr, '\t-', path
       
   110 
       
   111 if __name__ == '__main__':
       
   112     main()
       
   113 
       
   114 
       
   115