Пример #1
0
def svn(url, targetdir, final=None):
    '''
    Do an svn checkout of <url> to <targetdir>.
    '''
    print 'in svn: %s' % str(url)
    urlp = urlparse.urlparse(url)
    util.assuredir(targetdir)
    if not final:
        final = os.path.splitext(os.path.basename(urlp.path))[0]
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0
    rc = proc.run('svn checkout %s %s' % (url, fullpath))
    return rc
Пример #2
0
def svn(url, targetdir, final=None):
    '''
    Do an svn checkout of <url> to <targetdir>.
    '''
    print 'in svn: %s' % str(url)
    urlp = urlparse.urlparse(url)
    util.assuredir(targetdir)
    if not final:
        final = os.path.splitext(os.path.basename(urlp.path))[0]
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0
    rc = proc.run('svn checkout %s %s' % (url, fullpath))
    return rc
Пример #3
0
def prepare(src, dst, creates):
    '''If <creates> exists, do nothing.  Otherwise make sure directory
    <dst> exists.  Return true if actual unpacking should continue.
    '''
    if not os.path.exists(src):
        raise ValueError, 'No such source to unpack: %s' % src

    if creates:
        if not creates.startswith('/'):
            creates = os.path.join(dst,creates)
        if os.path.exists(creates):
            logging.debug('idem: unpack result already exists: %s' % creates)
            return False
    util.assuredir(dst)
    return True
Пример #4
0
def prepare(src, dst, creates):
    '''If <creates> exists, do nothing.  Otherwise make sure directory
    <dst> exists.  Return true if actual unpacking should continue.
    '''
    if not os.path.exists(src):
        raise ValueError, 'No such source to unpack: %s' % src

    if creates:
        if not creates.startswith('/'):
            creates = os.path.join(dst, creates)
        if os.path.exists(creates):
            logging.debug('idem: unpack result already exists: %s' % creates)
            return False
    util.assuredir(dst)
    return True
Пример #5
0
def web(url, targetdir, final=None):
    '''Download the file at <url> to <targetdir>.  If <final> is
    given download file to <targetdir>/<final> otherwise use the
    file name as determined by the tail of the URL.'''

    if not final:
        final = os.path.basename(url)
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0

    util.assuredir(targetdir)
    res = urlopen(url)
    targetfp = open(fullpath, 'w')
    shutil.copyfileobj(res, targetfp)
    targetfp.close()
    return 0
Пример #6
0
def web(url, targetdir, final=None):
    '''Download the file at <url> to <targetdir>.  If <final> is
    given download file to <targetdir>/<final> otherwise use the
    file name as determined by the tail of the URL.'''

    if not final:
        final = os.path.basename(url)
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0

    util.assuredir(targetdir)
    res = urlopen(url)
    targetfp = open(fullpath, 'w')
    shutil.copyfileobj(res, targetfp)
    targetfp.close()
    return 0
Пример #7
0
def unzip(src, dst, creates=None):
    '''
    Unzip <src> file into <dst> directory unless <creates> already exists.
    '''

    if not prepare(src, dst, creates):
        return

    # http://stackoverflow.com/questions/7806563/how-to-unzip-a-file-with-python-2-4
    zfile = zipfile.ZipFile(src)
    for name in zfile.namelist():
        (reldir, filename) = os.path.split(name)
        dirname = os.path.join(dst, reldir)
        if not os.path.exists(dirname):
            util.assuredir(dirname)
        fullpath = os.path.join(dst,name)
        fd = open(fullpath, 'w')
        fd.write(zfile.read(name))
        fd.close()
    zfile.close()
    return 0
Пример #8
0
def unzip(src, dst, creates=None):
    '''
    Unzip <src> file into <dst> directory unless <creates> already exists.
    '''

    if not prepare(src, dst, creates):
        return

    # http://stackoverflow.com/questions/7806563/how-to-unzip-a-file-with-python-2-4
    zfile = zipfile.ZipFile(src)
    for name in zfile.namelist():
        (reldir, filename) = os.path.split(name)
        dirname = os.path.join(dst, reldir)
        if not os.path.exists(dirname):
            util.assuredir(dirname)
        fullpath = os.path.join(dst, name)
        fd = open(fullpath, 'w')
        fd.write(zfile.read(name))
        fd.close()
    zfile.close()
    return 0
Пример #9
0
def git(url, targetdir, final=None):
    '''Make a "clone" of a git repository at <url> in to targetdir.  If
    <final> is not given it will be the last part of the <url>'s path.
    if <final> ends in '.git' it a bare clone will be made.  The URL
    options can be "tag=<tag>" to specify a tag to checkout.  If a
    "branch=<branch>" is also given it will name the branch hold the
    tagged checkout.  If no branch is given it defaults to the tag
    name.

    '''

    urlp = urlparse.urlparse(url)
    query = query2dict(urlp.query)
    tag = query.get('tag')
    branch = query.get('branch')

    url_no_query = urlparse.ParseResult(urlp.scheme, urlp.netloc, urlp.path,
                                        '', '', '').geturl()
    if not final:
        final = os.path.basename(urlp.path)
    bare = ""
    if final.endswith('.git'):
        bare = '--bare'
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0

    util.assuredir(targetdir)
    rc = proc.run("git clone %s %s %s" % (bare, url_no_query, fullpath))
    if rc: return rc

    if not tag:
        return 0

    if not branch:
        branch = tag

    rc = proc.run('git --work-tree=%s --git-dir=%s/.git checkout -b %s %s' %
                  (fullpath, fullpath, branch, tag))
    return rc
Пример #10
0
def git(url, targetdir, final = None):
    '''Make a "clone" of a git repository at <url> in to targetdir.  If
    <final> is not given it will be the last part of the <url>'s path.
    if <final> ends in '.git' it a bare clone will be made.  The URL
    options can be "tag=<tag>" to specify a tag to checkout.  If a
    "branch=<branch>" is also given it will name the branch hold the
    tagged checkout.  If no branch is given it defaults to the tag
    name.

    '''
    
    urlp = urlparse.urlparse(url)
    query = query2dict(urlp.query)
    tag = query.get('tag')
    branch = query.get('branch')

    url_no_query = urlparse.ParseResult(urlp.scheme, urlp.netloc, urlp.path, '', '', '').geturl()
    if not final:
        final = os.path.basename(urlp.path)
    bare = ""
    if final.endswith('.git'):
        bare = '--bare'
    fullpath = os.path.join(targetdir, final)
    if os.path.exists(fullpath):
        return 0

    util.assuredir(targetdir)
    rc = proc.run("git clone %s %s %s" % (bare, url_no_query, fullpath))
    if rc: return rc
    
    if not tag:
        return 0

    if not branch:
        branch = tag

    rc = proc.run('git --work-tree=%s --git-dir=%s/.git checkout -b %s %s' % (fullpath, fullpath, branch, tag))
    return rc