def os_check(): global os_platform, os_distro, os_version supported_os_platform = ['Linux'] supported_os_dist_debian = ['LinuxMint', 'debian', 'Ubuntu'] supported_os_dist_fedora = ['fedora', 'redhat', 'centos', 'Red Hat Enterprise Linux Server', 'CentOS'] supported_os_version_debian = [7, 8, 12, 14, 15, 17] supported_os_version_fedora = [6, 7] # getting the running OS details os_platform = platform.system() os_distro = platform.linux_distribution()[0] os_version = int(float(platform.linux_distribution()[1])) # checking the OS type if os_platform not in supported_os_platform: print colour.FAIL + ("Sorry, you are running on the %s platform which is NOT supported." % (os_platform)) + colour.ENDC sys.exit() # checking the OS distro if platform.linux_distribution()[0] in supported_os_dist_fedora: if os_version not in supported_os_version_fedora: print colour.FAIL + ("Sorry, you are running an OS based on %s with the major version %d which is NOT supported." % (os_distro, os_version)) + colour.ENDC sys.exit() elif platform.linux_distribution()[0] in supported_os_dist_debian: if os_version not in supported_os_version_debian: print colour.FAIL + ("Sorry, you are running an OS based on %s with the major version %d which is NOT supported." % (os_distro, os_version)) + colour.ENDC sys.exit() else: print colour.FAIL + ("Sorry, you are running an OS based on %s which is NOT supported." % (os_distro)) + colour.ENDC sys.exit() print colour.OKGREEN + "You are running a supported %s based OS with the major version %d." % (os_distro, os_version) + colour.ENDC
def build_c_unit_tests(): """ Builds unit tests in C """ libraryPath = ''; fileName = '' if ('win32' in sys.platform): fileName = 'cmocka.dll' if '64' in platform.machine(): libraryPath = 'code-experiments/test/unit-test/lib/win64' elif ('32' in platform.machine()) or ('x86' in platform.machine()): if 'cygwin' in os.environ['PATH']: libraryPath = 'code-experiments/test/unit-test/lib/win32_cygwin' else: libraryPath = 'code-experiments/test/unit-test/lib/win32_mingw' elif ('linux' in sys.platform): fileName = 'libcmocka.so' if 'Ubuntu' in platform.linux_distribution(): libraryPath = 'code-experiments/test/unit-test/lib/linux_ubuntu' elif 'Fedora' in platform.linux_distribution(): libraryPath = 'code-experiments/test/unit-test/lib/linux_fedora' elif ('darwin' in sys.platform): # Mac libraryPath = 'code-experiments/test/unit-test/lib/macosx' fileName = 'libcmocka.dylib' if (len(libraryPath) > 0): copy_file(os.path.join(libraryPath, fileName), os.path.join('code-experiments/test/unit-test', fileName)) copy_file('code-experiments/build/c/coco.c', 'code-experiments/test/unit-test/coco.c') copy_file('code-experiments/src/coco.h', 'code-experiments/test/unit-test/coco.h') make("code-experiments/test/unit-test", "clean") make("code-experiments/test/unit-test", "all")
def capture(): """ Capture current OS information """ result = OSInfo() result.family = OSInfo.family() if result.family == "windows": # i.e: subfamily = '7', version = "6.66612" result.subfamily = platform.release() result.version = Version(platform.version()) elif result.family == "linux": result.subfamily = platform.linux_distribution()[0] result.version = Version(platform.linux_distribution()[1]) elif result.family == "macos": result.subfamily = None result.version = Version(platform.mac_ver()[0]) elif result.family == "java": result.subfamily = " ".join(platform.java_ver()[2]) result.version = Version(platform.release()) else: result.subfamily = None # Default value is none in ToolInfo result.version = Version() # Default value is Version() in ToolInfo result.arch = OSInfo.architecture() return result
def install_command(self): """ Creates the installation command for the instance of the class. :param return: A string with the installation command. An empty string if the command could not be supplied. """ manager_dict = {'Fedora': 'dnf', 'Ubuntu': 'apt_get', 'Debian': 'apt_get', 'SuSE': 'zypper', 'redhat': 'yum', 'arch': 'pacman'} if (platform.linux_distribution()[0] in manager_dict.keys() and manager_dict[platform.linux_distribution()[0]] in self.package.keys()): manager = manager_dict[platform.linux_distribution()[0]] return [manager.replace("_", "-"), 'install', self.package[manager]] else: package_possibilites = ( {package for package in self.package.values()}) print('The package could not be automatically installed on your ' 'operating system. Please try installing it manually. It' ' should look like this: ' + repr(package_possibilites)) raise OSError
def get_platform_info(f): """ This function will capture specific platform information, such as OS name, architecture, and linux distro. """ f.write('\n\n================PLATFORM INFORMATION================\n') f.write('Platform: ') f.write(platform.system()) f.write('\n') f.write('Operating System: ') f.write(platform.platform()) f.write('\n') f.write('Architecture: ') f.write(str(platform.architecture())) f.write('\n') if platform.system()=="Linux": try: pld = platform.linux_distribution() if(pld): f.write('Linux Distribution: ') f.write(str(platform.linux_distribution())) f.write('\n') except Exception as exc: f.write('This Linux distribution does not support linux_distribution var:\n') f.write(str(exc)) f.write('\n\n')
def prepare_url(self): """ Prepare URL based on platform information """ if platform.system() == 'Darwin': self.version = 'osx-x86_64-1.1.0' else: # Linux distributions distro, version, machine = (platform.linux_distribution()[0], platform.linux_distribution()[1], platform.machine()) if distro == 'debian' and LooseVersion(version) >= LooseVersion('8.0') and machine == 'x86_64': self.version = 'ubuntu1404-x86_64-1.1.0' elif distro == 'debian' and LooseVersion(version) < LooseVersion('7.0') and machine == 'x86_64': self.version = 'ubuntu1204-x86_64-1.1.0' elif distro == 'Ubuntu' and LooseVersion(version) >= LooseVersion('14.04') and machine == 'x86_64': self.version = 'ubuntu1404-x86_64-1.1.0' elif distro == 'Ubuntu' and LooseVersion(version) < LooseVersion('14.04') and machine == 'x86_64': self.version = 'ubuntu1204-x86_64-1.1.0' elif distro == 'CentOS Linux' and LooseVersion(version) >= LooseVersion('7.3') and machine == 'x86_64': self.version = 'ubuntu1404-x86_64-1.1.0' elif machine == 'armv7l': # Raspberry, etc self.version = 'rpi-arm-raspbian-8.0-1.1.0' else: raise ValueError('Unsupported distribution, please create ticket at: {0!s}'.format(__issuesurl__)) self.url = 'https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/{0!s}.tar.bz2'.format(self.version)
def platform_information(): """detect platform information from remote host.""" logging.debug('platform_information: linux_distribution = ' + str(platform.linux_distribution())) distro, release, codename = platform.linux_distribution() # this could be an empty string in Debian if not codename and 'debian' in distro.lower(): debian_codenames = { '8': 'jessie', '7': 'wheezy', '6': 'squeeze', } major_version = release.split('.')[0] codename = debian_codenames.get(major_version, '') # In order to support newer jessie/sid or wheezy/sid strings # we test this if sid is buried in the minor, we should use # sid anyway. if not codename and '/' in release: major, minor = release.split('/') if minor == 'sid': codename = minor else: codename = major return ( str(distro).rstrip(), str(release).rstrip(), str(codename).rstrip() )
def __init__(self, args): self.args = args self.base_name = _base_name self.uname = platform.platform() self.arch = platform.machine() if self.uname.upper().find('DARWIN') != -1: self.me = 'darwin' self.version = '.'.join(platform.mac_ver()[0].split('.')[:-1]) self.release = _mac_version_to_name[self.version] else: # See if linux_distribution is going to provide anything useful self.me = 'linux' self.release, self.version, junk = [x.replace(' ', '') for x in platform.linux_distribution()] if self._linux_detection() is not True: if self.args.force is not True: print 'I am unable to properly determine your system release or version:', \ '\n\t', ' '.join(platform.linux_distribution()), \ '\nSometimes using a non-system specific version of python (like miniconda) will', \ '\nreport platform identifiers incorrectly. Please make sure that `python` is', \ '\n/usr/bin/python' sys.exit(1) else: print 'You have opted to force package creation regardless of package name.', \ '\nThis will cause the finished package to be named non-accordingly,', \ '\nas well as not being easily version controlled.' self.release = 'generic' self.version = '1.0' self.version_template = self._getVersionTemplate() self.redistributable_version = self._get_build_version() self.redistributable_name = '-'.join([self.base_name, str(self.redistributable_version)]) + '_' + \ '-'.join([self.release, self.version]) + '_' + \ self.arch + '.' + \ self.__class__.__name__.lower() self.temp_dir = tempfile.mkdtemp()
def get_distro(): if "FreeBSD" in platform.system(): release = re.sub("\-.*\Z", "", ustr(platform.release())) osinfo = ["freebsd", release, "", "freebsd"] elif "linux_distribution" in dir(platform): osinfo = list( platform.linux_distribution( full_distribution_name=0, supported_dists=platform._supported_dists + ("alpine",) ) ) full_name = platform.linux_distribution()[0].strip() osinfo.append(full_name) else: osinfo = platform.dist() # The platform.py lib has issue with detecting oracle linux distribution. # Merge the following patch provided by oracle as a temporary fix. if os.path.exists("/etc/oracle-release"): osinfo[2] = "oracle" osinfo[3] = "Oracle Linux" # The platform.py lib has issue with detecting BIG-IP linux distribution. # Merge the following patch provided by F5. if os.path.exists("/shared/vadc"): osinfo = get_f5_platform() # Remove trailing whitespace and quote in distro name osinfo[0] = osinfo[0].strip('"').strip(" ").lower() return osinfo
def test_linux_distribution_deprecation(self): with self.assertWarns(PendingDeprecationWarning) as cm: platform.linux_distribution() self.assertEqual(str(cm.warning), 'dist() and linux_distribution() functions are ' 'deprecated in Python 3.5 and will be removed in ' 'Python 3.7')
def __init__(self, node_id): self.props = {} self.node_id = node_id self.host = gethostname().lower() self.os = platform.system() self.arch = platform.machine() try: # only OS, not version self.dist = platform.linux_distribution()[0] if not self.dist: # Try a hack for ArchLinux self.dist = platform.linux_distribution( supported_dists=('arch'))[0] # only OS, not version except: # Python < 2.6 self.dist = platform.dist()[0] # only OS, not version self.release = platform.release() self.ips = [] try: self.ips = get_local_ips() except: pass if not self.ips: LOG.warn("No IPs were detected") self.crn_version = VERSION
def finalize_options(self): '''Overloaded build_ext implementation to append custom openssl include file and library linking options''' build_ext.build_ext.finalize_options(self) opensslIncludeDir = os.path.join(self.openssl, 'include') opensslLibraryDir = os.path.join(self.openssl, 'lib') # opensslconf.h has moved to /usr/include/x86_64-linux-gnu/openssl/ on Ubuntu 13.10 (Saucy) if platform.linux_distribution()[0] == 'Ubuntu' and platform.linux_distribution()[1] == '13.10': if platform.architecture()[0] == '64bit': self.include_dirs.append(os.path.join(opensslIncludeDir, 'x86_64-linux-gnu')) self.swig_opts = ['-I%s' % i for i in self.include_dirs + \ [opensslIncludeDir]] self.swig_opts.append('-includeall') #self.swig_opts.append('-D__i386__') # Uncomment for early OpenSSL 0.9.7 versions, or on Fedora Core if build fails #self.swig_opts.append('-DOPENSSL_NO_EC') # Try uncommenting if you can't build with EC disabled self.include_dirs += [os.path.join(self.openssl, opensslIncludeDir), os.path.join(os.getcwd(), 'SWIG')] if sys.platform == 'cygwin': # Cygwin SHOULD work (there's code in distutils), but # if one first starts a Windows command prompt, then bash, # the distutils code does not seem to work. If you start # Cygwin directly, then it would work even without this change. # Someday distutils will be fixed and this won't be needed. self.library_dirs += [os.path.join(self.openssl, 'bin')] self.library_dirs += [os.path.join(self.openssl, opensslLibraryDir)]
def FromCurrentSystem(cls): """Fill a Uname from the currently running platform.""" uname = platform.uname() fqdn = socket.getfqdn() system = uname[0] architecture, _ = platform.architecture() if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = platform.linux_distribution()[0] # Ubuntu version = platform.linux_distribution()[1] # 12.04 return cls(system=system, architecture=architecture, node=uname[1], release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn, libc_ver="_".join(platform.libc_ver()), )
def get_template_options(template): ''' Get lxc template options: arch & releases ''' result = { "arch" : [], "releases" : [], "system" : { "arch" : platform.machine(), "release" : platform.linux_distribution()[2], } } # XXX: some distros arch not equal to system arch... # Dunno what to do, maybe aliases in templates.conf... if result["system"]["arch"] == "x86_64": if platform.linux_distribution()[0] in ('Debian', 'Ubuntu'): result["system"]["arch"] = 'amd64' if not os.path.isfile('templates.conf'): return result config = configparser.SafeConfigParser(allow_no_value=True) config.readfp(open('templates.conf')) if config.has_section(template): if config.has_option(template, 'releases'): result['releases'].extend( config.get(template, 'releases').split(',') ) elif config.has_section('default'): if config.has_option('default', 'releases'): result['releases'].extend( config.get('default', 'releases').split(',') ) return result
def run_checks(): print "************************************" print "* Running checks on the system ... *" print "************************************" privledge_check() kernel = platform.system() global OS global flavor global version if kernel == 'Linux': OS = "Linux" flavor = platform.linux_distribution()[0] version = platform.linux_distribution()[1] if not QUIET: print str(flavor) + "(" + str(OS) + ")" + str(version) check_linux_folders() elif kernel == 'Darwin': OS = "OSX" flavor = "Unknown" version = platform.mac_ver()[0] if not QUIET: print str(OS) + " " + str(version) check_osx_folders() else: print "ERROR::Unknown OS. Cannot confirm that installation will be successful. Process will not continue." sys.exit() print
def get_system_type(): print platform.system() print platform.machine() print platform.mac_ver() print platform.win32_ver() print platform.linux_distribution() print platform.platform()
def get_noexec(noexec=''): """ Get the sudo noexec file path, if available. This will allow us to prevent applications from executing random commands thus escaping the shell """ if sys.platform.startswith('freebsd'): noexec = '/usr/local/libexec/sudo_noexec.so' elif sys.platform.startswith('netbsd'): noexec = '/usr/pkg/libexec/sudo_noexec.so' elif sys.platform.startswith('linux'): if platform.linux_distribution(full_distribution_name=0)[0] in ('centos', 'redhat'): noexec = '/usr/libexec/sudo_noexec.so' elif platform.linux_distribution(full_distribution_name=0)[0] in ('fedora'): noexec = '/usr/libexec/sudo/sudo_noexec.so' elif platform.linux_distribution(full_distribution_name=0)[0] in ('debian', 'ubuntu', 'SuSE'): noexec = '/usr/lib/sudo/sudo_noexec.so' if os.path.isfile(noexec): return 'LD_PRELOAD=%s' % noexec else: return 'LD_PRELOAD='
def Run(self, unused_args): """Populate platform information into a Uname response.""" uname = platform.uname() fqdn = socket.getfqdn() system = uname[0] if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = platform.linux_distribution()[0] # Ubuntu version = platform.linux_distribution()[1] # 12.04 self.SendReply(system=system, node=uname[1], release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn)
def version(bot, trigger): version = 'v2.7' if platform.system() == 'Linux': osver = ("%s %s" % (platform.linux_distribution()[0], platform.linux_distribution()[1])) elif platform.system() == 'Windows': osver = ("%s %s" % (platform.system(), platform.release())) else: osver = ("some OS which is not Linux or Windows") pyver = sys.version.split()[0] commit = git_info() latestver, latesturl = get_latest_version() if latestver != version: if bot.config.lang == 'ca': latestmsg = u"L'última versió estable disponible de Grantota és \x02%s\x02 (%s)." % (latestver, latesturl) elif bot.config.lang == 'es': latestmsg = u"La última versión estable disponible de Granota es \x02%s\x02 (%s)." % (latestver, latesturl) else: latestmsg = u"The lastest stable version of Granota available is \x02%s\x02 (%s)." % (latestver, latesturl) else: if bot.config.lang == 'ca': latestmsg = u"Estic utilitzant l'última versió estable de Granota." elif bot.config.lang == 'es': latestmsg = u"Estoy usando la última versión estable de Granota." else: latestmsg = u"I'm using the latest stable version of Granota." if commit == '': commitinfo = '' else: commitinfo = ' (commit %s)' % commit if bot.config.lang == 'ca': bot.say(u"Sóc \x02Granota %s\x02%s, en el sistema operatiu %s i utilitzant Python %s. %s" % (version, commitinfo, osver, pyver, latestmsg)) elif bot.config.lang == 'es': bot.say(u"Soy \x02Granota %s\x02%s, en el sistema operativo %s y usando Python %s. %s" % (version, commitinfo, osver, pyver, latestmsg)) else: bot.say(u"I'm \x02Granota %s\x02%s, on %s and using Python %s. %s" % (version, commitinfo, osver, pyver, latestmsg))
def installQt(self): qt5InstallPath = self.getQt5InstallPath() if not os.path.isdir(qt5InstallPath): print ('Downloading Qt from AWS') dest, tail = os.path.split(qt5InstallPath) url = 'NOT DEFINED' if platform.system() == 'Windows': url = 'https://hifi-public.s3.amazonaws.com/dependencies/vcpkg/qt5-install-5.12.3-windows2.tar.gz' elif platform.system() == 'Darwin': url = 'https://hifi-public.s3.amazonaws.com/dependencies/vcpkg/qt5-install-5.12.3-macos2.tar.gz' elif platform.system() == 'Linux': if platform.linux_distribution()[1][:3] == '16.': url = 'https://hifi-public.s3.amazonaws.com/dependencies/vcpkg/qt5-install-5.12.3-ubuntu-16.04.tar.gz' elif platform.linux_distribution()[1][:3] == '18.': url = 'https://hifi-public.s3.amazonaws.com/dependencies/vcpkg/qt5-install-5.12.3-ubuntu-18.04.tar.gz' else: print('UNKNOWN LINUX VERSION!!!') else: print('UNKNOWN OPERATING SYSTEM!!!') print('Extracting ' + url + ' to ' + dest) hifi_utils.downloadAndExtract(url, dest) else: print ('Qt has already been downloaded')
def get_linux_distribution(get_full_name, supported_dists): """Abstract platform.linux_distribution() call which is deprecated as of Python 3.5 and removed in Python 3.7""" try: supported = platform._supported_dists + (supported_dists,) osinfo = list( platform.linux_distribution( full_distribution_name=get_full_name, supported_dists=supported ) ) # The platform.linux_distribution() lib has issue with detecting OpenWRT linux distribution. # Merge the following patch provided by OpenWRT as a temporary fix. if os.path.exists("/etc/openwrt_release"): osinfo = get_openwrt_platform() if not osinfo or osinfo == ['', '', '']: return get_linux_distribution_from_distro(get_full_name) full_name = platform.linux_distribution()[0].strip() osinfo.append(full_name) except AttributeError: return get_linux_distribution_from_distro(get_full_name) return osinfo
def check_ubuntu(): ''' return the System version ''' dist = '%s %s' % (platform.linux_distribution()[0], platform.linux_distribution()[1]) return dist
def get_distro(): if 'FreeBSD' in platform.system(): release = re.sub('\-.*\Z', '', ustr(platform.release())) osinfo = ['freebsd', release, '', 'freebsd'] elif 'linux_distribution' in dir(platform): supported = platform._supported_dists + ('alpine',) osinfo = list(platform.linux_distribution(full_distribution_name=0, supported_dists=supported)) full_name = platform.linux_distribution()[0].strip() osinfo.append(full_name) else: osinfo = platform.dist() # The platform.py lib has issue with detecting oracle linux distribution. # Merge the following patch provided by oracle as a temporary fix. if os.path.exists("/etc/oracle-release"): osinfo[2] = "oracle" osinfo[3] = "Oracle Linux" if os.path.exists("/etc/euleros-release"): osinfo[0] = "euleros" # The platform.py lib has issue with detecting BIG-IP linux distribution. # Merge the following patch provided by F5. if os.path.exists("/shared/vadc"): osinfo = get_f5_platform() if os.path.exists("/etc/cp-release"): osinfo = get_checkpoint_platform() # Remove trailing whitespace and quote in distro name osinfo[0] = osinfo[0].strip('"').strip(' ').lower() return osinfo
def collect_job(): config = utils.get_config() disks = config[utils.DISK_SECTION] interfaces = config[utils.INET_SECTION] account = Account(config[utils.GENERAL_SECTION].get('email'), config[utils.GENERAL_SECTION].get('user_key'), config[utils.GENERAL_SECTION].get('api_key')) report = {} usage = {} net = {} if os.name == 'nt': report['os'] = platform.system()+"-"+platform.win32_ver()[0]+" "+platform.win32_ver()[2] report['arch'] = platform.architecture()[0] else: report['loadAverage'] = {} if not os.name == 'nt': for idx, la in enumerate(os.getloadavg()): time_la = "1" if idx == 0 else "5" if idx == 2 else "15" report['loadAverage'][time_la] = "{0:.2f}".format(la) if platform.system() == 'Linux': report['os'] = platform.linux_distribution()[0]+"-"+platform.linux_distribution()[1]+" "+platform.linux_distribution()[2] report['arch'] = platform.architecture()[0] else: report['os'] = "Mac OS X - "+platform.mac_ver()[0] report['arch'] = platform.architecture()[0] for disk in disks.keys(): if disks[disk] == utils.ENABLED and check_disk(disk): usage_temp = psutil.disk_usage(disk) usage[disk] = {'total': usage_temp.total, 'used': usage_temp.used, 'free': usage_temp.free, 'percentage': usage_temp.percent} for interf in interfaces.keys(): if interfaces[interf] == utils.ENABLED: net_temp = dict((k.lower(),v) for k, v in psutil.net_io_counters(pernic=True).iteritems())[interf] net[interf] = {'sent': net_temp.bytes_sent, 'recv': net_temp.bytes_recv} report['inet'] = net report['disks'] = usage report['processes'] = {'value': len(psutil.pids())} report['loadAverage'] = {} if not os.name == 'nt': for idx, la in enumerate(os.getloadavg()): time_la = "1" if idx == 0 else "5" if idx == 2 else "15" report['loadAverage'][time_la] = "{0:.2f}".format(la) report['users'] = {'value': len(psutil.users())} report['uptime'] = str(datetime.now() - datetime.fromtimestamp(psutil.boot_time())).split('.')[0] report['kindDevice'] = 3 api_key = account.api_key url = "%s/%s" % (system_config['ROUTES'].get('collect'), config[utils.GENERAL_SECTION].get('serial')) params = {'apiKey': api_key, 'data': json.dumps(report)} try: response = http.request('POST', url, params, {'user-key': account.user_key}, encode_multipart=False) except Exception, e: console.error("Check your connection") return
def get_os_release(): """Returns detailed OS release.""" if platform.linux_distribution()[0]: return " ".join(platform.linux_distribution()) elif platform.mac_ver()[0]: return "%s %s" % (platform.mac_ver()[0], platform.mac_ver()[2]) else: return "Unknown"
def __init__(self, bitrateArduino = 115200, arduinoPort = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A7007dag-if00-port0"): if platform.linux_distribution()[0].lower() == "Ubuntu".lower(): arduinoPort = "/dev/serial/by-id/pci-FTDI_FT232R_USB_UART_A7007dag-if00-port0" elif platform.linux_distribution()[0].lower() == "Fedora".lower(): arduinoPort = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A7007dag-if00-port0" self.arduino = serial.Serial(arduinoPort, bitrateArduino, timeout = 1) #self.polulu = serial.Serial(poluluPort, bitratePolulu, timeout = 1) sleep(1)
def getName(self): if not self.isLinux: return "Not linux" else: if platform.linux_distribution() != "": return platform.linux_distribution()[0] else: return "Linux"
def check_os(logger): if platform.system() != 'Linux': logger.log_debug('OS: ' + platform.system()) return False if platform.linux_distribution() != ('Ubuntu', '14.04', 'trusty'): logger.log_debug('OS: ' + platform.linux_distribution()) return False return True
def version(bot, trigger): if platform.system() == 'Linux': ver = ("%s %s" % (platform.linux_distribution()[0], platform.linux_distribution()[1])) elif platform.system() == 'Windows': ver = ("%s %s" % (platform.system(), platform.release())) else: ver = ("some OS which is not Linux or Windows") pyver = sys.version.split()[0] bot.say("I'm Granota, version 1.0, running on %s and using Python %s since %s" % (ver, pyver, startTime))
def __init__ (self, host, port): self.__host = host self.__port = port self.__dbg_flag = False self.__server_sock = None if platform.linux_distribution()[0] == "debian" or platform.linux_distribution()[0] == "Ubuntu": self.NOLINGER = struct.pack('ii', 1, 0) else: self.NOLINGER = struct.pack('HH', 1, 0)
linux_distro = "None" try: if platform.system() == "Darwin": v = platform.mac_ver() os_version = "Macintosh; Intel Mac OS X %s" % v[0].replace(".", "_") linux_distro = "OS X %s" % v[0] elif platform.system() == "Windows": v = platform.win32_ver() # TODO: Upgrade windows python (on build server) version to 3.5, so it correctly identifies Windows 10 os_version = "Windows NT %s; %s" % (v[0], v[1]) linux_distro = "Windows %s" % "-".join(platform.win32_ver()) elif platform.system() == "Linux": # Get the distro name and version (if any) linux_distro = "-".join(platform.linux_distribution()) except Exception as Ex: log.error("Error determining OS version in metrics.py") # Build user-agent user_agent = "Mozilla/5.0 (%s) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36" % os_version params = { "cid" : s.get("unique_install_id"), # Unique install ID "v" : 1, # Google Measurement API version "tid" : "UA-4381101-5", # Google Analytic Tracking ID "an" : info.PRODUCT_NAME, # App Name "aip" : 1, # Anonymize IP "aid" : "org.openshot.%s" % info.NAME, # App ID "av" : info.VERSION, # App Version
print("-# %sAttenzione%s:" % (bright_yellow, end)) if platform.linux_distribution() == "Parrot": print( " Utilizzando Parrot OS, potresti trovare tool all'interno del\n programma incompatibili col tuo sistema." ) print( " Una volta eseguita l'installazione non rinominare o spostare la cartella" ) print(" di %sfsociety%s.\n" % (bright_green, end)) return main() except requests.exceptions.ConnectionError: sys.stdout.write("- %sFail%s\n" % (red, end)) sys.stdout.flush() sys.exit("-# Verifica la tua connessione e riprova\n") except KeyboardInterrupt: sys.exit("\n") if __name__ == "__main__": os.system("clear") compatible = ["Kali", "Parrot"] get_sys = platform.linux_distribution()[0] if get_sys not in compatible: print( "-# (%s-%s) Spiacente, programma non compatibile col tuo sistema" % (red, end)) print("-# Sistemi supportati:\n - Kali Linux\n - Parrot OS".format( bright_green, end)) sys.exit() check_conn()
return os.path.expanduser("~/Library/Logs/cura") if hasattr(sys, "frozen"): dirpath = get_cura_dir_path() os.makedirs(dirpath, exist_ok=True) sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w") sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w") import platform import faulthandler #WORKAROUND: GITHUB-88 GITHUB-385 GITHUB-612 if Platform.isLinux( ): # Needed for platform.linux_distribution, which is not available on Windows and OSX # For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826 linux_distro_name = platform.linux_distribution()[0].lower() # TODO: Needs a "if X11_GFX == 'nvidia'" here. The workaround is only needed on Ubuntu+NVidia drivers. Other drivers are not affected, but fine with this fix. import ctypes from ctypes.util import find_library libGL = find_library("GL") ctypes.CDLL(libGL, ctypes.RTLD_GLOBAL) # When frozen, i.e. installer version, don't let PYTHONPATH mess up the search path for DLLs. if Platform.isWindows() and hasattr(sys, "frozen"): try: del os.environ["PYTHONPATH"] except KeyError: pass # WORKAROUND: GITHUB-704 GITHUB-708 # It looks like setuptools creates a .pth file in
#!/usr/bin/env python # # ELBE - Debian Based Embedded Rootfilesystem Builder # Copyright (C) 2016 Linutronix GmbH # # This file is part of ELBE. # # ELBE is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # ELBE is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with ELBE. If not, see <http://www.gnu.org/licenses/>. from elbepack.directories import pack_dir from platform import linux_distribution elbe_version = "2.0" running_os = linux_distribution() if pack_dir == '/usr/lib/python2.7/dist-packages/elbepack': is_devel = False else: is_devel = True
if osp.exists(d): filtered_dirs.append(d) compiler = ccompiler.new_compiler() _extra_compile_args = ['-DMSDBLIB'] WINDOWS = False SYSTEM = platform.system() print("setup.py: platform.system() => %r" % SYSTEM) print("setup.py: platform.architecture() => %r" % (platform.architecture(), )) if SYSTEM == 'Linux': print("setup.py: platform.linux_distribution() => %r" % (platform.linux_distribution(), )) if SYSTEM != 'Windows': print("setup.py: platform.libc_ver() => %r" % (platform.libc_ver(), )) # 32 bit or 64 bit system? BITNESS = struct.calcsize("P") * 8 include_dirs = [] library_dirs = [] if sys.platform == 'win32': WINDOWS = True else: FREETDS = None if sys.platform == 'darwin': FREETDS = fpath('freetds', 'darwin_%s' % BITNESS)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex(('127.0.0.1', port)) sock.close() return result == 0 if PortHasListener(10000): print 'Something is listening on port 10000 - will assume Minecraft is running.' exit(0) print 'Nothing is listening on port 10000 - will attempt to launch Minecraft from a new terminal.' if os.name == 'nt': os.startfile("launchClient.bat") elif sys.platform == 'darwin': subprocess.Popen(['open', '-a', 'Terminal.app', 'launchClient.sh']) elif platform.linux_distribution()[0] == 'Fedora': subprocess.Popen("gnome-terminal -e ./launchClient.sh", close_fds=True, shell=True) else: subprocess.Popen("x-terminal-emulator -e ./launchClient.sh", close_fds=True, shell=True) print 'Giving Minecraft some time to launch... ' for i in xrange(100): print '.', time.sleep(3) if PortHasListener(10000): print 'ok' exit(0)
def _os(self): distributor = None release = None def _str(s): if (s.startswith("'") and s.endswith("'")) \ or (s.startswith('"') and s.endswith('"')): return s[1:-1] else: return s def _os(): if distributor and release: return "%s-%s" % (distributor, release) else: return None def _parse(txt, distributor_key, release_key): distributor_ = None release_ = None lines = txt.strip().split('\n') for line in lines: if line.startswith(distributor_key): s = line[len(distributor_key):].strip() distributor_ = _str(s) elif line.startswith(release_key): s = line[len(release_key):].strip() release_ = _str(s) return distributor_, release_ # first try parsing the /etc/lsb-release file file = "/etc/lsb-release" if os.path.isfile(file): with open(file) as f: txt = f.read() distributor, release = _parse(txt, "DISTRIB_ID=", "DISTRIB_RELEASE=") result = _os() if result: return result # next, try getting the output of the lsb_release program import subprocess p = Popen(['/usr/bin/env', 'lsb_release', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) txt = p.communicate()[0] if not p.returncode: distributor_, release_ = _parse(txt, "Distributor ID:", "Release:") if distributor_ and not distributor: distributor = distributor_ if release_ and not release: release = release_ result = _os() if result: return result # try to read the /etc/os-release file # this file contains OS specific data on linux # distributions # see https://www.freedesktop.org/software/systemd/man/os-release.html os_release = '/etc/os-release' if os.path.isfile(os_release): with open(os_release, 'r') as f: txt = f.read() distributor_, release_ = _parse(txt, "ID=", "VERSION_ID=") if distributor_ and not distributor: distributor = distributor_ if release_ and not release: release = release_ result = _os() if result: return result # last, use python's dist detection. It is known to return incorrect # info on some systems though try: distributor_, release_, _ = platform.linux_distribution() except: distributor_, release_, _ = platform.dist() if distributor_ and not distributor: distributor = distributor_ if release_ and not release: release = release_ result = _os() if result: return result # last resort, accept missing release if distributor: return distributor # give up raise RezSystemError("cannot detect operating system")
def GetPreferredFilesystemType(self): (_, version, _) = platform.linux_distribution() if version.startswith('7'): return 'xfs' return 'ext4'
def is_ubuntu(): return platform.system() == 'Linux' and platform.linux_distribution( )[0] == 'Ubuntu'
#!/usr/bin/env python import os import sys, getopt import subprocess import platform import csv local_cwd = os.path.dirname(os.path.realpath(__file__)) print local_cwd os.chdir(local_cwd) distname, version, Id = platform.linux_distribution() print distname, version csvfile = 'report.csv' try: opts, args = getopt.getopt(sys.argv[1:], "hf:", ["csvfile="]) except getopt.GetoptError: print 'run_test.py --csvfile <outputfile>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'run_test.py --csvfile <outputfile>' sys.exit() elif opt in ("-f", "--csvfile"): csvfile = arg def run_one_test(width, height, num_images, image_file): args = [ "./4K_displaywall_bench", "-width",
def _get_linux_dist(): # pylint: disable=deprecated-method return ",".join(platform.linux_distribution(full_distribution_name=0))
#!/usr/bin/python import os import platform linux_distribution = platform.linux_distribution()[0] #linux_distribution = "debian" #print linux_distribution #distribution = "None" print linux_distribution, 'is the distribution' def linux_distribution(linux_distribution): distribution = "None" linux_distribution = platform.linux_distribution()[0] if linux_distribution == "Ubuntu" or linux_distribution == "debian": distribution = "Ubuntu" elif linux_distribution == "CentOS Linux" or linux_distribution == "redhat": distribution = "CentOS" elif linux_distribution == "SuSE": distribution = "SuSE" print distribution return distribution linux_distribution(linux_distribution) #Update system #os.system("sudo apt-get update 2>/dev/null 1>$2") # Install of the rapidrecovery-agent with "Yes" options
return v if sys.version_info[0] >= 3: string_types = (str, bytes) unicode_type = str else: string_types = (str, unicode) unicode_type = unicode DEFAULT_ENCODING = sys.getdefaultencoding() ON_WINDOWS = (platform.system() == 'Windows') ON_MAC = (platform.system() == 'Darwin') ON_LINUX = (platform.system() == 'Linux') ON_ARCH = (platform.linux_distribution()[0] == 'arch') ON_POSIX = (os.name == 'posix') IS_ROOT = ctypes.windll.shell32.IsUserAnAdmin( ) != 0 if ON_WINDOWS else os.getuid() == 0 HAVE_PYGMENTS = bool(pygments_version()) VER_3_4 = (3, 4) VER_3_5 = (3, 5) VER_3_5_1 = (3, 5, 1) VER_FULL = sys.version_info[:3] VER_MAJOR_MINOR = sys.version_info[:2] V_MAJOR_MINOR = 'v{0}{1}'.format(*sys.version_info[:2]) def docstring_by_version(**kwargs): """Sets a docstring by the python version."""
def main(): root_logger = logging.Logger("hang_analyzer", level=logging.DEBUG) handler = logging.StreamHandler(sys.stdout) handler.setFormatter(logging.Formatter(fmt="%(message)s")) root_logger.addHandler(handler) root_logger.info("Python Version: %s" % sys.version) root_logger.info("OS: %s" % platform.platform()) try: distro = platform.linux_distribution() root_logger.info("Linux Distribution: %s" % str(distro)) except AttributeError: root_logger.warning("Cannot determine Linux distro since Python is too old") try: uid = os.getuid() root_logger.info("Current User: %s" % str(uid)) current_login = os.getlogin() root_logger.info("Current Login: %s" % current_login) except OSError: root_logger.warning("Cannot determine Unix Current Login") except AttributeError: root_logger.warning("Cannot determine Unix Current Login, not supported on Windows") interesting_processes = ["mongo", "mongod", "mongos", "_test", "dbtest", "python", "java"] go_processes = [] process_ids = [] parser = OptionParser(description=__doc__) parser.add_option('-p', '--process-names', dest='process_names', help='Comma separated list of process names to analyze') parser.add_option('-g', '--go-process-names', dest='go_process_names', help='Comma separated list of go process names to analyze') parser.add_option('-d', '--process-ids', dest='process_ids', default=None, help='Comma separated list of process ids (PID) to analyze, overrides -p & -g') parser.add_option('-c', '--dump-core', dest='dump_core', action="store_true", default=False, help='Dump core file for each analyzed process') parser.add_option('-s', '--max-core-dumps-size', dest='max_core_dumps_size', default=10000, help='Maximum total size of core dumps to keep in megabytes') parser.add_option('-o', '--debugger-output', dest='debugger_output', action="append", choices=['file', 'stdout'], default=None, help="If 'stdout', then the debugger's output is written to the Python" " process's stdout. If 'file', then the debugger's output is written" " to a file named debugger_<process>_<pid>.log for each process it" " attaches to. This option can be specified multiple times on the" " command line to have the debugger's output written to multiple" " locations. By default, the debugger's output is written only to the" " Python process's stdout.") (options, args) = parser.parse_args() if options.debugger_output is None: options.debugger_output = ['stdout'] if options.process_ids is not None: # process_ids is an int list of PIDs process_ids = [int(pid) for pid in options.process_ids.split(',')] if options.process_names is not None: interesting_processes = options.process_names.split(',') if options.go_process_names is not None: go_processes = options.go_process_names.split(',') interesting_processes += go_processes [ps, dbg, jstack] = get_hang_analyzers() if ps is None or (dbg is None and jstack is None): root_logger.warning("hang_analyzer.py: Unsupported platform: %s" % (sys.platform)) exit(1) all_processes = ps.dump_processes(root_logger) # Find all running interesting processes: # If a list of process_ids is supplied, match on that. # Otherwise, do a substring match on interesting_processes. if process_ids: processes = [(pid, pname) for (pid, pname) in all_processes if pid in process_ids and pid != os.getpid()] running_pids = set([pid for (pid, pname) in all_processes]) missing_pids = set(process_ids) - running_pids if missing_pids: root_logger.warning("The following requested process ids are not running %s" % list(missing_pids)) else: processes = [(pid, pname) for (pid, pname) in all_processes if any(pname.find(ip) >= 0 for ip in interesting_processes) and pid != os.getpid()] root_logger.info("Found %d interesting processes %s" % (len(processes), processes)) max_dump_size_bytes = int(options.max_core_dumps_size) * 1024 * 1024 # Dump all other processes including go programs, except python & java. for (pid, process_name) in [(p, pn) for (p, pn) in processes if not re.match("^(java|python)", pn)]: process_logger = get_process_logger(options.debugger_output, pid, process_name) dbg.dump_info( root_logger, process_logger, pid, process_name, options.dump_core and check_dump_quota(max_dump_size_bytes, dbg.get_dump_ext())) # Dump java processes using jstack. for (pid, process_name) in [(p, pn) for (p, pn) in processes if pn.startswith("java")]: process_logger = get_process_logger(options.debugger_output, pid, process_name) jstack.dump_info(root_logger, process_logger, pid, process_name) # Signal go processes to ensure they print out stack traces, and die on POSIX OSes. # On Windows, this will simply kill the process since python emulates SIGABRT as # TerminateProcess. # Note: The stacktrace output may be captured elsewhere (i.e. resmoke). for (pid, process_name) in [(p, pn) for (p, pn) in processes if pn in go_processes]: root_logger.info("Sending signal SIGABRT to go process %s with PID %d" % (process_name, pid)) signal_process(root_logger, pid, signal.SIGABRT) # Dump python processes after signalling them. for (pid, process_name) in [(p, pn) for (p, pn) in processes if pn.startswith("python")]: root_logger.info("Sending signal SIGUSR1 to python process %s with PID %d" % (process_name, pid)) signal_process(root_logger, pid, signal.SIGUSR1) process_logger = get_process_logger(options.debugger_output, pid, process_name) dbg.dump_info( root_logger, process_logger, pid, process_name, take_dump=False) root_logger.info("Done analyzing all processes for hangs")
def get_os_release(): return ' '.join(platform.linux_distribution())
def detectos(self): temp=platform.linux_distribution() ver=temp[0]+" "+temp[1] return ver
def run(dirName, nzbName=None, issueid=None, comversion=None, manual=None, filename=None, module=None): if module is None: module = '' module += '[META-TAGGER]' logger.fdebug(module + ' dirName:' + dirName) ## Set the directory in which comictagger and other external commands are located - IMPORTANT - ## # ( User may have to modify, depending on their setup, but these are some guesses for now ) if platform.system() == "Windows": #if it's a source install. sys_type = 'windows' if os.path.isdir(os.path.join(mylar.CMTAGGER_PATH, '.git')): comictagger_cmd = os.path.join(mylar.CMTAGGER_PATH, 'comictagger.py') else: #regardless of 32/64 bit install if 'comictagger.exe' in mylar.CMTAGGER_PATH: comictagger_cmd = mylar.CMTAGGER_PATH else: comictagger_cmd = os.path.join(mylar.CMTAGGER_PATH, 'comictagger.exe') if mylar.UNRAR_CMD == 'None' or mylar.UNRAR_CMD == '' or mylar.UNRAR_CMD is None: unrar_cmd = "C:\Program Files\WinRAR\UnRAR.exe" else: unrar_cmd = mylar.UNRAR_CMD.strip() # test for UnRAR if not os.path.isfile(unrar_cmd): unrar_cmd = "C:\Program Files (x86)\WinRAR\UnRAR.exe" if not os.path.isfile(unrar_cmd): logger.fdebug( module + ' Unable to locate UnRAR.exe - make sure it is installed.') logger.fdebug(module + ' Aborting meta-tagging.') return "fail" logger.fdebug(module + ' UNRAR path set to : ' + unrar_cmd) elif platform.system() == "Darwin": #Mac OS X sys_type = 'mac' comictagger_cmd = os.path.join(mylar.CMTAGGER_PATH, 'comictagger.py') if mylar.UNRAR_CMD == 'None' or mylar.UNRAR_CMD == '' or mylar.UNRAR_CMD is None: unrar_cmd = "/usr/local/bin/unrar" else: unrar_cmd = mylar.UNRAR_CMD.strip() logger.fdebug(module + ' UNRAR path set to : ' + unrar_cmd) else: #for the 'nix sys_type = 'linux' if mylar.UNRAR_CMD == 'None' or mylar.UNRAR_CMD == '' or mylar.UNRAR_CMD is None: if 'freebsd' in platform.linux_distribution()[0].lower(): unrar_cmd = "/usr/local/bin/unrar" else: unrar_cmd = "/usr/bin/unrar" else: unrar_cmd = mylar.UNRAR_CMD.strip() logger.fdebug(module + ' UNRAR path set to : ' + unrar_cmd) #check for dependencies here - configparser try: import configparser except ImportError: logger.fdebug( module + ' configparser not found on system. Please install manually in order to write metadata' ) logger.fdebug( module + ' continuing with PostProcessing, but I am not using metadata.' ) return "fail" #set this to the lib path (ie. '<root of mylar>/lib') comictagger_cmd = os.path.join(mylar.CMTAGGER_PATH, 'comictagger.py') # if not os.path.exists( comictagger_cmd ): # print "ERROR: can't find the ComicTagger program: {0}".format( comictagger_cmd ) # print " You probably need to edit this script!" # sys.exit( 1 ) file_conversion = True file_extension_fixing = True if not os.path.exists(unrar_cmd): logger.fdebug(module + ' WARNING: cannot find the unrar command.') logger.fdebug(module + ' File conversion and extension fixing not available') logger.fdebug( module + ' You probably need to edit this script, or install the missing tool, or both!' ) return "fail" #file_conversion = False #file_extension_fixing = False ## Sets up other directories ## scriptname = os.path.basename(sys.argv[0]) downloadpath = os.path.abspath(dirName) sabnzbdscriptpath = os.path.dirname(sys.argv[0]) if manual is None: comicpath = os.path.join(downloadpath, "temp") else: chkpath, chkfile = os.path.split(filename) logger.fdebug(module + ' chkpath: ' + chkpath) logger.fdebug(module + ' chkfile: ' + chkfile) extensions = ('.cbr', '.cbz') if os.path.isdir(chkpath) and chkpath != downloadpath: logger.fdebug(module + ' Changing ' + downloadpath + ' location to ' + chkpath + ' as it is a directory.') downloadpath = chkpath comicpath = os.path.join(downloadpath, issueid) unrar_folder = os.path.join(comicpath, "unrard") logger.fdebug(module + ' Paths / Locations:') logger.fdebug(module + ' scriptname : ' + scriptname) logger.fdebug(module + ' downloadpath : ' + downloadpath) logger.fdebug(module + ' sabnzbdscriptpath : ' + sabnzbdscriptpath) logger.fdebug(module + ' comicpath : ' + comicpath) logger.fdebug(module + ' unrar_folder : ' + unrar_folder) logger.fdebug(module + ' Running the ComicTagger Add-on for Mylar') if os.path.exists(comicpath): shutil.rmtree(comicpath) logger.fdebug(module + ' Attempting to create directory @: ' + str(comicpath)) try: os.makedirs(comicpath) except OSError: raise logger.fdebug(module + ' Created directory @ : ' + str(comicpath)) logger.fdebug(module + ' Filename is : ' + str(filename)) if filename is None: filename_list = glob.glob(os.path.join(downloadpath, "*.cbz")) filename_list.extend(glob.glob(os.path.join(downloadpath, "*.cbr"))) fcount = 1 for f in filename_list: if fcount > 1: logger.fdebug( module + ' More than one cbr/cbz within path, performing Post-Process on first file detected: ' + f) break if f.endswith('.cbz'): logger.fdebug( module + ' .cbz file detected. Excluding from temporary directory move at this time.' ) comicpath = downloadpath else: shutil.move(f, comicpath) filename = f #just the filename itself fcount += 1 else: # if the filename is identical to the parent folder, the entire subfolder gets copied since it's the first match, instead of just the file #if os.path.isfile(filename): #if the filename doesn't exist - force the path assuming it's the 'download path' filename = os.path.join(downloadpath, filename) logger.fdebug( module + ' The path where the file is that I was provided is probably wrong - modifying it to : ' + filename) shutil.move(filename, os.path.join(comicpath, os.path.split(filename)[1])) logger.fdebug(module + ' moving : ' + filename + ' to ' + os.path.join(comicpath, os.path.split(filename)[1])) try: filename = os.path.split(filename)[1] # just the filename itself except: logger.warn( 'Unable to detect filename within directory - I am aborting the tagging. You best check things out.' ) return "fail" #print comicpath #print os.path.join( comicpath, filename ) if filename.endswith('.cbr'): f = os.path.join(comicpath, filename) if zipfile.is_zipfile(f): logger.fdebug(module + ' zipfile detected') base = os.path.splitext(f)[0] shutil.move(f, base + ".cbz") logger.fdebug(module + ' {0}: renaming {1} to be a cbz'.format( scriptname, os.path.basename(f))) if file_extension_fixing: if filename.endswith('.cbz'): logger.info(module + ' Filename detected as a .cbz file.') f = os.path.join(comicpath, filename) logger.fdebug(module + ' filename : ' + f) if os.path.isfile(f): try: rar_test_cmd_output = "is not RAR archive" #default, in case of error rar_test_cmd_output = subprocess.check_output( [unrar_cmd, "t", f]) except: logger.fdebug(module + ' This is a zipfile. Unable to test rar.') if not "is not RAR archive" in rar_test_cmd_output: base = os.path.splitext(f)[0] shutil.move(f, base + ".cbr") logger.fdebug(module + ' {0}: renaming {1} to be a cbr'.format( scriptname, os.path.basename(f))) else: try: with open(f): pass except: logger.warn(module + ' No zip file present') return "fail" #if the temp directory is the LAST directory in the path, it's part of the CT logic path above #and can be removed to allow a copy back to the original path to work. if 'temp' in os.path.basename(os.path.normpath(comicpath)): pathbase = os.path.dirname(os.path.dirname(comicpath)) base = os.path.join(pathbase, filename) else: base = os.path.join( re.sub(issueid, '', comicpath), filename) #extension is already .cbz logger.fdebug(module + ' Base set to : ' + base) logger.fdebug(module + ' Moving : ' + f + ' - to - ' + base) shutil.move(f, base) try: with open(base): logger.fdebug( module + ' Verified file exists in location: ' + base) removetemp = True except: logger.fdebug( module + ' Cannot verify file exist in location: ' + base) removetemp = False if removetemp == True: if comicpath != downloadpath: shutil.rmtree(comicpath) logger.fdebug( module + ' Successfully removed temporary directory: ' + comicpath) else: logger.fdebug( module + ' Unable to remove temporary directory since it is identical to the download location : ' + comicpath) logger.fdebug(module + ' new filename : ' + base) nfilename = base # Now rename all CBR files to RAR if filename.endswith('.cbr'): #logger.fdebug('renaming .cbr to .rar') f = os.path.join(comicpath, filename) base = os.path.splitext(f)[0] baserar = base + ".rar" shutil.move(f, baserar) ## Changes any cbr files to cbz files for insertion of metadata ## if file_conversion: f = os.path.join(comicpath, filename) logger.fdebug(module + ' {0}: converting {1} to be zip format'.format( scriptname, os.path.basename(f))) basename = os.path.splitext(f)[0] zipname = basename + ".cbz" # Move into the folder where we will be unrar-ing things os.makedirs(unrar_folder) os.chdir(unrar_folder) # Extract and zip up logger.fdebug(module + ' {0}: Comicpath is ' + baserar) #os.path.join(comicpath,basename)) logger.fdebug(module + ' {0}: Unrar is ' + unrar_folder) try: #subprocess.Popen( [ unrar_cmd, "x", os.path.join(comicpath,basename) ] ).communicate() output = subprocess.check_output([unrar_cmd, 'x', baserar]) except CalledProcessError as e: if e.returncode == 3: logger.warn(module + ' [Unrar Error 3] - Broken Archive.') elif e.returncode == 1: logger.warn(module + ' [Unrar Error 1] - No files to extract.') logger.warn(module + ' Marking this as an incomplete download.') return "unrar error" shutil.make_archive(basename, "zip", unrar_folder) # get out of unrar folder and clean up os.chdir(comicpath) shutil.rmtree(unrar_folder) ## Changes zip to cbz f = os.path.join(comicpath, os.path.splitext(filename)[0] + ".zip") #print "zipfile" + f try: with open(f): pass except: logger.warn(module + ' No zip file present:' + f) return "fail" base = os.path.splitext(f)[0] shutil.move(f, base + ".cbz") nfilename = base + ".cbz" #else: # logger.fdebug(module + ' Filename:' + filename) # nfilename = filename #if os.path.isfile( nfilename ): # logger.fdebug(module + ' File exists in given location already : ' + nfilename) # file_dir, file_n = os.path.split(nfilename) #else: # #remove the IssueID from the path # file_dir = re.sub(issueid, '', comicpath) # file_n = os.path.split(nfilename)[1] if manual is None: file_dir = downloadpath else: file_dir = re.sub(issueid, '', comicpath) try: file_n = os.path.split(nfilename)[1] except: logger.error( module + ' unable to retrieve filename properly. Check your logs as there is probably an error or misconfiguration indicated (such as unable to locate unrar or configparser)' ) return "fail" logger.fdebug(module + ' Converted directory: ' + str(file_dir)) logger.fdebug(module + ' Converted filename: ' + str(file_n)) logger.fdebug(module + ' Destination path: ' + os.path.join(file_dir, file_n)) #dirName,file_n)) logger.fdebug(module + ' dirName: ' + dirName) logger.fdebug(module + ' absDirName: ' + os.path.abspath(dirName)) ##set up default comictagger options here. if comversion is None or comversion == '': comversion = '1' comversion = re.sub('[^0-9]', '', comversion).strip() cvers = 'volume=' + str(comversion) tagoptions = ["-s", "--verbose", "-m", cvers] ## check comictagger version - less than 1.15.beta - take your chances. if sys_type == 'windows': ctversion = subprocess.check_output([comictagger_cmd, "--version"]) else: ctversion = subprocess.check_output( [sys.executable, comictagger_cmd, "--version"]) ctend = ctversion.find(':') ctcheck = re.sub("[^0-9]", "", ctversion[:ctend]) ctcheck = re.sub('\.', '', ctcheck).strip() if int(ctcheck) >= int('1115'): #(v1.1.15) if mylar.COMICVINE_API == mylar.DEFAULT_CVAPI: logger.fdebug( module + ' ' + ctversion[:ctend] + ' being used - no personal ComicVine API Key supplied. Take your chances.' ) use_cvapi = "False" else: logger.fdebug( module + ' ' + ctversion[:ctend] + ' being used - using personal ComicVine API key supplied via mylar.' ) use_cvapi = "True" tagoptions.extend(["--cv-api-key", mylar.COMICVINE_API]) else: logger.fdebug( module + ' ' + ctversion[:ctend] + ' being used - personal ComicVine API key not supported in this version. Good luck.' ) use_cvapi = "False" i = 1 tagcnt = 0 if mylar.CT_TAG_CR: tagcnt = 1 logger.fdebug(module + ' CR Tagging enabled.') if mylar.CT_TAG_CBL: if not mylar.CT_TAG_CR: i = 2 #set the tag to start at cbl and end without doing another tagging. tagcnt = 2 logger.fdebug(module + ' CBL Tagging enabled.') if tagcnt == 0: logger.warn( module + ' You have metatagging enabled, but you have not selected the type(s) of metadata to write. Please fix and re-run manually' ) return "fail" #if it's a cbz file - check if no-overwrite existing tags is enabled / disabled in config. if nfilename.endswith('.cbz'): if mylar.CT_CBZ_OVERWRITE: logger.fdebug( module + ' Will modify existing tag blocks even if it exists.') else: logger.fdebug( module + ' Will NOT modify existing tag blocks even if they exist already.' ) tagoptions.extend(["--nooverwrite"]) if issueid is None: tagoptions.extend(["-f", "-o"]) else: tagoptions.extend(["-o", "--id", issueid]) original_tagoptions = tagoptions og_tagtype = None while (i <= tagcnt): if i == 1: tagtype = 'cr' # CR meta-tagging cycle. tagdisp = 'ComicRack tagging' elif i == 2: tagtype = 'cbl' #Cbl meta-tagging cycle tagdisp = 'Comicbooklover tagging' f_tagoptions = original_tagoptions if og_tagtype is not None: for index, item in enumerate(f_tagoptions): if item == og_tagtype: f_tagoptions[index] = tagtype else: f_tagoptions.extend(["--type", tagtype, nfilename]) og_tagtype = tagtype logger.info(module + ' ' + tagdisp + ' meta-tagging processing started.') #CV API Check here. if mylar.CVAPI_COUNT == 0 or mylar.CVAPI_COUNT >= 200: cvapi_check() if sys_type == 'windows': currentScriptName = str(comictagger_cmd).decode("string_escape") else: currentScriptName = sys.executable + ' ' + str( comictagger_cmd).decode("string_escape") logger.fdebug(module + ' Enabling ComicTagger script: ' + str(currentScriptName) + ' with options: ' + str(f_tagoptions)) # generate a safe command line string to execute the script and provide all the parameters script_cmd = shlex.split(currentScriptName, posix=False) + f_tagoptions # use subprocess to run the command and capture output logger.fdebug(module + ' Executing command: ' + str(script_cmd)) logger.fdebug(module + ' Absolute path to script: ' + script_cmd[0]) try: p = subprocess.Popen(script_cmd) out, err = p.communicate() #@UnusedVariable logger.fdebug(module + '[COMIC-TAGGER] : ' + str(out)) logger.info(module + '[COMIC-TAGGER] Successfully wrote ' + tagdisp) except OSError, e: logger.warn( module + '[COMIC-TAGGER] Unable to run comictagger with the options provided: ' + str(script_cmd)) #increment CV API counter. mylar.CVAPI_COUNT += 1 ## Tag each CBZ, and move it back to original directory ## #if use_cvapi == "True": # if issueid is None: # subprocess.Popen( [ comictagger_cmd, "-s", "-t", tagtype, "--cv-api-key", mylar.COMICVINE_API, "-f", "-o", "--verbose", "--nooverwrite", nfilename ] ).communicate() # else: # subprocess.Popen( [ comictagger_cmd, "-s", "-t", tagtype, "--cv-api-key", mylar.COMICVINE_API, "-o", "--id", issueid, "--verbose", nfilename ] ).communicate() # logger.info(module + ' ' + tagdisp + ' meta-tagging complete') # #increment CV API counter. # mylar.CVAPI_COUNT +=1 #else: # if issueid is None: # subprocess.Popen( [ comictagger_cmd, "-s", "-t", tagtype, "-f", "-o", "--verbose", "--nooverwrite", nfilename ] ).communicate() # else: # subprocess.Popen( [ comictagger_cmd, "-s", "-t", tagtype, "-o", "--id", issueid, "--verbose", "--nooverwrite", nfilename ] ).communicate() # #increment CV API counter. # mylar.CVAPI_COUNT +=1 i += 1
def __init__(self, strict=False): self.os = self.dist = self.os_ver = self.full_os_ver = self.osnick = self.arch = '?' # self.os = os.getenv("READIES_PLATFORM_OS", '?') # self.dist = os.getenv("READIES_PLATFORM_DIST", '?') # self.os_ver = os.getenv("READIES_PLATFORM_OS_VER", '?') # self.full_os_ver = os.getenv("READIES_PLATFORM_FULL_OS_VER", '?') # self.osnick = os.getenv("READIES_PLATFORM_OSNICK", '?') # self.arch = os.getenv("READIES_PLATFORM_ARCH", '?') self.os = platform.system().lower() if self.os == 'linux': if False: dist = platform.linux_distribution() distname = dist[0].lower() self.os_ver = self.full_os_ver = dist[1] else: try: os_release = Platform.OSRelease() distname = os_release.distname() self.os_ver = self.full_os_ver = os_release.version() self.osnick = os_release.osnick() if self.osnick == "": self.osnick = distname + str(self.os_ver) except: if strict: assert (False), "Cannot determine distribution" distname = 'unknown' self.os_ver = self.full_os_ver = 'unknown' if distname == 'fedora' or distname == 'ubuntu' or distname == 'debian' or distname == 'arch': pass elif distname.startswith('centos'): distname = 'centos' elif distname.startswith('redhat') or distname == 'rhel': distname = 'redhat' elif distname.startswith('suse'): distname = 'suse' elif distname.startswith('amzn'): distname = 'amzn' self.osnick = 'amzn' + str(os_release.version()) else: if strict: assert (False), "Cannot determine distribution" self.dist = distname elif self.os == 'darwin': self.os = 'macosx' self.dist = '' mac_ver = platform.mac_ver() self.full_os_ver = mac_ver[0] # e.g. 10.14, but also 10.5.8 self.os_ver = '.'.join( self.full_os_ver.split('.')[:2]) # major.minor # self.arch = mac_ver[2] # e.g. x64_64 self.osnick = self.os + str(self.full_os_ver.split('.')[1]) nicks = { "10.15": "catalina", "10.14": "mojave", "10.13": "highsierra", "10.12": "sierra", "10.11": "elcapitan", "10.10": "yosemite", "10.9": "mavericks", "10.8": "mountainlion", "10.7": "lion", "10.6": "snowleopard", "10.5": "leopard", "10.4": "tiger", "10.3": "panther", "10.2": "jaguar", "10.1": "puma", "10.0": "cheetah" } if self.os_ver in nicks: self.osnick = nicks[self.os_ver] elif self.os == 'windows': self.dist = self.os self.os_ver = platform.release() self.full_os_ver = os.version() elif self.os == 'sunos': self.os = 'solaris' self.os_ver = '' self.dist = '' elif self.os == 'freebsd': self.dist = '' ver = sh('freebsd-version') m = re.search(r'([^-]*)-(.*)', ver) self.os_ver = self.full_os_ver = m.group(1) self.osnick = self.os + self.os_ver else: if strict: assert (False), "Cannot determine OS" self.os_ver = '' self.dist = '' self.arch = platform.machine().lower() if self.arch == 'amd64' or self.arch == 'x86_64': self.arch = 'x64' elif self.arch == 'i386' or self.arch == 'i686' or self.arch == 'i86pc': self.arch = 'x86' elif self.arch == 'aarch64': self.arch = 'arm64v8' elif self.arch == 'armv7l': self.arch = 'arm32v7'
def IsThisPlatform(root='/'): (distribution, _, _) = platform.linux_distribution() if distribution == 'Red Hat Enterprise Linux Server': return True return False
def linux_distribution(): try: return platform.linux_distribution() except: return "N/A"
def build(ctx, rebuild=False, race=False, build_include=None, build_exclude=None, puppy=False, development=True, precompile_only=False, skip_assets=False, embedded_path=None, rtloader_root=None, python_home_2=None, python_home_3=None, arch='x64'): """ Build the agent. If the bits to include in the build are not specified, the values from `invoke.yaml` will be used. Example invokation: inv agent.build --build-exclude=systemd """ build_include = DEFAULT_BUILD_TAGS if build_include is None else build_include.split( ",") build_exclude = [] if build_exclude is None else build_exclude.split(",") ldflags, gcflags, env = get_build_flags(ctx, embedded_path=embedded_path, rtloader_root=rtloader_root, python_home_2=python_home_2, python_home_3=python_home_3, arch=arch) if not sys.platform.startswith('linux'): for ex in LINUX_ONLY_TAGS: if ex not in build_exclude: build_exclude.append(ex) # remove all tags that are only available on debian distributions distname = platform.linux_distribution()[0].lower() if distname not in REDHAT_AND_DEBIAN_DIST: for ex in REDHAT_AND_DEBIAN_ONLY_TAGS: if ex not in build_exclude: build_exclude.append(ex) if sys.platform == 'win32': windres_target = "pe-x86-64" if arch == "x86": env["GOARCH"] = "386" windres_target = "pe-i386" # This generates the manifest resource. The manifest resource is necessary for # being able to load the ancient C-runtime that comes along with Python 2.7 # command = "rsrc -arch amd64 -manifest cmd/agent/agent.exe.manifest -o cmd/agent/rsrc.syso" ver = get_version_numeric_only(ctx) build_maj, build_min, build_patch = ver.split(".") command = "windmc --target {target_arch} -r cmd/agent cmd/agent/agentmsg.mc ".format( target_arch=windres_target) ctx.run(command, env=env) command = "windres --target {target_arch} --define MAJ_VER={build_maj} --define MIN_VER={build_min} --define PATCH_VER={build_patch} --define BUILD_ARCH_{build_arch}=1".format( build_maj=build_maj, build_min=build_min, build_patch=build_patch, target_arch=windres_target, build_arch=arch) command += "-i cmd/agent/agent.rc -O coff -o cmd/agent/rsrc.syso" ctx.run(command, env=env) if puppy: # Puppy mode overrides whatever passed through `--build-exclude` and `--build-include` build_tags = get_default_build_tags(puppy=True) else: build_tags = get_build_tags(build_include, build_exclude) cmd = "go build {race_opt} {build_type} -tags \"{go_build_tags}\" " cmd += "-o {agent_bin} -gcflags=\"{gcflags}\" -ldflags=\"{ldflags}\" {REPO_PATH}/cmd/agent" args = { "race_opt": "-race" if race else "", "build_type": "-a" if rebuild else ("-i" if precompile_only else ""), "go_build_tags": " ".join(build_tags), "agent_bin": os.path.join(BIN_PATH, bin_name("agent", android=False)), "gcflags": gcflags, "ldflags": ldflags, "REPO_PATH": REPO_PATH, } ctx.run(cmd.format(**args), env=env) # Render the configuration file template # # We need to remove cross compiling bits if any because go generate must # build and execute in the native platform env.update({ "GOOS": "", "GOARCH": "", }) cmd = "go generate {}/cmd/agent" ctx.run(cmd.format(REPO_PATH), env=env) if not skip_assets: refresh_assets(ctx, build_tags, development=development, puppy=puppy)
#!/usr/bin/env python # dist.py - Identify Linux Distro # # Copyright 2016 Andrew Peabody. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import platform print("Distro: " + platform.linux_distribution()[0]); print("Version: " + platform.linux_distribution()[1]);
#!/usr/bin/python2 import sys import platform from lxml import etree # This script checks the validity of assigned CCEs, lists granted and remaining # available CCEs, and checks for duplicates. release = '%.0f' % float(platform.linux_distribution()[1]) xccdf_ns = "http://checklists.nist.gov/xccdf/1.1" tree = etree.parse('../output/unlinked-rhel' + str(release) + '-xccdf.xml') cces_assigned = tree.findall("//{%s}ident[@system='http://cce.mitre.org']" % xccdf_ns) assigned_ids = [] granted_ids = [] # print the list of assigned CCEs print "Assigned CCEs:" for item in cces_assigned: print item.text assigned_ids.append(item.text) print "-------------" # check for duplicates in the assigned CCE list dup_assigned_ids = [ item for item in cces_assigned if cces_assigned.count(item) > 1 ] for item in dup_assigned_ids: print "Duplicate assignment of CCE: %s" % item
from setuptools import setup, find_packages import platform import re distro, version, _ = platform.dist() if not distro: distro, version, _ = platform.linux_distribution( supported_dists=['system']) # Default to cent7 data_files = [ ('/usr/lib/systemd/system', ['pkg/hubble.service']), ('/etc/hubble', ['conf/hubble']), ] if distro == 'redhat' or distro == 'centos': if version.startswith('6'): data_files = [ ('/etc/init.d', ['pkg/hubble']), ('/etc/hubble', ['conf/hubble']), ] elif version.startswith('7'): data_files = [ ('/usr/lib/systemd/system', ['pkg/hubble.service']), ('/etc/hubble', ['conf/hubble']), ] elif distro == 'Amazon Linux AMI': data_files = [ ('/etc/init.d', ['pkg/hubble']), ('/etc/hubble', ['conf/hubble']), ]
import numpy as np from sklearn.pipeline import Pipeline from sklearn.linear_model import LogisticRegression from sklearn.model_selection import LeaveOneGroupOut from sklearn.svm import LinearSVC from sklearn.preprocessing import StandardScaler if sys.platform == 'darwin': cfg = os.path.join("/Users", "njchiang", "CloudStation", "Grad", "Research", "montilab-ucla", "analogy", "config", "project.json") plat = "osx" elif sys.platform == "linux": import platform if platform.linux_distribution()[0] == "debian": cfg = os.path.join("/home", "njchiang", "data", "CloudStation", "Grad", "Research", "montilab-ucla", "analogy", "config", "project.json") plat = "linux" else: cfg = os.path.join("/u", "project", "monti", "Analysis", "Analogy", "code", "analogy", "config", "project.json") plat = "hoff" else: cfg = os.path.join("D:\\", "CloudStation", "Grad", "Research", "montilab-ucla", "analogy", "config", "project.json") plat = "win" with open(cfg, "r") as f: projectSettings = json.load(f)
def hello () : return "Python %s - Flask & Uwsgi - Ubuntu %s." % ( version [0] , linux_distribution () [1] ) #Yeah, I love spaces!
def _generate_environment(instack_root): """Generate an environment dict for instack The returned dict will have the necessary values for use as the env parameter when calling instack via the subprocess module. :param instack_root: The path containing the instack-undercloud elements and json files. """ instack_env = dict(os.environ) # Rabbit uses HOSTNAME, so we need to make sure it's right instack_env['HOSTNAME'] = CONF.undercloud_hostname or socket.gethostname() # Find the paths we need json_file_dir = '/usr/share/instack-undercloud/json-files' if not os.path.isdir(json_file_dir): json_file_dir = os.path.join(instack_root, 'json-files') instack_undercloud_elements = '/usr/share/instack-undercloud' if not os.path.isdir(instack_undercloud_elements): instack_undercloud_elements = os.path.join(instack_root, 'elements') tripleo_puppet_elements = '/usr/share/tripleo-puppet-elements' if not os.path.isdir(tripleo_puppet_elements): tripleo_puppet_elements = os.path.join(os.getcwd(), 'tripleo-puppet-elements', 'elements') if 'ELEMENTS_PATH' in os.environ: instack_env['ELEMENTS_PATH'] = os.environ['ELEMENTS_PATH'] else: instack_env['ELEMENTS_PATH'] = ('%s:%s:' '/usr/share/tripleo-image-elements:' '/usr/share/diskimage-builder/elements' ) % (tripleo_puppet_elements, instack_undercloud_elements) # Distro-specific values distro = platform.linux_distribution()[0] if distro.startswith('Red Hat Enterprise Linux'): instack_env['NODE_DIST'] = os.environ.get('NODE_DIST') or 'rhel7' instack_env['JSONFILE'] = (os.environ.get('JSONFILE') or os.path.join( json_file_dir, 'rhel-7-undercloud-packages.json')) instack_env['REG_METHOD'] = 'disable' instack_env['REG_HALT_UNREGISTER'] = '1' elif distro.startswith('CentOS'): instack_env['NODE_DIST'] = os.environ.get('NODE_DIST') or 'centos7' instack_env['JSONFILE'] = (os.environ.get('JSONFILE') or os.path.join( json_file_dir, 'centos-7-undercloud-packages.json')) elif distro.startswith('Fedora'): instack_env['NODE_DIST'] = os.environ.get('NODE_DIST') or 'fedora' raise RuntimeError('Fedora is not currently supported') else: raise RuntimeError('%s is not supported' % distro) # Convert conf opts to env values for opt in _opts: env_name = opt.name.upper() instack_env[env_name] = six.text_type(CONF[opt.name]) # Opts that needs extra processing if CONF.inspection_runbench and not CONF.inspection_extras: raise RuntimeError('inspection_extras must be enabled for ' 'inspection_runbench to work') if CONF.inspection_extras: instack_env['INSPECTION_COLLECTORS'] = 'default,extra-hardware,logs' else: instack_env['INSPECTION_COLLECTORS'] = 'default,logs' inspection_kernel_args = [] if CONF.undercloud_debug: inspection_kernel_args.append('ipa-debug=1') if CONF.inspection_runbench: inspection_kernel_args.append('ipa-inspection-benchmarks=cpu,mem,disk') if CONF.inspection_extras: inspection_kernel_args.append('ipa-inspection-dhcp-all-interfaces=1') instack_env['INSPECTION_KERNEL_ARGS'] = ' '.join(inspection_kernel_args) instack_env['PUBLIC_INTERFACE_IP'] = instack_env['LOCAL_IP'] instack_env['LOCAL_IP'] = instack_env['LOCAL_IP'].split('/')[0] if instack_env['UNDERCLOUD_SERVICE_CERTIFICATE']: instack_env['UNDERCLOUD_SERVICE_CERTIFICATE'] = os.path.abspath( instack_env['UNDERCLOUD_SERVICE_CERTIFICATE']) # We're not in a chroot so this doesn't make sense, and it causes weird # errors if it's set. if instack_env.get('DIB_YUM_REPO_CONF'): del instack_env['DIB_YUM_REPO_CONF'] instack_env['TRIPLEO_INSTALL_USER'] = getpass.getuser() instack_env['TRIPLEO_UNDERCLOUD_CONF_FILE'] = PATHS.CONF_PATH instack_env['TRIPLEO_UNDERCLOUD_PASSWORD_FILE'] = PATHS.PASSWORD_PATH _generate_endpoints(instack_env) _write_password_file(instack_env) if CONF.generate_service_certificate: public_vip = CONF.undercloud_public_vip instack_env['UNDERCLOUD_SERVICE_CERTIFICATE'] = ( '/etc/pki/tls/certs/undercloud-%s.pem' % public_vip) return instack_env
def detect_platform(): base_mapping = { 'gentoo base system': 'gentoo', 'centos linux': 'centos', 'mandriva linux': 'mandriva', 'elementary os': 'ubuntu', 'trisquel': 'ubuntu', 'linaro': 'ubuntu', 'linuxmint': 'ubuntu', 'amazon': 'ubuntu', 'redhat enterprise linux': 'rhel', 'red hat enterprise linux server': 'rhel', 'oracle linux server': 'rhel', 'fedora': 'rhel', 'olpc': 'rhel', 'xo-system': 'rhel', 'kali linux': 'debian', } platform_mapping = { 'ubuntu': 'debian', 'rhel': 'centos', } if hasattr(pyplatform, 'mac_ver') and pyplatform.mac_ver()[0] != '': return 'osx', 'osx' if pyplatform.system() != 'Linux': res = pyplatform.system().lower() return res, res dist = '' (major, minor, _) = pyplatform.python_version_tuple() major = int(major) minor = int(minor) if (major * 10 + minor) >= 36: import distro dist = distro.linux_distribution()[0].split()[0] elif (major * 10 + minor) >= 26: dist = pyplatform.linux_distribution()[0] else: dist = pyplatform.dist()[0] if dist == '': if os.path.exists('/etc/os-release'): release = open('/etc/os-release').read() if 'Arch Linux' in release: dist = 'arch' if dist == '': if os.path.exists('/etc/system-release'): release = open('/etc/system-release').read() if 'Amazon Linux AMI' in release: dist = 'centos' if dist == '': try: dist = subprocess.check_output(['strings', '-4', '/etc/issue' ]).split()[0].strip().decode() except subprocess.CalledProcessError as e: dist = 'unknown' res = dist.strip(' \'"\t\n\r').lower() if res in base_mapping: res = base_mapping[res] res_mapped = res if res in platform_mapping: res_mapped = platform_mapping[res] return res, res_mapped
def get_os_distribution(): return platform.linux_distribution()[0]
def get_os_distribution_version_major(): return platform.linux_distribution()[1].split('.')[0]