Пример #1
0
    def testRemove(self):
        self.mox.StubOutWithMock(utils, 'RunCommand')
        path1 = 'gs://bucket/some/gs/path'
        path2 = 'gs://bucket/some/other/path'

        # Set up the test replay script.
        # Run 1, one path.
        utils.RunCommand([self.gsutil, 'rm', path1],
                         redirect_stdout=True,
                         redirect_stderr=True,
                         return_result=True)
        # Run 2, two paths.
        utils.RunCommand([self.gsutil, 'rm', path1, path2],
                         redirect_stdout=True,
                         redirect_stderr=True,
                         return_result=True)
        # Run 3, one path, recursive.
        utils.RunCommand([self.gsutil, 'rm', '-R', path1],
                         redirect_stdout=True,
                         redirect_stderr=True,
                         return_result=True)
        self.mox.ReplayAll()

        # Run the test verification.
        gslib.Remove(path1)
        gslib.Remove(path1, path2)
        gslib.Remove(path1, recurse=True)
        self.mox.VerifyAll()
Пример #2
0
    def testRemove(self):
        gs_path = 'gs://bucket/some/path'
        local_path = '/some/local/path'
        http_path = 'http://host.domain/some/path'

        self.mox.StubOutWithMock(gslib, 'Remove')
        self.mox.StubOutWithMock(filelib, 'Remove')

        # Set up the test replay script.
        # Run 1, two local files.
        filelib.Remove(local_path, local_path + '.1')
        # Run 2, local and GS.
        gslib.Remove(local_path, gs_path, ignore_no_match=True)
        # Run 4, GS and GS
        gslib.Remove(gs_path,
                     gs_path + '.1',
                     ignore_no_match=True,
                     recurse=True)
        # Run 7, local and HTTP
        self.mox.ReplayAll()

        # Run the test verification.
        urilib.Remove(local_path, local_path + '.1')
        urilib.Remove(local_path, gs_path, ignore_no_match=True)
        urilib.Remove(gs_path,
                      gs_path + '.1',
                      ignore_no_match=True,
                      recurse=True)
        self.assertRaises(urilib.NotSupportedForTypes, urilib.Remove,
                          local_path, http_path)
        self.mox.VerifyAll()
Пример #3
0
    def _SetUpDirs(self):
        self.file1_local = os.path.join(self.filesdir, self.FILE1)
        self.file2_local = os.path.join(self.filesdir, self.FILE2)
        self.subdir_local = os.path.join(self.filesdir, self.SUBDIR)
        self.subfile_local = os.path.join(self.filesdir, self.SUBFILE)

        self.file1_gs = os.path.join(self.GS_DIR, self.FILE1)
        self.file2_gs = os.path.join(self.GS_DIR, self.FILE2)
        self.subdir_gs = os.path.join(self.GS_DIR, self.SUBDIR)
        self.subfile_gs = os.path.join(self.GS_DIR, self.SUBFILE)

        # Pre-populate local dir with contents.
        with open(self.file1_local, 'w') as out1:
            out1.write(self.FILE1_CONTENTS)

        with open(self.file2_local, 'w') as out2:
            out2.write(self.FILE2_CONTENTS)

        os.makedirs(self.subdir_local)

        with open(self.subfile_local, 'w') as out3:
            out3.write(self.SUBFILE_CONTENTS)

        # Make sure gs:// directory is ready (empty).
        gslib.Remove(os.path.join(self.GS_DIR, '*'),
                     recurse=True,
                     ignore_no_match=True)
Пример #4
0
  def testRemoveNoMatch(self):
    path = 'gs://bucket/some/gs/path'

    # Set up the test replay script.
    cmd = [self.gsutil, 'rm', path]
    cros_build_lib.RunCommand(cmd, redirect_stdout=True, redirect_stderr=True)
    self.mox.ReplayAll()

    # Run the test verification.
    gslib.Remove(path, ignore_no_match=True)
    self.mox.VerifyAll()
Пример #5
0
  def testRemove(self):
    path1 = 'gs://bucket/some/gs/path'
    path2 = 'gs://bucket/some/other/path'

    # Set up the test replay script.
    # Run 1, one path.
    cros_build_lib.RunCommand([self.gsutil, 'rm', path1],
                              redirect_stdout=True, redirect_stderr=True)
    # Run 2, two paths.
    cros_build_lib.RunCommand([self.gsutil, 'rm', path1, path2],
                              redirect_stdout=True, redirect_stderr=True)
    # Run 3, one path, recursive.
    cros_build_lib.RunCommand([self.gsutil, 'rm', '-R', path1],
                              redirect_stdout=True, redirect_stderr=True)
    self.mox.ReplayAll()

    # Run the test verification.
    gslib.Remove(path1)
    gslib.Remove(path1, path2)
    gslib.Remove(path1, recurse=True)
    self.mox.VerifyAll()
Пример #6
0
    def testRemoveNoMatch(self):
        self.mox.StubOutWithMock(utils, 'RunCommand')
        path = 'gs://bucket/some/gs/path'

        # Set up the test replay script.
        cmd = [self.gsutil, 'rm', path]
        utils.RunCommand(cmd,
                         redirect_stdout=True,
                         redirect_stderr=True,
                         return_result=True)
        self.mox.ReplayAll()

        # Run the test verification.
        gslib.Remove(path, ignore_no_match=True)
        self.mox.VerifyAll()
Пример #7
0
  def testRemoveNotFoundExceptionIgnoreNoMatch(self):
    """Verify that setting ignore_no_match to True ignores NotFoundExceptions"""
    path = 'gs://bucket/some/gs/path/that/totally/does/not/exist'

    # Set up the test replay script.
    cmd = [self.gsutil, 'rm', '-R', path]
    failure_msg = 'Removing ' + path + '...\nNotFoundException: 404 ' + path
    self.cmd_result.error = failure_msg
    error = cros_build_lib.RunCommandError(failure_msg, self.cmd_result)
    cros_build_lib.RunCommand(cmd, redirect_stdout=True,
                              redirect_stderr=True).AndRaise(error)
    self.mox.ReplayAll()

    # Run the test verification.
    gslib.Remove(path, recurse=True, ignore_no_match=True)
    self.mox.VerifyAll()
Пример #8
0
def Remove(*args, **kwargs):
  """Delete the file(s) at uris, or directory(s) with recurse set.

  Args:
    args: One or more URIs.
    ignore_no_match: If True, then do not complain if anything was not
      removed because no URI match was found.  Like rm -f.  Defaults to False.
    recurse: Remove recursively starting at path.  Same as rm -R.  Defaults
      to False.
  """
  uri_types = set([GetUriType(u) for u in args])

  if TYPE_GS in uri_types:
    # GS support only allows local files among list.
    if len(uri_types) == 1 or (TYPE_LOCAL in uri_types and len(uri_types) == 2):
      return gslib.Remove(*args, **kwargs)

  if TYPE_LOCAL in uri_types and len(uri_types) == 1:
    return filelib.Remove(*args, **kwargs)

  raise NotSupportedForTypes(*list(uri_types))