class SvnWCCommandPath(FSPathBase):
path implementation offering access/modification to svn working copies.
It has methods similar to the functions in os.path and similar to the
commands of the svn client.
class attributes and properties:
basename: <property object (dynamically calculated value)>
ext: <property object (dynamically calculated value)>
purebasename: <property object (dynamically calculated value)>
sep: /
strpath: <property object (dynamically calculated value)>
url: <property object (dynamically calculated value)>
methods:
def add(self):
add ourself to svn
arguments:
return value:
<None>
def blame(self):
return a list of tuples of three elements:
(revision, commiter, line)
arguments:
return value:
<List>
source: path/svn/wccommand.py
| 284 |
| 285 |
| 286 |
| 287 |
| 288 |
| 289 |
| 290 |
| 291 |
| 292 |
| 293 |
| 294 |
| 295 |
| 296 |
| 297 |
| 298 |
| 299 | |
def blame(self): |
""" return a list of tuples of three elements: |
(revision, commiter, line)""" |
out = self._svn('blame') |
result = [] |
blamelines = out.splitlines() |
reallines = py.path.svnurl(self.url).readlines() |
for i, (blameline, line) in py.builtin.enumerate( |
zip(blamelines, reallines)): |
m = rex_blame.match(blameline) |
if not m: |
raise ValueError("output line %r of svn blame does not match " |
"expected format" % (line, )) |
rev, name, _ = m.groups() |
result.append((int(rev), name, line)) |
return result | |
def check(self, **kw):
check a path for existence, or query its properties
without arguments, this returns True if the path exists (on the
filesystem), False if not
with (keyword only) arguments, the object compares the value
of the argument with the value of a property with the same name
(if it has one, else it raises a TypeError)
when for example the keyword argument 'ext' is '.py', this will
return True if self.ext == '.py', False otherwise
arguments:
return value:
<Boolean>
source: path/common.py
| 96 |
| 97 |
| 98 |
| 99 |
| 100 |
| 101 |
| 102 |
| 103 |
| 104 |
| 105 |
| 106 |
| 107 |
| 108 |
| 109 |
| 110 |
| 111 |
| 112 |
| 113 |
| 114 |
| 115 | |
def check(self, **kw): |
""" check a path for existence, or query its properties |
|
without arguments, this returns True if the path exists (on the |
filesystem), False if not |
|
with (keyword only) arguments, the object compares the value |
of the argument with the value of a property with the same name |
(if it has one, else it raises a TypeError) |
|
when for example the keyword argument 'ext' is '.py', this will |
return True if self.ext == '.py', False otherwise |
""" |
if kw: |
kw = kw.copy() |
if not checktype(self, kw): |
return False |
else: |
kw = {'exists' : 1} |
return self.Checkers(self)._evaluate(kw) | |
def checkout(self, url=None, rev=None):
checkout from url to local wcpath.
arguments:
return value:
<None>
source: path/svn/wccommand.py
| 121 |
| 122 |
| 123 |
| 124 |
| 125 |
| 126 |
| 127 |
| 128 |
| 129 |
| 130 |
| 131 |
| 132 |
| 133 |
| 134 |
| 135 |
| 136 | |
def checkout(self, url=None, rev=None): |
""" checkout from url to local wcpath. """ |
args = [] |
if url is None: |
url = self.url |
if rev is None or rev == -1: |
if (py.std.sys.platform != 'win32' and |
svncommon._getsvnversion() == '1.3'): |
url += "@HEAD" |
else: |
if svncommon._getsvnversion() == '1.3': |
url += "@%d" % rev |
else: |
args.append('-r' + str(rev)) |
args.append(url) |
self._authsvn('co', args) | |
def cleanup(self):
remove any locks from the resource
arguments:
return value:
<UNKNOWN>
source: path/svn/wccommand.py
| 228 |
| 229 |
| 230 |
| 231 |
| 232 |
| 233 |
| 234 | |
def cleanup(self): |
""" remove any locks from the resource """ |
|
try: |
self.unlock() |
except: |
pass | |
def commit(self, msg='', rec=1):
commit with support for non-recursive commits
arguments:
return value:
AnyOf(<Int>, <None>)
source: path/svn/wccommand.py
| 302 |
| 303 |
| 304 |
| 305 |
| 306 |
| 307 |
| 308 |
| 309 |
| 310 |
| 311 |
| 312 |
| 313 |
| 314 |
| 315 |
| 316 | |
def commit(self, msg='', rec=1): |
""" commit with support for non-recursive commits """ |
from py.__.path.svn import cache |
|
cmd = 'commit -m "%s" --force-log' % (msg.replace('"', '\\"'),) |
if not rec: |
cmd += ' -N' |
out = self._authsvn(cmd) |
try: |
del cache.info[self] |
except KeyError: |
pass |
if out: |
m = self._rex_commit.match(out) |
return int(m.group(1)) | |
def common(self, other):
return the common part shared with the other path
or None if there is no common part.
source: path/common.py
| 170 |
| 171 |
| 172 |
| 173 |
| 174 |
| 175 |
| 176 |
| 177 |
| 178 |
| 179 | |
def common(self, other): |
""" return the common part shared with the other path |
or None if there is no common part. |
""" |
last = None |
for x, y in zip(self.parts(), other.parts()): |
if x != y: |
return last |
last = x |
return last | |
def copy(self, target):
copy path to target.
arguments:
return value:
<None>
def diff(self, rev=None):
return a diff of the current path against revision rev (defaulting
to the last one).
arguments:
return value:
<String>
source: path/svn/wccommand.py
| 274 |
| 275 |
| 276 |
| 277 |
| 278 |
| 279 |
| 280 |
| 281 |
| 282 | |
def diff(self, rev=None): |
""" return a diff of the current path against revision rev (defaulting |
to the last one). |
""" |
args = [] |
if rev is not None: |
args.append("-r %d" % rev) |
out = self._authsvn('diff', args) |
return out | |
def dirpath(self, *args):
return the directory Path of the current Path.
source: path/svn/wccommand.py
|
|
def dirpath(self, *args): |
""" return the directory Path of the current Path. """ |
return self.__class__(self.localpath.dirpath(*args), auth=self.auth) | |
def dump(self, obj):
pickle object into path location
arguments:
- self: <UNKNOWN>
- obj: <UNKNOWN>
return value:
<UNKNOWN>
def ensure(self, *args, **kwargs):
ensure that an args-joined path exists (by default as
a file). if you specify a keyword argument 'directory=True'
then the path is forced to be a directory path.
source: path/svn/wccommand.py
| 158 |
| 159 |
| 160 |
| 161 |
| 162 |
| 163 |
| 164 |
| 165 |
| 166 |
| 167 |
| 168 |
| 169 |
| 170 |
| 171 |
| 172 |
| 173 |
| 174 |
| 175 |
| 176 |
| 177 | |
def ensure(self, *args, **kwargs): |
""" ensure that an args-joined path exists (by default as |
a file). if you specify a keyword argument 'directory=True' |
then the path is forced to be a directory path. |
""" |
try: |
p = self.join(*args) |
if p.check(): |
if p.check(versioned=False): |
p.add() |
return p |
if kwargs.get('dir', 0): |
return p._ensuredirs() |
parent = p.dirpath() |
parent._ensuredirs() |
p.write("") |
p.add() |
return p |
except: |
error_enhance(sys.exc_info()) | |
def info(self, usecache=1):
return an Info structure with svn-provided information.
arguments:
return value:
AnyOf(<Instance of Class InfoSvnWCCommand>, <None>)
source: path/svn/wccommand.py
| 386 |
| 387 |
| 388 |
| 389 |
| 390 |
| 391 |
| 392 |
| 393 |
| 394 |
| 395 |
| 396 |
| 397 |
| 398 |
| 399 |
| 400 |
| 401 |
| 402 |
| 403 |
| 404 |
| 405 |
| 406 |
| 407 |
| 408 |
| 409 |
| 410 |
| 411 | |
def info(self, usecache=1): |
""" return an Info structure with svn-provided information. """ |
info = usecache and cache.info.get(self) |
if not info: |
try: |
output = self._svn('info') |
except py.process.cmdexec.Error, e: |
if e.err.find('Path is not a working copy directory') != -1: |
raise py.error.ENOENT(self, e.err) |
raise |
|
|
|
if (output.strip() == '' or |
output.lower().find('not a versioned resource') != -1): |
raise py.error.ENOENT(self, output) |
info = InfoSvnWCCommand(output) |
|
|
|
if py.std.sys.platform != 'win32': |
if info.path != self.localpath: |
raise py.error.ENOENT(self, "not a versioned resource:" + |
" %s != %s" % (info.path, self.localpath)) |
cache.info[self] = info |
self.rev = info.rev |
return info | |
def join(self, *args, **kwargs):
return a new Path (with the same revision) which is composed
of the self Path followed by 'args' path components.
source: path/svn/wccommand.py
| 377 |
| 378 |
| 379 |
| 380 |
| 381 |
| 382 |
| 383 |
| 384 | |
def join(self, *args, **kwargs): |
""" return a new Path (with the same revision) which is composed |
of the self Path followed by 'args' path components. |
""" |
if not args: |
return self |
localpath = self.localpath.join(*args, **kwargs) |
return self.__class__(localpath, auth=self.auth) | |
def listdir(self, fil=None, sort=None):
return a sequence of Paths.
listdir will return either a tuple or a list of paths
depending on implementation choices.
arguments:
- self: <Instance of Class SvnWCCommandPath>
- fil: AnyOf(<None>, <String>, <Instance of Class checker>)
- sort: AnyOf(<None>, <Boolean>)
return value:
AnyOf(<None>, <List>)
source: path/svn/wccommand.py
| 413 |
| 414 |
| 415 |
| 416 |
| 417 |
| 418 |
| 419 |
| 420 |
| 421 |
| 422 |
| 423 |
| 424 |
| 425 |
| 426 |
| 427 |
| 428 |
| 429 |
| 430 |
| 431 |
| 432 |
| 433 |
| 434 |
| 435 |
| 436 |
| 437 | |
def listdir(self, fil=None, sort=None): |
""" return a sequence of Paths. |
|
listdir will return either a tuple or a list of paths |
depending on implementation choices. |
""" |
if isinstance(fil, str): |
fil = common.fnmatch(fil) |
|
def notsvn(path): |
return path.basename != '.svn' |
|
|
paths = [] |
for localpath in self.localpath.listdir(notsvn): |
p = self.__class__(localpath, auth=self.auth) |
paths.append(p) |
|
|
if fil or sort: |
paths = filter(fil, paths) |
paths = isinstance(paths, list) and paths or list(paths) |
if callable(sort): |
paths.sort(sort) |
elif sort: |
paths.sort() |
return paths | |
def load(self):
return object unpickled from self.read()
arguments:
return value:
<Dict>
source: path/common.py
| 359 |
| 360 |
| 361 |
| 362 |
| 363 |
| 364 |
| 365 |
| 366 | |
def load(self): |
""" return object unpickled from self.read() """ |
f = self.open('rb') |
try: |
from cPickle import load |
return self._callex(load, f) |
finally: |
f.close() | |
def lock(self):
set a lock (exclusive) on the resource
arguments:
return value:
<None>
source: path/svn/wccommand.py
|
|
def lock(self): |
""" set a lock (exclusive) on the resource """ |
out = self._authsvn('lock').strip() |
if not out: |
|
raise Exception(out[4:]) | |
def log(self, rev_start=None, rev_end=1, verbose=False):
return a list of LogEntry instances for this path.
rev_start is the starting revision (defaulting to the first one).
rev_end is the last revision (defaulting to HEAD).
if verbose is True, then the LogEntry instances also know which files changed.
arguments:
return value:
<List>
source: path/svn/wccommand.py
| 462 |
| 463 |
| 464 |
| 465 |
| 466 |
| 467 |
| 468 |
| 469 |
| 470 |
| 471 |
| 472 |
| 473 |
| 474 |
| 475 |
| 476 |
| 477 |
| 478 |
| 479 |
| 480 |
| 481 |
| 482 |
| 483 |
| 484 |
| 485 |
| 486 |
| 487 |
| 488 |
| 489 |
| 490 |
| 491 |
| 492 |
| 493 |
| 494 |
| 495 |
| 496 |
| 497 | |
def log(self, rev_start=None, rev_end=1, verbose=False): |
""" return a list of LogEntry instances for this path. |
rev_start is the starting revision (defaulting to the first one). |
rev_end is the last revision (defaulting to HEAD). |
if verbose is True, then the LogEntry instances also know which files changed. |
""" |
from py.__.path.svn.urlcommand import _Head, LogEntry |
assert self.check() |
rev_start = rev_start is None and _Head or rev_start |
rev_end = rev_end is None and _Head or rev_end |
|
|
if rev_start is _Head and rev_end == 1: |
rev_opt = "" |
else: |
rev_opt = "-r %s:%s" % (rev_start, rev_end) |
verbose_opt = verbose and "-v" or "" |
locale_env = svncommon.fixlocale() |
|
auth_opt = self._makeauthoptions() |
stdin, stdout, stderr = os.popen3(locale_env + |
'svn log --xml %s %s %s "%s"' % ( |
rev_opt, verbose_opt, auth_opt, |
self.strpath)) |
from xml.dom import minidom |
from xml.parsers.expat import ExpatError |
try: |
tree = minidom.parse(stdout) |
except ExpatError: |
|
|
raise ValueError('no such revision') |
result = [] |
for logentry in filter(None, tree.firstChild.childNodes): |
if logentry.nodeType == logentry.ELEMENT_NODE: |
result.append(LogEntry(logentry)) |
return result | |
def mkdir(self, *args):
create & return the directory joined with args.
source: path/svn/wccommand.py
| 179 |
| 180 |
| 181 |
| 182 |
| 183 |
| 184 |
| 185 | |
def mkdir(self, *args): |
""" create & return the directory joined with args. """ |
if args: |
return self.join(*args).mkdir() |
else: |
self._svn('mkdir') |
return self | |
def move(self, target):
move this path to target.
arguments:
return value:
<None>
source: path/common.py
| 368 |
| 369 |
| 370 |
| 371 |
| 372 |
| 373 |
| 374 |
| 375 |
| 376 | |
def move(self, target): |
""" move this path to target. """ |
if target.relto(self): |
raise py.error.EINVAL(target, "cannot move path into a subdirectory of itself") |
try: |
self.rename(target) |
except py.error.EXDEV: |
self.copy(target) |
self.remove() | |
def mtime(self):
Return the last modification time of the file.
arguments:
return value:
<Int>
def new(self, **kw):
create a modified version of this path. A 'rev' argument
indicates a new revision.
the following keyword arguments modify various path parts:
http://host.com/repo/path/file.ext
|-----------------------| dirname
|------| basename
|--| purebasename
|--| ext
source: path/svn/wccommand.py
| 360 |
| 361 |
| 362 |
| 363 |
| 364 |
| 365 |
| 366 |
| 367 |
| 368 |
| 369 |
| 370 |
| 371 |
| 372 |
| 373 |
| 374 |
| 375 | |
def new(self, **kw): |
""" create a modified version of this path. A 'rev' argument |
indicates a new revision. |
the following keyword arguments modify various path parts: |
|
http://host.com/repo/path/file.ext |
|-----------------------| dirname |
|------| basename |
|--| purebasename |
| |