示例#1
1
def get_platform_full():
    type_info = ""
    try:
        type_info = "%s PROC: %s ARCH: %s" % (" ".join(platform.win32_ver()),
                                              platform.processor(), " ".join(
                                                  platform.architecture()))
    except Exception, e:
        type_info = " ".join(platform.win32_ver())
示例#2
0
def get_os_info():
    """
    Get Operating System type/distribution and major version

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    """
    info = platform.system_alias(platform.system(), platform.release(), platform.version())
    os_type, os_ver, _ = info
    os_type = os_type.lower()
    if os_type.startswith("linux"):
        info = platform.linux_distribution()
        # On arch, platform.linux_distribution() is reportedly ('','',''),
        # so handle it defensively
        if info[0]:
            os_type = info[0]
        if info[1]:
            os_ver = info[1]
    elif os_type.startswith("darwin"):
        os_ver = subprocess.Popen(["sw_vers", "-productVersion"], stdout=subprocess.PIPE).communicate()[0]
        os_ver = os_ver.partition(".")[0]
    elif os_type.startswith("freebsd"):
        # eg "9.3-RC3-p1"
        os_ver = os_ver.partition("-")[0]
        os_ver = os_ver.partition(".")[0]
    elif platform.win32_ver()[1]:
        os_ver = platform.win32_ver()[1]
    else:
        # Cases known to fall here: Cygwin python
        os_ver = ""
    return os_type, os_ver
示例#3
0
def WriteReportSum(path,caseSucCount, caseLosCount,caseNRCount,interfaceSucCount,interfaceLosCount,interfaceNRCount,checkPointSucCount, checkPointLosCount, startTime): 
    import platform, socket
    oExcel=excel(path)
    platformSys=platform.system()+' '+platform.win32_ver()[0]+"("+platform.win32_ver()[2]+")"
    localIP = socket.gethostbyname(socket.gethostname())
    oExcel.write_data(1, 7, 1,platformSys)
    oExcel.write_data(1, 7, 2,localIP)
    oExcel.write_data(1, 11, 1,"MTing")
    oExcel.write_data(1, 11, 2,"Tomcat")
    oExcel.write_data(1, 11, 3,"MYSQL")
    oExcel.write_data(1, 15, 1,startTime)
    
    oExcel.write_data(1, 19, 2,caseSucCount)
    oExcel.write_data(1, 20, 2,caseLosCount)
    oExcel.write_data(1, 22, 2,caseNRCount)
    
    oExcel.write_data(1, 19, 4,interfaceSucCount)
    oExcel.write_data(1, 20, 4,interfaceLosCount)
    oExcel.write_data(1, 22, 4,interfaceNRCount)
    
    oExcel.write_data(1, 19, 6,checkPointSucCount)
    oExcel.write_data(1, 20, 6,checkPointLosCount)
    
    endTime=GetCalTime()
    oExcel.write_data(1, 15, 2,endTime)
    oExcel.write_data(1, 15, 3,endTime-startTime)
    oExcel.close()
    del oExcel
示例#4
0
文件: sysinfo.py 项目: lyasper/pclib
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()
示例#5
0
def format_platform_info():
    platform_info = [
        'architecture: %s %s\n' % platform.architecture(),
        'machine: %s\n' % platform.machine(),
        'platform: %s\n' % platform.platform(),
    ]
    libc_ver = '%s: %s\n' % platform.libc_ver()
    if libc_ver.strip():
        platform_info.append(libc_ver)

    if platform.dist() != ('', '', ''):
        platform_info.append('GNU/Linux: %s\n' % ' '.join(platform.dist()))
    elif platform.mac_ver() != ('', ('', '', ''), ''):
        platform_info.append('Mac OS X: %s\n' % platform.mac_ver()[0])
    elif platform.win32_ver() != ('', '', '', ''):
        platform_info.append('Windows: %s\n' % platform.win32_ver()[0])

    platform_info.append('python_compiler: %s\n' % platform.python_compiler())
    platform_info.append(
        'python_implementation: %s\n' % platform.python_implementation())

    platform_info.append('locale: %s\n' % (locale.getlocale(),))
    platform_info.append('default encoding: %s\n' % sys.getdefaultencoding())
    platform_info.append('file system encoding: %s\n' % sys.getfilesystemencoding())

    return platform_info
    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
示例#7
0
def get_dist():
    if platform.dist()[0]:
        return platform.dist()[0].lower()
    elif platform.mac_ver()[0]:
        darwin_version = platform.mac_ver()[0].rsplit('.', 1)[0]
        return 'darwin%s' % darwin_version
    elif platform.win32_ver()[0]:
        return platform.win32_ver()[0].lower()
    return 'unknown'
 def _sys_get_os(self):
     return {
         'distro':  platform.system(),
         'version': platform.win32_ver()[0],
         'arch':    platform.architecture()[0],
         'kernel':  'N/A',
         'type':    platform.system(),
         'csd':     platform.win32_ver()[1],
     }
示例#9
0
文件: version.py 项目: bryson/salt
def system_information():
    """
    Report system versions.
    """

    def system_version():
        """
        Return host system version.
        """
        lin_ver = platform.linux_distribution()
        mac_ver = platform.mac_ver()
        win_ver = platform.win32_ver()

        if lin_ver[0]:
            return " ".join(lin_ver)
        elif mac_ver[0]:
            if isinstance(mac_ver[1], (tuple, list)) and "".join(mac_ver[1]):
                return " ".join([mac_ver[0], ".".join(mac_ver[1]), mac_ver[2]])
            else:
                return " ".join([mac_ver[0], mac_ver[2]])
        elif win_ver[0]:
            return " ".join(win_ver)
        else:
            return ""

    version = system_version()
    release = platform.release()
    if platform.win32_ver()[0]:
        import win32api

        if (sys.version_info.major == 2 and sys.version_info >= (2, 7, 12)) or (
            sys.version_info.major == 3 and sys.version_info >= (3, 5, 2)
        ):
            if win32api.GetVersionEx(1)[8] > 1:
                server = {
                    "Vista": "2008Server",
                    "7": "2008ServerR2",
                    "8": "2012Server",
                    "8.1": "2012ServerR2",
                    "10": "2016Server",
                }
                release = server.get(platform.release(), "UNKServer")
                _, ver, sp, extra = platform.win32_ver()
                version = " ".join([release, ver, sp, extra])

    system = [
        ("system", platform.system()),
        ("dist", " ".join(platform.dist())),
        ("release", release),
        ("machine", platform.machine()),
        ("version", version),
    ]

    for name, attr in system:
        yield name, attr
        continue
示例#10
0
def geisysteminfo():
    """"""
    print platform.system()
    print platform.version()
    print platform.architecture()
    print platform.node()
    print platform.java_ver()
    print platform.dist()
    print platform.python_version()
    print platform.win32_ver()
示例#11
0
文件: version.py 项目: bryson/salt
def system_information():
    '''
    Report system versions.
    '''

    def system_version():
        '''
        Return host system version.
        '''
        lin_ver = platform.linux_distribution()
        mac_ver = platform.mac_ver()
        win_ver = platform.win32_ver()

        if lin_ver[0]:
            return ' '.join(lin_ver)
        elif mac_ver[0]:
            if isinstance(mac_ver[1], (tuple, list)) and ''.join(mac_ver[1]):
                return ' '.join([mac_ver[0], '.'.join(mac_ver[1]), mac_ver[2]])
            else:
                return ' '.join([mac_ver[0], mac_ver[2]])
        elif win_ver[0]:
            return ' '.join(win_ver)
        else:
            return ''

    version = system_version()
    release = platform.release()
    if platform.win32_ver()[0]:
        import win32api
        if ((sys.version_info.major == 2 and sys.version_info >= (2, 7, 12))
                or (sys.version_info.major == 3 and sys.version_info >=
                    (3, 5, 2))):
            if win32api.GetVersionEx(1)[8] > 1:
                server = {
                    'Vista': '2008Server',
                    '7': '2008ServerR2',
                    '8': '2012Server',
                    '8.1': '2012ServerR2',
                    '10': '2016Server'
                }
                release = server.get(platform.release(), 'UNKServer')
                _, ver, sp, extra = platform.win32_ver()
                version = ' '.join([release, ver, sp, extra])

    system = [
        ('system', platform.system()),
        ('dist', ' '.join(platform.dist())),
        ('release', release),
        ('machine', platform.machine()),
        ('version', version),
    ]

    for name, attr in system:
        yield name, attr
        continue
def get_dist():
    '''
    Get the current os and version
    '''
    if platform.dist()[0]:
        return platform.dist()[0].lower()
    elif platform.mac_ver()[0]:
        darwin_version = platform.mac_ver()[0].rsplit('.', 1)[0]
        return 'darwin%s' % darwin_version
    elif platform.win32_ver()[0]:
        return platform.win32_ver()[0].lower()
    return 'unknown'
示例#13
0
 def get_os():
     """get operating system name of computer"""
     osname = platform.system()
     osver = ""
     if osname == "Darwin":
         osname = "Mac OSX"
         osver = platform.mac_ver()[0]
     if osname in ["Windows", "Win32"]:
         osver = platform.win32_ver()[0] + " " + platform.win32_ver()[1]
     if osname == "Linux":
         osver = platform.linux_distribution()[0] + " " + platform.linux_distribution()[1]
     return osname + " " + osver
    def testGotTimeline(self):
        if sys.platform in ('win32', 'cygwin'):
            if platform.win32_ver()[0] == 'XP':
                raise unittest.SkipTest(
                    'Test flaky on Windows XP. http://crbug.com/321529')

        # While the timeline is recording, call window.webkitRequestAnimationFrame.
        # This will create a FireAnimationEvent, which can be checked below. See:
        # https://developer.mozilla.org/en/docs/Web/API/window.requestAnimationFrame
        with inspector_timeline.InspectorTimeline.Recorder(self._tab):
            self._tab.ExecuteJavaScript("""
          var done = false;
          function sleep(ms) {
            var endTime = (new Date().getTime()) + ms;
            while ((new Date().getTime()) < endTime);
          }
          window.webkitRequestAnimationFrame(function() {
            sleep(10);
            window.done = true;
          });
          """)
            self._WaitForAnimationFrame()

        # There should be at least a FireAnimationFrame record with some duration.
        events = self._tab.timeline_model.GetAllEventsOfName(
            'FireAnimationFrame')
        self.assertTrue(len(events) > 0)
        self.assertTrue(events[0].duration > 0)
示例#15
0
    def _init_windows(self):
        #XXX Right answer here is GetSystemInfo().
        #XXX Does this work on all Windows flavours?
        self.os = "windows"
        PROCESSOR_ARCHITECTURE = os.environ.get("PROCESSOR_ARCHITECTURE")
        if PROCESSOR_ARCHITECTURE == "IA64":
            self.arch = "ia64"
        elif PROCESSOR_ARCHITECTURE == "x86":
            self.arch = "x86"
        elif PROCESSOR_ARCHITECTURE == "AMD64":
            self.arch = "x64"
        else:
            raise InternalError("unknown Windows PROCESSOR_ARCHITECTURE: %r"
                                % PROCESSOR_ARCHITECTURE)

        # Get some additional info from Python's core platform.py, if
        # available.
        #XXX Would be nice to extend platform.py's win32_ver to use
        #    the extra OSVERSIONINFOEX structure elements (esp. service
        #    package version).
        try:
            import platform
        except ImportError:
            log.debug("cannot get extra windows os info: no platform.py")
        else:
            release, version, csd, ptype = platform.win32_ver()
            if not release:
                log.debug("platform.py could not get extra windows os info")
            if release: self.os_name = release
            if version: self.os_ver = version
            if csd:     self.os_csd = csd
示例#16
0
文件: debug.py 项目: Coi-l/calibre
def print_basic_debug_info(out=None):
    if out is None:
        out = sys.stdout
    out = functools.partial(prints, file=out)
    import platform
    from calibre.constants import (__appname__, get_version, isportable, isosx,
                                   isfrozen, is64bit)
    out(__appname__, get_version(), 'Portable' if isportable else '',
        'embedded-python:', isfrozen, 'is64bit:', is64bit)
    out(platform.platform(), platform.system(), platform.architecture())
    if iswindows and not is64bit:
        try:
            import win32process
            if win32process.IsWow64Process():
                out('32bit process running on 64bit windows')
        except:
            pass
    out(platform.system_alias(platform.system(), platform.release(),
            platform.version()))
    out('Python', platform.python_version())
    try:
        if iswindows:
            out('Windows:', platform.win32_ver())
        elif isosx:
            out('OSX:', platform.mac_ver())
        else:
            out('Linux:', platform.linux_distribution())
    except:
        pass
    from calibre.customize.ui import has_external_plugins, initialized_plugins
    if has_external_plugins():
        names = (p.name for p in initialized_plugins() if getattr(p, 'plugin_path', None) is not None)
        out('Successfully initialized third party plugins:', ' && '.join(names))
示例#17
0
def get_system_stats():
    systemStats = {
        'machine': platform.machine(),
        'platform': sys.platform,
        'processor': platform.processor(),
        'pythonV': platform.python_version(),
    }

    platf = sys.platform
    
    if  Platform.is_linux(platf):
        grep = subprocess.Popen(['grep', 'model name', '/proc/cpuinfo'], stdout=subprocess.PIPE, close_fds=True)
        wc = subprocess.Popen(['wc', '-l'], stdin=grep.stdout, stdout=subprocess.PIPE, close_fds=True)
        systemStats['cpuCores'] = int(wc.communicate()[0])

    if Platform.is_darwin(platf):
        systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])

    if Platform.is_freebsd(platf):
        systemStats['cpuCores'] = int(subprocess.Popen(['sysctl', 'hw.ncpu'], stdout=subprocess.PIPE, close_fds=True).communicate()[0].split(': ')[1])

    if Platform.is_linux(platf):
        systemStats['nixV'] = platform.dist()

    elif Platform.is_darwin(platf):
        systemStats['macV'] = platform.mac_ver()

    elif Platform.is_freebsd(platf):
        version = platform.uname()[2]
        systemStats['fbsdV'] = ('freebsd', version, '')  # no codename for FreeBSD

    elif Platform.is_win32(platf):
        systemStats['winV'] = platform.win32_ver()

    return systemStats
示例#18
0
def _os_info():
    """Get operating system info.

    Return:
        A list of lines with version info.
    """
    lines = []
    releaseinfo = None
    if sys.platform == "linux":
        osver = ", ".join([e for e in platform.dist() if e])
        releaseinfo = _release_info()
    elif sys.platform == "win32":
        osver = ", ".join(platform.win32_ver())
    elif sys.platform == "darwin":
        # pylint: disable=unpacking-non-sequence
        # See https://bitbucket.org/logilab/pylint/issue/165/
        release, versioninfo, machine = platform.mac_ver()
        if all(not e for e in versioninfo):
            versioninfo = ""
        else:
            versioninfo = ".".join(versioninfo)
        osver = ", ".join([e for e in (release, versioninfo, machine) if e])
    else:
        osver = "?"
    lines.append("OS Version: {}".format(osver))
    if releaseinfo is not None:
        for (fn, data) in releaseinfo:
            lines += ["", "--- {} ---".format(fn), data]
    return lines
示例#19
0
 def get_platform(self):
     dist = ('linux', '0')
     if platform.system().lower() == 'linux':
         dist = platform.linux_distribution()
     elif platform.system().lower() == 'windows':
         dist = ('windows', platform.win32_ver()[0])
     return (self._format_string(dist[0]), self._format_string(dist[1]))
示例#20
0
文件: debug.py 项目: randy1/calibre
def print_basic_debug_info(out=None):
    if out is None:
        out = sys.stdout
    out = functools.partial(prints, file=out)
    import platform
    from calibre.constants import (__appname__, get_version, isportable, isosx,
                                   isfrozen, is64bit)
    out(__appname__, get_version(), 'Portable' if isportable else '',
        'isfrozen:', isfrozen, 'is64bit:', is64bit)
    out(platform.platform(), platform.system(), platform.architecture())
    if iswindows and not is64bit:
        try:
            import win32process
            if win32process.IsWow64Process():
                out('32bit process running on 64bit windows')
        except:
            pass
    out(platform.system_alias(platform.system(), platform.release(),
            platform.version()))
    out('Python', platform.python_version())
    try:
        if iswindows:
            out('Windows:', platform.win32_ver())
        elif isosx:
            out('OSX:', platform.mac_ver())
        else:
            out('Linux:', platform.linux_distribution())
    except:
        pass
示例#21
0
def _os_info():
    """Get operating system info.

    Return:
        A list of lines with version info.
    """
    lines = []
    releaseinfo = None
    if sys.platform == 'linux':
        osver = ''
        releaseinfo = _release_info()
    elif sys.platform == 'win32':
        osver = ', '.join(platform.win32_ver())
    elif sys.platform == 'darwin':
        release, versioninfo, machine = platform.mac_ver()
        if all(not e for e in versioninfo):
            versioninfo = ''
        else:
            versioninfo = '.'.join(versioninfo)
        osver = ', '.join([e for e in [release, versioninfo, machine] if e])
    else:
        osver = '?'
    lines.append('OS Version: {}'.format(osver))
    if releaseinfo is not None:
        for (fn, data) in releaseinfo:
            lines += ['', '--- {} ---'.format(fn), data]
    return lines
示例#22
0
def get_system_info(hass, include_components):
    """Return info about the system."""
    info_object = {
        'arch': platform.machine(),
        'dev': 'dev' in current_version,
        'docker': False,
        'os_name': platform.system(),
        'python_version': platform.python_version(),
        'timezone': dt_util.DEFAULT_TIME_ZONE.zone,
        'version': current_version,
        'virtualenv': os.environ.get('VIRTUAL_ENV') is not None,
        'hassio': hass.components.hassio.is_hassio(),
    }

    if include_components:
        info_object['components'] = list(hass.config.components)

    if platform.system() == 'Windows':
        info_object['os_version'] = platform.win32_ver()[0]
    elif platform.system() == 'Darwin':
        info_object['os_version'] = platform.mac_ver()[0]
    elif platform.system() == 'FreeBSD':
        info_object['os_version'] = platform.release()
    elif platform.system() == 'Linux':
        import distro
        linux_dist = yield from hass.async_add_job(
            distro.linux_distribution, False)
        info_object['distribution'] = linux_dist[0]
        info_object['os_version'] = linux_dist[1]
        info_object['docker'] = os.path.isfile('/.dockerenv')

    return info_object
示例#23
0
文件: update.py 项目: exic/ankiqt
 def _data(self):
     # we may get an interrupted system call, so try this in a loop
     n = 0
     theos = "unknown"
     while n < 100:
         n += 1
         try:
             system = platform.system()
             if isMac:
                 theos = "mac:%s" % (platform.mac_ver()[0])
             elif isWin:
                 theos = "win:%s" % (platform.win32_ver()[0])
             elif system == "Linux":
                 dist = platform.dist()
                 theos = "lin:%s:%s" % (dist[0], dist[1])
             else:
                 theos = system
             break
         except:
             continue
     d = {"ver": aqt.appVersion,
          "os": theos,
          "id": self.config['id'],
          "lm": self.config['lastMsg'],
          "crt": self.config['created']}
     return d
示例#24
0
  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()),
              )
示例#25
0
    def create(self):
        vbox = wx.BoxSizer(wx.VERTICAL)

        title = wx.StaticText(self, -1, "Fields to Omit")
        vbox.Add(title, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.TOP | wx.BOTTOM, 10)

        if platform.win32_ver()[0] == 'XP':
            self.anonList = AnonymizeListXP(self)
        else:
            self.anonList = AnonymizeList(self)

        hbox = wx.BoxSizer(wx.HORIZONTAL)

        self.store = wx.Button(self, -1, "Set as Default", size=(120, -1))
        self.revert = wx.Button(self, -1, "Revert to Defaults", size=(120, -1))
        self.revert.Bind(wx.EVT_BUTTON, self.RevertState)
        self.store.Bind(wx.EVT_BUTTON, self.SaveState)

        opts = wx.ALIGN_RIGHT | wx.TOP | wx.LEFT

        hbox.Add(self.store, 0, opts, 10)
        hbox.Add(self.revert, 0, opts, 10)

        vbox.Add(self.anonList, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        vbox.Add(hbox, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.BOTTOM, 15)
        self.SetSizer(vbox)
示例#26
0
  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)
示例#27
0
def display_platform():
    # environment info
    is_virtualenv = "VIRTUAL_ENV" in os.environ
    print("sys.executable: ", sys.executable)
    print("virtualenv:", os.environ.get("VIRTUAL_ENV", "no"))

    # operating system info

    def linux_distribution():
      try:
        return platform.linux_distribution()
      except:
        return "N/A"

    print("""Python version: %s
    dist: %s
    linux_distribution: %s
    system: %s
    machine: %s
    platform: %s
    version: %s
    mac_ver: %s
    win32_ver: %s
    """ % (
    sys.version.split('\n'),
    str(platform.dist()),
    linux_distribution(),
    platform.system(),
    platform.machine(),
    platform.platform(),
    platform.version(),
    platform.mac_ver(),
    platform.win32_ver(),
    ))
示例#28
0
 def capture_exception(self, request=None):
     if not RAVEN_AVAILABLE:
         return
     if os.path.exists(".git"):
         log.warning("A .git directory exist crash report is turn off for developers")
         return
     server_config = Config.instance().get_section_config("Server")
     if server_config.getboolean("report_errors"):
         if self._client is None:
             self._client = raven.Client(CrashReport.DSN, release=__version__, raise_send_errors=True)
         if request is not None:
             self._client.http_context({
                 "method": request.method,
                 "url": request.path,
                 "data": request.json,
             })
         self._client.tags_context({
             "os:name": platform.system(),
             "os:release": platform.release(),
             "os:win_32": " ".join(platform.win32_ver()),
             "os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
             "os:linux": " ".join(platform.linux_distribution()),
             "python:version": "{}.{}.{}".format(sys.version_info[0],
                                                 sys.version_info[1],
                                                 sys.version_info[2]),
             "python:bit": struct.calcsize("P") * 8,
             "python:encoding": sys.getdefaultencoding(),
             "python:frozen": "{}".format(hasattr(sys, "frozen"))
         })
         try:
             report = self._client.captureException()
         except Exception as e:
             log.error("Can't send crash report to Sentry: {}".format(e))
             return
         log.info("Crash report sent with event ID: {}".format(self._client.get_ident(report)))
示例#29
0
    def get_os_version():
        if AbstractOSIntegration.is_mac():
            return platform.mac_ver()[0]
        if AbstractOSIntegration.is_windows():
            """
            5.0.2195    Windows 2000
            5.1.2600    Windows XP
                        Windows XP 64-Bit Edition Version 2002 (Itanium)
            5.2.3790    Windows Server 2003
                        Windows XP x64 Edition (AMD64/EM64T)
                        Windows XP 64-Bit Edition Version 2003 (Itanium)
            6.0.6000    Windows Vista
            6.0.6001    Windows Vista SP1
                        Windows Server 2008
            6.1.7600    Windows 7
                        Windows Server 2008 R2
            6.1.7601    Windows 7 SP1
                        Windows Server 2008 R2 SP1
            6.2.9200    Windows 8
                        Windows Server 2012
            6.3.9200    Windows 8.1
                        Windows Server 2012 R2
            6.3.9600    Windows 8.1 with Update 1
            6.4.        Windows 10
            """
            return platform.win32_ver()[1]

        raise RuntimeError('Cannot determine GNU/Linux version')
示例#30
0
 def captureException(self, exception, value, tb):
     if not RAVEN_AVAILABLE:
         return
     if os.path.exists(".git"):
         log.warning("A .git directory exist crash report is turn off for developers")
         return
     local_server = Servers.instance().localServerSettings()
     if local_server["report_errors"]:
         if self._client is None:
             self._client = raven.Client(CrashReport.DSN, release=__version__)
         self._client.tags_context({
             "os:name": platform.system(),
             "os:release": platform.release(),
             "os:win_32": " ".join(platform.win32_ver()),
             "os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
             "os:linux": " ".join(platform.linux_distribution()),
             "python:version": "{}.{}.{}".format(sys.version_info[0],
                                                 sys.version_info[1],
                                                 sys.version_info[2]),
             "python:bit": struct.calcsize("P") * 8,
             "python:encoding": sys.getdefaultencoding(),
             "python:frozen": "{}".format(hasattr(sys, "frozen"))
         })
         try:
             report = self._client.captureException((exception, value, tb))
         except Exception as e:
             log.error("Can't send crash report to Sentry: {}".format(e))
             return
         log.info("Crash report sent with event ID: {}".format(self._client.get_ident(report)))
示例#31
0
             'python_compiler': platform.python_compiler(),
             'python_implementation': platform.python_implementation(),
             'python_revision': platform.python_revision(),
             'python_version': platform.python_version(),
             'python_version_tuple': platform.python_version_tuple(),
             'release': platform.release(),
             'system': platform.system(),
             'uname': platform.uname(),
             'machine': platform.machine(),
             'node': platform.node(),
             'platform': platform.platform(),
             'processor': platform.processor(),
             'architecture': platform.architecture(),
             'version': platform.version(),
             'java_ver': platform.java_ver(),
             'win32_ver': platform.win32_ver(),
             'mac_ver': platform.mac_ver(),
             'linux_distribution': platform.linux_distribution(),
             'libc_ver': platform.libc_ver()
         }) + ';', verinfodata)
 if (sys.version[0] == "3"):
     '''verinfodata = verinfodata.replace('__build_python_info__ = {"python_branch": None, "python_build": None, "python_compiler": None, "python_implementation": None, "python_revision": None, "python_version": None, "python_version_tuple": None, "release": None, "system": None, "uname": None, "machine": None, "node": None, "platform": None, "processor": None, "version": None, "java_ver": None, "win32_ver": None, "mac_ver": None, "linux_distribution": None, "libc_ver": None};', '__build_python_info__ = '+str({'python_branch': platform.python_branch(), 'python_build': platform.python_build(), 'python_compiler': platform.python_compiler(), 'python_implementation': platform.python_implementation(), 'python_revision': platform.python_revision(), 'python_version': platform.python_version(), 'python_version_tuple': platform.python_version_tuple(), 'release': platform.release(), 'system': platform.system(), 'uname': (platform.uname()[0], platform.uname()[1], platform.uname()[2], platform.uname()[3], platform.uname()[4], platform.uname()[5]), 'machine': platform.machine(), 'node': platform.node(), 'platform': platform.platform(), 'processor': platform.processor(), 'architecture': platform.architecture(), 'version': platform.version(), 'java_ver': platform.java_ver(), 'win32_ver': platform.win32_ver(), 'mac_ver': platform.mac_ver(), 'linux_distribution': platform.linux_distribution(), 'libc_ver': platform.libc_ver()})+';');'''
     verinfodata = re.sub(
         "__build_python_info__ \= \{.*\}\;",
         '__build_python_info__ = ' + str({
             'python_branch':
             platform.python_branch(),
             'python_build':
             platform.python_build(),
             'python_compiler':
             platform.python_compiler(),
示例#32
0
from PyQt5.QtCore import PYQT_VERSION_STR

# Get settings
s = settings.get_settings()

# Determine OS version
os_version = "X11; Linux %s" % platform.machine()
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 = {
示例#33
0
# -*- coding: utf-8 -*-
import distutils.spawn
import os
from platform import win32_ver
import sys
import warnings

from colorama import Fore

MACOS = 'darwin'
WIN = 'win32'
IS_MACOS = sys.platform == MACOS
IS_WIN = sys.platform == WIN
WIN_VER = None
if IS_WIN:
    WIN_VER = win32_ver()[0]


def print_say(text, self, color=""):
    """
        Gives Jarvis the ability to print text
        and talk when sound is enabled.
        :param text: the text to print (or talk)
               color: Fore.COLOR (ex Fore.BLUE), color for text
        :return: Nothing to return.

        .. deprecated::
            Use ``JarvisAPI.say(text, color="", speak=True))`` instead.
    """
    warnings.warn(
        "GeneralUtilities.print_say is deprecated now and will be \
示例#34
0
def main():
    FULLDIR = "{}\\{}".format(MAINDIR, PROJECTDIR)
    print("""
  ######################################
  # R3FADVLOG Development Environment Setup #
  ######################################

  This script will create your R3FADVLOG dev environment for you.

  Before you run this, you should already have:
    - A properly setup ACE3 Development Environment

  If you have not done those things yet, please abort this script in the next step and do so first.

  This script will create two hard links on your system, both pointing to your R3FADVLOG project folder:
    [Arma 3 installation directory]\\{} => R3FADVLOG project folder
    P:\\{}                              => R3FADVLOG project folder
    """.format(FULLDIR, FULLDIR))
    print("\n")

    try:
        reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
        key = winreg.OpenKey(
            reg, r"SOFTWARE\Wow6432Node\bohemia interactive\arma 3")
        armapath = winreg.EnumValue(key, 1)[1]
    except:
        print("Failed to determine Arma 3 Path.")
        return 1

    if not os.path.exists("P:\\z\\ace"):
        print("No ACE3 Development Environment detected.")
        return 2

    scriptpath = os.path.realpath(__file__)
    projectpath = os.path.dirname(os.path.dirname(scriptpath))

    print("# Detected Paths:")
    print("  Arma Path:    {}".format(armapath))
    print("  Project Path: {}".format(projectpath))

    repl = input("\nAre these correct? (y/n): ")
    if repl.lower() != "y":
        return 3

    print("\n# Creating links ...")

    if os.path.exists("P:\\{}\\{}".format(MAINDIR, PROJECTDIR)):
        print("Link on P: already exists. Please finish the setup manually.")
        return 4

    if os.path.exists(os.path.join(armapath, MAINDIR, PROJECTDIR)):
        print(
            "Link in Arma directory already exists. Please finish the setup manually."
        )
        return 5

    try:
        if not os.path.exists("P:\\{}".format(MAINDIR)):
            os.mkdir("P:\\{}".format(MAINDIR))
        if not os.path.exists(os.path.join(armapath, MAINDIR)):
            os.mkdir(os.path.join(armapath, MAINDIR))

        if platform.win32_ver()[0] == "7":
            subprocess.call([
                "cmd", "/c", "mklink", "/D",
                "P:\\{}\\{}".format(MAINDIR, PROJECTDIR), projectpath
            ])
            subprocess.call([
                "cmd", "/c", "mklink", "/D",
                os.path.join(armapath, MAINDIR, PROJECTDIR), projectpath
            ])
        else:
            subprocess.call([
                "cmd", "/c", "mklink", "/D", "/J",
                "P:\\{}\\{}".format(MAINDIR, PROJECTDIR), projectpath
            ])
            subprocess.call([
                "cmd", "/c", "mklink", "/D", "/J",
                os.path.join(armapath, MAINDIR, PROJECTDIR), projectpath
            ])
    except:
        raise
        print(
            "Something went wrong during the link creation. Please finish the setup manually."
        )
        return 6

    print("# Links created successfully.")

    return 0
示例#35
0
def system_info():
    '''
    Get the sysem information.
    Return a tuple with the platform type, the architecture and the
    distribution
    '''

    # Get the platform info
    platform = sys.platform
    if platform.startswith('win'):
        platform = Platform.WINDOWS
    elif platform.startswith('darwin'):
        platform = Platform.DARWIN
    elif platform.startswith('linux'):
        platform = Platform.LINUX
    else:
        raise FatalError(_("Platform %s not supported") % platform)

    # Get the architecture info
    if platform == Platform.WINDOWS:
        platform_str = sysconfig.get_platform()
        if platform_str in ['win-amd64', 'win-ia64']:
            arch = Architecture.X86_64
        else:
            arch = Architecture.X86
    else:
        uname = os.uname()
        arch = uname[4]
        if arch == 'x86_64':
            arch = Architecture.X86_64
        elif arch.endswith('86'):
            arch = Architecture.X86
        elif arch == "Power Macintosh":
            arch = Architecture.PPC
        else:
            raise FatalError(_("Architecture %s not supported") % arch)

    # Get the distro info
    if platform == Platform.LINUX:
        d = pplatform.linux_distribution()
        if d[0] in ['Ubuntu', 'debian']:
            distro = Distro.DEBIAN
            if d[2] == 'maverick':
                distro_version = DistroVersion.UBUNTU_MAVERICK
            elif d[2] == 'lucid':
                distro_version = DistroVersion.UBUNTU_LUCID
            elif d[2] == 'natty':
                distro_version = DistroVersion.UBUNTU_NATTY
            elif d[2] == 'oneiric':
                distro_version = DistroVersion.UBUNTU_ONEIRIC
            elif d[2] == 'precise':
                distro_version = DistroVersion.UBUNTU_PRECISE
            elif d[2] == 'quantal':
                distro_version = DistroVersion.UBUNTU_QUANTAL
            elif d[2] == 'raring':
                distro_version = DistroVersion.UBUNTU_RARING
            elif d[2] == 'saucy':
                distro_version = DistroVersion.UBUNTU_SAUCY
            elif d[2] == 'trusty':
                distro_version = DistroVersion.UBUNTU_TRUSTY
            elif d[2] == 'utopic':
                distro_version = DistroVersion.UBUNTU_UTOPIC
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.DEBIAN_SQUEEZE
            elif d[1].startswith('7.') or d[1].startswith('wheezy'):
                distro_version = DistroVersion.DEBIAN_WHEEZY
            elif d[1].startswith('jessie'):
                distro_version = DistroVersion.DEBIAN_JESSIE
            else:
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0] in ['RedHat', 'Fedora', 'CentOS']:
            distro = Distro.REDHAT
            if d[1] == '16':
                distro_version = DistroVersion.FEDORA_16
            elif d[1] == '17':
                distro_version = DistroVersion.FEDORA_17
            elif d[1] == '18':
                distro_version = DistroVersion.FEDORA_18
            elif d[1] == '19':
                distro_version = DistroVersion.FEDORA_19
            elif d[1] == '20':
                distro_version = DistroVersion.FEDORA_20
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.REDHAT_6
            else:
                # FIXME Fill this
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0].strip() in ['openSUSE']:
            distro = Distro.SUSE
            if d[1] == '12.1':
                distro_version = DistroVersion.OPENSUSE_12_1
            elif d[1] == '12.2':
                distro_version = DistroVersion.OPENSUSE_12_2
            elif d[1] == '12.3':
                distro_version = DistroVersion.OPENSUSE_12_3
            else:
                # FIXME Fill this
                raise FatalError("Distribution OpenSuse '%s' "
                                 "not supported" % str(d))
        else:
            raise FatalError("Distribution '%s' not supported" % str(d))
    elif platform == Platform.WINDOWS:
        distro = Distro.WINDOWS
        win32_ver = pplatform.win32_ver()[0].lower()
        dmap = {
            'xp': DistroVersion.WINDOWS_XP,
            'vista': DistroVersion.WINDOWS_VISTA,
            '7': DistroVersion.WINDOWS_7,
            '8': DistroVersion.WINDOWS_8,
            'post2008server': DistroVersion.WINDOWS_8
        }
        if win32_ver in dmap:
            distro_version = dmap[win32_ver]
        else:
            raise FatalError("Windows version '%s' not supported" % win32_ver)
    elif platform == Platform.DARWIN:
        distro = Distro.OS_X
        ver = pplatform.mac_ver()[0]
        if ver.startswith('10.10'):
            distro_version = DistroVersion.OS_X_YOSEMITE
        elif ver.startswith('10.9'):
            distro_version = DistroVersion.OS_X_MAVERICKS
        elif ver.startswith('10.8'):
            distro_version = DistroVersion.OS_X_MOUNTAIN_LION
        elif ver.startswith('10.7'):
            distro_version = DistroVersion.OS_X_LION
        elif ver.startswith('10.6'):
            distro_version = DistroVersion.OS_X_SNOW_LEOPARD
        elif ver.startswith('10.5'):
            distro_version = DistroVersion.OS_X_LEOPARD
        else:
            raise FatalError("Mac version %s not supported" % ver)

    num_of_cpus = determine_num_of_cpus()

    return platform, arch, distro, distro_version, num_of_cpus
示例#36
0
    def __init__(self,
                 resource_id,
                 subject,
                 agent,
                 retry=True,
                 host=None,
                 session_headers=None):
        """
        Client constructor
        :param resource_id -- ID of the resource being accessed (URI format)
        as it appears in the registry.
        :param subject -- The subject that is using the service
        :type subject: cadcutil.auth.Subject
        :param agent -- Name of the agent (application) that accesses the
        service and its version, e.g. foo/1.0.2
        :type agent: Subject
        :param retry -- True if the client retries on transient errors False
        otherwise
        :param host -- override the name of the host the service is running on
        (for testing purposes)
        :param session_headers -- Headers used throughout the session -
        dictionary format expected.
        """

        self.logger = logging.getLogger('BaseWsClient')
        logging.getLogger('BaseWsClient').addHandler(logging.NullHandler())

        if resource_id is None:
            raise ValueError('No resource ID provided')
        if agent is None or not agent:
            raise ValueError('agent is None or empty string')

        self._session = None
        self.subject = subject
        self.resource_id = resource_id
        self.retry = retry
        self.session_headers = session_headers

        # agent is / delimited key value pairs, separated by a space,
        # containing the application name and version,
        # plus the name and version of application libraries.
        # eg: foo/1.0.2 foo-lib/1.2.3
        self.agent = agent

        # Get the package name and version, plus any imported libraries.
        self.package_info = "cadcutils/{} requests/{}".format(
            cadctools_version.version, requests.__version__)
        self.python_info = "{}/{}".format(platform.python_implementation(),
                                          platform.python_version())
        self.system_info = "{}/{}".format(platform.system(),
                                          platform.version())
        o_s = sys.platform
        if o_s.lower().startswith('linux'):
            distname, version, osid = distro.linux_distribution()
            self.os_info = "{} {}".format(distname, version)
        elif o_s == "darwin":
            release, version, machine = platform.mac_ver()
            self.os_info = "Mac OS X {}".format(release)
        elif o_s.lower().startswith("win32"):
            release, version, csd, ptype = platform.win32_ver()
            self.os_info = "{} {}".format(release, version)

        # build the corresponding capabilities instance
        self.caps = WsCapabilities(self, host)
        self._host = host
        if host is None:
            base_url = self.caps.get_access_url(SERVICE_AVAILABILITY_ID)
            self._host = urlparse(base_url).hostname

        # Clients should add entries to this dict for specialized
        # conversion of HTTP error codes into particular exceptions.
        #
        # Use this form to include a search string in the response to
        # handle multiple possibilities for a single HTTP code.
        #     XXX : {'SEARCHSTRING1' : exceptionInstance1,
        #            'SEARCHSTRING2' : exceptionInstance2}
        #
        # Otherwise provide a simple HTTP code -> exception mapping
        #     XXX : exceptionInstance
        #
        # The actual conversion is performed by get_exception()
        self._HTTP_STATUS_CODE_EXCEPTIONS = {
            401: exceptions.UnauthorizedException()
        }
示例#37
0
def main():  # pylint: disable=too-many-branches,too-many-locals,too-many-statements
    """Execute Main program."""
    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:
        if _IS_WINDOWS or sys.platform == "cygwin":
            distro = platform.win32_ver()
            root_logger.info("Windows Distribution: %s", distro)
        else:
            distro = platform.linux_distribution()
            root_logger.info("Linux Distribution: %s", 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", 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(
        '-m',
        '--process-match',
        dest='process_match',
        choices=['contains', 'exact'],
        default='contains',
        help="Type of match for process names (-p & -g), specify 'contains', or"
        " 'exact'. Note that the process name match performs the following"
        " conversions: change all process names to lowecase, strip off the file"
        " extension, like '.exe' on Windows. Default is 'contains'.")
    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, _) = 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)

    # Canonicalize the process names to lowercase to handle cases where the name of the Python
    # process is /System/Library/.../Python on OS X and -p python is specified to hang_analyzer.py.
    all_processes = [(pid, process_name.lower())
                     for (pid, process_name) in all_processes]

    # 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 pname_match(options.process_match, pname, 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 python processes by signalling them. The resmoke.py process will generate
    # the report.json, when signalled, so we do this before attaching to other processes.
    for (pid, process_name) in [(p, pn) for (p, pn) in processes
                                if pn.startswith("python")]:
        # On Windows, we set up an event object to wait on a signal. For Cygwin, we register
        # a signal handler to wait for the signal since it supports POSIX signals.
        if _IS_WINDOWS:
            root_logger.info(
                "Calling SetEvent to signal python process %s with PID %d",
                process_name, pid)
            signal_event_object(root_logger, pid)
        else:
            root_logger.info(
                "Sending signal SIGUSR1 to python process %s with PID %d",
                process_name, pid)
            signal_process(root_logger, pid, signal.SIGUSR1)

    trapped_exceptions = []

    # Dump all processes, 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)
        try:
            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()))
        except Exception as err:  # pylint: disable=broad-except
            root_logger.info("Error encountered when invoking debugger %s",
                             err)
            trapped_exceptions.append(traceback.format_exc())

        # 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)
        try:
            jstack.dump_info(root_logger, pid)
        except Exception as err:  # pylint: disable=broad-except
            root_logger.info("Error encountered when invoking debugger %s",
                             err)
            trapped_exceptions.append(traceback.format_exc())

        # 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)

    root_logger.info("Done analyzing all processes for hangs")

    for exception in trapped_exceptions:
        root_logger.info(exception)
    if trapped_exceptions:
        sys.exit(1)
        sys.exit(1)
    import platform

print platform.uname()
if platform.linux_distribution()[0] == "":
    pass
else:
    print platform.linux_distribution()
print platform.system()
print platform.platform()
print platform.architecture()
print platform.version()
print platform.release()
print platform.node()
print platform.machine()
print platform.win32_ver()

print os.name
print sys.platform

if 'nt' in os.name:
    print 'Windows'
elif 'posix' in os.name:
    print 'Linux'

try:
    with open('/etc/issue') as f:
        content = f.read().lower().strip()
        output_list = re.split(r' ', content)
        linux_type = list(output_list)[0]
except IOError:
def getOsVersion():
    version = platform.win32_ver()[1]
    build = getVersionRegKey('BuildLabEx').split('.')[1]
    return '{}.{}'.format(version, build)
示例#40
0
        os_version = OSVERSIONINFOEXW()
        os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
        retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))

        # Om failure, assume we have a newer version of windows
        if retcode != 0:
            return (10, 0)

        return (os_version.dwMajorVersion, os_version.dwMinorVersion)

    except:
        return (10, 0)


if platform.win32_ver()[0]:
    windows = get_windows_version()
elif os.environ.get("RENPY_PLATFORM", "").startswith("ios"):
    ios = True
elif platform.mac_ver()[0]:
    macintosh = True
elif "ANDROID_PRIVATE" in os.environ:
    android = True
elif sys.platform == 'emscripten' or "RENPY_EMSCRIPTEN" in os.environ:
    emscripten = True
else:
    linux = True

# A flag that's true if we're on a smartphone or tablet-like platform.
mobile = android or ios or emscripten
示例#41
0
from psutil._common import *

# Windows specific extended namespace
__all__ = base_module_namespace[:]
__all__.extend([
    "ABOVE_NORMAL_PRIORITY_CLASS", "BELOW_NORMAL_PRIORITY_CLASS",
    "HIGH_PRIORITY_CLASS", "IDLE_PRIORITY_CLASS", "NORMAL_PRIORITY_CLASS",
    "REALTIME_PRIORITY_CLASS"
])

# --- module level constants (gets pushed up to psutil module)

NUM_CPUS = _psutil_mswindows.get_num_cpus()
TOTAL_PHYMEM = _psutil_mswindows.get_total_phymem()
BOOT_TIME = _psutil_mswindows.get_system_uptime()
_WIN2000 = platform.win32_ver()[0] == '2000'
ERROR_ACCESS_DENIED = 5

# process priority constants:
# http://msdn.microsoft.com/en-us/library/ms686219(v=vs.85).aspx
from _psutil_mswindows import (ABOVE_NORMAL_PRIORITY_CLASS,
                               BELOW_NORMAL_PRIORITY_CLASS,
                               HIGH_PRIORITY_CLASS, IDLE_PRIORITY_CLASS,
                               NORMAL_PRIORITY_CLASS, REALTIME_PRIORITY_CLASS)

# --- public functions


def avail_phymem():
    "Return the amount of physical memory available on the system, in bytes."
    return _psutil_mswindows.get_avail_phymem()
示例#42
0
 def get_os_version(self):
     """Return the major version of Windows installed."""
     parts = platform.win32_ver()
     return parts[0]
示例#43
0
def diagnostic_info():
    """Return diagnostic information as a string"""
    s = "BleachBit version %s" % bleachbit.APP_VERSION
    try:
        import gtk
        s += '\nGTK+ version %s' % '.'.join([str(x) for x in gtk.gtk_version])
    except ImportError:
        s += '\nGTK+ not detected'
    import sqlite3
    s += "\nSQLite version %s" % sqlite3.sqlite_version
    s += "\nlocal_cleaners_dir = %s" % bleachbit.local_cleaners_dir
    s += "\nlocale_dir = %s" % bleachbit.locale_dir
    s += "\noptions_dir = %s" % bleachbit.options_dir.decode(bleachbit.FSE)
    s += "\npersonal_cleaners_dir = %s" % bleachbit.personal_cleaners_dir.decode(
        bleachbit.FSE)
    s += "\nsystem_cleaners_dir = %s" % bleachbit.system_cleaners_dir
    s += "\nlocale.getdefaultlocale = %s" % str(locale.getdefaultlocale())
    if 'posix' == os.name:
        envs = ('DESKTOP_SESSION', 'LOGNAME', 'USER', 'SUDO_UID')
    if 'nt' == os.name:
        envs = ('APPDATA', 'LocalAppData', 'LocalAppDataLow', 'Music',
                'USERPROFILE', 'ProgramFiles', 'ProgramW6432', 'TMP')
    for env in envs:
        if os.getenv(env):
            s += "\nos.getenv('%s') = %s" % (env,
                                             os.getenv(env).decode(bleachbit.FSE))
        else:
            s += "\nos.getenv('%s') = %s" % (env, os.getenv(env))
    s += "\nos.path.expanduser('~') = %s" % bleachbit.expanduser(
        '~').decode(bleachbit.FSE)
    if sys.platform.startswith('linux'):
        if hasattr(platform, 'linux_distribution'):
            s += "\nplatform.linux_distribution() = %s" % str(
                platform.linux_distribution())
        else:
            s += "\nplatform.dist() = %s" % str(platform.dist())

    # Mac Version Name - Dictionary
    macosx_dict = {'5': 'Leopard', '6': 'Snow Leopard', '7': 'Lion', '8': 'Mountain Lion',
                   '9': 'Mavericks', '10': 'Yosemite', '11': 'El Capitan', '12': 'Sierra'}

    if sys.platform.startswith('darwin'):
        if hasattr(platform, 'mac_ver'):
            for key in macosx_dict:
                if (platform.mac_ver()[0].split('.')[1] == key):
                    s += "\nplatform.mac_ver() = %s" % str(
                        platform.mac_ver()[0] + " (" + macosx_dict[key] + ")")
        else:
            s += "\nplatform.dist() = %s" % str(platform.dist())

    if 'nt' == os.name:
        s += "\nplatform.win32_ver[1]() = %s" % platform.win32_ver()[1]
    s += "\nplatform.platform = %s" % platform.platform()
    s += "\nplatform.version = %s" % platform.version()
    s += "\nsys.argv = %s" % sys.argv
    s += "\nsys.executable = %s" % sys.executable
    s += "\nsys.version = %s" % sys.version
    if 'nt' == os.name:
        s += "\nwin32com.shell.shell.IsUserAnAdmin() = %s" % shell.IsUserAnAdmin(
        )
    s += "\n__file__ = %s" % __file__

    return s
示例#44
0
# Data files (including DLLs) to include with the package.
package_data = [ ]

# A list of extension objects that we use.
extensions = [ ]

# A list of macros that are defined for all modules.
global_macros = [ ]

# True if we're building on android.
android = "PYGAME_SDL2_ANDROID" in os.environ

# True if we're building on ios.
ios = "PYGAME_SDL2_IOS" in os.environ

windows = platform.win32_ver()[0]

# The cython command.
if windows:
    cython_command = os.path.join(os.path.dirname(sys.executable), "Scripts", "cython.exe")
else:
    cython_command = "cython"


if sys.version_info[0] >= 3:
    version_flag = "-3"
    gen = "gen3"
else:
    version_flag = "-2"
    gen = "gen"
示例#45
0
def get_day_name_offset_dict(user_locale):
    """ The day name to offset dict maps a day name to a numerical day offset which can be used to add days to the current date.
        Day names will match the provided user locale and will be in lowercase.
    """

    offset_dict = {}

    # Todays birthdays will be shown normally (as a date) so start from tomorrow
    start_date = datetime.now() + relativedelta(days=1)

    # Method 1: Babel
    try:
        babel_locale = Locale.parse(user_locale, sep='_')
        cur_date = start_date

        # Iterate through the following 7 days
        for i in range(1, 8):
            offset_dict[format_date(cur_date, 'EEEE',
                                    locale=babel_locale).lower()] = i
            cur_date = cur_date + relativedelta(days=1)

        return offset_dict
    except UnknownLocaleError as e:
        logger.debug(f'Babel UnknownLocaleError: {e}')

    # Method 2: System locale
    cur_date = start_date
    locale_check_list = [
        user_locale, user_locale + 'UTF-8', user_locale + 'utf-8'
    ]
    system_locale = None

    # Windows
    if any(platform.win32_ver()):
        for locale_to_check in locale_check_list:
            if locale_to_check in locale.windows_locale.values():
                system_locale = locale_to_check
                break
    # POSIX
    else:
        for locale_to_check in locale_check_list:
            if locale_to_check in locale.locale_alias.values():
                system_locale = locale_to_check
                break

    # Check if system locale was found
    if system_locale:
        locale.setlocale(locale.LC_ALL, system_locale)

        # Iterate through the following 7 days
        for i in range(1, 8):
            offset_dict[cur_date.strftime('%A').lower()] = i
            cur_date = cur_date + relativedelta(days=1)

        return offset_dict
    else:
        logger.debug(
            f"Unable to find system locale for provided user locale: '{user_locale}'"
        )

    # Failure
    logger.error(
        f"Failed to generate day name offset dictionary for provided user locale: '{user_locale}'"
    )
    raise SystemError
示例#46
0
 def test_win32_ver(self):
     res = platform.win32_ver()
示例#47
0
def get_sys_info():
    # delay these imports until now as they are only needed in this
    # function which then exits.
    import platform
    import json
    import multiprocessing
    from numba import config
    from numba import cuda as cu
    from numba.cuda import cudadrv
    from numba.cuda.cudadrv.driver import driver as cudriver
    from numba import roc
    from numba.roc.hlc import hlc, libhlc
    import textwrap as tw
    import ctypes as ct
    import llvmlite.binding as llvmbind
    import locale
    from datetime import datetime
    from itertools import chain
    from subprocess import check_output, CalledProcessError

    try:
        fmt = "%-45s : %-s"
        print("-" * 80)
        print("__Time Stamp__")
        print(datetime.utcnow())
        print("")

        print("__Hardware Information__")
        system_name = platform.system()
        print(fmt % ("Machine", platform.machine()))
        print(fmt % ("CPU Name", llvmbind.get_host_cpu_name()))
        if system_name == 'Linux':
            strmatch = 'Cpus_allowed'
            try:
                loc = '/proc/self/status'
                with open(loc, 'rt') as f:
                    proc_stat = f.read().splitlines()
                    for x in proc_stat:
                        if x.startswith(strmatch):
                            if x.startswith('%s:' % strmatch):
                                hexnum = '0x%s' % x.split(':')[1].strip()
                                acc_cpus = int(hexnum, 16)
                                _n = str(bin(acc_cpus).count('1'))
                                print(fmt % ("Number of accessible CPU cores",
                                                _n))
                            elif x.startswith('%s_list:' % strmatch):
                                _a = x.split(':')[1].strip()
                                print(fmt % ("Listed accessible CPUs cores",
                                                _a))
            except Exception:
                print(fmt % ("CPU count", multiprocessing.cpu_count()))
            # See if CFS is in place
            # https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt
            try:
                def scrape_lines(loc):
                    with open(loc, 'rt') as f:
                        return f.read().splitlines()
                loc = '/sys/fs/cgroup/cpuacct/cpu.cfs_period_us'
                cfs_period = int(scrape_lines(loc)[0])
                loc = '/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us'
                cfs_quota = int(scrape_lines(loc)[0])
                if cfs_quota == -1:
                    print(fmt % ("CFS restrictions", "None"))
                else:
                    runtime_amount = float(cfs_quota)/float(cfs_period)
                    print(fmt % ("CFS restrictions (CPUs worth of runtime)",
                                 runtime_amount))
            except Exception:
                print(fmt % ("CFS restrictions", 'Information not available'))
        else:
            print(fmt % ("CPU count", multiprocessing.cpu_count()))

        try:
            featuremap = llvmbind.get_host_cpu_features()
        except RuntimeError:
            print(fmt % ("CPU Features", "NA"))
        else:
            features = sorted([key for key, value in featuremap.items()
                               if value])
            cpu_feat = tw.fill(' '.join(features), 80)
            print(fmt % ("CPU Features", ""))
            print(cpu_feat)
        print("")

        print("__OS Information__")
        print(fmt % ("Platform", platform.platform(aliased=True)))
        print(fmt % ("Release", platform.release()))
        print(fmt % ("System Name", system_name))
        print(fmt % ("Version", platform.version()))
        try:
            if system_name == 'Linux':
                info = platform.linux_distribution()
            elif system_name == 'Windows':
                info = platform.win32_ver()
            elif system_name == 'Darwin':
                info = platform.mac_ver()
            else:
                raise RuntimeError("Unknown system.")
            buf = ''.join([x
                           if x != '' else ' '
                           for x in list(chain.from_iterable(info))])
            print(fmt % ("OS specific info", buf))

            if system_name == 'Linux':
                print(fmt % ("glibc info", ' '.join(platform.libc_ver())))
        except:
            print("Error: System name incorrectly identified or unknown.")
        print("")

        print("__Python Information__")
        print(fmt % ("Python Compiler", platform.python_compiler()))
        print(
            fmt %
            ("Python Implementation",
             platform.python_implementation()))
        print(fmt % ("Python Version", platform.python_version()))
        lcl = []
        try:
            for x in locale.getdefaultlocale():
                if x is not None:
                    lcl.append(x)
        except Exception as e:
            lcl.append(str(e))
        print(fmt % ("Python Locale ", ' '.join(lcl)))

        print("")
        print("__LLVM information__")
        print(
            fmt %
            ("LLVM version", '.'.join(
                [str(k) for k in llvmbind.llvm_version_info])))

        print("")
        print("__CUDA Information__")
        # Look for GPUs
        try:
            cu.list_devices()[0]  # will a device initialise?
        except Exception as e:
            msg_not_found = "CUDA driver library cannot be found"
            msg_disabled_by_user = "******"
            msg_end = " or no CUDA enabled devices are present."
            msg_generic_problem = "Error: CUDA device intialisation problem."
            msg = getattr(e, 'msg', None)
            if msg is not None:
                if msg_not_found in msg:
                    err_msg = msg_not_found + msg_end
                elif msg_disabled_by_user in msg:
                    err_msg = msg_disabled_by_user + msg_end
                else:
                    err_msg = msg_generic_problem + " Message:" + msg
            else:
                err_msg = msg_generic_problem + " " + str(e)
            # Best effort error report
            print("%s\nError class: %s" % (err_msg, str(type(e))))
        else:
            try:
                cu.detect()
                dv = ct.c_int(0)
                cudriver.cuDriverGetVersion(ct.byref(dv))
                print(fmt % ("CUDA driver version", dv.value))
                print("CUDA libraries:")
                cudadrv.libs.test(sys.platform, print_paths=False)
            except:
                print(
                    "Error: Probing CUDA failed (device and driver present, runtime problem?)\n")

        print("")
        print("__ROC Information__")
        roc_is_available = roc.is_available()
        print(fmt % ("ROC available", roc_is_available))

        toolchains = []
        try:
            libhlc.HLC()
            toolchains.append('librocmlite library')
        except:
            pass
        try:
            cmd = hlc.CmdLine().check_tooling()
            toolchains.append('ROC command line tools')
        except:
            pass

        # if no ROC try and report why
        if not roc_is_available:
            from numba.roc.hsadrv.driver import hsa
            try:
                hsa.is_available
            except Exception as e:
                msg = str(e)
            else:
               msg = 'No ROC toolchains found.'
            print(fmt % ("Error initialising ROC due to", msg))

        if toolchains:
            print(fmt % ("Available Toolchains", ', '.join(toolchains)))

        try:
            # ROC might not be available due to lack of tool chain, but HSA
            # agents may be listed
            from numba.roc.hsadrv.driver import hsa, dgpu_count
            decode = lambda x: x.decode('utf-8') if isinstance(x, bytes) else x
            print("\nFound %s HSA Agents:" % len(hsa.agents))
            for i, agent in enumerate(hsa.agents):
                print('Agent id  : %s' % i)
                print('    vendor: %s' % decode(agent.vendor_name))
                print('      name: %s' % decode(agent.name))
                print('      type: %s' % agent.device)
                print("")

            _dgpus = []
            for a in hsa.agents:
                if a.is_component and a.device == 'GPU':
                   _dgpus.append(decode(a.name))
            print(fmt % ("Found %s discrete GPU(s)" % dgpu_count(), \
                  ', '.join(_dgpus)))
        except Exception as e:
            print("No HSA Agents found, encountered exception when searching:")
            print(e)


        print("")
        print("__SVML Information__")
        # replicate some SVML detection logic from numba.__init__ here.
        # if SVML load fails in numba.__init__ the splitting of the logic
        # here will help diagnosis of the underlying issue
        have_svml_library = True
        try:
            if sys.platform.startswith('linux'):
                llvmbind.load_library_permanently("libsvml.so")
            elif sys.platform.startswith('darwin'):
                llvmbind.load_library_permanently("libsvml.dylib")
            elif sys.platform.startswith('win'):
                llvmbind.load_library_permanently("svml_dispmd")
            else:
                have_svml_library = False
        except:
            have_svml_library = False
        func = getattr(llvmbind.targets, "has_svml", None)
        llvm_svml_patched = func() if func is not None else False
        svml_operational = (config.USING_SVML and llvm_svml_patched \
                            and have_svml_library)
        print(fmt % ("SVML state, config.USING_SVML", config.USING_SVML))
        print(fmt % ("SVML library found and loaded", have_svml_library))
        print(fmt % ("llvmlite using SVML patched LLVM", llvm_svml_patched))
        print(fmt % ("SVML operational", svml_operational))

        # Check which threading backends are available.
        print("")
        print("__Threading Layer Information__")
        def parse_error(e, backend):
            # parses a linux based error message, this is to provide feedback
            # and hide user paths etc
            try:
                path, problem, symbol =  [x.strip() for x in e.msg.split(':')]
                extn_dso = os.path.split(path)[1]
                if backend in extn_dso:
                    return "%s: %s" % (problem, symbol)
            except Exception:
                pass
            return "Unknown import problem."

        try:
            from numba.npyufunc import tbbpool
            print(fmt % ("TBB Threading layer available", True))
        except ImportError as e:
            # might be a missing symbol due to e.g. tbb libraries missing
            print(fmt % ("TBB Threading layer available", False))
            print(fmt % ("+--> Disabled due to",
                         parse_error(e, 'tbbpool')))

        try:
            from numba.npyufunc import omppool
            print(fmt % ("OpenMP Threading layer available", True))
        except ImportError as e:
            print(fmt % ("OpenMP Threading layer available", False))
            print(fmt % ("+--> Disabled due to",
                         parse_error(e, 'omppool')))

        try:
            from numba.npyufunc import workqueue
            print(fmt % ("Workqueue Threading layer available", True))
        except ImportError as e:
            print(fmt % ("Workqueue Threading layer available", False))
            print(fmt % ("+--> Disabled due to",
                         parse_error(e, 'workqueue')))

        # look for numba env vars that are set
        print("")
        print("__Numba Environment Variable Information__")
        _envvar_found = False
        for k, v in os.environ.items():
            if k.startswith('NUMBA_'):
                print(fmt % (k, v))
                _envvar_found = True
        if not _envvar_found:
            print("None set.")

        # Look for conda and conda information
        print("")
        print("__Conda Information__")
        cmd = ["conda", "info", "--json"]
        try:
            conda_out = check_output(cmd)
        except Exception as e:
            print(
                "Conda not present/not working.\nError was %s\n" % e)
        else:
            data = ''.join(conda_out.decode("utf-8").splitlines())
            jsond = json.loads(data)
            keys = ['conda_build_version',
                    'conda_env_version',
                    'platform',
                    'python_version',
                    'root_writable']
            for k in keys:
                try:
                    print(fmt % (k, jsond[k]))
                except KeyError:
                    pass

            # get info about current environment
            cmd = ["conda", "list"]
            try:
                conda_out = check_output(cmd)
            except CalledProcessError as e:
                print("Error: Conda command failed. Error was %s\n" % e.output)
            else:
                print("")
                print("__Current Conda Env__")
                data = conda_out.decode("utf-8").splitlines()
                for k in data:
                    if k[0] != '#':  # don't show where the env is, personal data
                        print(k)

        print("-" * 80)

    except Exception as e:
        print("Error: The system reporting tool has failed unexpectedly.")
        print("Exception was:")
        print(e)

    finally:
        print(
            "%s" %
            "If requested, please copy and paste the information between\n"
            "the dashed (----) lines, or from a given specific section as\n"
            "appropriate.\n\n"
            "=============================================================\n"
            "IMPORTANT: Please ensure that you are happy with sharing the\n"
            "contents of the information present, any information that you\n"
            "wish to keep private you should remove before sharing.\n"
            "=============================================================\n")
示例#48
0
def system_information():
    '''
    Report system versions.
    '''
    def system_version():
        '''
        Return host system version.
        '''
        lin_ver = linux_distribution()
        mac_ver = platform.mac_ver()
        win_ver = platform.win32_ver()

        if lin_ver[0]:
            return ' '.join(lin_ver)
        elif mac_ver[0]:
            if isinstance(mac_ver[1], (tuple, list)) and ''.join(mac_ver[1]):
                return ' '.join([mac_ver[0], '.'.join(mac_ver[1]), mac_ver[2]])
            else:
                return ' '.join([mac_ver[0], mac_ver[2]])
        elif win_ver[0]:
            return ' '.join(win_ver)
        else:
            return ''

    if platform.win32_ver()[0]:
        # Get the version and release info based on the Windows Operating
        # System Product Name. As long as Microsoft maintains a similar format
        # this should be future proof
        import win32api  # pylint: disable=3rd-party-module-not-gated
        import win32con  # pylint: disable=3rd-party-module-not-gated

        # Get the product name from the registry
        hkey = win32con.HKEY_LOCAL_MACHINE
        key = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'
        value_name = 'ProductName'
        reg_handle = win32api.RegOpenKey(hkey, key)

        # Returns a tuple of (product_name, value_type)
        product_name, _ = win32api.RegQueryValueEx(reg_handle, value_name)

        version = 'Unknown'
        release = ''
        if 'Server' in product_name:
            for item in product_name.split(' '):
                # If it's all digits, then it's version
                if re.match(r'\d+', item):
                    version = item
                # If it starts with R and then numbers, it's the release
                # ie: R2
                if re.match(r'^R\d+$', item):
                    release = item
            release = '{0}Server{1}'.format(version, release)
        else:
            for item in product_name.split(' '):
                # If it's a number, decimal number, Thin or Vista, then it's the
                # version
                if re.match(r'^(\d+(\.\d+)?)|Thin|Vista$', item):
                    version = item
            release = version

        _, ver, service_pack, extra = platform.win32_ver()
        version = ' '.join([release, ver, service_pack, extra])
    else:
        version = system_version()
        release = platform.release()

    system = [
        ('system', platform.system()),
        ('dist', ' '.join(linux_distribution(full_distribution_name=False))),
        ('release', release),
        ('machine', platform.machine()),
        ('version', version),
        ('locale', __salt_system_encoding__),
    ]

    for name, attr in system:
        yield name, attr
        continue
示例#49
0
from .exceptions import ExecCommandFailed

# Copied from https://docs.python.org/3/library/platform.html#cross-platform.
is_64bits = sys.maxsize > 2**32

# Distinguish specific code for various Python versions.
# Variables 'is_pyXY' mean that Python X.Y and up is supported.
# Keep even unsupported versions here to keep 3rd-party hooks working.
is_py35 = sys.version_info >= (3, 5)
is_py36 = sys.version_info >= (3, 6)
is_py37 = sys.version_info >= (3, 7)
is_py38 = sys.version_info >= (3, 8)
is_py39 = sys.version_info >= (3, 9)

is_win = sys.platform.startswith('win')
is_win_10 = is_win and (platform.win32_ver()[0] == '10')
is_cygwin = sys.platform == 'cygwin'
is_darwin = sys.platform == 'darwin'  # Mac OS X

# Unix platforms
is_linux = sys.platform.startswith('linux')
is_solar = sys.platform.startswith('sun')  # Solaris
is_aix = sys.platform.startswith('aix')
is_freebsd = sys.platform.startswith('freebsd')
is_openbsd = sys.platform.startswith('openbsd')
is_hpux = sys.platform.startswith('hp-ux')

# Some code parts are similar to several unix platforms
# (e.g. Linux, Solaris, AIX)
# Mac OS X is not considered as unix since there are many
# platform specific details for Mac in PyInstaller.
示例#50
0
    def __call__(self,
                 stdin=None,
                 stdout=True,
                 stderr=True,
                 cwd=None,
                 env=None):
        """Execute command, wait for it to finish, return (stdout, stderr).

        Runs the command line tool and waits for it to finish. If it returns
        a non-zero error level, an exception is raised. Otherwise two strings
        are returned containing stdout and stderr.

        The optional stdin argument should be a string of data which will be
        passed to the tool as standard input.

        The optional stdout and stderr argument may be filenames (string),
        but otherwise are treated as a booleans, and control if the output
        should be captured as strings (True, default), or ignored by sending
        it to /dev/null to avoid wasting memory (False). If sent to a file
        or ignored, then empty string(s) are returned.

        The optional cwd argument is a string giving the working directory
        to run the command from. See Python's subprocess module documentation
        for more details.

        The optional env argument is a dictionary setting the environment
        variables to be used in the new process. By default the current
        process' environment variables are used. See Python's subprocess
        module documentation for more details.

        Default example usage::

            from Bio.Emboss.Applications import WaterCommandline
            water_cmd = WaterCommandline(gapopen=10, gapextend=0.5,
                                         stdout=True, auto=True,
                                         asequence="a.fasta", bsequence="b.fasta")
            print("About to run: %s" % water_cmd)
            std_output, err_output = water_cmd()

        This functionality is similar to subprocess.check_output() added in
        Python 2.7. In general if you require more control over running the
        command, use subprocess directly.

        As of Biopython 1.56, when the program called returns a non-zero error
        level, a custom ApplicationError exception is raised. This includes
        any stdout and stderr strings captured as attributes of the exception
        object, since they may be useful for diagnosing what went wrong.
        """
        if not stdout:
            stdout_arg = open(os.devnull, "w")
        elif isinstance(stdout, basestring):
            stdout_arg = open(stdout, "w")
        else:
            stdout_arg = subprocess.PIPE

        if not stderr:
            stderr_arg = open(os.devnull, "w")
        elif isinstance(stderr, basestring):
            if stdout == stderr:
                stderr_arg = stdout_arg  # Write both to the same file
            else:
                stderr_arg = open(stderr, "w")
        else:
            stderr_arg = subprocess.PIPE

        # We may not need to supply any piped input, but we setup the
        # standard input pipe anyway as a work around for a python
        # bug if this is called from a Windows GUI program.  For
        # details, see http://bugs.python.org/issue1124861
        #
        # Using universal newlines is important on Python 3, this
        # gives unicode handles rather than bytes handles.

        # Windows 7, 8 and 8.1 want shell = True
        # TODO: Test under Windows 10 and revisit platform detection.
        if sys.platform != "win32":
            use_shell = True
        else:
            win_ver = platform.win32_ver()[0]
            if win_ver in ["7", "8", "post2012Server"]:
                use_shell = True
            else:
                use_shell = False
        child_process = subprocess.Popen(str(self),
                                         stdin=subprocess.PIPE,
                                         stdout=stdout_arg,
                                         stderr=stderr_arg,
                                         universal_newlines=True,
                                         cwd=cwd,
                                         env=env,
                                         shell=use_shell)
        # Use .communicate as can get deadlocks with .wait(), see Bug 2804
        stdout_str, stderr_str = child_process.communicate(stdin)
        if not stdout:
            assert not stdout_str, stdout_str
        if not stderr:
            assert not stderr_str, stderr_str
        return_code = child_process.returncode

        # Particularly important to close handles on Jython and PyPy
        # (where garbage collection is less predictable) and on Windows
        # (where cannot delete files with an open handle):
        if not stdout or isinstance(stdout, basestring):
            # We opened /dev/null or a file
            stdout_arg.close()
        if not stderr or (isinstance(stderr, basestring) and stdout != stderr):
            # We opened /dev/null or a file
            stderr_arg.close()

        if return_code:
            raise ApplicationError(return_code, str(self), stdout_str,
                                   stderr_str)
        return stdout_str, stderr_str
示例#51
0
def main():

    # Configure verbose logging if the user requested it
    # (NOTE: in a future version of ue4-docker the `Logger` class will be properly integrated with standard logging)
    if '-v' in sys.argv or '--verbose' in sys.argv:
        sys.argv = list(
            [arg for arg in sys.argv if arg not in ['-v', '--verbose']])
        logging.getLogger().setLevel(logging.DEBUG)

    # Verify that Docker is installed
    if DockerUtils.installed() == False:
        _exitWithError(
            'Error: could not detect Docker daemon version. Please ensure Docker is installed.'
        )

    # Under Windows, verify that the host is a supported version
    if platform.system(
    ) == 'Windows' and WindowsUtils.isSupportedWindowsVersion() == False:
        _exitWithError(
            'Error: the detected version of Windows ({}) is not supported. Windows 10 / Windows Server version 1607 or newer is required.'
            .format(platform.win32_ver()[1]))

    # Under macOS, verify that the host is a supported version
    if platform.system() == 'Darwin' and DarwinUtils.isSupportedMacOsVersion(
    ) == False:
        _exitWithError(
            'Error: the detected version of macOS ({}) is not supported. macOS {} or newer is required.'
            .format(DarwinUtils.getMacOsVersion(),
                    DarwinUtils.minimumRequiredVersion()))

    # Our supported commands
    COMMANDS = {
        'build': {
            'function': build,
            'description':
            'Builds container images for a specific version of UE4'
        },
        'clean': {
            'function': clean,
            'description': 'Cleans built container images'
        },
        'export': {
            'function':
            export,
            'description':
            'Exports components from built container images to the host system'
        },
        'info': {
            'function':
            info,
            'description':
            'Displays information about the host system and Docker daemon'
        },
        'setup': {
            'function':
            setup,
            'description':
            'Automatically configures the host system where possible'
        },
        'version': {
            'function': version,
            'description': 'Prints the ue4-docker version number'
        }
    }

    # Truncate argv[0] to just the command name without the full path
    sys.argv[0] = os.path.basename(sys.argv[0])

    # Determine if a command has been specified
    if len(sys.argv) > 1:

        # Verify that the specified command is valid
        command = sys.argv[1]
        if command not in COMMANDS:
            print('Error: unrecognised command "{}".'.format(command),
                  file=sys.stderr)
            sys.exit(1)

        # Invoke the command
        sys.argv = [sys.argv[0]] + sys.argv[2:]
        COMMANDS[command]['function']()

    else:

        # Print usage syntax
        print('Usage: {} COMMAND [OPTIONS]\n'.format(sys.argv[0]))
        print('Windows and Linux containers for Unreal Engine 4\n')
        print('Commands:')
        PrettyPrinting.printColumns([
            (command, COMMANDS[command]['description']) for command in COMMANDS
        ])
        print('\nRun `{} COMMAND --help` for more information on a command.'.
              format(sys.argv[0]))
示例#52
0
def system_info():
    '''
    Get the system information.
    Return a tuple with the platform type, the architecture and the
    distribution
    '''
    # Get the platform info
    platform = os.environ.get('OS', '').lower()
    if not platform:
        platform = sys.platform
    if platform.startswith('win'):
        platform = Platform.WINDOWS
    elif platform.startswith('darwin'):
        platform = Platform.DARWIN
    elif platform.startswith('linux'):
        platform = Platform.LINUX
    else:
        raise FatalError(_("Platform %s not supported") % platform)

    # Get the architecture info
    if platform == Platform.WINDOWS:
        arch = windows_arch()
        if arch in ('x64', 'amd64'):
            arch = Architecture.X86_64
        elif arch == 'x86':
            arch = Architecture.X86
        else:
            raise FatalError(_("Windows arch %s is not supported") % arch)
    else:
        uname = os.uname()
        arch = uname[4]
        if arch == 'x86_64':
            arch = Architecture.X86_64
        elif arch.endswith('86'):
            arch = Architecture.X86
        elif arch.startswith('armv7'):
            arch = Architecture.ARMv7
        elif arch.startswith('arm64'):
            arch = Architecture.ARM64
        elif arch.startswith('arm'):
            arch = Architecture.ARM
        else:
            raise FatalError(_("Architecture %s not supported") % arch)

    # Get the distro info
    if platform == Platform.LINUX:
        if sys.version_info >= (3, 8, 0):
            try:
                import distro
            except ImportError:
                print(
                    '''Python >= 3.8 detected and the 'distro' python package was not found.
Please install the 'python3-distro' or 'python-distro' package from your linux package manager or from pypi using pip.
Terminating.''',
                    file=sys.stderr)
                sys.exit(1)
            d = distro.linux_distribution()
        else:
            d = pplatform.linux_distribution()

        if d[0] == '' and d[1] == '' and d[2] == '':
            if os.path.exists('/etc/arch-release'):
                # FIXME: the python2.7 platform module does not support Arch Linux.
                # Mimic python3.4 platform.linux_distribution() output.
                d = ('arch', 'Arch', 'Linux')
            elif os.path.exists('/etc/os-release'):
                with open('/etc/os-release', 'r') as f:
                    if 'ID="amzn"\n' in f.readlines():
                        d = ('RedHat', 'amazon', '')
                    else:
                        f.seek(0, 0)
                        for line in f:
                            # skip empty lines and comment lines
                            if line.strip(
                            ) and not line.lstrip().startswith('#'):
                                k, v = line.rstrip().split("=")
                                if k == 'NAME':
                                    name = v.strip('"')
                                elif k == 'VERSION_ID':
                                    version = v.strip('"')
                        d = (name, version, '')

        if d[0] in [
                'Ubuntu', 'debian', 'Debian GNU/Linux', 'LinuxMint',
                'Linux Mint'
        ]:
            distro = Distro.DEBIAN
            distro_version = d[2].lower()
            split_str = d[2].split()
            if split_str:
                distro_version = split_str[0].lower()
            if distro_version in ['maverick', 'isadora']:
                distro_version = DistroVersion.UBUNTU_MAVERICK
            elif distro_version in ['lucid', 'julia']:
                distro_version = DistroVersion.UBUNTU_LUCID
            elif distro_version in ['natty', 'katya']:
                distro_version = DistroVersion.UBUNTU_NATTY
            elif distro_version in ['oneiric', 'lisa']:
                distro_version = DistroVersion.UBUNTU_ONEIRIC
            elif distro_version in ['precise', 'maya']:
                distro_version = DistroVersion.UBUNTU_PRECISE
            elif distro_version in ['quantal', 'nadia']:
                distro_version = DistroVersion.UBUNTU_QUANTAL
            elif distro_version in ['raring', 'olivia']:
                distro_version = DistroVersion.UBUNTU_RARING
            elif distro_version in ['saucy', 'petra']:
                distro_version = DistroVersion.UBUNTU_SAUCY
            elif distro_version in ['trusty', 'qiana', 'rebecca']:
                distro_version = DistroVersion.UBUNTU_TRUSTY
            elif distro_version in ['utopic']:
                distro_version = DistroVersion.UBUNTU_UTOPIC
            elif distro_version in ['vivid']:
                distro_version = DistroVersion.UBUNTU_VIVID
            elif distro_version in ['wily']:
                distro_version = DistroVersion.UBUNTU_WILY
            elif distro_version in [
                    'xenial', 'sarah', 'serena', 'sonya', 'sylvia'
            ]:
                distro_version = DistroVersion.UBUNTU_XENIAL
            elif distro_version in ['artful']:
                distro_version = DistroVersion.UBUNTU_ARTFUL
            elif distro_version in [
                    'bionic', 'tara', 'tessa', 'tina', 'tricia'
            ]:
                distro_version = DistroVersion.UBUNTU_BIONIC
            elif distro_version in ['cosmic']:
                distro_version = DistroVersion.UBUNTU_COSMIC
            elif distro_version in ['disco']:
                distro_version = DistroVersion.UBUNTU_DISCO
            elif distro_version in ['eoan']:
                distro_version = DistroVersion.UBUNTU_EOAN
            elif distro_version in ['focal', 'ulyana']:
                distro_version = DistroVersion.UBUNTU_FOCAL
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.DEBIAN_SQUEEZE
            elif d[1].startswith('7.') or d[1].startswith('wheezy'):
                distro_version = DistroVersion.DEBIAN_WHEEZY
            elif d[1].startswith('8.') or d[1].startswith('jessie'):
                distro_version = DistroVersion.DEBIAN_JESSIE
            elif d[1].startswith('9.') or d[1].startswith('stretch'):
                distro_version = DistroVersion.DEBIAN_STRETCH
            elif d[1].startswith('10.') or d[1].startswith('buster'):
                distro_version = DistroVersion.DEBIAN_BUSTER
            elif d[1].startswith('11.') or d[1].startswith('bullseye'):
                distro_version = DistroVersion.DEBIAN_BULLSEYE
            elif d[1] == 'unstable' and d[2] == 'sid':
                distro_version = DistroVersion.DEBIAN_SID
            else:
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0] in [
                'RedHat', 'Fedora', 'CentOS',
                'Red Hat Enterprise Linux Server', 'CentOS Linux',
                'Amazon Linux'
        ]:
            distro = Distro.REDHAT
            if d[1] == '16':
                distro_version = DistroVersion.FEDORA_16
            elif d[1] == '17':
                distro_version = DistroVersion.FEDORA_17
            elif d[1] == '18':
                distro_version = DistroVersion.FEDORA_18
            elif d[1] == '19':
                distro_version = DistroVersion.FEDORA_19
            elif d[1] == '20':
                distro_version = DistroVersion.FEDORA_20
            elif d[1] == '21':
                distro_version = DistroVersion.FEDORA_21
            elif d[1] == '22':
                distro_version = DistroVersion.FEDORA_22
            elif d[1] == '23':
                distro_version = DistroVersion.FEDORA_23
            elif d[1] == '24':
                distro_version = DistroVersion.FEDORA_24
            elif d[1] == '25':
                distro_version = DistroVersion.FEDORA_25
            elif d[1] == '26':
                distro_version = DistroVersion.FEDORA_26
            elif d[1] == '27':
                distro_version = DistroVersion.FEDORA_27
            elif d[1] == '28':
                distro_version = DistroVersion.FEDORA_28
            elif d[1] == '29':
                distro_version = DistroVersion.FEDORA_29
            elif d[1] == '30':
                distro_version = DistroVersion.FEDORA_30
            elif d[1] == '31':
                distro_version = DistroVersion.FEDORA_31
            elif d[1] == '32':
                distro_version = DistroVersion.FEDORA_32
            elif d[0] == 'Fedora':
                # str(int()) is for ensuring that the fedora version is
                # actually a number
                distro_version = 'fedora_' + str(int(d[1]))
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.REDHAT_6
            elif d[1].startswith('7.'):
                distro_version = DistroVersion.REDHAT_7
            elif d[1].startswith('8.'):
                distro_version = DistroVersion.REDHAT_8
            elif d[0] == 'Amazon Linux' and d[1].startswith('2'):
                distro_version = DistroVersion.AMAZON_LINUX_2
            elif d[1] == 'amazon':
                distro_version = DistroVersion.AMAZON_LINUX
            else:
                # FIXME Fill this
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0].strip() in ['openSUSE']:
            distro = Distro.SUSE
            if d[1] == '42.2':
                distro_version = DistroVersion.OPENSUSE_42_2
            elif d[1] == '42.3':
                distro_version = DistroVersion.OPENSUSE_42_3
            else:
                # FIXME Fill this
                raise FatalError("Distribution OpenSuse '%s' "
                                 "not supported" % str(d))
        elif d[0].strip() in ['openSUSE Tumbleweed']:
            distro = Distro.SUSE
            distro_version = DistroVersion.OPENSUSE_TUMBLEWEED
        elif d[0].strip() in ['arch', 'Arch Linux']:
            distro = Distro.ARCH
            distro_version = DistroVersion.ARCH_ROLLING
        elif d[0].strip() in ['Gentoo Base System']:
            distro = Distro.GENTOO
            distro_version = DistroVersion.GENTOO_VERSION
        else:
            raise FatalError("Distribution '%s' not supported" % str(d))
    elif platform == Platform.WINDOWS:
        distro = Distro.WINDOWS
        win32_ver = pplatform.win32_ver()[0]
        dmap = {
            'xp': DistroVersion.WINDOWS_XP,
            'vista': DistroVersion.WINDOWS_VISTA,
            '7': DistroVersion.WINDOWS_7,
            'post2008Server': DistroVersion.WINDOWS_8,
            '8': DistroVersion.WINDOWS_8,
            'post2012Server': DistroVersion.WINDOWS_8_1,
            '8.1': DistroVersion.WINDOWS_8_1,
            '10': DistroVersion.WINDOWS_10
        }
        if win32_ver in dmap:
            distro_version = dmap[win32_ver]
        else:
            raise FatalError("Windows version '%s' not supported" % win32_ver)
    elif platform == Platform.DARWIN:
        distro = Distro.OS_X
        ver = pplatform.mac_ver()[0]
        if ver.startswith(('11.', '10.16')):
            distro_version = DistroVersion.OS_X_BIG_SUR
        elif ver.startswith('10.15'):
            distro_version = DistroVersion.OS_X_CATALINA
        elif ver.startswith('10.14'):
            distro_version = DistroVersion.OS_X_MOJAVE
        elif ver.startswith('10.13'):
            distro_version = DistroVersion.OS_X_HIGH_SIERRA
        elif ver.startswith('10.12'):
            distro_version = DistroVersion.OS_X_SIERRA
        elif ver.startswith('10.11'):
            distro_version = DistroVersion.OS_X_EL_CAPITAN
        elif ver.startswith('10.10'):
            distro_version = DistroVersion.OS_X_YOSEMITE
        elif ver.startswith('10.9'):
            distro_version = DistroVersion.OS_X_MAVERICKS
        elif ver.startswith('10.8'):
            distro_version = DistroVersion.OS_X_MOUNTAIN_LION
        else:
            raise FatalError("Mac version %s not supported" % ver)

    num_of_cpus = determine_num_of_cpus()

    return platform, arch, distro, distro_version, num_of_cpus
示例#53
0
文件: About.py 项目: hasit/Transana
    def OnKeyUp(self, event):
        """ OnKeyUp event captures the release of keys so they can be processed """
        # If ALT and SHIFT are pressed ...
        if event.AltDown() and event.ShiftDown():
            # ... get the key that was pressed
            key = event.GetKeyCode()
            # If F11 is pressed, show COMPONENT VERSION information
            if (key == wx.WXK_F11) or (key in [ord('S'), ord('s')]):
                # Import Python's ctypes, Transana's DBInterface, Python's sys modules, and numpy
                import Crypto, ctypes, DBInterface, paramiko, sys, numpy

                if sys.platform == 'win32':
                    sysplat = 'Windows'
                    sysver = platform.win32_ver()[0]
                elif sys.platform == 'darwin':
                    sysplat = 'Mac OS X'
                    sysver = platform.mac_ver()[0]
                else:
                    sysplat = sys.platform
                    sysver = platform.version()
                str = 'Platform:  %s %s' % (sysplat, sysver)
                # Build a string that contains the version information for crucial programming components
                str += '\n\nTransana %s uses the following tools:\n\n'% (TransanaConstants.versionNumber)
                if (platform.architecture()[0] == '32bit') or (sys.maxint == 2 ** 31 - 1):
                    arc = '32-bit'
                elif platform.architecture()[0] == '64bit':
                    arc = '64-bit'
                else:
                    arc = 'Unknown architecture'
                str = '%sPython:  %s  (%s)\n' % (str, sys.version[:6].strip(), arc)
                if 'unicode' in wx.PlatformInfo:
                    str2 = 'unicode'
                else:
                    str2 = 'ansi'
                str = '%swxPython:  %s - %s\n' % (str, wx.VERSION_STRING, str2)
                if TransanaConstants.DBInstalled in ['MySQLdb-embedded', 'MySQLdb-server']:
                    import MySQLdb
                    str = '%sMySQL for Python:  %s\n' % (str, MySQLdb.__version__)
                elif TransanaConstants.DBInstalled in ['PyMySQL']:
                    import pymysql
                    str = '%sPyMySQL:  %s\n' % (str, pymysql.version_info)
                elif TransanaConstants.DBInstalled in ['sqlite3']:
                    import sqlite3
                    str = '%ssqlite:  %s\n' % (str, sqlite3.version)
                else:
                    str = '%sUnknown Database:  Unknown Version\n' % (str, )
                if DBInterface._dbref != None:
                    # Get a Database Cursor
                    dbCursor = DBInterface._dbref.cursor()
                    if TransanaConstants.DBInstalled in ['MySQLdb-embedded', 'MySQLdb-server', 'PyMySQL']:
                        # Query the Database about what Database Names have been defined
                        dbCursor.execute('SELECT VERSION()')
                        vs = dbCursor.fetchall()
                        for v in vs:
                            str = "%sMySQL:  %s\n" % (str, v[0])
                str = "%sctypes:  %s\n" % (str, ctypes.__version__)
                str = "%sCrypto:  %s\n" % (str, Crypto.__version__)
                str = "%sparamiko:  %s\n" % (str, paramiko.__version__)
                str = "%snumpy:     %s\n" % (str, numpy.__version__)
                str = "%sEncoding:  %s\n" % (str, TransanaGlobal.encoding)
                str = "%sLanguage:  %s\n" % (str, TransanaGlobal.configData.language)
                # Replace the Description text with the version information text
                self.description.SetLabel(str)

                query = "SELECT COUNT(SeriesNum) FROM Series2"
                dbCursor.execute(query)
                seriesCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(DocumentNum) FROM Documents2"
                dbCursor.execute(query)
                documentCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(EpisodeNum) FROM Episodes2"
                dbCursor.execute(query)
                episodeCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(CoreDataNum) FROM CoreData2"
                dbCursor.execute(query)
                coreDataCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(TranscriptNum) FROM Transcripts2 WHERE ClipNum = 0"
                dbCursor.execute(query)
                transcriptCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(CollectNum) FROM Collections2"
                dbCursor.execute(query)
                collectionCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(quoteNum) FROM Quotes2"
                dbCursor.execute(query)
                quoteCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(clipNum) FROM Clips2"
                dbCursor.execute(query)
                clipCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(TranscriptNum) FROM Transcripts2 WHERE ClipNum <> 0"
                dbCursor.execute(query)
                clipTranscriptCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(SnapshotNum) FROM Snapshots2"
                dbCursor.execute(query)
                snapshotCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(NoteNum) FROM Notes2"
                dbCursor.execute(query)
                noteCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(Keyword) FROM Keywords2"
                dbCursor.execute(query)
                keywordCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(Keyword) FROM ClipKeywords2"
                dbCursor.execute(query)
                clipKeywordCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(Keyword) FROM SnapshotKeywords2"
                dbCursor.execute(query)
                snapshotKeywordCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(Keyword) FROM SnapshotKeywordStyles2"
                dbCursor.execute(query)
                snapshotKeywordStylesCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(AddVidNum) FROM AdditionalVids2"
                dbCursor.execute(query)
                addVidCount = dbCursor.fetchall()[0][0]
                
                query = "SELECT COUNT(ConfigName) FROM Filters2"
                dbCursor.execute(query)
                filterCount = dbCursor.fetchall()[0][0]

                tmpStr = """Data Records:
  Libraries: %s
  Documents: %s
  Episodes: %s
  Episode Transcripts: %s
  Collections: %s
  Quotes: %s
  Clips: %s
  Clip Transcripts: %s
  Snapshots: %s
  Notes:  %s
  Keywords: %s
  Quote/Clip Keywords: %s
  Snapshot Keywords: %s
  Snapshot Keyword Styles: %s
  Additional Videos:  %s
  Filters:  %s
  Core Data: %s\n  """
                data = (seriesCount, documentCount, episodeCount, transcriptCount, collectionCount, quoteCount,
                        clipCount, clipTranscriptCount,
                        snapshotCount, noteCount, keywordCount, clipKeywordCount, snapshotKeywordCount,
                        snapshotKeywordStylesCount, addVidCount, filterCount, coreDataCount)
                
                # Eliminate the Credits text
                self.credits.SetLabel(tmpStr % data)
                self.translations.SetLabel('')
                self.ffmpeg.SetLabel('')
            # If F12 is pressed ...
            elif (key == wx.WXK_F12) or (key in [ord('H'), ord('h')]):
                # Replace the Version information text with the original description text
                self.description.SetLabel(self.description_str)
                # Replace the blank credits text with the original credits text
                self.credits.SetLabel(self.credits_str)
                self.translations.SetLabel(self.translations_str)
                self.ffmpeg.SetLabel(self.ffmpeg_str)
            # Fit the window to the altered controls
            self.Fit()
            TransanaGlobal.CenterOnPrimary(self)

        # If ALT and SHIFT aren't both pressed ...
        else:
            # ... then we don't do anything
            pass
示例#54
0
def get_os_spec_info(os_name):
    # Linux man page for `/proc`:
    # http://man7.org/linux/man-pages/man5/proc.5.html

    # Windows documentation for `wmic OS`:
    # https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-operatingsystem

    # MacOS man page for `sysctl`:
    # https://www.unix.com/man-page/osx/3/sysctl/
    # MacOS man page for `vm_stat`:
    # https://www.unix.com/man-page/osx/1/vm_stat/

    class CmdBufferOut(tuple):
        buffer_output_flag = True

    class CmdReadFile(tuple):
        read_file_flag = True

    shell_params = {
        'Linux': {
            'cmd': (
                CmdReadFile(('/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us',)),
                CmdReadFile(('/sys/fs/cgroup/cpuacct/cpu.cfs_period_us',)),
            ),
            'cmd_optional': (
                CmdReadFile(('/proc/meminfo',)),
                CmdReadFile(('/proc/self/status',)),
            ),
            'kwds': {
                # output string fragment -> result dict key
                'MemTotal:': _mem_total,
                'MemAvailable:': _mem_available,
                'Cpus_allowed:': _cpus_allowed,
                'Cpus_allowed_list:': _cpus_list,
                '/sys/fs/cgroup/cpuacct/cpu.cfs_quota_us': _cfs_quota,
                '/sys/fs/cgroup/cpuacct/cpu.cfs_period_us': _cfs_period,
            },
        },
        'Windows': {
            'cmd': (),
            'cmd_optional': (
                CmdBufferOut(('wmic', 'OS', 'get', 'TotalVirtualMemorySize')),
                CmdBufferOut(('wmic', 'OS', 'get', 'FreeVirtualMemory')),
            ),
            'kwds': {
                # output string fragment -> result dict key
                'TotalVirtualMemorySize': _mem_total,
                'FreeVirtualMemory': _mem_available,
            },
        },
        'Darwin': {
            'cmd': (),
            'cmd_optional': (
                ('sysctl', 'hw.memsize'),
                ('vm_stat'),
            ),
            'kwds': {
                # output string fragment -> result dict key
                'hw.memsize:': _mem_total,
                'free:': _mem_available,
            },
            'units': {
                _mem_total: 1,  # Size is given in bytes.
                _mem_available: 4096,  # Size is given in 4kB pages.
            },
        },
    }

    os_spec_info = {}
    params = shell_params.get(os_name, {})
    cmd_selected = params.get('cmd', ())

    if _psutil_import:
        vm = psutil.virtual_memory()
        os_spec_info.update({
            _mem_total: vm.total,
            _mem_available: vm.available,
        })
        p = psutil.Process()
        cpus_allowed = p.cpu_affinity() if hasattr(p, 'cpu_affinity') else []
        if cpus_allowed:
            os_spec_info[_cpus_allowed] = len(cpus_allowed)
            os_spec_info[_cpus_list] = ' '.join(str(n) for n in cpus_allowed)

    else:
        _warning_log.append(
            "Warning (psutil): psutil cannot be imported. "
            "For more accuracy, consider installing it.")
        # Fallback to internal heuristics
        cmd_selected += params.get('cmd_optional', ())

    # Assuming the shell cmd returns a unique (k, v) pair per line
    # or a unique (k, v) pair spread over several lines:
    # Gather output in a list of strings containing a keyword and some value.
    output = []
    for cmd in cmd_selected:
        if hasattr(cmd, 'read_file_flag'):
            # Open file within Python
            if os.path.exists(cmd[0]):
                try:
                    with open(cmd[0], 'r') as f:
                        out = f.readlines()
                        if out:
                            out[0] = ' '.join((cmd[0], out[0]))
                            output.extend(out)
                except OSError as e:
                    _error_log.append(f'Error (file read): {e}')
                    continue
            else:
                _warning_log.append('Warning (no file): {}'.format(cmd[0]))
                continue
        else:
            # Spawn a subprocess
            try:
                out = check_output(cmd, stderr=PIPE)
            except (OSError, CalledProcessError) as e:
                _error_log.append(f'Error (subprocess): {e}')
                continue
            if hasattr(cmd, 'buffer_output_flag'):
                out = b' '.join(line for line in out.splitlines()) + b'\n'
            output.extend(out.decode().splitlines())

    # Extract (k, output) pairs by searching for keywords in output
    kwds = params.get('kwds', {})
    for line in output:
        match = kwds.keys() & line.split()
        if match and len(match) == 1:
            k = kwds[match.pop()]
            os_spec_info[k] = line
        elif len(match) > 1:
            print(f'Ambiguous output: {line}')

    # Try to extract something meaningful from output string
    def format():
        # CFS restrictions
        split = os_spec_info.get(_cfs_quota, '').split()
        if split:
            os_spec_info[_cfs_quota] = float(split[-1])
        split = os_spec_info.get(_cfs_period, '').split()
        if split:
            os_spec_info[_cfs_period] = float(split[-1])
        if os_spec_info.get(_cfs_quota, -1) != -1:
            cfs_quota = os_spec_info.get(_cfs_quota, '')
            cfs_period = os_spec_info.get(_cfs_period, '')
            runtime_amount = cfs_quota / cfs_period
            os_spec_info[_cfs_restrict] = runtime_amount

    def format_optional():
        # Memory
        units = {_mem_total: 1024, _mem_available: 1024}
        units.update(params.get('units', {}))
        for k in (_mem_total, _mem_available):
            digits = ''.join(d for d in os_spec_info.get(k, '') if d.isdigit())
            os_spec_info[k] = int(digits or 0) * units[k]
        # Accessible CPUs
        split = os_spec_info.get(_cpus_allowed, '').split()
        if split:
            n = split[-1]
            n = n.split(',')[-1]
            os_spec_info[_cpus_allowed] = str(bin(int(n or 0, 16))).count('1')
        split = os_spec_info.get(_cpus_list, '').split()
        if split:
            os_spec_info[_cpus_list] = split[-1]

    try:
        format()
        if not _psutil_import:
            format_optional()
    except Exception as e:
        _error_log.append(f'Error (format shell output): {e}')

    # Call OS specific functions
    os_specific_funcs = {
        'Linux': {
            _libc_version: lambda: ' '.join(platform.libc_ver())
        },
        'Windows': {
            _os_spec_version: lambda: ' '.join(
                s for s in platform.win32_ver()),
        },
        'Darwin': {
            _os_spec_version: lambda: ''.join(
                i or ' ' for s in tuple(platform.mac_ver()) for i in s),
        },
    }
    key_func = os_specific_funcs.get(os_name, {})
    os_spec_info.update({k: f() for k, f in key_func.items()})
    return os_spec_info
示例#55
0
# vim: set fileencoding=utf-8
"""Implementations of wifi functions of Linux."""

import re
import platform
import time
import logging
from ctypes import *
from ctypes.wintypes import *
from comtypes import GUID

from .const import *
from .profile import Profile

if platform.release().lower() == 'xp':
    if platform.win32_ver()[2].lower() in ['sp2', 'sp3']:
        CLIENT_VERSION = 1
else:
    CLIENT_VERSION = 2
"""
Some types does not exist in python2 ctypes.wintypes so we fake them
using how its defined in python3 ctypes.wintypes.
"""
if not "PDWORD" in dir():
    PDWORD = POINTER(DWORD)

if not "PWCHAR" in dir():
    PWCHAR = POINTER(WCHAR)

ERROR_SUCCESS = 0
WLAN_MAX_PHY_TYPE_NUMBER = 8
示例#56
0
      osvers = 'slc' + dist[1].split('.')[0]
   elif re.search('CentOS', dist[0]):
      osvers = 'centos' + dist[1].split('.')[0]
   elif re.search('Scientific', dist[0]):
      if dist[1].split('.')[0] >= '7':
         osvers = 'centos' + dist[1].split('.')[0]
      else:
         osvers = 'slc' + dist[1].split('.')[0]
   elif re.search('Ubuntu', dist[0]):
      osvers = 'ubuntu' + dist[1].split('.')[0] + dist[1].split('.')[1]
   elif re.search('Fedora', dist[0]):
      osvers = 'fedora' + dist[1].split('.')[0]
   else:
      osvers = 'linux' + string.join(platform.linux_distribution()[1].split('.')[:2],'')
elif system == 'Windows':
   osvers = win + platform.win32_ver()[0]
else:
   osvers = 'unk-os'

#---Determine the compiler and version--------------------------------
if os.getenv('COMPILER') and os.getenv('COMPILER') not in ['native', 'classic'] and not os.getenv("CC"):
  compiler = os.getenv('COMPILER')
else:
  if os.getenv('CC'):
    ccommand = os.getenv('CC')
  elif system == 'Windows':
    ccommand = 'cl'
  elif system == 'Darwin':
    ccommand = 'clang'
  else:
    ccommand = 'gcc'
示例#57
0
def work( storage, message ) :
	# print( "Control message: %s" % message )
	import re
	args = re.split("\s", message)
	message = args[0]

	if message == storage['commands']['reset'] :
		storage['COMMON']['handler'].reset()
		return 'OK'
	elif message == storage['commands']['identity'] :
		return storage['COMMON']['handler'].orchestrator.getIdentity()[:8]

	elif message == storage['commands']['sync'] :
		stream = args[1]
		# print type(args), args
		storage['COMMON']['handler'].getOrchestrator().reset( streams = [stream] )
		# print "Reseted"
		return 'OK'

	elif message == storage['commands']['chpasswd'] :
		new_passwd = args[1]
		import threading
		print(storage.keys())
		chpasswd_thread = threading.Thread( target = storage['chpasswd_func'], args = ( new_passwd, ) )
		chpasswd_thread.start()
		return 'OK'


	elif message == storage['commands']['kill'] :
		storage['COMMON']['handler'].stop()
		import threading
		kill_thread = threading.Thread(target = storage['wait_exit_func'])
		kill_thread.start()
		return "OK"

	elif message == storage['commands']['mute'] :
		# if (storage['COMMON']['handler'])		# If it is interrogating,
		storage['COMMON']['handler'].send_function = storage['dummy_send_func']
		return "OK" # just for the hell of it

	elif message == storage['commands']['unmute'] :
		storage['COMMON']['handler'].send_function = storage['real_send_func']
		return "OK" #

	elif message == storage['commands']['nuke'] :
		storage['nuke_func']()
		return "OK" #

	elif message == storage['commands']['check_sync'] :
		import json
		orch = storage['COMMON']['handler'].getOrchestrator()
		ret_dict = {}
		for stream in orch.getStreams() :
			ret_dict[stream] = orch.getKeyCycles(stream)
		ret = json.dumps(ret_dict).replace( " ","" )
		return ret

	elif message == storage['commands']['sysinfo'] :
		import platform, json, getpass, locale
		ret = "+".join([				   # 113 bytes
			platform.node(),
			platform.machine(),
			platform.version(),
			'-'.join(locale.getdefaultlocale()),
			platform.platform(),
			platform.release(),
			platform.system(),
			platform.processor(),
			getpass.getuser(),
			'-'.join(platform.win32_ver()),
			'-'.join(platform.libc_ver()),
			# '-'.join(platform.mac_ver()),
		])
		# ret = json.dumps(info).replace( " ","" )	# to save some bytes
		return ret
	else :
		return "N/A"
示例#58
0
def system_info():
    '''
    Get the sysem information.
    Return a tuple with the platform type, the architecture and the
    distribution
    '''

    # Get the platform info
    platform = sys.platform
    if platform.startswith('win'):
        platform = Platform.WINDOWS
    elif platform.startswith('darwin'):
        platform = Platform.DARWIN
    elif platform.startswith('linux'):
        platform = Platform.LINUX
    else:
        raise FatalError(_("Platform %s not supported") % platform)

    # Get the architecture info
    if platform == Platform.WINDOWS:
        platform_str = sysconfig.get_platform()
        if platform_str in ['win-amd64', 'win-ia64']:
            arch = Architecture.X86_64
        else:
            arch = Architecture.X86
    else:
        uname = os.uname()
        arch = uname[4]
        if arch == 'x86_64':
            arch = Architecture.X86_64
        elif arch.endswith('86'):
            arch = Architecture.X86
        else:
            raise FatalError(_("Architecture %s not supported") % arch)

    # Get the distro info
    if platform == Platform.LINUX:
        d = pplatform.linux_distribution()

        if d[0] == '' and d[1] == '' and d[2] == '':
            if os.path.exists('/etc/arch-release'):
                # FIXME: the python2.7 platform module does not support Arch Linux.
                # Mimic python3.4 platform.linux_distribution() output.
                d = ('arch', 'Arch', 'Linux')

        if d[0] in ['Ubuntu', 'debian', 'LinuxMint']:
            distro = Distro.DEBIAN
            if d[2] in ['maverick', 'isadora']:
                distro_version = DistroVersion.UBUNTU_MAVERICK
            elif d[2] in ['lucid', 'julia']:
                distro_version = DistroVersion.UBUNTU_LUCID
            elif d[2] in ['natty', 'katya']:
                distro_version = DistroVersion.UBUNTU_NATTY
            elif d[2] in ['oneiric', 'lisa']:
                distro_version = DistroVersion.UBUNTU_ONEIRIC
            elif d[2] in ['precise', 'maya']:
                distro_version = DistroVersion.UBUNTU_PRECISE
            elif d[2] in ['quantal', 'nadia']:
                distro_version = DistroVersion.UBUNTU_QUANTAL
            elif d[2] in ['raring', 'olivia']:
                distro_version = DistroVersion.UBUNTU_RARING
            elif d[2] in ['saucy', 'petra']:
                distro_version = DistroVersion.UBUNTU_SAUCY
            elif d[2] in ['trusty', 'qiana', 'rebecca']:
                distro_version = DistroVersion.UBUNTU_TRUSTY
            elif d[2] in ['utopic']:
                distro_version = DistroVersion.UBUNTU_UTOPIC
            elif d[2] in ['vivid']:
                distro_version = DistroVersion.UBUNTU_VIVID
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.DEBIAN_SQUEEZE
            elif d[1].startswith('7.') or d[1].startswith('wheezy'):
                distro_version = DistroVersion.DEBIAN_WHEEZY
            elif d[1].startswith('8.') or d[1].startswith('jessie'):
                distro_version = DistroVersion.DEBIAN_JESSIE
            elif d[1].startswith('stretch'):
                distro_version = DistroVersion.DEBIAN_STRETCH
            else:
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0] in [
                'RedHat', 'Fedora', 'CentOS',
                'Red Hat Enterprise Linux Server', 'CentOS Linux'
        ]:
            distro = Distro.REDHAT
            if d[1] == '16':
                distro_version = DistroVersion.FEDORA_16
            elif d[1] == '17':
                distro_version = DistroVersion.FEDORA_17
            elif d[1] == '18':
                distro_version = DistroVersion.FEDORA_18
            elif d[1] == '19':
                distro_version = DistroVersion.FEDORA_19
            elif d[1] == '20':
                distro_version = DistroVersion.FEDORA_20
            elif d[1] == '21':
                distro_version = DistroVersion.FEDORA_21
            elif d[1] == '22':
                distro_version = DistroVersion.FEDORA_22
            elif d[1].startswith('6.'):
                distro_version = DistroVersion.REDHAT_6
            elif d[1].startswith('7.'):
                distro_version = DistroVersion.REDHAT_7
            else:
                # FIXME Fill this
                raise FatalError("Distribution '%s' not supported" % str(d))
        elif d[0].strip() in ['openSUSE']:
            distro = Distro.SUSE
            if d[1] == '12.1':
                distro_version = DistroVersion.OPENSUSE_12_1
            elif d[1] == '12.2':
                distro_version = DistroVersion.OPENSUSE_12_2
            elif d[1] == '12.3':
                distro_version = DistroVersion.OPENSUSE_12_3
            else:
                # FIXME Fill this
                raise FatalError("Distribution OpenSuse '%s' "
                                 "not supported" % str(d))
        elif d[0].strip() in ['arch']:
            distro = Distro.ARCH
            distro_version = DistroVersion.ARCH_ROLLING
        else:
            raise FatalError("Distribution '%s' not supported" % str(d))
    elif platform == Platform.WINDOWS:
        distro = Distro.WINDOWS
        win32_ver = pplatform.win32_ver()[0]
        dmap = {
            'xp': DistroVersion.WINDOWS_XP,
            'vista': DistroVersion.WINDOWS_VISTA,
            '7': DistroVersion.WINDOWS_7,
            'post2008Server': DistroVersion.WINDOWS_8,
            '8': DistroVersion.WINDOWS_8
        }
        if win32_ver in dmap:
            distro_version = dmap[win32_ver]
        else:
            raise FatalError("Windows version '%s' not supported" % win32_ver)
    elif platform == Platform.DARWIN:
        distro = Distro.OS_X
        ver = pplatform.mac_ver()[0]
        if ver.startswith('10.10'):
            distro_version = DistroVersion.OS_X_YOSEMITE
        elif ver.startswith('10.9'):
            distro_version = DistroVersion.OS_X_MAVERICKS
        elif ver.startswith('10.8'):
            distro_version = DistroVersion.OS_X_MOUNTAIN_LION
        else:
            raise FatalError("Mac version %s not supported" % ver)

    num_of_cpus = determine_num_of_cpus()

    return platform, arch, distro, distro_version, num_of_cpus
示例#59
0
    _METADATA['os'] = SON([
        ('type', platform.system()),
        ('name', platform.system()),
        ('architecture', platform.machine()),
        # (mac|i|tv)OS(X) version (e.g. 10.11.6) instead of darwin
        # kernel version.
        ('version', platform.mac_ver()[0])
    ])
elif sys.platform == 'win32':
    _METADATA['os'] = SON([
        ('type', platform.system()),
        # "Windows XP", "Windows 7", "Windows 10", etc.
        ('name', ' '.join((platform.system(), platform.release()))),
        ('architecture', platform.machine()),
        # Windows patch level (e.g. 5.1.2600-SP3)
        ('version', '-'.join(platform.win32_ver()[1:3]))
    ])
elif sys.platform.startswith('java'):
    _name, _ver, _arch = platform.java_ver()[-1]
    _METADATA['os'] = SON([
        # Linux, Windows 7, Mac OS X, etc.
        ('type', _name),
        ('name', _name),
        # x86, x86_64, AMD64, etc.
        ('architecture', _arch),
        # Linux kernel version, OSX version, etc.
        ('version', _ver)
    ])
else:
    # Get potential alias (e.g. SunOS 5.11 becomes Solaris 2.11)
    _aliased = platform.system_alias(
示例#60
0
"""
Test for Windows read directory changes emitter.
"""
import platform

from Queue import Queue
from watchdog.tests import mk, WatchdogTestCase

# read_directory_changes is only supported on Windows.
if WatchdogTestCase.os_family != 'nt':
    raise WatchdogTestCase.skipTest('Windows specific.')

windows_signature = platform.win32_ver()
windows_major_version = int(windows_signature[1].split('.')[0])
if windows_major_version < 6:
    raise WatchdogTestCase.skipTest('2008 and above')

from watchdog.events import EVENT_TYPE_CREATED
from watchdog.observers.read_directory_changes import WindowsApiEmitter
from watchdog.tests.observers.emitter_mixin import EmitterSystemMixin


class TestWindowsApiEmitter(WatchdogTestCase, EmitterSystemMixin):
    """
    Unit tests for WindowsApiEmitter.
    """
    def setUp(self):
        super(TestWindowsApiEmitter, self).setUp()
        self.emitter_queue = Queue()
        # Configure emitter for temp folder.
        self.sut = self.makeEmitter()