Esempio n. 1
0
def _is_deb_based(distro=None):
    if not distro:
        try:
            distro = OsRelease().id()
        except OsReleaseIdError:
            distro = "unknown"
    return distro in _DEB_BASED_PLATFORM
Esempio n. 2
0
    def is_host_compatible_with_base(self):
        codename = None
        with suppress(errors.OsReleaseCodenameError):
            codename = OsRelease().version_codename()
            logger.debug('Running on {!r}'.format(codename))

        # TODO support more bases
        return codename == 'xenial' or codename == 'trusty'
Esempio n. 3
0
def _get_repo_for_platform():
    distro = OsRelease().id()
    if _is_deb_based(distro):
        from ._deb import Ubuntu
        return Ubuntu
    else:
        from ._base import DummyRepo
        return DummyRepo
Esempio n. 4
0
 def message(self):
     message = "The package {!r} was not found.".format(self.package_name)
     # If the package was multiarch, try to help.
     distro = OsRelease().id()
     if _is_deb_based(distro) and ":" in self.package_name:
         (name, arch) = self.package_name.split(":", 2)
         if arch:
             message += (
                 "\nYou may need to add support for this architecture with "
                 "'dpkg --add-architecture {}'.".format(arch))
     return message
Esempio n. 5
0
 def __init__(self):
     try:
         distro = OsRelease().name()
     except errors.OsReleaseNameError:
         distro = "this system"
     super().__init__(distro=distro)
Esempio n. 6
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.snapcraft_command = '/snap/bin/snapcraft'
        elif os.getenv('SNAPCRAFT_FROM_DEB', False):
            self.snapcraft_command = '/usr/bin/snapcraft'
            self.snapcraft_parser_command = '/usr/bin/snapcraft-parser'
        else:
            self.snapcraft_command = os.path.join(os.getcwd(), 'bin',
                                                  'snapcraft')
            self.snapcraft_parser_command = os.path.join(
                os.getcwd(), 'bin', 'snapcraft-parser')

        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.patchelf_command = '/snap/snapcraft/current/bin/patchelf'
        else:
            self.patchelf_command = 'patchelf'

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(
            fixtures.EnvironmentVariable('XDG_CONFIG_HOME',
                                         os.path.join(self.path, '.config')))
        self.useFixture(
            fixtures.EnvironmentVariable('XDG_CACHE_HOME',
                                         os.path.join(self.path, '.cache')))
        self.useFixture(
            fixtures.EnvironmentVariable('XDG_DATA_HOME',
                                         os.path.join(self.path, 'data')))
        self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb'))

        patcher = mock.patch('xdg.BaseDirectory.xdg_config_home',
                             new=os.path.join(self.path, '.config'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch('xdg.BaseDirectory.xdg_data_home',
                             new=os.path.join(self.path, 'data'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch('xdg.BaseDirectory.xdg_cache_home',
                             new=os.path.join(self.path, '.cache'))
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_config_dirs',
                                  new=[xdg.BaseDirectory.xdg_config_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_data_dirs',
                                  new=[xdg.BaseDirectory.xdg_data_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = 'parts'
        self.stage_dir = 'stage'
        self.prime_dir = 'prime'

        project = _ProjectOptions()
        self.deb_arch = project.deb_arch
        self.arch_triplet = project.arch_triplet

        release = OsRelease()
        self.distro_series = release.version_codename()
Esempio n. 7
0
    def setUp(self):
        super().setUp()
        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.snapcraft_command = '/snap/bin/snapcraft'
        elif os.getenv('SNAPCRAFT_FROM_DEB', False):
            self.snapcraft_command = '/usr/bin/snapcraft'
            self.snapcraft_parser_command = '/usr/bin/snapcraft-parser'
        elif os.getenv('VIRTUAL_ENV'):
            self.snapcraft_command = os.path.join(
                os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft')
            self.snapcraft_parser_command = os.path.join(
                os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft-parser')
        else:
            raise EnvironmentError(
                'snapcraft is not setup correctly for testing. Either set '
                'SNAPCRAFT_FROM_SNAP or SNAPCRAFT_FROM_DEB to run from either '
                'the snap or deb, or make sure your venv is properly setup '
                'as described in HACKING.md.')

        if os.getenv('SNAPCRAFT_FROM_SNAP', False):
            self.patchelf_command = '/snap/snapcraft/current/bin/patchelf'
            self.execstack_command = (
                '/snap/snapcraft/current/usr/sbin/execstack')
        else:
            self.patchelf_command = 'patchelf'
            self.execstack_command = 'execstack'

        self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps')
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path

        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_CONFIG_HOME', os.path.join(self.path, '.config')))
        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_CACHE_HOME', os.path.join(self.path, '.cache')))
        self.useFixture(fixtures.EnvironmentVariable(
            'XDG_DATA_HOME', os.path.join(self.path, 'data')))
        self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb'))

        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_config_home',
            new=os.path.join(self.path, '.config'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_data_home',
            new=os.path.join(self.path, 'data'))
        patcher.start()
        self.addCleanup(patcher.stop)
        patcher = mock.patch(
            'xdg.BaseDirectory.xdg_cache_home',
            new=os.path.join(self.path, '.cache'))
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher_dirs = mock.patch(
            'xdg.BaseDirectory.xdg_config_dirs',
            new=[xdg.BaseDirectory.xdg_config_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        patcher_dirs = mock.patch(
            'xdg.BaseDirectory.xdg_data_dirs',
            new=[xdg.BaseDirectory.xdg_data_home])
        patcher_dirs.start()
        self.addCleanup(patcher_dirs.stop)

        # Note that these directories won't exist when the test starts,
        # they might be created after calling the snapcraft command on the
        # project dir.
        self.parts_dir = 'parts'
        self.stage_dir = 'stage'
        self.prime_dir = 'prime'

        self.deb_arch = platform.get_deb_arch()
        self.arch_triplet = platform.get_arch_triplet()

        release = OsRelease()
        self.distro_series = release.version_codename()
Esempio n. 8
0
def _is_deb_based(distro=None):
    if not distro:
        distro = OsRelease().id()
    return distro in _DEB_BASED_PLATFORM
Esempio n. 9
0
 def __init__(self):
     super().__init__(distro=OsRelease().name())