author | Mario Ferraro <fadinlight@gmail.com> |
Tue, 25 Aug 2009 15:55:26 +0100 | |
changeset 2799 | 0fe7767592d0 |
parent 180 | a1c6123f9d06 |
permissions | -rwxr-xr-x |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""Helper functions that wrap the pysvn Python svn bindings. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
ls(): returns list of selected directory entries from an SVN repository |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
lsDirs(): wrapper around ls() that only returns node_kind.dir entries |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
lsFiles(): wrapper around ls() that only returns node_kind.files entries |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
exists(): returns True if repo_path exists in the svn repository |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
PYSVN_ALL_NODE_KINDS: all directory entry node_kinds supported by pysvn |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
PYSVN_FILE_DIR_NODE_KINDS: actual file and directory node_kinds |
63
9b1909e46633
Move tests/ to top level of trunk/. Fix tests to run from new location. Add
Todd Larsen <tlarsen@google.com>
parents:
52
diff
changeset
|
26 |
|
9b1909e46633
Move tests/ to top level of trunk/. Fix tests to run from new location. Add
Todd Larsen <tlarsen@google.com>
parents:
52
diff
changeset
|
27 |
This module requires that the pysvn module be installed. |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
""" |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
30 |
__authors__ = [ |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
# alphabetical order by last name, please |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
'"Todd Larsen" <tlarsen@google.com>', |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
] |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
|
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
36 |
import os |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
import pysvn |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
|
180 | 39 |
# top level script needs to use a relative import |
40 |
import settings |
|
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
#: all of the directory entry node_kinds supported py pysvn |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
PYSVN_ALL_NODE_KINDS = set([pysvn.node_kind.none, pysvn.node_kind.dir, |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
pysvn.node_kind.file, pysvn.node_kind.unknown]) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
#: actual file and directory node_kinds (includes dir and file, but excludes |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
48 |
#: the "non-file" none and unknown) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
49 |
PYSVN_FILE_DIR_NODE_KINDS = set([pysvn.node_kind.dir, pysvn.node_kind.file]) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
|
52
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
52 |
# pysvn Client object initialized lazily the first time getPySvnClient() |
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
53 |
# is called. |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
54 |
_client = None |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
55 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
56 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
57 |
def getPySvnClient(): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
58 |
"""Returns the module-global pysvn Client object (creating one if needed). |
52
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
59 |
|
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
60 |
Lazily initializes a global pysvn Client object, returning the same one |
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
61 |
once it exists. |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
62 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
63 |
global _client |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
64 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
65 |
if not _client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
66 |
_client = pysvn.Client() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
67 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
68 |
return _client |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
69 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
70 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
71 |
def formatDirPath(path): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
72 |
"""Appends trailing separator to non-empty path if it is missing. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
73 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
74 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
75 |
path: path string, which may be with or without a trailing separator, |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
76 |
or even empty or None |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
77 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
78 |
Returns: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
79 |
path unchanged if path evaluates to False or already ends with a trailing |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
80 |
separator; otherwise, a / separator is appended |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
81 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
82 |
if path and not path.endswith('/'): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
83 |
path = path + '/' |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
84 |
return path |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
85 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
86 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
87 |
def formatDirPaths(*args): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
88 |
"""Apply formatDirPath() to all supplied arguments, returning them in order. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
89 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
90 |
return tuple([formatDirPath(arg) for arg in args]) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
91 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
92 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
93 |
def getCanonicalSvnPath(path): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
94 |
"""Returns the supplied svn repo path *without* the trailing / character. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
95 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
96 |
Some pysvn methods raise exceptions if svn directory URLs end with a |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
97 |
trailing / ("non-canonical form") and some do not. Go figure... |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
98 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
99 |
if path and path.endswith('/'): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
100 |
path = path[:-1] |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
101 |
return path |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
102 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
103 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
104 |
def useLocalOsSep(path): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
105 |
"""Return path with all / characters replaced with os.sep, to be OS-agnostic. |
52
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
106 |
|
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
107 |
Args: |
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
108 |
path: an SVN path (either working copy path or relative path, but not a |
25d8f4623447
Changes to address comments by Sverre about the previous commit.
Todd Larsen <tlarsen@google.com>
parents:
44
diff
changeset
|
109 |
full repository URL) that uses the canonical / separators |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
110 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
111 |
return path.replace('/', os.sep) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
112 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
113 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
114 |
def getExpandedWorkingCopyPath(path, wc_root=None): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
115 |
"""Returns expanded, local, native filesystem working copy path. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
116 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
117 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
118 |
path: path to expand and convert to local filesystem directory separators |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
119 |
wc_root: if present, prepended to path first |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
120 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
121 |
path = useLocalOsSep(path) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
122 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
123 |
if wc_root: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
124 |
# prepend (Windows-compatible) working copy root if one was supplied |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
125 |
path = os.path.join(useLocalOsSep(wc_root), path) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
126 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
127 |
path = settings.getExpandedPath(path) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
128 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
129 |
if not path.endswith(os.sep): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
130 |
path = path + os.sep |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
131 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
132 |
return path |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
133 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
134 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
135 |
def encodeRevision(rev): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
136 |
"""Encode supplied revision into a pysvn.Revision instance. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
137 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
138 |
This function is currently very simplistic and does not produce all possible |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
139 |
types of pysvn.Revision object. See below for current limitations. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
140 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
141 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
142 |
rev: integer revision number or None |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
143 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
144 |
Returns: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
145 |
HEAD pysvn.Revision object if rev is None, |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
146 |
otherwise a pysvn.opt_revision_kind.number pysvn.Revision object created |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
147 |
using the supplied integer revision number |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
148 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
149 |
if rev is None: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
150 |
return pysvn.Revision(pysvn.opt_revision_kind.head) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
151 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
152 |
return pysvn.Revision(pysvn.opt_revision_kind.number, int(rev)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
153 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
154 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
155 |
def ls(repo_path, client=None, keep_kinds=PYSVN_FILE_DIR_NODE_KINDS, **kwargs): |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
156 |
"""Returns a list of (possibly recursive) svn repo directory entries. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
157 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
158 |
Args: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
159 |
repo_path: absolute svn repository path URL, including the server and |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
160 |
directory path within the repo |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
161 |
client: pysvn Client instance; default is None, which will use the pysvn |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
162 |
Client created by first call to getPySvnClient() (or create one if |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
163 |
necessary) |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
164 |
keep_kinds: types of directory entries to keep in the returned list; a |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
165 |
collection of pysvn.node_kind objects; default is |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
166 |
PYSVN_FILE_DIR_NODE_KINDS |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
167 |
**kwargs: keyword arguments passed on to Client.list(), including: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
168 |
recurse: indicates if return results should include entries from |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
169 |
subdirectories of repo_path as well; default is False |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
170 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
171 |
Returns: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
172 |
list of (Unicode, coming from pysvn) strings representing the entries |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
173 |
of types indicated by keep_kinds; strings are altered to match the |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
174 |
output of the actual 'svn ls' command: repo_path prefix is removed, |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
175 |
directories end with the / separator. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
176 |
""" |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
177 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
178 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
179 |
|
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
180 |
raw_entries = client.list(repo_path, **kwargs) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
181 |
entries = [] |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
182 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
183 |
# Find shortest repos_path that is a 'dir' entry; will be prefix of all |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
184 |
# other entries, since Client.list() always returns repo_path as one of |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
185 |
# the entries. It is easier and more reliable to do this search than to |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
186 |
# try to manipulate repo_path into the prefix (since the user could supply |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
187 |
# any number of valid, but different, formats). |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
188 |
shortest_path = raw_entries[0][0].repos_path |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
189 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
190 |
for svn_list, _ in raw_entries: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
191 |
if svn_list.kind == pysvn.node_kind.dir: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
192 |
entry_path = svn_list.repos_path |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
193 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
194 |
if len(entry_path) < len(shortest_path): |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
195 |
shortest_path = entry_path |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
196 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
197 |
# normalize the path name of entry_prefix to include a trailing separator |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
198 |
entry_prefix = formatDirPath(shortest_path) |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
199 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
200 |
for svn_list,_ in raw_entries: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
201 |
# only include requested node kinds (dir, file, etc.) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
202 |
if svn_list.kind not in keep_kinds: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
203 |
continue |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
204 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
205 |
entry_path = svn_list.repos_path |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
206 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
207 |
# omit the repo_path directory entry itself (simiilar to omitting '.' as |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
208 |
# is done by the actual 'svn ls' command) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
209 |
if entry_path == shortest_path: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
210 |
continue |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
211 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
212 |
# all entry_paths except for the shortest should start with that |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
213 |
# shortest entry_prefix, so assert that and remove the prefix |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
214 |
assert entry_path.startswith(entry_prefix) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
215 |
entry_path = entry_path[len(entry_prefix):] |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
216 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
217 |
# normalize directory entry_paths to include a trailing separator |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
218 |
if ((svn_list.kind == pysvn.node_kind.dir) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
219 |
and (not entry_path.endswith('/'))): |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
220 |
entry_path = entry_path + '/' |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
221 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
222 |
entries.append(entry_path) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
223 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
224 |
return entries |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
225 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
226 |
|
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
227 |
def lsDirs(repo_path, **kwargs): |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
228 |
"""Wrapper around ls() that only returns node_kind.dir entries. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
229 |
""" |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
230 |
return ls(repo_path, keep_kinds=(pysvn.node_kind.dir,), **kwargs) |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
231 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
232 |
|
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
233 |
def lsFiles(repo_path, **kwargs): |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
234 |
"""Wrapper around ls() that only returns node_kind.files entries. |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
235 |
""" |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
236 |
return ls(repo_path, keep_kinds=(pysvn.node_kind.file,), **kwargs) |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
237 |
|
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
238 |
|
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
239 |
def exists(repo_path, client=None): |
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
240 |
"""Returns True if repo_path exists in the svn repository.""" |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
241 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
242 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
243 |
|
30
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
244 |
try: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
245 |
raw_entries = client.list(repo_path) |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
246 |
return True |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
247 |
except pysvn._pysvn.ClientError: |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
248 |
# Client.list() raises an exception if the path is not present in the repo |
636baa95715c
Helper module used by utility and tool scripts to access svn repositories.
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
249 |
return False |
44
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
250 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
251 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
252 |
def branchItems(src, dest, items, rev=None, client=None): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
253 |
"""Branch a list of items (files and/or directories). |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
254 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
255 |
Using the supplied pysvn client object, a list of items (expected to be |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
256 |
present in the src directory) is branched from the absolute svn repo src |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
257 |
path URL to the relative working client dest directory. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
258 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
259 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
260 |
src: absolute svn repository source path URL, including the server and |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
261 |
directory path within the repo |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
262 |
dest: relative svn repository destination path in the current working copy |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
263 |
items: list of relative paths of items in src/ to branch to dest/ (no item |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
264 |
should begin with the / separator) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
265 |
client: pysvn Client instance; default is None, which will use the pysvn |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
266 |
Client created by first call to getPySvnClient() (or create one if |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
267 |
necessary) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
268 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
269 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
270 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
271 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
272 |
src = formatDirPath(src) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
273 |
dest = useLocalOsSep(formatDirPath(dest)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
274 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
275 |
for item in items: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
276 |
assert not item.startswith('/') |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
277 |
src_item = getCanonicalSvnPath(src + item) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
278 |
# attempt to be compatible with Windows working copy paths |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
279 |
item = useLocalOsSep(item) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
280 |
client.copy(src_item, dest + item, src_revision=encodeRevision(rev)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
281 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
282 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
283 |
def branchDir(src, dest, client=None, rev=None): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
284 |
"""Branch one directory to another. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
285 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
286 |
Using the supplied pysvn client object, the absolute svn repo path URL src |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
287 |
directory is branched to the relative working client dest directory. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
288 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
289 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
290 |
src: absolute svn repository source path URL, including the server and |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
291 |
directory path within the repo |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
292 |
dest: relative svn repository destination path in the current working copy |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
293 |
client: pysvn Client instance; default is None, which will use the pysvn |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
294 |
Client created by first call to getPySvnClient() (or create one if |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
295 |
necessary) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
296 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
297 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
298 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
299 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
300 |
src = getCanonicalSvnPath(src) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
301 |
dest = useLocalOsSep(formatDirPath(dest)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
302 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
303 |
client.copy(src, dest, src_revision=encodeRevision(rev)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
304 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
305 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
306 |
def exportItems(src, dest, items, rev=None, client=None): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
307 |
"""Export a list of items (files and/or directories). |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
308 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
309 |
Using the supplied pysvn client object, a list of items (expected to be |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
310 |
present in the src directory) is exported from the absolute svn repo src |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
311 |
path URL to the local filesystem directory. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
312 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
313 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
314 |
src: absolute svn repository source path URL, including the server and |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
315 |
directory path within the repo |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
316 |
dest: local filesystem destination path |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
317 |
items: list of relative paths of items in src/ to export to dest/ (no item |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
318 |
should begin with the / separator) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
319 |
client: pysvn Client instance; default is None, which will use the pysvn |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
320 |
Client created by first call to getPySvnClient() (or create one if |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
321 |
necessary) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
322 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
323 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
324 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
325 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
326 |
src = formatDirPath(src) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
327 |
dest = useLocalOsSep(formatDirPath(dest)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
328 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
329 |
for item in items: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
330 |
assert not item.startswith('/') |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
331 |
src_item = getCanonicalSvnPath(src + item) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
332 |
# attempt to be compatible with Windows local filesystem paths |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
333 |
dest_item = useLocalOsSep(getCanonicalSvnPath(dest + item)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
334 |
client.export(src_item, dest_item, revision=encodeRevision(rev)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
335 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
336 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
337 |
def exportDir(src, dest, client=None, rev=None): |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
338 |
"""Export one directory to another. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
339 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
340 |
Using the supplied pysvn client object, the absolute svn repo path URL src |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
341 |
directory is exported to the the local filesystem directory. |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
342 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
343 |
Args: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
344 |
src: absolute svn repository source path URL, including the server and |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
345 |
directory path within the repo |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
346 |
dest: local filesystem destination path |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
347 |
client: pysvn Client instance; default is None, which will use the pysvn |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
348 |
Client created by first call to getPySvnClient() (or create one if |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
349 |
necessary) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
350 |
""" |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
351 |
if not client: |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
352 |
client = getPySvnClient() |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
353 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
354 |
src = getCanonicalSvnPath(src) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
355 |
dest = useLocalOsSep(getCanonicalSvnPath(dest)) |
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
356 |
|
9d3a0f98df34
New svn_helper.py functionality for new_branch.py and related scripts.
Todd Larsen <tlarsen@google.com>
parents:
30
diff
changeset
|
357 |
client.export(src, dest, revision=encodeRevision(rev)) |