Ejemplo n.º 1
0
 def ServerInfo(self):
     """
     Info: Gets server and device info
     Args: None
     Returns: dict
     Errors: None
     """
     info = {}
     info["pa_count_devices"] = pyo.pa_count_devices()  # type: ignore
     info["pa_get_default_input"] = pyo.pa_get_default_input(
     )  # type: ignore
     info["pa_get_default_output"] = pyo.pa_get_default_output(
     )  # type: ignore
     info["pm_get_input_devices"] = pyo.pm_get_input_devices(
     )  # type: ignore
     info["pa_count_host_apis"] = pyo.pa_count_host_apis()  # type: ignore
     info["pa_get_default_host_api"] = pyo.pa_get_default_host_api(
     )  # type: ignore
     info["pm_count_devices"] = pyo.pm_count_devices()  # type: ignore
     info["pa_get_input_devices"] = pyo.pa_get_input_devices(
     )  # type: ignore
     info["pm_get_default_input"] = pyo.pm_get_default_input(
     )  # type: ignore
     info["pm_get_output_devices"] = pyo.pm_get_output_devices(
     )  # type: ignore
     info["pm_get_default_output"] = pyo.pm_get_default_output(
     )  # type: ignore
     info["pa_get_devices_infos"] = pyo.pa_get_devices_infos(
     )  # type: ignore
     info["pa_get_version"] = pyo.pa_get_version()  # type: ignore
     info["pa_get_version_text"] = pyo.pa_get_version_text()  # type: ignore
     return info
Ejemplo n.º 2
0
def get_devices_infos():
    in_devices, out_devices = pyo.pa_get_devices_infos()
    for index, device in chain(in_devices.items(), out_devices.items()):
        device.update({
            'default sr': '{} Hz'.format(device['default sr']),
            'host api index': str(device['host api index']),
            'latency': '{} s'.format(round(device['latency'], 6)),
        })
    return (in_devices, out_devices)
Ejemplo n.º 3
0
def getDevices(kind=None):
    """Returns a dict of dict of audio devices of sepcified `kind`

    The dict keys are names and items are dicts of properties
    """
    inputs, outputs = pyo.pa_get_devices_infos()
    if kind is None:
        allDevs = inputs.update(outputs)
    elif kind=='output':
        allDevs = outputs
    else:
        allDevs = inputs
    devs = {}
    for ii in allDevs:  # in pyo this is a dict but keys are ii ! :-/
        dev = allDevs[ii]
        devs[dev['name']] = dev
        dev['id'] = ii
    return devs
Ejemplo n.º 4
0
def getDevices(kind=None):
    """Returns a dict of dict of audio devices of sepcified `kind`

    The dict keys are names and items are dicts of properties
    """
    inputs, outputs = pyo.pa_get_devices_infos()
    if kind is None:
        allDevs = inputs.update(outputs)
    elif kind == 'output':
        allDevs = outputs
    else:
        allDevs = inputs
    devs = {}
    for ii in allDevs:  # in pyo this is a dict but keys are ii ! :-/
        dev = allDevs[ii]
        devs[dev['name']] = dev
        dev['id'] = ii
    return devs
Ejemplo n.º 5
0
def getDevices(kind=None):
    """Returns a dict of dict of audio devices of sepcified `kind`

    The dict keys are names and items are dicts of properties
    """
    osEncoding = sys.getfilesystemencoding()
    inputs, outputs = pyo.pa_get_devices_infos()
    if kind is None:
        allDevs = inputs.update(outputs)
    elif kind == 'output':
        allDevs = outputs
    else:
        allDevs = inputs
    devs = {}
    for ii in allDevs:  # in pyo this is a dict but keys are ii ! :-/
        dev = allDevs[ii]
        devName = dev['name'].decode(osEncoding)  # convert to unicode
        devs[devName] = dev
        dev['id'] = ii
    return devs
Ejemplo n.º 6
0
def getDevices(kind=None):
    """Returns a dict of dict of audio devices of sepcified `kind`

    The dict keys are names and items are dicts of properties
    """
    osEncoding = sys.getfilesystemencoding()
    inputs, outputs = pyo.pa_get_devices_infos()
    if kind is None:
        allDevs = inputs.update(outputs)
    elif kind=='output':
        allDevs = outputs
    else:
        allDevs = inputs
    devs = {}
    for ii in allDevs:  # in pyo this is a dict but keys are ii ! :-/
        dev = allDevs[ii]
        devName = dev['name'].decode(osEncoding) # convert to unicode
        devs[devName] = dev
        dev['id'] = ii
    return devs
Ejemplo n.º 7
0
    def _setSystemInfo(self):
        # machine name
        self['systemHostName'] = platform.node()

        self['systemMemTotalRAM'], self['systemMemFreeRAM'] = getRAM()

        # locale information:
        import locale
        loc = '.'.join(map(str, locale.getlocale()))  # (None, None) -> str
        if loc == 'None.None':
            loc = locale.setlocale(locale.LC_ALL, '')
        self[
            'systemLocale'] = loc  # == the locale in use, from OS or user-pref

        # platform name, etc
        if sys.platform in ['darwin']:
            OSXver, junk, architecture = platform.mac_ver()
            platInfo = 'darwin ' + OSXver + ' ' + architecture
            # powerSource = ...
        elif sys.platform.startswith('linux'):
            platInfo = 'linux ' + platform.release()
            # powerSource = ...
        elif sys.platform in ['win32']:
            platInfo = 'windowsversion=' + repr(sys.getwindowsversion())
            # powerSource = ...
        else:
            platInfo = ' [?]'
            # powerSource = ...
        self['systemPlatform'] = platInfo
        #self['systemPowerSource'] = powerSource

        # count all unique people (user IDs logged in), and find current user name & UID
        self['systemUser'], self['systemUserID'] = _getUserNameUID()
        try:
            users = shellCall("who -q").splitlines()[0].split()
            self['systemUsersCount'] = len(set(users))
        except:
            self['systemUsersCount'] = False

        # when last rebooted?
        try:
            lastboot = shellCall("who -b").split()
            self['systemRebooted'] = ' '.join(lastboot[2:])
        except:  # windows
            sysInfo = shellCall('systeminfo').splitlines()
            lastboot = [
                line for line in sysInfo if line.find("System Up Time") == 0
                or line.find("System Boot Time") == 0
            ]
            lastboot += ['[?]']  # put something in the list just in case
            self['systemRebooted'] = lastboot[0].strip()

        # R (and r2py) for stats:
        try:
            Rver, err = shellCall("R --version", stderr=True)
            Rversion = Rver.splitlines()[0]
            if Rversion.startswith('R version'):
                self['systemRavailable'] = Rversion.strip()
            try:
                import rpy2
                self['systemRpy2'] = rpy2.__version__
            except:
                pass
        except:
            pass

        # encryption / security tools:
        try:
            vers, se = shellCall('openssl version', stderr=True)
            if se:
                vers = str(vers) + se.replace('\n', ' ')[:80]
            if vers.strip():
                self['systemSec.OpenSSLVersion'] = vers
        except:
            pass
        try:
            so, se = shellCall('gpg --version', stderr=True)
            if so.find('GnuPG') > -1:
                self['systemSec.GPGVersion'] = so.splitlines()[0]
                self['systemSec.GPGHome'] = ''.join([
                    line.replace('Home:', '').lstrip()
                    for line in so.splitlines() if line.startswith('Home:')
                ])
        except:
            pass
        try:
            import ssl
            self['systemSec.pythonSSL'] = True
        except ImportError:
            self['systemSec.pythonSSL'] = False

        # pyo for sound:
        try:
            import pyo
            self['systemPyoVersion'] = '%i.%i.%i' % pyo.getVersion()
            try:
                # requires pyo svn r1024 or higher:
                inp, out = pyo.pa_get_devices_infos()
                self['systemPyo.InputDevices'] = inp
                self['systemPyo.OutputDevices'] = out
            except AttributeError:
                pass
        except ImportError:
            pass

        # flac (free lossless audio codec) for google-speech:
        flacv = ''
        if sys.platform == 'win32':
            flacexe = 'C:\\Program Files\\FLAC\\flac.exe'
            if os.path.exists(flacexe):
                flacv = core.shellCall(flacexe + ' --version')
        else:
            flac, se = core.shellCall('which flac', stderr=True)
            if not se and flac and not flac.find('Command not found') > -1:
                flacv = core.shellCall('flac --version')
        if flacv:
            self['systemFlacVersion'] = flacv

        # detect internet access or fail quickly:
        #web.setupProxy() & web.testProxy(web.proxies)  # can take a long time to fail if there's no connection
        self['systemHaveInternetAccess'] = web.haveInternetAccess()
        if not self['systemHaveInternetAccess']:
            self['systemHaveInternetAccess'] = 'False (proxies not attempted)'
Ejemplo n.º 8
0
    def _setSystemInfo(self):
        """system info"""
        # system encoding
        osEncoding=sys.getfilesystemencoding()

        # machine name
        self['systemHostName'] = platform.node()

        self['systemMemTotalRAM'], self['systemMemFreeRAM'] = getRAM()

        # locale information:
        loc = '.'.join([str(x) for x in locale.getlocale()])  # (None, None) -> str
        if loc == 'None.None':
            loc = locale.setlocale(locale.LC_ALL, '')
        self['systemLocale'] = loc  # == the locale in use, from OS or user-pref

        # platform name, etc
        if sys.platform in ['darwin']:
            OSXver, _junk, architecture = platform.mac_ver()
            platInfo = 'darwin ' + OSXver + ' ' + architecture
            # powerSource = ...
        elif sys.platform.startswith('linux'):
            platInfo = 'linux ' + platform.release()
            # powerSource = ...
        elif sys.platform in ['win32']:
            platInfo = 'windowsversion=' + repr(sys.getwindowsversion())
            # powerSource = ...
        else:
            platInfo = ' [?]'
            # powerSource = ...
        self['systemPlatform'] = platInfo
        #self['systemPowerSource'] = powerSource

        # count all unique people (user IDs logged in), and find current user name & UID
        self['systemUser'], self['systemUserID'] = _getUserNameUID()
        try:
            users = shellCall("who -q").splitlines()[0].split()
            self['systemUsersCount'] = len(set(users))
        except:
            self['systemUsersCount'] = False

        # when last rebooted?
        try:
            lastboot = shellCall("who -b").split()
            self['systemRebooted'] = ' '.join(lastboot[2:])
        except: # windows
            sysInfo = shellCall('systeminfo').splitlines()
            lastboot = [line for line in sysInfo if line.startswith("System Up Time") or line.startswith("System Boot Time")]
            lastboot += ['[?]'] # put something in the list just in case
            self['systemRebooted'] = lastboot[0].strip()

        # R (and r2py) for stats:
        try:
            Rver = shellCall(["R", "--version"])
            Rversion = Rver.splitlines()[0]
            if Rversion.startswith('R version'):
                self['systemRavailable'] = Rversion.strip()
            try:
                import rpy2
                self['systemRpy2'] = rpy2.__version__
            except ImportError:
                pass
        except:
            pass

        # encryption / security tools:
        try:
            vers, se = shellCall('openssl version', stderr=True)
            if se:
                vers = str(vers) + se.replace('\n', ' ')[:80]
            if vers.strip():
                self['systemSec.OpenSSLVersion'] = vers
        except:
            pass
        try:
            so = shellCall(['gpg', '--version'])
            if so.find('GnuPG') > -1:
                self['systemSec.GPGVersion'] = so.splitlines()[0]
                self['systemSec.GPGHome'] = ''.join([line.replace('Home:', '').lstrip()
                                                    for line in so.splitlines()
                                                    if line.startswith('Home:')])
        except:
            pass
        try:
            import ssl
            self['systemSec.pythonSSL'] = True
        except ImportError:
            self['systemSec.pythonSSL'] = False

        # pyo for sound:
        try:
            import pyo
            self['systemPyoVersion'] = '%i.%i.%i' % pyo.getVersion()
            try:
                # requires pyo svn r1024 or higher:
                inp, out = pyo.pa_get_devices_infos()
                for devList in [inp, out]:
                    for key in devList.keys():
                        if isinstance(devList[key]['name'], str):
                            devList[key]['name'] = devList[key]['name'].decode(osEncoding)
                self['systemPyo.InputDevices'] = inp
                self['systemPyo.OutputDevices'] = out
            except AttributeError:
                pass
        except ImportError:
            pass

        # flac (free lossless audio codec) for google-speech:
        flacv = ''
        if sys.platform == 'win32':
            flacexe = 'C:\\Program Files\\FLAC\\flac.exe'
            if os.path.exists(flacexe):
                flacv = core.shellCall(flacexe + ' --version')
        else:
            flac, se = core.shellCall('which flac', stderr=True)
            if not se and flac and not flac.find('Command not found') > -1:
                flacv = core.shellCall('flac --version')
        if flacv:
            self['systemFlacVersion'] = flacv

        # detect internet access or fail quickly:
        #web.setupProxy() & web.testProxy(web.proxies)  # can take a long time to fail if there's no connection
        self['systemHaveInternetAccess'] = web.haveInternetAccess()
        if not self['systemHaveInternetAccess']:
            self['systemHaveInternetAccess'] = 'False (proxies not attempted)'
from pyo import pa_get_devices_infos

inputs, outputs =  pa_get_devices_infos()

def getInput(*args):
    if len(args) == 1:
        for input in inputs:
            if args[0] in inputs[input]['name']:
                return input
        return 0
    elif len(args) == 0:
        for input in inputs:
            print "Input index : ", input, ", Name : ", inputs[input]['name']
    else:
        return -1

def getOutput(*args):
    if len(args) == 1:
        for output in outputs:
            if args[0] in outputs[output]['name']:
                return output
        return 0
    elif len(args) == 0:
        for output in outputs:
            print "Output index: ", output, ", Name: ", outputs[output]['name']
    else:
        return -1
            
def clean():
    global inputs, outputs
    del inputs
Ejemplo n.º 10
0
    def _setSystemInfo(self):
        """system info"""
        # system encoding
        osEncoding = sys.getfilesystemencoding()

        # machine name
        self['systemHostName'] = platform.node()

        self['systemMemTotalRAM'], self['systemMemFreeRAM'] = getRAM()

        # locale information:
        loc = '.'.join([str(x)
                        for x in locale.getlocale()])  # (None, None) -> str
        if loc == 'None.None':
            loc = locale.setlocale(locale.LC_ALL, '')
        self[
            'systemLocale'] = loc  # == the locale in use, from OS or user-pref

        # platform name, etc
        if sys.platform in ['darwin']:
            OSXver, _junk, architecture = platform.mac_ver()
            platInfo = 'darwin ' + OSXver + ' ' + architecture
            # powerSource = ...
        elif sys.platform.startswith('linux'):
            platInfo = 'linux ' + platform.release()
            # powerSource = ...
        elif sys.platform in ['win32']:
            platInfo = 'windowsversion=' + repr(sys.getwindowsversion())
            # powerSource = ...
        else:
            platInfo = ' [?]'
            # powerSource = ...
        self['systemPlatform'] = platInfo
        #self['systemPowerSource'] = powerSource

        # count all unique people (user IDs logged in), and find current user name & UID
        self['systemUser'], self['systemUserID'] = _getUserNameUID()
        try:
            users = shellCall("who -q").splitlines()[0].split()
            self['systemUsersCount'] = len(set(users))
        except:
            self['systemUsersCount'] = False

        # when last rebooted?
        try:
            lastboot = shellCall("who -b").split()
            self['systemRebooted'] = ' '.join(lastboot[2:])
        except:  # windows
            sysInfo = shellCall('systeminfo').splitlines()
            lastboot = [
                line for line in sysInfo if line.startswith("System Up Time")
                or line.startswith("System Boot Time")
            ]
            lastboot += ['[?]']  # put something in the list just in case
            self['systemRebooted'] = lastboot[0].strip()

        # R (and r2py) for stats:
        try:
            Rver = shellCall(["R", "--version"])
            Rversion = Rver.splitlines()[0]
            if Rversion.startswith('R version'):
                self['systemRavailable'] = Rversion.strip()
            try:
                import rpy2
                self['systemRpy2'] = rpy2.__version__
            except ImportError:
                pass
        except:
            pass

        # encryption / security tools:
        try:
            vers, se = shellCall('openssl version', stderr=True)
            if se:
                vers = str(vers) + se.replace('\n', ' ')[:80]
            if vers.strip():
                self['systemSec.OpenSSLVersion'] = vers
        except:
            pass
        try:
            so = shellCall(['gpg', '--version'])
            if so.find('GnuPG') > -1:
                self['systemSec.GPGVersion'] = so.splitlines()[0]
                self['systemSec.GPGHome'] = ''.join([
                    line.replace('Home:', '').lstrip()
                    for line in so.splitlines() if line.startswith('Home:')
                ])
        except:
            pass
        try:
            import ssl
            self['systemSec.pythonSSL'] = True
        except ImportError:
            self['systemSec.pythonSSL'] = False

        # pyo for sound:
        try:
            travis = bool(str(os.environ.get('TRAVIS')).lower() == 'true')
            assert not travis  # skip sound-related stuff on travis-ci.org

            import pyo
            self['systemPyoVersion'] = '%i.%i.%i' % pyo.getVersion()
            try:
                # requires pyo svn r1024 or higher:
                inp, out = pyo.pa_get_devices_infos()
                for devList in [inp, out]:
                    for key in devList.keys():
                        if isinstance(devList[key]['name'], str):
                            devList[key]['name'] = devList[key]['name'].decode(
                                osEncoding)
                self['systemPyo.InputDevices'] = inp
                self['systemPyo.OutputDevices'] = out
            except AttributeError:
                pass
        except AssertionError, ImportError:
            pass
Ejemplo n.º 11
0
    def _setSystemInfo(self):
        """system info"""
        # system encoding
        osEncoding=sys.getfilesystemencoding()

        # machine name
        self['systemHostName'] = platform.node()

        self['systemMemTotalRAM'], self['systemMemFreeRAM'] = getRAM()

        # locale information:
        loc = '.'.join([str(x) for x in locale.getlocale()])  # (None, None) -> str
        if loc == 'None.None':
            loc = locale.setlocale(locale.LC_ALL, '')
        self['systemLocale'] = loc  # == the locale in use, from OS or user-pref

        # platform name, etc
        if sys.platform in ['darwin']:
            OSXver, _junk, architecture = platform.mac_ver()
            platInfo = 'darwin ' + OSXver + ' ' + architecture
            # powerSource = ...
        elif sys.platform.startswith('linux'):
            platInfo = 'linux ' + platform.release()
            # powerSource = ...
        elif sys.platform in ['win32']:
            platInfo = 'windowsversion=' + repr(sys.getwindowsversion())
            # powerSource = ...
        else:
            platInfo = ' [?]'
            # powerSource = ...
        self['systemPlatform'] = platInfo
        #self['systemPowerSource'] = powerSource

        # count all unique people (user IDs logged in), and find current user name & UID
        self['systemUser'], self['systemUserID'] = _getUserNameUID()
        try:
            users = shellCall("who -q").splitlines()[0].split()
            self['systemUsersCount'] = len(set(users))
        except:
            self['systemUsersCount'] = False

        # when last rebooted?
        try:
            lastboot = shellCall("who -b").split()
            self['systemRebooted'] = ' '.join(lastboot[2:])
        except: # windows
            sysInfo = shellCall('systeminfo').splitlines()
            lastboot = [line for line in sysInfo if line.startswith("System Up Time") or line.startswith("System Boot Time")]
            lastboot += ['[?]'] # put something in the list just in case
            self['systemRebooted'] = lastboot[0].strip()

        # R (and r2py) for stats:
        try:
            Rver = shellCall(["R", "--version"])
            Rversion = Rver.splitlines()[0]
            if Rversion.startswith('R version'):
                self['systemRavailable'] = Rversion.strip()
            try:
                import rpy2
                self['systemRpy2'] = rpy2.__version__
            except ImportError:
                pass
        except:
            pass

        # encryption / security tools:
        try:
            vers, se = shellCall('openssl version', stderr=True)
            if se:
                vers = str(vers) + se.replace('\n', ' ')[:80]
            if vers.strip():
                self['systemSec.OpenSSLVersion'] = vers
        except:
            pass
        try:
            so = shellCall(['gpg', '--version'])
            if so.find('GnuPG') > -1:
                self['systemSec.GPGVersion'] = so.splitlines()[0]
                self['systemSec.GPGHome'] = ''.join([line.replace('Home:', '').lstrip()
                                                    for line in so.splitlines()
                                                    if line.startswith('Home:')])
        except:
            pass
        try:
            import ssl
            self['systemSec.pythonSSL'] = True
        except ImportError:
            self['systemSec.pythonSSL'] = False

        # pyo for sound:
        try:
            travis = bool(str(os.environ.get('TRAVIS')).lower() == 'true')
            assert not travis  # skip sound-related stuff on travis-ci.org

            import pyo
            self['systemPyoVersion'] = '%i.%i.%i' % pyo.getVersion()
            try:
                # requires pyo svn r1024 or higher:
                inp, out = pyo.pa_get_devices_infos()
                for devList in [inp, out]:
                    for key in devList.keys():
                        if isinstance(devList[key]['name'], str):
                            devList[key]['name'] = devList[key]['name'].decode(osEncoding)
                self['systemPyo.InputDevices'] = inp
                self['systemPyo.OutputDevices'] = out
            except AttributeError:
                pass
        except AssertionError, ImportError:
            pass
Ejemplo n.º 12
0
def discover_pa_devices():
    return pyo.pa_get_devices_infos()