/usr/share/pyshared/bitten/build/svntools.py is in trac-bitten-slave 0.6+final-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | # -*- coding: utf-8 -*-
#
# Copyright (C) 2007 Christopher Lenz <cmlenz@gmx.de>
# Copyright (C) 2007-2010 Edgewall Software
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://bitten.edgewall.org/wiki/License.
"""Recipe commands for Subversion."""
import logging
import posixpath
import re
import shutil
import os
log = logging.getLogger('bitten.build.svntools')
__docformat__ = 'restructuredtext en'
class Error(EnvironmentError):
pass
def copytree(src, dst, symlinks=False):
"""Recursively copy a directory tree using copy2().
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the contents of the files pointed to by symbolic
links are copied.
Adapted from shtuil.copytree
"""
names = os.listdir(src)
if not os.path.isdir(dst):
os.makedirs(dst)
errors = []
for name in names:
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if symlinks and os.path.islink(srcname):
linkto = os.readlink(srcname)
os.symlink(linkto, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks)
else:
shutil.copy2(srcname, dstname)
except (IOError, os.error), why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error, err:
errors.extend(err.args[0])
try:
shutil.copystat(src, dst)
except WindowsError:
# can't copy file access times on Windows
pass
except OSError, why:
errors.extend((src, dst, str(why)))
if errors:
raise Error, errors
def checkout(ctxt, url, path=None, revision=None, dir_='.', verbose='false', shared_path=None,
username=None, password=None, no_auth_cache='false'):
"""Perform a checkout from a Subversion repository.
:param ctxt: the build context
:type ctxt: `Context`
:param url: the URL of the repository
:param path: the path inside the repository
:param revision: the revision to check out
:param dir\_: the name of a local subdirectory to check out into
:param verbose: whether to log the list of checked out files
:param shared_path: a shared directory to do the checkout in, before copying to dir\_
:param username: a username of the repository
:param password: a password of the repository
:param no\_auth\_cache: do not cache authentication tokens
"""
args = ['checkout']
if revision:
args += ['-r', revision]
if path:
final_url = posixpath.join(url, path.lstrip('/'))
else:
final_url = url
if username:
args += ['--username', username]
if password:
args += ['--password', password]
if no_auth_cache.lower() == 'true':
args += ['--no-auth-cache']
args += [final_url, dir_]
cofilter = None
if verbose.lower() == 'false':
cre = re.compile(r'^[AU]\s.*$')
cofilter = lambda s: cre.sub('', s)
if shared_path is not None:
# run checkout on shared_path, then copy
shared_path = ctxt.resolve(shared_path)
checkout(ctxt, url, path, revision, dir_=shared_path, verbose=verbose)
try:
copytree(shared_path, ctxt.resolve(dir_))
except Exception, e:
ctxt.log('error copying shared tree (%s)' % e)
from bitten.build import shtools
returncode = shtools.execute(ctxt, file_='svn', args=args,
filter_=cofilter)
if returncode != 0:
ctxt.error('svn checkout failed (%s)' % returncode)
def export(ctxt, url, path=None, revision=None, dir_='.',
username=None, password=None, no_auth_cache='false'):
"""Perform an export from a Subversion repository.
:param ctxt: the build context
:type ctxt: `Context`
:param url: the URL of the repository
:param path: the path inside the repository
:param revision: the revision to check out
:param dir\_: the name of a local subdirectory to export out into
:param username: a username of the repository
:param password: a password of the repository
:param no\_auth\_cache: do not cache authentication tokens
"""
args = ['export', '--force']
if revision:
args += ['-r', revision]
if path:
url = posixpath.join(url, path)
if username:
args += ['--username', username]
if password:
args += ['--password', password]
if no_auth_cache.lower() == 'true':
args += ['--no-auth-cache']
args += [url, dir_]
from bitten.build import shtools
returncode = shtools.execute(ctxt, file_='svn', args=args)
if returncode != 0:
ctxt.error('svn export failed (%s)' % returncode)
def update(ctxt, revision=None, dir_='.',
username=None, password=None, no_auth_cache='false'):
"""Update the local working copy from the Subversion repository.
:param ctxt: the build context
:type ctxt: `Context`
:param revision: the revision to check out
:param dir\_: the name of a local subdirectory containing the working copy
:param username: a username of the repository
:param password: a password of the repository
:param no\_auth\_cache: do not cache authentication tokens
"""
args = ['update']
if revision:
args += ['-r', revision]
if username:
args += ['--username', username]
if password:
args += ['--password', password]
if no_auth_cache.lower() == 'true':
args += ['--no-auth-cache']
args += [dir_]
from bitten.build import shtools
returncode = shtools.execute(ctxt, file_='svn', args=args)
if returncode != 0:
ctxt.error('svn update failed (%s)' % returncode)
|