Esempio n. 1
0
 def test_common_ancestor(self):
   self.assertEqual( 'base-1.2.3', file_path.common_ancestor([
     'base-1.2.3/foo.txt',
     'base-1.2.3/bar.txt',
     'base-1.2.3/baz.txt',
   ]) )
   self.assertEqual( 'base-1.2.3', file_path.common_ancestor([
     'base-1.2.3/foo.txt',
     'base-1.2.3/bar.txt',
     'base-1.2.3/here/baz.txt',
   ]) )
   self.assertEqual( 'base-1.2.3', file_path.common_ancestor([
     'base-1.2.3/foo.txt',
     'base-1.2.3/bar.txt',
     'base-1.2.3',
   ]) )
   self.assertEqual( 'base-1.2.3', file_path.common_ancestor([
     'base-1.2.3/foo.txt',
     'base-1.2.3/bar.txt',
     'base-1.2.3/',
   ]) )
   self.assertEqual( None, file_path.common_ancestor([
     'base-1.2.3/foo.txt',
     'base-1.2.3/bar.txt',
     'base-1.2.4/baz.txt',
   ]) )
Esempio n. 2
0
  def test_common_ancestor_more_multiple_ancestors(self):
    self.assert_filename_equal( 'foo/bar/base-1.2.3', file_path.common_ancestor([
      'foo/bar/base-1.2.3/foo.txt',
      'foo/bar/base-1.2.3/bar.txt',
      'foo/bar/base-1.2.3/',
    ]) )

    self.assertEqual( 'foo', file_path.common_ancestor([
      'foo/bar/base-1.2.3/foo.txt',
      'foo/bar/base-1.2.3/bar.txt',
      'foo/baz/base-1.2.3/',
    ]) )
Esempio n. 3
0
 def _find_root_dir_with_file_marker(clazz, files):
     common_ancestor = file_path.common_ancestor(files)
     if not common_ancestor:
         return None
     marker = file_find.find_in_ancestors(common_ancestor, '.bes_test_root')
     if not marker:
         return None
     return path.dirname(marker)
  def dirs(self, package_name, levels, root_dir):
    check.check_string(package_name)

    dirs = self._native_package.package_dirs(package_name)
    if levels:
      dirs = [ self._level_path(p, levels) for p in dirs ]
      dirs = algorithm.unique(dirs)
    if root_dir:
      ancestor = file_path.common_ancestor(dirs)
      if ancestor:
        print(ancestor)
    else:
      for f in dirs:
        print(f)
    return 0
Esempio n. 5
0
    def remove(self, package_name, force_package_root):
        'Remove a package.'
        check.check_string(package_name)
        check.check_bool(force_package_root)

        if not self.is_installed(package_name):
            raise native_package_error(
                'package not installed: "{}"'.format(package_name))
        files = self.package_files(package_name)
        dirs = self.package_dirs(package_name)

        sudo.validate(prompt='sudo password for remove:')
        for filename in files:
            if path.exists(filename):
                args = ['rm', '-f', filename]
                sudo.call_sudo(args)

        sorted_dirs = sorted(dirs, key=lambda d: d.count(os.sep), reverse=True)
        for dirname in sorted_dirs:
            if path.exists(dirname):
                if dir_util.is_empty(dirname):
                    args = ['rmdir', dirname]
                    sudo.call_sudo(args)

        if force_package_root:
            root_dir = file_path.common_ancestor(dirs)
            if root_dir and path.isdir(root_dir):
                if root_dir in [
                        '/', '/Applications', '/Library', '/bin', '/usr/bin',
                        '/usr/local', '/opt'
                ]:
                    raise native_package_error(
                        'Trying to delete a system directory: "{}"'.format(
                            root_dir))
                args = ['rm', '-r', '-f', root_dir]
                sudo.call_sudo(args)

        args = ['--forget', package_name]
        pkgutil.call_pkgutil(args, use_sudo=True)
Esempio n. 6
0
 def test_common_ancestor_just_one_deep_entry(self):
   self.assert_filename_equal( 'foo/base-1.2.3', file_path.common_ancestor([
     'foo/base-1.2.3/foo.txt',
   ]) )
Esempio n. 7
0
 def test_common_ancestor_just_one_entry(self):
   self.assertEqual( 'base-1.2.3', file_path.common_ancestor([
     'base-1.2.3/foo.txt',
   ]) )
Esempio n. 8
0
 def test_common_ancestor_empty_filenames(self):
   self.assertEqual( None, file_path.common_ancestor([]) )
Esempio n. 9
0
 def test_common_ancestor_multiple_ancestors_absolute(self):
   self.assert_filename_equal( '/foo/base-1.2.3', file_path.common_ancestor([
     '/foo/base-1.2.3/foo.txt',
     '/foo/base-1.2.3/bar.txt',
     '/foo/base-1.2.3/',
   ]) )
Esempio n. 10
0
 def _common_base_for_members(clazz, members):
     'Return a common base dir for the given members or None if no common base exists.'
     members = [
         m for m in members if m not in clazz.COMMON_BASE_MEMBERS_EXCLUDE
     ]
     return file_path.common_ancestor(members)