From e38fa31f36901f309769403a759979b853983d77 Mon Sep 17 00:00:00 2001 From: Tomer Filiba Date: Sat, 6 Oct 2012 11:49:31 +0200 Subject: [PATCH] fixes to chown. closes #34 --- .gitattributes | 2 ++ plumbum/cmd.py | 20 -------------------- plumbum/local_machine.py | 17 ++++++++++++++++- tests/test_local.py | 3 +-- 4 files changed, 19 insertions(+), 23 deletions(-) create mode 100644 .gitattributes delete mode 100644 plumbum/cmd.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..9e5cb0a31 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.py text eol=lf +*.rst text eol=lf diff --git a/plumbum/cmd.py b/plumbum/cmd.py deleted file mode 100644 index 875dec7e0..000000000 --- a/plumbum/cmd.py +++ /dev/null @@ -1,20 +0,0 @@ -""" -Module hack: ``from plumbum.cmd import ls`` -""" -import sys -from types import ModuleType -from plumbum.local_machine import local - -__all__ = [] - -class LocalModule(ModuleType): - """The module-hack that allows us to use ``from plumbum.cmd import some_program``""" - def __init__(self, name): - ModuleType.__init__(self, name, __doc__) - self.__file__ = None - self.__package__ = ".".join(name.split(".")[:-1]) - def __getattr__(self, name): - return local[name] - -LocalModule = LocalModule("plumbum.cmd") -sys.modules[LocalModule.__name__] = LocalModule diff --git a/plumbum/local_machine.py b/plumbum/local_machine.py index a6269c063..8dfda0b1e 100644 --- a/plumbum/local_machine.py +++ b/plumbum/local_machine.py @@ -7,16 +7,17 @@ import logging import stat import time +import platform from tempfile import mkdtemp from subprocess import Popen, PIPE from contextlib import contextmanager +from types import ModuleType from plumbum.path import Path, FSUser from plumbum.remote_path import RemotePath from plumbum.commands import CommandNotFound, ConcreteCommand from plumbum.session import ShellSession from plumbum.lib import _setdoc -import platform try: from pwd import getpwuid, getpwnam @@ -580,3 +581,17 @@ def tempdir(self): * ``encoding`` - the local machine's default encoding (``sys.getfilesystemencoding()``) """ +#=================================================================================================== +# Module hack: ``from plumbum.cmd import ls`` +#=================================================================================================== +class LocalModule(ModuleType): + """The module-hack that allows us to use ``from plumbum.cmd import some_program``""" + def __init__(self, name): + ModuleType.__init__(self, name, __doc__) + self.__file__ = None + self.__package__ = ".".join(name.split(".")[:-1]) + def __getattr__(self, name): + return local[name] + +LocalModule = LocalModule("plumbum.cmd") +sys.modules[LocalModule.__name__] = LocalModule diff --git a/tests/test_local.py b/tests/test_local.py index dab6b6714..2ced9fd6f 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -15,9 +15,8 @@ def test_basename(self): def test_dirname(self): name = LocalPath("/some/long/path/to/file.txt").dirname self.assertTrue(isinstance(name, LocalPath)) - self.assertEqual("/some/long/path/to", str(name)) + self.assertEqual("/some/long/path/to", str(name).replace("\\", "/")) - # requires being run as root def _test_chown(self): path = LocalPath("/tmp/delme.txt") path.delete()