[py-svn] r6974 - in py/dist/py/path: . local svn
hpk at codespeak.net
hpk at codespeak.net
Sun Oct 17 06:58:37 CEST 2004
Author: hpk
Date: Sun Oct 17 06:58:36 2004
New Revision: 6974
Added:
py/dist/py/path/local/posix.py
- copied unchanged from r6969, py/dist/py/path/local/_posix.py
py/dist/py/path/local/win.py
- copied unchanged from r6954, py/dist/py/path/local/_win.py
Removed:
py/dist/py/path/local/_posix.py
py/dist/py/path/local/_win.py
Modified:
py/dist/py/path/common.py
py/dist/py/path/local/local.py
py/dist/py/path/local/test_local.py
py/dist/py/path/svn/wccommand.py
Log:
- a couple of renames and fixes
- moved the py.path.local move() impl to the FSPathBase
because it is kind of generic
- fs-paths have to offer a "rename" operation actually
which the move() implementation refers to.
Modified: py/dist/py/path/common.py
==============================================================================
--- py/dist/py/path/common.py (original)
+++ py/dist/py/path/common.py Sun Oct 17 06:58:36 2004
@@ -275,3 +275,12 @@
except:
self._except(sys.exc_info())
+ def move(self, target):
+ if target.relto(self):
+ raise py.path.Invalid("cannot move path into a subdirectory of itself")
+ try:
+ self.rename(target)
+ except py.path.Invalid:
+ self.copy(target)
+ self.remove()
+
Deleted: /py/dist/py/path/local/_posix.py
==============================================================================
--- /py/dist/py/path/local/_posix.py Sun Oct 17 06:58:36 2004
+++ (empty file)
@@ -1,111 +0,0 @@
-"""
-module to access local filesystem pathes
-(mostly filename manipulations but also file operations)
-"""
-import os, sys, stat
-
-import py
-#__________________________________________________________
-#
-# Local Path Posix Mixin
-#__________________________________________________________
-
-class PosixMixin:
- # an instance needs to be a local path instance
- def owner(self):
- """ return owner name of file. """
- try:
- from pwd import getpwuid
- return getpwuid(self.stat().st_uid)[0]
- except:
- self._except(sys.exc_info())
-
- def group(self):
- """ return group name of file. """
- try:
- from grp import getgrgid
- return getgrgid(self.stat().st_gid)[0]
- except:
- self._except(sys.exc_info())
-
- def mode(self):
- """ return permission mode of the path object """
- return self.stat().st_mode
-
- def chmod(self, mode, rec=0):
- """ change permissions to the given mode. If mode is an
- integer it directly encodes the os-specific modes.
- (xxx if mode is a string then it specifies access rights
- in '/bin/chmod' style, e.g. a+r).
- if rec is True perform recursively.
- """
- try:
- if not isinstance(mode, int):
- raise NotImplementedError
- if rec:
- for x in self.visit():
- os.chmod(str(x), mode)
- os.chmod(str(self), mode)
- except:
- self._except(sys.exc_info())
-
- def chown(self, user, group, rec=0):
- """ change ownership to the given user and group.
- user and group may be specified by a number or
- by a name. if rec is True change ownership
- recursively.
- """
- uid = getuserid(user)
- gid = getgroupid(group)
- try:
- if rec:
- for x in self.visit(rec=py.path.checker(link=0)):
- os.chown(str(x), uid, gid)
- os.chown(str(self), uid, gid)
- except:
- self._except(sys.exc_info())
-
- def readlink(self):
- """ return value of a symbolic link. """
- try:
- return os.readlink(self.strpath)
- except:
- self._except(sys.exc_info())
-
- def mklinkto(self, oldname):
- """ hard link to an old name. """
- try:
- os.link(str(oldname), str(self))
- except:
- self._except(sys.exc_info())
-
- def mksymlinkto(self, value, absolute=1):
- """ create a symbolic link with the given value (pointing to another name). """
- try:
- if absolute:
- os.symlink(str(value), self.strpath)
- else:
- base = self.common(value)
- # with posix local paths '/' is always a common base
- relsource = self.__class__(value).relto(base)
- reldest = self.relto(base)
- n = reldest.count(self.sep)
- target = self.sep.join(('..', )*n + (relsource, ))
- os.symlink(target, self.strpath)
- except:
- self._except(sys.exc_info())
-
-
-def getuserid(user):
- import pwd
- if isinstance(user, int):
- return user
- entry = pwd.getpwnam(user)
- return entry[2]
-
-def getgroupid(group):
- import grp
- if isinstance(group, int):
- return group
- entry = grp.getgrnam(group)
- return entry[2]
Deleted: /py/dist/py/path/local/_win.py
==============================================================================
--- /py/dist/py/path/local/_win.py Sun Oct 17 06:58:36 2004
+++ (empty file)
@@ -1,8 +0,0 @@
-"""
-module for win-specific local path stuff
-
-(implementor needed :-)
-"""
-
-class WinMixin:
- pass
Modified: py/dist/py/path/local/local.py
==============================================================================
--- py/dist/py/path/local/local.py (original)
+++ py/dist/py/path/local/local.py Sun Oct 17 06:58:36 2004
@@ -11,9 +11,9 @@
from py.__impl__.path import common
if sys.platform == 'win32':
- from py.__impl__.path.local._win import WinMixin as PlatformMixin
+ from py.__impl__.path.local.win import WinMixin as PlatformMixin
else:
- from py.__impl__.path.local._posix import PosixMixin as PlatformMixin
+ from py.__impl__.path.local.posix import PosixMixin as PlatformMixin
class LocalPath(common.FSPathBase, PlatformMixin):
""" the fully specialized local path implementation.
@@ -267,15 +267,6 @@
except:
self._except(sys.exc_info())
- def move(self, target):
- if target.relto(self):
- raise py.path.Invalid("cannot move path into a subdirectory of itself")
- try:
- self.rename(target)
- except py.path.Invalid:
- self.copy(target)
- self.remove()
-
def rename(self, target):
try:
os.rename(str(self), str(target))
Modified: py/dist/py/path/local/test_local.py
==============================================================================
--- py/dist/py/path/local/test_local.py (original)
+++ py/dist/py/path/local/test_local.py Sun Oct 17 06:58:36 2004
@@ -4,11 +4,10 @@
from py.__impl__.path.test.fscommon import CommonFSTests, setuptestfs
class TestLocalPath(CommonFSTests):
- def __init__(self):
- print "tmpdir is", config.tmpdir
- self.root = config.tmpdir / 'local'
- self.root.ensure(dir=1)
- setuptestfs(self.root)
+ def setup_class(cls):
+ cls.root = config.tmpdir / 'TestLocalPath'
+ cls.root.ensure(dir=1)
+ setuptestfs(cls.root)
def test_initialize_curdir(self):
assert str(local()) == os.getcwd()
@@ -146,177 +145,6 @@
tmpdir.remove(rec=1)
-class TestPOSIXLocalPath:
- #root = local(TestLocalPath.root)
- disabled = sys.platform == 'win32'
-
- def __init__(self):
- print "tmpdir is", config.tmpdir
- self.root = config.tmpdir / 'local'
- self.root.ensure(dir=1)
- setuptestfs(self.root)
-
- def test_hardlink(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath.mklinkto(filepath)
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
-
- def test_symlink_are_identical(self):
- tmpdir = local(local.mkdtemp())
- try:
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(filepath)
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
-
- def test_symlink_isfile(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("")
- linkpath.mksymlinkto(filepath)
- assert linkpath.check(file=1)
- assert not linkpath.check(link=0, file=1)
- finally:
- tmpdir.remove(rec=1)
-
- def test_symlink_relative(self):
- tmpdir = local(local.mkdtemp())
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("Hello")
- linkpath.mksymlinkto(filepath, absolute=False)
- assert linkpath.readlink() == "file"
- assert filepath.read() == linkpath.read()
- finally:
- tmpdir.remove(rec=1)
-
- def test_visit_recursive_symlink(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(tmpdir)
- visitor = tmpdir.visit(None, checker(link=0))
- assert list(visitor) == [linkpath]
- #check.equal(list(tmpdir.visit()), [linkpath])
- finally:
- tmpdir.remove(rec=1)
-
- def test_symlink_isdir(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(tmpdir)
- assert linkpath.check(dir=1)
- assert not linkpath.check(link=0, dir=1)
- finally:
- tmpdir.remove(rec=1)
-
- def test_symlink_remove(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- linkpath.mksymlinkto(linkpath) # point to itself
- assert linkpath.check(dir=0)
- assert linkpath.check(link=1)
- linkpath.remove()
- assert not linkpath.check()
- finally:
- tmpdir.remove(rec=1)
-
- def test_realpath_file(self):
- tmpdir = local.mkdtemp()
- try:
- linkpath = tmpdir.join('test')
- filepath = tmpdir.join('file')
- filepath.write("")
- linkpath.mksymlinkto(filepath)
- realpath = linkpath.realpath()
- assert realpath.get('basename') == 'file'
- finally:
- tmpdir.remove(rec=1)
-
- def test_owner(self):
- from pwd import getpwuid
- assert getpwuid(self.root.stat().st_uid)[0] == self.root.owner()
-
- def test_group(self):
- from grp import getgrgid
- assert getgrgid(self.root.stat().st_gid)[0] == self.root.group()
-
- def XXXtest_atime(self):
- # XXX disabled. this test is just not platform independent enough
- # because acesstime resolution is very different through
- # filesystems even on one platform.
- import time
- path = self.root.join('samplefile')
- atime = path.atime()
- time.sleep(1)
- path.read(1)
- assert path.atime() != atime
-
- def testcommondir(self):
- # XXX This is here in local until we find a way to implement this
- # using the subversion command line api.
- p1 = self.root.join('something')
- p2 = self.root.join('otherthing')
- assert p1.commondir(p2) == self.root
- assert p2.commondir(p1) == self.root
-
- def testcommondir_nocommon(self):
- # XXX This is here in local until we find a way to implement this
- # using the subversion command line api.
- p1 = self.root.join('something')
- p2 = local(os.sep+'blabla')
- assert p1.commondir(p2) is None
-
-
- def test_chmod_simple_int(self):
- print "self.root is", self.root
- mode = self.root.mode()
- self.root.chmod(mode/2)
- try:
- assert self.root.mode() != mode
- finally:
- self.root.chmod(mode)
- assert self.root.mode() == mode
-
- def test_chmod_rec_int(self):
- # XXX fragile test
- print "self.root is", self.root
- recfilter = checker(dotfile=0)
- oldmodes = {}
- for x in self.root.visit(rec=recfilter):
- oldmodes[x] = x.mode()
- self.root.chmod(0772, rec=1)
- try:
- for x in self.root.visit(rec=recfilter):
- assert x.mode() & 0777 == 0772
- finally:
- for x,y in oldmodes.items():
- x.chmod(y)
-
- def test_chown_identity(self):
- owner = self.root.owner()
- group = self.root.group()
- self.root.chown(owner, group)
-
- def test_chown_identity_rec_mayfail(self):
- owner = self.root.owner()
- group = self.root.group()
- self.root.chown(owner, group)
-
class TestMisc:
root = local(TestLocalPath.root)
Modified: py/dist/py/path/svn/wccommand.py
==============================================================================
--- py/dist/py/path/svn/wccommand.py (original)
+++ py/dist/py/path/svn/wccommand.py Sun Oct 17 06:58:36 2004
@@ -134,7 +134,7 @@
def copy(self, target):
py.process.cmdexec("svn copy %s %s" %(str(self), str(target)))
- def move(self, target):
+ def rename(self, target):
py.process.cmdexec("svn move --force %s %s" %(str(self), str(target)))
def status(self, updates=0, rec=0):
More information about the pytest-commit
mailing list