Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the FreeBSD Installer #574

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/rosdep2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ def create_default_installer_context(verbose=False):
from .platforms import pip
from .platforms import gem
from .platforms import redhat
from .platforms import freebsd
from .platforms import slackware
from .platforms import source

platform_mods = [arch, cygwin, debian, gentoo, opensuse, osx, redhat, slackware]
platform_mods = [arch, cygwin, debian, gentoo, opensuse, osx, redhat, slackware, freebsd]
installer_mods = [source, pip, gem] + platform_mods

context = InstallerContext()
Expand Down
1 change: 1 addition & 0 deletions src/rosdep2/catkin_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .platforms.osx import BREW_INSTALLER
from .platforms.pip import PIP_INSTALLER
from .platforms.redhat import YUM_INSTALLER
from .platforms.freebsd import PKG_INSTALLER
from .rep3 import download_targets_data
from .rosdistrohelper import get_targets
from .rospkg_loader import DEFAULT_VIEW_KEY
Expand Down
63 changes: 26 additions & 37 deletions src/rosdep2/platforms/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,65 +28,54 @@

# Original from cygwin.py by Tingfan Wu [email protected]
# Modified for FreeBSD by Rene Ladan [email protected]

import os
import subprocess
# Updated for FreeBSD with pkg by Trenton Schulz [email protected]

from rospkg.os_detect import OS_FREEBSD

from .source import SOURCE_INSTALLER
from ..installers import Installer
from .pip import PIP_INSTALLER
from ..installers import PackageManagerInstaller
from ..shell_utils import read_stdout

PKG_ADD_INSTALLER = 'pkg_add'
PKG_INSTALLER = 'pkg'


def register_installers(context):
context.set_installer(PKG_ADD_INSTALLER, PkgAddInstaller())
context.set_installer(PKG_INSTALLER, PkgInstaller())


def register_platforms(context):
context.add_os_installer_key(OS_FREEBSD, SOURCE_INSTALLER)
context.add_os_installer_key(OS_FREEBSD, PKG_ADD_INSTALLER)
context.set_default_os_installer_key(OS_FREEBSD, lambda self: PKG_ADD_INSTALLER)
context.add_os_installer_key(OS_FREEBSD, PKG_INSTALLER)
context.add_os_installer_key(OS_FREEBSD, PIP_INSTALLER)
context.set_default_os_installer_key(OS_FREEBSD, lambda self: PKG_INSTALLER)


def pkg_info_detect_single(p):
if p == 'builtin':
def pkg_detect_single(p, exec_fn):
if p == "builtin":
return True
# The next code is a lot of hassle, but there is no
# better way in FreeBSD using just the base tools
portname = p
if p == 'gtk20':
portname = 'gtk-2.\*'
elif p == 'py-gtk2':
portname = 'py27-gtk-2.\*'
elif p[:9] in ['autoconf2', 'automake1']:
portname = p[:8] + '-' + p[8] + '.' + p[9:] + '\*'
elif p[:3] == 'py-':
portname = 'py27-' + p[3:] + '\*'
else:
portname = p + '-\*'
pop = subprocess.Popen('/usr/sbin/pkg_info -qE ' + portname, shell=True)
return os.waitpid(pop.pid, 0)[1] == 0 # pkg_info -E returns 0 if pkg installed, 1 if not


def pkg_info_detect(packages):
return [p for p in packages if pkg_info_detect_single(p)]


class PkgAddInstaller(Installer):

cmd = ['/usr/sbin/pkg', 'query', '%n', p]
std_out = exec_fn(cmd)
return std_out.split() != []


def pkg_detect(packages, exec_fn=None):
if exec_fn is None:
exec_fn = read_stdout
return [p for p in packages if pkg_detect_single(p, exec_fn)]


class PkgInstaller(PackageManagerInstaller):
"""
An implementation of the Installer for use on FreeBSD-style
systems.
"""

def __init__(self):
super(PkgAddInstaller, self).__init__(pkg_info_detect)
super(PkgInstaller, self).__init__(pkg_detect)

def get_install_command(self, resolved, interactive=True, reinstall=False, quiet=False):
packages = self.get_packages_to_install(resolved, reinstall=reinstall)
if not packages:
return []
else:
# pkg_add does not have a non-interactive command
return [self.elevate_priv(['/usr/sbin/pkg_add', '-r']) + packages]
return [self.elevate_priv(['/usr/sbin/pkg', 'install', '-y']) + packages]
75 changes: 75 additions & 0 deletions test/test_rosdep_freebsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright (c) 2011, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Copied from test_rosdep_suse.py by Author Ken Conley/[email protected]
# Converted to FreeBSD by Trenton Schulz/[email protected]

import os
import traceback
from mock import patch, Mock


def get_test_dir():
# not used yet
return os.path.abspath(os.path.join(os.path.dirname(__file__), 'freebsd'))


def test_pkg_detect():
from rosdep2.platforms.freebsd import pkg_detect

m = Mock()
m.return_value = ''

val = pkg_detect([], exec_fn=m)
assert val == [], val

val = pkg_detect(['tinyxml'], exec_fn=m)
assert val == [], val


def test_PkgInstaller():
from rosdep2.platforms.freebsd import PkgInstaller

@patch.object(PkgInstaller, 'get_packages_to_install')
def test(mock_method):
installer = PkgInstaller()
mock_method.return_value = []
assert [] == installer.get_install_command(['fake'])

# no interactive option with YUM
mock_method.return_value = ['a', 'b']
expected = [['sudo', '-H', '/usr/sbin/pkg', 'install', '-y', 'a', 'b']]
val = installer.get_install_command(['whatever'], interactive=False)
assert val == expected, val
expected = [['sudo', '-H', '/usr/sbin/pkg', 'install', '-y', 'a', 'b']]
val = installer.get_install_command(['whatever'], interactive=True)
assert val == expected, val
try:
test()
except AssertionError:
traceback.print_exc()
raise