main.py
来自「linux subdivision ying gai ke yi le ba」· Python 代码 · 共 620 行 · 第 1/2 页
PY
620 行
#!/usr/bin/env python
#
# main.py: a shared, automated test suite for Subversion
#
# Subversion is a tool for revision control.
# See http://subversion.tigris.org for more information.
#
# ====================================================================
# Copyright (c) 2000-2004 CollabNet. 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://subversion.tigris.org/license-1.html.
# If newer versions of this license are posted there, you may use a
# newer version instead, at your option.
#
######################################################################
import sys # for argv[]
import os # for popen2()
import shutil # for rmtree()
import re
import stat # for ST_MODE
import string # for atof()
import copy # for deepcopy()
import time # for time()
import getopt
from svntest import Failure
from svntest import Skip
from svntest import testcase
from svntest import wc
######################################################################
#
# HOW TO USE THIS MODULE:
#
# Write a new python script that
#
# 1) imports this 'svntest' package
#
# 2) contains a number of related 'test' routines. (Each test
# routine should take no arguments, and return a 0 on success or
# non-zero on failure. Each test should also contain a short
# docstring.)
#
# 3) places all the tests into a list that begins with None.
#
# 4) calls svntest.main.client_test() on the list.
#
# Also, your tests will probably want to use some of the common
# routines in the 'Utilities' section below.
#
#####################################################################
# Global stuff
### Grandfather in SVNTreeUnequal, which used to live here. If you're
# ever feeling saucy, you could go through the testsuite and change
# main.SVNTreeUnequal to test.SVNTreeUnequal.
import tree
SVNTreeUnequal = tree.SVNTreeUnequal
class SVNLineUnequal(Failure):
"Exception raised if two lines are unequal"
pass
class SVNUnmatchedError(Failure):
"Exception raised if an expected error is not found"
pass
class SVNCommitFailure(Failure):
"Exception raised if a commit failed"
pass
class SVNRepositoryCopyFailure(Failure):
"Exception raised if unable to copy a repository"
pass
# Windows specifics
if sys.platform == 'win32':
windows = 1
file_schema_prefix = 'file:///'
_exe = '.exe'
else:
windows = 0
file_schema_prefix = 'file://'
_exe = ''
# The locations of the svn, svnadmin and svnlook binaries, relative to
# the only scripts that import this file right now (they live in ../).
svn_binary = os.path.abspath('../../../clients/cmdline/svn' + _exe)
svnadmin_binary = os.path.abspath('../../../svnadmin/svnadmin' + _exe)
svnlook_binary = os.path.abspath('../../../svnlook/svnlook' + _exe)
svnversion_binary = os.path.abspath('../../../svnversion/svnversion' + _exe)
# Username and password used by the working copies
wc_author = 'jrandom'
wc_passwd = 'rayjandom'
# Global variable indicating if we want verbose output.
verbose_mode = 0
# Global variable indicating if we want test data cleaned up after success
cleanup_mode = 0
# Global URL to testing area. Default to ra_local, current working dir.
test_area_url = file_schema_prefix + os.path.abspath(os.getcwd())
if windows == 1:
test_area_url = string.replace(test_area_url, '\\', '/')
# Global variable indicating the FS type for repository creations.
fs_type = "bdb"
# Where we want all the repositories and working copies to live.
# Each test will have its own!
general_repo_dir = "repositories"
general_wc_dir = "working_copies"
# A relative path that will always point to latest repository
current_repo_dir = None
current_repo_url = None
# temp directory in which we will create our 'pristine' local
# repository and other scratch data. This should be removed when we
# quit and when we startup.
temp_dir = 'local_tmp'
# (derivatives of the tmp dir.)
pristine_dir = os.path.join(temp_dir, "repos")
greek_dump_dir = os.path.join(temp_dir, "greekfiles")
config_dir = os.path.abspath(os.path.join(temp_dir, "config"))
default_config_dir = config_dir
#
# Our pristine greek-tree state.
#
# If a test wishes to create an "expected" working-copy tree, it should
# call main.greek_state.copy(). That method will return a copy of this
# State object which can then be edited.
#
_item = wc.StateItem
greek_state = wc.State('', {
'iota' : _item("This is the file 'iota'."),
'A' : _item(),
'A/mu' : _item("This is the file 'mu'."),
'A/B' : _item(),
'A/B/lambda' : _item("This is the file 'lambda'."),
'A/B/E' : _item(),
'A/B/E/alpha' : _item("This is the file 'alpha'."),
'A/B/E/beta' : _item("This is the file 'beta'."),
'A/B/F' : _item(),
'A/C' : _item(),
'A/D' : _item(),
'A/D/gamma' : _item("This is the file 'gamma'."),
'A/D/G' : _item(),
'A/D/G/pi' : _item("This is the file 'pi'."),
'A/D/G/rho' : _item("This is the file 'rho'."),
'A/D/G/tau' : _item("This is the file 'tau'."),
'A/D/H' : _item(),
'A/D/H/chi' : _item("This is the file 'chi'."),
'A/D/H/psi' : _item("This is the file 'psi'."),
'A/D/H/omega' : _item("This is the file 'omega'."),
})
######################################################################
# Utilities shared by the tests
def get_admin_name():
"Return name of SVN administrative subdirectory."
# todo: One day this sucker will try to intelligently discern what
# the admin dir is. For now, '.svn' will suffice.
return '.svn'
def get_start_commit_hook_path(repo_dir):
"Return the path of the start-commit-hook conf file in REPO_DIR."
return os.path.join(repo_dir, "hooks", "start-commit")
def get_pre_commit_hook_path(repo_dir):
"Return the path of the pre-commit-hook conf file in REPO_DIR."
return os.path.join(repo_dir, "hooks", "pre-commit")
def get_post_commit_hook_path(repo_dir):
"Return the path of the post-commit-hook conf file in REPO_DIR."
return os.path.join(repo_dir, "hooks", "post-commit")
# Run any binary, logging the command line (TODO: and return code)
def run_command(command, error_expected, binary_mode=0, *varargs):
"""Run COMMAND with VARARGS; return stdout, stderr as lists of lines.
If ERROR_EXPECTED is None, any stderr also will be printed."""
args = ''
for arg in varargs: # build the command string
args = args + ' "' + str(arg) + '"'
# Log the command line
if verbose_mode:
print 'CMD:', os.path.basename(command) + args,
if binary_mode:
mode = 'b'
else:
mode = 't'
start = time.time()
infile, outfile, errfile = os.popen3(command + args, mode)
stdout_lines = outfile.readlines()
stderr_lines = errfile.readlines()
outfile.close()
infile.close()
errfile.close()
if verbose_mode:
stop = time.time()
print '<TIME = %.6f>' % (stop - start)
if (not error_expected) and (stderr_lines):
map(sys.stdout.write, stderr_lines)
raise Failure
return stdout_lines, stderr_lines
def set_config_dir(cfgdir):
"Set the config directory."
global config_dir
config_dir = cfgdir
def reset_config_dir():
"Reset the config directory to the default value."
global config_dir
global default_config_dir
config_dir = default_config_dir
# For running subversion and returning the output
def run_svn(error_expected, *varargs):
"""Run svn with VARARGS; return stdout, stderr as lists of lines.
If ERROR_EXPECTED is None, any stderr also will be printed. If
you're just checking that something does/doesn't come out of
stdout/stderr, you might want to use actions.run_and_verify_svn() or
actions.run_and_verify_svn_error()."""
global config_dir
return run_command(svn_binary, error_expected, 0,
*varargs + ('--config-dir', config_dir))
# For running svnadmin. Ignores the output.
def run_svnadmin(*varargs):
"Run svnadmin with VARARGS, returns stdout, stderr as list of lines."
return run_command(svnadmin_binary, 1, 0, *varargs)
# For running svnlook. Ignores the output.
def run_svnlook(*varargs):
"Run svnlook with VARARGS, returns stdout, stderr as list of lines."
return run_command(svnlook_binary, 1, 0, *varargs)
def run_svnversion(*varargs):
"Run svnversion with VARARGS, returns stdout, stderr as list of lines."
return run_command(svnversion_binary, 1, 0, *varargs)
# Chmod recursively on a whole subtree
def chmod_tree(path, mode, mask):
def visit(arg, dirname, names):
mode, mask = arg
for name in names:
fullname = os.path.join(dirname, name)
if not os.path.islink(fullname):
new_mode = (os.stat(fullname)[stat.ST_MODE] & ~mask) | mode
os.chmod(fullname, new_mode)
os.path.walk(path, visit, (mode, mask))
# For clearing away working copies
def safe_rmtree(dirname, retry=0):
"Remove the tree at DIRNAME, making it writable first"
def rmtree(dirname):
chmod_tree(dirname, 0666, 0666)
shutil.rmtree(dirname)
if not os.path.exists(dirname):
return
if retry:
for delay in (0.5, 1, 2, 4):
try:
rmtree(dirname)
break
except:
time.sleep(delay)
else:
rmtree(dirname)
else:
rmtree(dirname)
# For making local mods to files
def file_append(path, new_text):
"Append NEW_TEXT to file at PATH"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?