mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
Revert "Windows symlink: extract rmfile() to utils"
This reverts commit 9b52063279.
This commit is contained in:
@@ -7,7 +7,6 @@ from dvc.command.base import CmdBase
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.logger import Logger
|
||||
from dvc.runtime import Runtime
|
||||
from dvc.utils import rmfile
|
||||
|
||||
|
||||
class DataRemoveError(DvcException):
|
||||
@@ -98,7 +97,7 @@ class CmdDataRemove(CmdBase):
|
||||
self._remove_state_file(data_item)
|
||||
self._remove_cloud_cache(data_item)
|
||||
|
||||
rmfile(data_item.data.relative)
|
||||
os.remove(data_item.data.relative)
|
||||
Logger.debug(u'[Cmd-Remove] Remove data item {}. Success.'.format(data_item.data.relative))
|
||||
pass
|
||||
|
||||
@@ -124,7 +123,7 @@ class CmdDataRemove(CmdBase):
|
||||
|
||||
def _remove_dvc_path(self, dvc_path, name):
|
||||
Logger.debug(u'[Cmd-Remove] Remove {} {}.'.format(name, dvc_path.relative))
|
||||
rmfile(dvc_path.relative)
|
||||
os.remove(dvc_path.relative)
|
||||
self.remove_dir_if_empty(dvc_path.relative)
|
||||
Logger.debug(u'[Cmd-Remove] Remove {}. Success.'.format(name))
|
||||
|
||||
@@ -151,7 +150,7 @@ class CmdDataRemove(CmdBase):
|
||||
else:
|
||||
self.remove_file(file)
|
||||
|
||||
rmfile(target)
|
||||
os.rmdir(target)
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import fasteners
|
||||
|
||||
from dvc.command.run import CmdRun
|
||||
@@ -6,7 +7,6 @@ from dvc.exceptions import DvcException
|
||||
from dvc.path.data_item import NotInDataDirError
|
||||
from dvc.runtime import Runtime
|
||||
from dvc.state_file import StateFile
|
||||
from dvc.utils import rmfile
|
||||
|
||||
|
||||
class ReproError(DvcException):
|
||||
@@ -134,7 +134,7 @@ class ReproChange(object):
|
||||
def reproduce_data_file(self):
|
||||
Logger.debug('Reproducing data item "{}". Removing the file...'.format(
|
||||
self._data_item.data.dvc))
|
||||
rmfile(self._data_item.data.relative)
|
||||
os.remove(self._data_item.data.relative)
|
||||
|
||||
Logger.debug('Reproducing data item "{}". Re-runs cmd: {}'.format(
|
||||
self._data_item.data.relative, ' '.join(self._repro_argv)))
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ from dvc.path.data_item import NotInDataDirError
|
||||
from dvc.repository_change import RepositoryChange
|
||||
from dvc.runtime import Runtime
|
||||
from dvc.state_file import StateFile
|
||||
from dvc.utils import cached_property, rmfile
|
||||
from dvc.utils import cached_property
|
||||
|
||||
|
||||
class RunError(DvcException):
|
||||
@@ -126,7 +126,7 @@ class CmdRun(CmdBase):
|
||||
def remove_new_files(repo_change):
|
||||
for data_item in repo_change.new_data_items:
|
||||
Logger.error('Removing created file: {}'.format(data_item.data.relative))
|
||||
rmfile(data_item.data.relative)
|
||||
os.remove(data_item.data.relative)
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class Logger(object):
|
||||
DEFAULT_LEVEL = 1
|
||||
DEFAULT_LEVEL = 2
|
||||
|
||||
LEVEL = DEFAULT_LEVEL
|
||||
|
||||
|
||||
+3
-21
@@ -2,10 +2,6 @@ import os
|
||||
import stat
|
||||
import shutil
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.logger import Logger
|
||||
|
||||
|
||||
def cached_property(f):
|
||||
def get(self):
|
||||
try:
|
||||
@@ -24,23 +20,9 @@ def cached_property(f):
|
||||
def rmtree(dir):
|
||||
'''Cross platform rmtree()'''
|
||||
if os.name == 'nt':
|
||||
if os.path.exists(dir) and not os.access(dir, os.W_OK):
|
||||
if not os.access(dir, os.W_OK):
|
||||
os.chmod(dir, stat.S_IWUSR)
|
||||
else:
|
||||
raise DvcException('Windows rmtree() error')
|
||||
raise
|
||||
|
||||
before = os.path.exists(dir)
|
||||
|
||||
if os.path.exists(dir) and os.path.islink(dir):
|
||||
os.unlink(dir)
|
||||
else:
|
||||
# shutil.rmtree(dir, ignore_errors=True)
|
||||
shutil.rmtree(dir)
|
||||
# os.remove(dir)
|
||||
|
||||
after = os.path.exists(dir)
|
||||
Logger.error('$$$$$$$$$$$$$$$$$$ rmtree(%s) before=%s, after=%s' % (dir, before, after))
|
||||
|
||||
|
||||
def rmfile(file):
|
||||
os.remove(file)
|
||||
shutil.rmtree(dir, ignore_errors=True)
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ class DirHierarchyEnvironment(BasicEnvironment):
|
||||
self.settings = Settings([], self._git, self._config)
|
||||
|
||||
self.dir1 = os.path.join('dir1')
|
||||
self.dir11 = os.path.join('dir1', 'dir11')
|
||||
self.dir11 = os.path.join('dir1/dir11')
|
||||
self.dir2 = os.path.join('dir2')
|
||||
|
||||
os.mkdir('cache')
|
||||
|
||||
@@ -4,7 +4,6 @@ import tempfile
|
||||
from unittest import TestCase
|
||||
|
||||
from dvc.executor import Executor, ExecutorError
|
||||
from dvc.utils import rmfile, rmtree
|
||||
|
||||
|
||||
class TestExecutor(TestCase):
|
||||
@@ -22,7 +21,7 @@ class TestExecutor(TestCase):
|
||||
fd2.close()
|
||||
|
||||
def tearDown(self):
|
||||
rmtree(self.test_dir)
|
||||
shutil.rmtree(self.test_dir)
|
||||
|
||||
def test_suppress_output(self):
|
||||
output = Executor.exec_cmd_only_success(['ls', self.test_dir])
|
||||
@@ -44,8 +43,8 @@ class TestExecutor(TestCase):
|
||||
expected = {self.file1, self.file2, os.path.basename(stdout_file), os.path.basename(stderr_file)}
|
||||
self.assertEqual(output_set, expected)
|
||||
|
||||
rmfile(stdout_file)
|
||||
rmfile(stderr_file)
|
||||
os.remove(stdout_file)
|
||||
os.remove(stderr_file)
|
||||
|
||||
def test_wrong_command(self):
|
||||
with self.assertRaises(ExecutorError):
|
||||
|
||||
@@ -9,7 +9,6 @@ from dvc.path.factory import PathFactory
|
||||
from dvc.git_wrapper import GitWrapperI
|
||||
from dvc.repository_change import RepositoryChange
|
||||
from dvc.settings import Settings
|
||||
from dvc.utils import rmtree
|
||||
|
||||
|
||||
class BasicTestRepositoryChange(TestCase):
|
||||
@@ -56,7 +55,7 @@ class TestRepositoryChange(BasicTestRepositoryChange):
|
||||
stdout=self._devnull, stderr=None).wait()
|
||||
subprocess.Popen(['git', 'commit', '-m', '"Adding one file3"'],
|
||||
stdout=self._devnull, stderr=None).wait()
|
||||
rmtree(file_to_remove)
|
||||
os.remove(file_to_remove)
|
||||
|
||||
change = RepositoryChange(['ls', '-la'],
|
||||
self.settings,
|
||||
|
||||
Reference in New Issue
Block a user