Quellcode durchsuchen

Remove gclient_utils.RemoveDirectory().

The 'RemoveDirectory()' function in gclient_utils is deprecated and
rmtree() should be used instead for consistency.

This patch modifies all clients in depot_tools to use rmtree() instead
and removes the RemoveDirectory function.

+ The SVNWrapperTestCase.testRevertNoDotSvn() mocking
  expectation has been slightly changed. This was required
  because the test invokes code that used to call
  gclient_utils.RemoveDirectory() directly, while only
  gclient_utils.rmtree() was mocked.

BUG=NONE
R=maruel@chromium.org, ilevy@chromium.org
TEST=manually run gclient_utils_test / gclient_smoketest / scm_unittest / gclient_scm_test

Review URL: https://chromiumcodereview.appspot.com/14134010

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@196133 0039d316-1c4b-4281-b951-d872f2087c98
digit@chromium.org vor 12 Jahren
Ursprung
Commit
dc112ac587
7 geänderte Dateien mit 18 neuen und 22 gelöschten Zeilen
  1. 1 1
      gclient.py
  2. 3 3
      gclient_scm.py
  3. 0 3
      gclient_utils.py
  4. 4 4
      scm.py
  5. 3 3
      testing_support/trial_dir.py
  6. 6 7
      tests/gclient_scm_test.py
  7. 1 1
      tests/gclient_utils_test.py

+ 1 - 1
gclient.py

@@ -1167,7 +1167,7 @@ solutions = [
             # Delete the entry
             # Delete the entry
             print('\n________ deleting \'%s\' in \'%s\'' % (
             print('\n________ deleting \'%s\' in \'%s\'' % (
                 entry_fixed, self.root_dir))
                 entry_fixed, self.root_dir))
-            gclient_utils.RemoveDirectory(e_dir)
+            gclient_utils.rmtree(e_dir)
       # record the current list of entries for next time
       # record the current list of entries for next time
       self._SaveEntries()
       self._SaveEntries()
     return 0
     return 0

+ 3 - 3
gclient_scm.py

@@ -526,7 +526,7 @@ class GitWrapper(SCMWrapper):
         full_path = os.path.join(self.checkout_path, path)
         full_path = os.path.join(self.checkout_path, path)
         if not os.path.islink(full_path):
         if not os.path.islink(full_path):
           print('\n_____ removing unversioned directory %s' % path)
           print('\n_____ removing unversioned directory %s' % path)
-          gclient_utils.RemoveDirectory(full_path)
+          gclient_utils.rmtree(full_path)
 
 
 
 
   def revert(self, options, args, file_list):
   def revert(self, options, args, file_list):
@@ -1080,7 +1080,7 @@ class SVNWrapper(SCMWrapper):
                    'try again.') % (url, self.checkout_path))
                    'try again.') % (url, self.checkout_path))
         # Ok delete it.
         # Ok delete it.
         print('\n_____ switching %s to a new checkout' % self.relpath)
         print('\n_____ switching %s to a new checkout' % self.relpath)
-        gclient_utils.RemoveDirectory(self.checkout_path)
+        gclient_utils.rmtree(self.checkout_path)
         # We need to checkout.
         # We need to checkout.
         command = ['checkout', url, self.checkout_path]
         command = ['checkout', url, self.checkout_path]
         command = self._AddAdditionalUpdateFlags(command, options, revision)
         command = self._AddAdditionalUpdateFlags(command, options, revision)
@@ -1106,7 +1106,7 @@ class SVNWrapper(SCMWrapper):
             and os.path.isdir(full_path)
             and os.path.isdir(full_path)
             and not os.path.islink(full_path)):
             and not os.path.islink(full_path)):
           print('\n_____ removing unversioned directory %s' % status[1])
           print('\n_____ removing unversioned directory %s' % status[1])
-          gclient_utils.RemoveDirectory(full_path)
+          gclient_utils.rmtree(full_path)
 
 
   def updatesingle(self, options, args, file_list):
   def updatesingle(self, options, args, file_list):
     filename = args.pop()
     filename = args.pop()

+ 0 - 3
gclient_utils.py

@@ -158,9 +158,6 @@ def rmtree(path):
 
 
   remove(os.rmdir, path)
   remove(os.rmdir, path)
 
 
-# TODO(maruel): Rename the references.
-RemoveDirectory = rmtree
-
 
 
 def safe_makedirs(tree):
 def safe_makedirs(tree):
   """Creates the directory in a safe manner.
   """Creates the directory in a safe manner.

+ 4 - 4
scm.py

@@ -567,7 +567,7 @@ class SVN(object):
             # Warning: It's bad, it assumes args[2] is the directory
             # Warning: It's bad, it assumes args[2] is the directory
             # argument.
             # argument.
             if os.path.isdir(args[2]):
             if os.path.isdir(args[2]):
-              gclient_utils.RemoveDirectory(args[2])
+              gclient_utils.rmtree(args[2])
           else:
           else:
             # Progress was made, convert to update since an aborted checkout
             # Progress was made, convert to update since an aborted checkout
             # is now an update.
             # is now an update.
@@ -856,7 +856,7 @@ class SVN(object):
       buf.close()
       buf.close()
       return result
       return result
     finally:
     finally:
-      gclient_utils.RemoveDirectory(bogus_dir)
+      gclient_utils.rmtree(bogus_dir)
 
 
   @staticmethod
   @staticmethod
   def _DiffItemInternal(filename, cwd, info, bogus_dir, full_move, revision):
   def _DiffItemInternal(filename, cwd, info, bogus_dir, full_move, revision):
@@ -1054,8 +1054,8 @@ class SVN(object):
           logging.info('os.remove(%s)' % file_path)
           logging.info('os.remove(%s)' % file_path)
           os.remove(file_path)
           os.remove(file_path)
         elif os.path.isdir(file_path):
         elif os.path.isdir(file_path):
-          logging.info('RemoveDirectory(%s)' % file_path)
-          gclient_utils.RemoveDirectory(file_path)
+          logging.info('rmtree(%s)' % file_path)
+          gclient_utils.rmtree(file_path)
         else:
         else:
           logging.critical(
           logging.critical(
             ('No idea what is %s.\nYou just found a bug in gclient'
             ('No idea what is %s.\nYou just found a bug in gclient'

+ 3 - 3
testing_support/trial_dir.py

@@ -43,14 +43,14 @@ class TrialDir(object):
       TrialDir.TRIAL_ROOT = os.path.realpath(tempfile.mkdtemp(prefix='trial'))
       TrialDir.TRIAL_ROOT = os.path.realpath(tempfile.mkdtemp(prefix='trial'))
       atexit.register(self._clean)
       atexit.register(self._clean)
     self.root_dir = os.path.join(TrialDir.TRIAL_ROOT, self.subdir)
     self.root_dir = os.path.join(TrialDir.TRIAL_ROOT, self.subdir)
-    gclient_utils.RemoveDirectory(self.root_dir)
+    gclient_utils.rmtree(self.root_dir)
     os.makedirs(self.root_dir)
     os.makedirs(self.root_dir)
 
 
   def tear_down(self):
   def tear_down(self):
     """Cleans the trial subdirectory for this instance."""
     """Cleans the trial subdirectory for this instance."""
     if not self.leak:
     if not self.leak:
       logging.debug('Removing %s' % self.root_dir)
       logging.debug('Removing %s' % self.root_dir)
-      gclient_utils.RemoveDirectory(self.root_dir)
+      gclient_utils.rmtree(self.root_dir)
     else:
     else:
       logging.error('Leaking %s' % self.root_dir)
       logging.error('Leaking %s' % self.root_dir)
     self.root_dir = None
     self.root_dir = None
@@ -60,7 +60,7 @@ class TrialDir(object):
     """Cleans the root trial directory."""
     """Cleans the root trial directory."""
     if not TrialDir.SHOULD_LEAK:
     if not TrialDir.SHOULD_LEAK:
       logging.debug('Removing %s' % TrialDir.TRIAL_ROOT)
       logging.debug('Removing %s' % TrialDir.TRIAL_ROOT)
-      gclient_utils.RemoveDirectory(TrialDir.TRIAL_ROOT)
+      gclient_utils.rmtree(TrialDir.TRIAL_ROOT)
     else:
     else:
       logging.error('Leaking %s' % TrialDir.TRIAL_ROOT)
       logging.error('Leaking %s' % TrialDir.TRIAL_ROOT)
 
 

+ 6 - 7
tests/gclient_scm_test.py

@@ -55,7 +55,7 @@ class BaseTestCase(GCBaseTestCase, SuperMoxTestBase):
         'CheckCallAndFilterAndHeader')
         'CheckCallAndFilterAndHeader')
     self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
     self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileRead')
     self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
     self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite')
-    self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory')
+    self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'rmtree')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, '_CaptureInfo')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
     self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus')
@@ -210,7 +210,6 @@ class SVNWrapperTestCase(BaseTestCase):
     gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
     gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
     # Checkout.
     # Checkout.
-    gclient_scm.os.path.exists(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
     gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(False)
     gclient_scm.os.path.exists(self.base_path).AndReturn(False)
@@ -226,7 +225,7 @@ class SVNWrapperTestCase(BaseTestCase):
         ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
         ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
         cwd=self.root_dir,
         cwd=self.root_dir,
         file_list=files_list)
         file_list=files_list)
-
+    gclient_scm.gclient_utils.rmtree(self.base_path)
     self.mox.ReplayAll()
     self.mox.ReplayAll()
     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
                             relpath=self.relpath)
                             relpath=self.relpath)
@@ -268,7 +267,7 @@ class SVNWrapperTestCase(BaseTestCase):
     gclient_scm.os.path.isfile(file_path).AndReturn(False)
     gclient_scm.os.path.isfile(file_path).AndReturn(False)
     gclient_scm.os.path.islink(file_path).AndReturn(False)
     gclient_scm.os.path.islink(file_path).AndReturn(False)
     gclient_scm.os.path.isdir(file_path).AndReturn(True)
     gclient_scm.os.path.isdir(file_path).AndReturn(True)
-    gclient_scm.gclient_utils.RemoveDirectory(file_path)
+    gclient_scm.gclient_utils.rmtree(file_path)
     gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
     gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
     gclient_scm.scm.SVN.RunAndGetFileList(
     gclient_scm.scm.SVN.RunAndGetFileList(
         options.verbose,
         options.verbose,
@@ -293,13 +292,13 @@ class SVNWrapperTestCase(BaseTestCase):
     ]
     ]
     gclient_scm.scm.SVN.CaptureStatus(
     gclient_scm.scm.SVN.CaptureStatus(
         None, self.base_path, no_ignore=False).AndReturn(items)
         None, self.base_path, no_ignore=False).AndReturn(items)
-    # RemoveDirectory() doesn't work on path ending with '.', like 'foo/.'.
+    # gclient_utils.rmtree() doesn't work on path ending with '.', like 'foo/.'.
     file_path = self.base_path
     file_path = self.base_path
     gclient_scm.os.path.exists(file_path).AndReturn(True)
     gclient_scm.os.path.exists(file_path).AndReturn(True)
     gclient_scm.os.path.isfile(file_path).AndReturn(False)
     gclient_scm.os.path.isfile(file_path).AndReturn(False)
     gclient_scm.os.path.islink(file_path).AndReturn(False)
     gclient_scm.os.path.islink(file_path).AndReturn(False)
     gclient_scm.os.path.isdir(file_path).AndReturn(True)
     gclient_scm.os.path.isdir(file_path).AndReturn(True)
-    gclient_scm.gclient_utils.RemoveDirectory(file_path)
+    gclient_scm.gclient_utils.rmtree(file_path)
     # pylint: disable=E1120
     # pylint: disable=E1120
     gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
     gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
     gclient_scm.SVNWrapper.update(options, [], ['.'])
     gclient_scm.SVNWrapper.update(options, [], ['.'])
@@ -463,7 +462,7 @@ class SVNWrapperTestCase(BaseTestCase):
     gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
     gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
     gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
     gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
     gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False)
     gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False)
-    gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir'))
+    gclient_scm.gclient_utils.rmtree(join(self.base_path, 'dir'))
 
 
     self.mox.ReplayAll()
     self.mox.ReplayAll()
     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
     scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,

+ 1 - 1
tests/gclient_utils_test.py

@@ -34,7 +34,7 @@ class GclientUtilsUnittest(GclientUtilBase):
         'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision',
         'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision',
         'MakeDateRevision', 'MakeFileAutoFlush', 'MakeFileAnnotated',
         'MakeDateRevision', 'MakeFileAutoFlush', 'MakeFileAnnotated',
         'PathDifference', 'ParseCodereviewSettingsContent', 'NumLocalCpus',
         'PathDifference', 'ParseCodereviewSettingsContent', 'NumLocalCpus',
-        'PrintableObject', 'RemoveDirectory', 'RunEditor',
+        'PrintableObject', 'RunEditor',
         'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper',
         'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper',
         'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'Queue', 're',
         'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'Queue', 're',
         'rmtree', 'safe_makedirs', 'stat', 'subprocess', 'subprocess2', 'sys',
         'rmtree', 'safe_makedirs', 'stat', 'subprocess', 'subprocess2', 'sys',