def get_machinekit_hal_changelog_data(self: object) -> None: control_template_file = "{}/debian/control.in".format( self.normalized_path) with open(control_template_file, "r") as reader: control_template_string = reader.read() self.name = re.search( "Source: (.+)\n", control_template_string).group(1).strip().lower() version_file = "{}/VERSION".format(self.normalized_path) with open(version_file, "r") as reader: version_string = reader.read() base_version = version_string.strip().split('.') self.major_version = base_version[0] self.minor_version = base_version[1] self.distro_id = sh.lsb_release("-is", _tty_out=False).strip().replace( " ", "").lower() self.distro_codename = sh.lsb_release("-cs", _tty_out=False).strip().replace( " ", "").lower() self.git_sha = sh.git("rev-parse", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_count = int( sh.git("rev-list", "--count", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip()) self.commiter_name = sh.git("show", "-s", "--pretty=%cn", "HEAD", _tty_out=False, _cwd=self.normalized_path).rstrip('\n') self.commiter_email = sh.git("show", "-s", "--format=%ce", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_message_short = sh.git("show", "-s", "--format=format:%s", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.commit_time = sh.git("show", "-s", "--format=format:%aD", "HEAD", _tty_out=False, _cwd=self.normalized_path).strip() self.debian_host_architecture = sh.dpkg_architecture( "-qDEB_HOST_ARCH", _tty_out=False).strip() self.debian_build_architecture = sh.dpkg_architecture( "-qDEB_BUILD_ARCH", _tty_out=False).strip()
def os_properties(self): namespace = PropertyNamespace('os', _('Operating system')) if LSB: namespace.add_property('is_lsb', _('LSB OS'), True, True) namespace.add_property('distributor_id', _('Distributor ID'), lsb_release('-i', '-s'), True) namespace.add_property('description', _('Description'), lsb_release('-d', '-s'), True) namespace.add_property('release', _('Release'), lsb_release('-r', '-s'), True) namespace.add_property('codename', _('Codename'), lsb_release('-c', '-s'), True) namespace.add_property('sysinfo', _('System info'), uname('-a'), True) else: namespace.add_property('is_lsb', _('LSB OS'), False) namespace.add_property('architecture', _('OS architecture'), platform.architecture(), report=True) namespace.add_property('python_version', _('Python version'), platform.python_version(), report=True) namespace.add_property('hostname', _('Hostname'), platform.node()) namespace.add_property('platform', _('Platform'), sys.platform, report=True) namespace.add_property('machine', _('Machine'), platform.machine(), report=True) namespace.add_property('processor', _('Processor'), platform.processor(), report=True) namespace.add_property('cpus', _('Number of CPUs'), psutil.cpu_count(), report=True) namespace.add_property('total_phymem', _('Total physical memory'), pretty_size(psutil.virtual_memory().total), report=True) namespace.add_property( 'disk_partitions', _('Disk partitions'), '; '.join([ '%s %s %s %s' % (partition.device, partition.mountpoint, partition.fstype, partition.opts) for partition in psutil.disk_partitions() ]))
def get_release_label(): """Gets the right package label from the OS version. Raise exception if not found.""" release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) for k, v in OS_MAPPING.iteritems(): if re.search(k, release): return v raise Exception("Could not find package label for OS version: {0}.".format(release))
def get_platform_release_label(release=None): """Gets the right package label from the OS version. Raise exception if not found. 'release' can be provided to override the underlying OS version. """ if not release: release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) for k, v in OS_MAPPING.iteritems(): if re.search(k, release): return v raise Exception("Could not find package label for OS version: {0}.".format(release))
def get_distribution_codename(): codename = sh.uname().lower().strip() if codename == "linux": # lets try to be more specific using lsb_release try: output = sh.lsb_release("-c") # pylint: disable=E1101 _, codename = output.split("\t") except sh.CommandNotFound as e: pass codename = codename.strip() return codename
def get_release_label(): """Gets the right package label from the OS version""" release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) for k, v in OS_MAPPING.iteritems(): if re.search(k, release): return v print("Pre-built toolchain archives not available for your platform.") print("Clone and build native toolchain from source using this repository:") print(" https://github.com/cloudera/native-toolchain") raise Exception("Could not find package label for OS version: {0}.".format(release))
def os_properties(self): namespace = PropertyNamespace('os', _('Operating system')) if LSB: namespace.add_property('is_lsb', _('LSB OS'), True, True) namespace.add_property('distributor_id', _('Distributor ID'), lsb_release('-i', '-s'), True) namespace.add_property('description', _('Description'), lsb_release('-d', '-s'), True) namespace.add_property('release', _('Release'), lsb_release('-r', '-s'), True) namespace.add_property('codename', _('Codename'), lsb_release('-c', '-s'), True) namespace.add_property('sysinfo', _('System info'), uname('-a'), True) else: namespace.add_property('is_lsb', _('LSB OS'), False) namespace.add_property('architecture', _('OS architecture'), platform.architecture(), report=True) namespace.add_property('python_version', _('Python version'), platform.python_version(), report=True) namespace.add_property('hostname', _('Hostname'), platform.node()) namespace.add_property('platform', _('Platform'), sys.platform, report=True) namespace.add_property('machine', _('Machine'), platform.machine(), report=True) namespace.add_property('processor', _('Processor'), platform.processor(), report=True) namespace.add_property('cpus', _('Number of CPUs'), psutil.cpu_count(), report=True) namespace.add_property('total_phymem', _('Total physical memory'), pretty_size(psutil.virtual_memory().total), report=True) namespace.add_property('disk_partitions', _('Disk partitions'), '; '.join(['%s %s %s %s' % (partition.device, partition.mountpoint, partition.fstype, partition.opts) for partition in psutil.disk_partitions()]))
def get_release_label(): """Gets the right package label from the OS version""" release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) for k, v in OS_MAPPING.iteritems(): if re.search(k, release): return v print("Pre-built toolchain archives not available for your platform.") print( "Clone and build native toolchain from source using this repository:") print(" https://github.com/cloudera/native-toolchain") raise Exception( "Could not find package label for OS version: {0}.".format(release))
def build_packages(self: object): self.assert_parent_dir_writable() try: dpkg_buildpackage_string_arguments = [ "-uc", "-us", "-a", self.architecture, "-B" ] if sh.lsb_release("-cs", _tty_out=False).strip().lower() in [ "stretch", "bionic" ]: dpkg_buildpackage_string_arguments.append("-d") sh.dpkg_buildpackage(*dpkg_buildpackage_string_arguments, _out=sys.stdout.buffer, _err=sys.stderr.buffer, _cwd=self.source_dir) except sh.ErrorReturnCode as e: message = "Packages cannot be built because of an error\n{0}".format( e) raise ValueError(message)
def get_platform_release_label(release=None): """Gets the right package label from the OS version. Raise exception if not found. 'release' can be provided to override the underlying OS version. """ global lsb_release_cache if not release: if lsb_release_cache: release = lsb_release_cache else: release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) # Only need to check against the major release if RHEL or CentOS for platform in ['centos', 'redhatenterpriseserver']: if platform in release: release = release.split('.')[0] break lsb_release_cache = release for mapping in OS_MAPPING: if re.search(mapping.lsb_release, release): return mapping raise Exception("Could not find package label for OS version: {0}.".format(release))
def get_platform_release_label(release=None): """Gets the right package label from the OS version. Raise exception if not found. 'release' can be provided to override the underlying OS version. """ global lsb_release_cache if not release: if lsb_release_cache: release = lsb_release_cache else: release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) # Only need to check against the major release if RHEL or CentOS for platform in ['centos', 'redhatenterpriseserver']: if platform in release: release = release.split('.')[0] break lsb_release_cache = release for k, v in OS_MAPPING.iteritems(): if re.search(k, release): return v raise Exception("Could not find package label for OS version: {0}.".format(release))
def build_packages(self: object): parent_directory = os.path.realpath("{0}/..".format( self.normalized_path)) if not os.access(parent_directory, os.W_OK): raise ValueError( "Directory {0} is not writable.".format(parent_directory)) try: dpkg_buildpackage_string_arguments = [ "-uc", "-us", "-a", self.host_architecture, "-B" ] if sh.lsb_release("-cs", _tty_out=False).strip().lower() in [ "stretch", "bionic" ]: dpkg_buildpackage_string_arguments.append("-d") sh.dpkg_buildpackage(*dpkg_buildpackage_string_arguments, _out=sys.stdout.buffer, _err=sys.stderr.buffer, _cwd=self.normalized_path) except sh.ErrorReturnCode as e: message = "Packages cannot be build because of an error\n{0}".format( e) raise ValueError(message)
def map_release_label(): """Gets the right package label from the OS version""" release = "".join(map(lambda x: x.lower(), sh.lsb_release("-irs").split())) return OS_MAPPING[next(k for k in OS_MAPPING if re.search(k, release))]
import arrow import docker as docker_py from docker.utils import kwargs_from_env from docker.errors import DockerException from stackhut_common import utils from stackhut_common.runtime import rpc from stackhut_common.utils import log from stackhut_toolkit import utils as t_utils template_env = Environment(loader=FileSystemLoader(t_utils.get_res_path('templates'))) # OS Types - for docker flags OS_TYPE = None try: os_str = (str(sh.lsb_release('-i', '-s'))).strip() if os_str in ['Fedora']: OS_TYPE = 'SELINUX' else: OS_TYPE = 'UNKNOWN' except sh.CommandNotFound as e: OS_TYPE = 'UNKNOWN' # TODO - move to docker machine/toolkit instead class DockerClient: client = None ip = 'localhost' x = "https://github.com/boot2docker/boot2docker/blob/master/doc/WORKAROUNDS.md" def __init__(self, _exit, verbose):
import docker as docker_py from docker.utils import kwargs_from_env from docker.errors import DockerException from .common import utils from .common.runtime import rpc from .common.utils import log from . import toolkit_utils template_env = Environment( loader=FileSystemLoader(toolkit_utils.get_res_path('templates'))) # OS Types - for docker flags OS_TYPE = None try: os_str = (str(sh.lsb_release('-i', '-s'))).strip() if os_str in ['Fedora']: OS_TYPE = 'SELINUX' else: OS_TYPE = 'UNKNOWN' except sh.CommandNotFound as e: OS_TYPE = 'UNKNOWN' class DockerMachineState(Enum): NOTEXIST = 1 STOPPED = 2 RUNNING = 3 UNKNOWN = 4