Ejemplo n.º 1
0
 def _determine_type(clazz, filename):
     possible = [archive_tar, archive_zip, archive_xz]
     if host.is_macos():
         possible.append(archive_dmg)
     for p in possible:
         if p.file_is_valid(filename):
             return p
     return None
Ejemplo n.º 2
0
 def _create_tmp_repo(self, *args):
     # make the temp dir predictable on macos
     if host.is_macos():
         d = '/private/tmp'
     else:
         d = None
     tmp_dir = self.make_temp_dir(dir=d)
     git.init(tmp_dir, *args)
     return tmp_dir
Ejemplo n.º 3
0
def _find_impl_class():
    from bes.system.host import host
    if host.is_linux():
        from .vmware_app_linux import vmware_app_linux
        return vmware_app_linux
    elif host.is_macos():
        from .vmware_app_macos import vmware_app_macos
        return vmware_app_macos
    elif host.is_windows():
        from .vmware_app_windows import vmware_app_windows
        return vmware_app_windows
    else:
        host.raise_unsupported_system()
Ejemplo n.º 4
0
class best_cli(cli):
    def __init__(self):
        super(best_cli, self).__init__('best')

    from bes.system.host import host

    COMMAND_GROUPS = []

    if host.is_macos():
        from .best_cli_macos import MACOS_COMMAND_GROUPS
        COMMAND_GROUPS.extend(MACOS_COMMAND_GROUPS)

    if host.is_unix():
        from .best_cli_unix import UNIX_COMMAND_GROUPS
        COMMAND_GROUPS.extend(UNIX_COMMAND_GROUPS)

    if host.is_windows():
        from .best_cli_windows import WINDOWS_COMMAND_GROUPS
        COMMAND_GROUPS.extend(WINDOWS_COMMAND_GROUPS)

    from .best_cli_common import COMMON_COMMAND_GROUPS
    COMMAND_GROUPS.extend(COMMON_COMMAND_GROUPS)

    #@abstractmethod
    def command_group_list(self):
        'Return a list of command groups for this cli.'
        return self.COMMAND_GROUPS

    from bes.cli.cli_env_cli_args import cli_env_cli_args
    from bes.cli.cli_version_cli_args import cli_version_cli_args
    from bes.cli.cli_help_cli_args import cli_help_cli_args
    cli_version_cli_args.version_module_name = 'bes'
    cli_version_cli_args.version_dependencies = None
    COMMANDS = [
        cli_command('env', 'env_add_args', 'Print env information',
                    cli_env_cli_args),
        cli_command('help', 'help_add_args', 'Print help', cli_help_cli_args),
        cli_command('version', 'version_add_args', 'Print version information',
                    cli_version_cli_args),
    ]

    #@abstractmethod
    def command_list(self):
        'Return a list of commands for this cli.'
        return self.COMMANDS

    @classmethod
    def run(clazz):
        raise SystemExit(best_cli().main())
Ejemplo n.º 5
0
#-*- coding:utf-8; mode:python; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*-

from ..system.check import check

from bes.system.host import host
if host.is_macos():
  from .native_package_macos import native_package_macos as native_package
elif host.is_linux():
  from .native_package_linux import native_package_linux as native_package
elif host.is_windows():
  from .native_package_windows import native_package_windows as native_package
else:
  host.raise_unsupported_system()

check.register_class(native_package,
                     name = 'native_package',
                     include_seq = False)
Ejemplo n.º 6
0
class test_python_installation(unit_test):

  @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
  def test_macos_xcode_38(self):
    tmp_dir = python_testing.make_temp_fake_python_installation('3.8',
                                                                '19.2.3',
                                                                'xcode',
                                                                system = 'macos',
                                                                debug = self.DEBUG)

    piv = python_installation(path.join(tmp_dir, 'bin/python3'), system = 'macos')
    self.assertEqual( '3.8', piv.python_version )
    self.assert_filename_equal( path.join(tmp_dir, 'bin/python3'), piv.python_exe )
    self.assert_filename_equal( path.join(tmp_dir, 'bin/pip3'), piv.pip_exe )
    self.assert_filename_list_equal( [ path.join(tmp_dir, 'bin') ], piv.PATH )

  @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
  def test_macos_system_27(self):
    tmp_dir = python_testing.make_temp_fake_python_installation('2.7',
                                                                None,
                                                                'system',
                                                                system = 'macos',
                                                                debug = self.DEBUG)

    piv = python_installation(path.join(tmp_dir, 'bin/python'), system = 'macos')
    self.assertEqual( '2.7', piv.python_version )
    self.assert_filename_equal( path.join(tmp_dir, 'bin/python2.7'), piv.python_exe )
    self.assert_filename_equal( None, piv.pip_exe )
    self.assert_filename_list_equal( [ path.join(tmp_dir, 'bin') ], piv.PATH )

  @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
  def test_macos_brew_37(self):
    tmp_dir = python_testing.make_temp_fake_python_installation('3.7',
                                                                '21.0.1',
                                                                'brew',
                                                                system = 'macos',
                                                                debug = self.DEBUG)

    piv = python_installation(path.join(tmp_dir, 'bin/python3.7'), system = 'macos')
    self.assertEqual( '3.7', piv.python_version )
    self.assert_filename_equal( path.join(tmp_dir, 'bin/python3.7'), piv.python_exe )
    self.assert_filename_equal( path.join(tmp_dir, 'bin/pip3.7'), piv.pip_exe )
    self.assert_filename_list_equal( [ path.join(tmp_dir, 'bin') ], piv.PATH )
    
  @unit_test_function_skip.skip_if(not host.is_windows(), 'not windows')
  def test_windows_python_38(self):
    tmp_dir = python_testing.make_temp_fake_python_installation('3.8',
                                                                '19.2.3',
                                                                None,
                                                                system = 'windows',
                                                                debug = self.DEBUG)

    piv = python_installation(path.join(tmp_dir, 'python.bat'), system = 'windows')
    self.assertEqual( '3.8', piv.python_version )
    self.assert_filename_equal( path.join(tmp_dir, 'python.bat'), piv.python_exe )
    self.assert_filename_equal( path.join(tmp_dir, 'Scripts', 'pip3.8.bat'), piv.pip_exe )
    self.assert_filename_list_equal( [
      tmp_dir,
      path.join(tmp_dir, 'Scripts'),
    ], piv.PATH )

  @unit_test_function_skip.skip_if(not host.is_windows(), 'not windows')
  def test_windows_python_27(self):
    tmp_dir = python_testing.make_temp_fake_python_installation('2.7',
                                                                '20.3.4',
                                                                None,
                                                                system = 'windows',
                                                                debug = self.DEBUG)

    piv = python_installation(path.join(tmp_dir, 'python.bat'), system = 'windows')
    self.assertEqual( '2.7', piv.python_version )
    self.assert_filename_equal( path.join(tmp_dir, 'python.bat'), piv.python_exe )
    self.assert_filename_equal( path.join(tmp_dir, 'Scripts', 'pip2.7.bat'), piv.pip_exe )
Ejemplo n.º 7
0
class test_temp_archive(unit_test):

    DEBUG = unit_test.DEBUG

    #DEBUG = True

    def test_make_temp_archive_tgz(self):
        a = self._make_temp_archive('tgz')
        self.assertTrue(path.isfile(a))
        self.assertTrue(tarfile.is_tarfile(a))
        self.assertFalse(zipfile.is_zipfile(a))

    def test_make_temp_archive_bz2(self):
        a = self._make_temp_archive('tar.bz2')
        self.assertTrue(path.isfile(a))
        self.assertTrue(tarfile.is_tarfile(a))
        self.assertFalse(zipfile.is_zipfile(a))

    def test_make_temp_archive_tar(self):
        a = self._make_temp_archive('tar')
        self.assertTrue(path.isfile(a))
        self.assertTrue(tarfile.is_tarfile(a))
        self.assertFalse(zipfile.is_zipfile(a))

    @unit_test_function_skip.skip_if(not host.is_macos(),
                                     'dmg is only supported on macos')
    def test_make_temp_archive_dmg(self):
        a = self._make_temp_archive('dmg')
        self.assertTrue(path.isfile(a))
        self.assertFalse(tarfile.is_tarfile(a))
        self.assertFalse(zipfile.is_zipfile(a))
        self.spew('checking: %s' % (a))
        self.assertTrue(dmg.is_dmg_file(a))

    def test_make_temp_archive_zip(self):
        a = self._make_temp_archive('zip')
        self.assertTrue(path.isfile(a))
        self.assertTrue(zipfile.is_zipfile(a))
        self.assertFalse(tarfile.is_tarfile(a))

    def test_make_temp_archive_from_file(self):
        tmp_file = temp_file.make_temp_file(content='foo.txt\n',
                                            suffix='.foo.txt')
        tmp_archive = self._make_temp_archive(
            'tgz', items=[temp_archive.item('foo.txt', filename=tmp_file)])
        self.assertTrue(path.isfile(tmp_archive))
        self.assertTrue(tarfile.is_tarfile(tmp_archive))
        self.assertFalse(zipfile.is_zipfile(tmp_archive))
        tmp_dir = temp_file.make_temp_dir()

        with tarfile.open(tmp_archive, mode='r') as archive:
            archive.extractall(path=tmp_dir)
            tmp_member_path = path.join(tmp_dir, 'foo.txt')
            self.assertTrue(path.isfile(tmp_member_path))
            self.assertEqual(b'foo.txt\n', file_util.read(tmp_member_path))

    def _make_temp_archive(self, extension, items=None):
        items = items or [temp_archive.item('foo.txt', content='foo.txt\n')]
        ta = temp_archive.make_temp_archive(items,
                                            extension,
                                            delete=not self.DEBUG)
        if self.DEBUG:
            self.spew('temp_archive(%s): %s' % (extension, ta))
        return ta
Ejemplo n.º 8
0
class test_native_package(unit_test):
    @classmethod
    def setUpClass(clazz):
        unit_test_class_skip.raise_skip_if_not_macos()

    def test_installed_packages(self):
        np = native_package()
        self.assertTrue(len(np.installed_packages()) > 0)

    @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
    def test_package_manifest_macos(self):
        np = native_package()
        manifest = np.package_files(self._macos_example_pkg())
        self.assertTrue(len(manifest) > 0)

    @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
    def test_package_files_macos(self):
        np = native_package()
        files = np.package_files(self._macos_example_pkg())
        self.assertTrue(len(files) > 0)

    @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
    def test_package_info_macos(self):
        np = native_package()
        info = np.package_info(self._macos_example_pkg())
        self.assertTrue(len(info) > 0)

    @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
    def test_is_installed_macos(self):
        np = native_package()
        self.assertFalse(np.is_installed('bash'))
        self.assertTrue(np.is_installed(self._macos_example_pkg()))

    @unit_test_function_skip.skip_if(not host.is_linux(), 'not linux')
    def test_is_installed_linux(self):
        np = native_package()
        self.assertTrue(np.is_installed('bash'))
        self.assertFalse(np.is_installed('foosomethingnottherelikely'))

    @unit_test_function_skip.skip_if(not host.is_macos(), 'not macos')
    def test_owner_macos(self):
        np = native_package()
        pkg = self._macos_example_pkg()
        manifest = np.package_files(pkg)
        self.assertEqual(pkg, np.owner(manifest[0]))

    @unit_test_function_skip.skip_if(not host.is_linux(), 'not linux')
    def test_owner_linux(self):
        np = native_package()
        self.assertEqual('coreutils', np.owner('/bin/ls'))
        self.assertEqual('bash', np.owner('/bin/bash'))

    def test_installed_packages(self):
        np = native_package()
        self.assertTrue(len(np.installed_packages()) > 0)

    @classmethod
    def _macos_example_pkg(clazz):
        if int(host.VERSION_MAJOR) >= 11:
            return 'com.apple.files.data-template'
        else:
            return 'com.apple.pkg.Core'