Changeset 186

Show
Ignore:
Timestamp:
02/28/07 15:52:34 (2 years ago)
Author:
mk
Message:

Fix shutil.rmtree issue on Windows (closes #49).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cheesecake/cheesecake_index.py

    r185 r186  
    3232from util import StdoutRedirector 
    3333from util import time_function 
     34from util import rmtree 
    3435from codeparser import CodeParser 
    3536from __init__ import __version__ as VERSION 
    36 import pep8  
     37import pep8 
    3738 
    3839__docformat__ = 'reStructuredText en' 
     
    13971398            if os.path.isdir(dirname): 
    13981399                self.log("Removing directory %s" % dirname) 
    1399                 shutil.rmtree(dirname) 
     1400                rmtree(dirname) 
    14001401 
    14011402        delete_dir(self.sandbox) 
     
    16261627        self.sandbox_pkg_dir = os.path.join(self.sandbox, self.package_name) 
    16271628        if os.path.isdir(self.sandbox_pkg_dir): 
    1628             shutil.rmtree(self.sandbox_pkg_dir) 
     1629            rmtree(self.sandbox_pkg_dir) 
    16291630 
    16301631        # Call appropriate function to unpack the package. 
  • trunk/cheesecake/util.py

    r184 r186  
    55import shutil 
    66import signal 
     7import stat 
    78import sys 
    89import tarfile 
     
    231232    end = time.time() 
    232233    return ret, end-start 
     234 
     235def rmtree(topdir): 
     236    """Remove the whole directory tree (including subdirectories). 
     237 
     238    Works around some Windows-specific behaviour of shutil.rmtree. 
     239    """ 
     240    all_privileges = stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC 
     241 
     242    # Make all files and diretories writable. 
     243    os.chmod(topdir, all_privileges) 
     244    for root, dirnames, filenames in os.walk(topdir): 
     245        for name in dirnames + filenames: 
     246            try: 
     247                os.chmod(os.path.join(root, name), all_privileges) 
     248            except OSError: 
     249                pass 
     250 
     251    shutil.rmtree(topdir, ignore_errors=True) 
     252 
  • trunk/tests/unit/_mockup_cheesecake.py

    r97 r186  
    77from cheesecake.cheesecake_index import Cheesecake 
    88from cheesecake.cheesecake_index import CheesecakeIndex 
     9from cheesecake.util import rmtree 
    910 
    1011from _helper_cheesecake import create_empty_files_in_directory 
     
    4647 
    4748    def tearDown(self): 
    48         shutil.rmtree(self.temp_top_dir) 
     49        rmtree(self.temp_top_dir) 
    4950        os.unlink(self._mock_logfile) 
    5051 
  • trunk/tests/unit/test_index_pylint.py

    r177 r186  
    66from _helper_cheesecake import DATA_PATH, Glutton, create_empty_file 
    77from cheesecake.cheesecake_index import IndexPyLint 
     8from cheesecake.util import rmtree 
    89from cheesecake import logger 
    910 
     
    4748 
    4849        # Clean up. 
    49         shutil.rmtree(_package_dir) 
     50        rmtree(_package_dir) 
  • trunk/tests/unit/test_index_unit_tested.py

    r136 r186  
    99from cheesecake.cheesecake_index import Cheesecake 
    1010from cheesecake.cheesecake_index import IndexUnitTested 
     11from cheesecake.util import rmtree 
    1112from cheesecake import logger 
    1213 
     
    5758    def tearDown(self): 
    5859        if os.path.exists(self.sandbox_dir): 
    59             shutil.rmtree(self.sandbox_dir) 
     60            rmtree(self.sandbox_dir) 
    6061 
    6162    def test_doctest(self): 
  • trunk/tests/unit/test_index_unittests.py

    r155 r186  
    1010from cheesecake.cheesecake_index import IndexUnitTests 
    1111from cheesecake import logger 
     12from cheesecake.util import rmtree 
    1213 
    1314 
     
    3536    def tearDown(self): 
    3637        if os.path.exists(self.project_dir): 
    37             shutil.rmtree(self.project_dir) 
     38            rmtree(self.project_dir) 
    3839 
    3940    def test_unit_tests_index(self): 
  • trunk/tests/unit/test_init_cleanup.py

    r66 r186  
    66from _helper_cheesecake import DATA_PATH 
    77from cheesecake.cheesecake_index import Cheesecake 
     8from cheesecake.util import rmtree 
    89 
    910 
     
    1213        if hasattr(self, 'cheesecake'): 
    1314            if os.path.isdir(self.cheesecake.sandbox): 
    14                 shutil.rmtree(self.cheesecake.sandbox) 
     15                rmtree(self.cheesecake.sandbox) 
    1516        if hasattr(self, 'logfile'): 
    1617            if os.path.isfile(self.logfile):