Skip to content

Commit

Permalink
fixes to chown. closes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerfiliba committed Oct 6, 2012
1 parent cb7bd87 commit e38fa31
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.py text eol=lf
*.rst text eol=lf
20 changes: 0 additions & 20 deletions plumbum/cmd.py

This file was deleted.

17 changes: 16 additions & 1 deletion plumbum/local_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e38fa31

Please sign in to comment.