slaposのcfgファイルをダウンロード

1354 ワード

# coding utf-8
import urllib
import re
import os

"""
 slapos .cfg 
"""
def getUrlFromCfg(url,dir):
    u = urllib.urlopen(url)
    buffer = u.read()
    # , 
    if not os.path.isfile(dir+'/buildout.cfg'):
        open(dir+'/buildout.cfg', 'wb').write(buffer)
    # 
    cfg_re = re.compile("""\/.*\/buildout\.cfg""")
    # , 
    cfg_list = cfg_re.findall(buffer)
    init_url = 'http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.7:/component'
    if len(cfg_list) > 0:
        for cfg in cfg_list:
            end_url = init_url + cfg
            dir = 'slapos/'+cfg.split('/')[1]
            # , 
            if not os.path.exists(dir):
                os.mkdir(dir)
            # 
            getUrlFromCfg(end_url,dir)
    u.close()

first_cfg = ' http://git.erp5.org/gitweb/slapos.git/blob_plain/refs/tags/slapos-0.7:/component/slapos/buildout.cfg'

getUrlFromCfg(first_cfg,'slapos')

'''
print u.info()
print "a %s b %d c.
" % (u.geturl(),len(buffer) ) '''