当前位置: 首页>>代码示例>>Python>>正文


Python core.shellCall函数代码示例

本文整理汇总了Python中psychopy.core.shellCall函数的典型用法代码示例。如果您正苦于以下问题:Python shellCall函数的具体用法?Python shellCall怎么用?Python shellCall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了shellCall函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: flac2wav

def flac2wav(path, keep=True):
    """Uncompress: convert .flac file (on disk) to .wav format (new file).

    If `path` is a directory name, convert all .flac files in the directory.

    `keep` to retain the original .flac file(s), default `True`.
    """
    flac_path = _getFlacPath()
    flac_files = []
    if path.endswith(".flac"):
        flac_files = [path]
    elif type(path) == str and os.path.isdir(path):
        flac_files = glob.glob(os.path.join(path, "*.flac"))
    if len(flac_files) == 0:
        logging.warn("failed to find .flac file(s) from %s" % path)
        return None
    wav_files = []
    for flacfile in flac_files:
        wavfile = flacfile.strip(".flac") + ".wav"
        flac_cmd = [flac_path, "-d", "--totally-silent", "-f", "-o", wavfile, flacfile]
        __, se = core.shellCall(flac_cmd, stderr=True)
        if se or not os.path.isfile(flacfile):  # just try again
            logging.warn("Failed to convert to .wav; trying again")
            __, se = core.shellCall(flac_cmd, stderr=True)
            if se:
                logging.error(se)
        if not keep:
            os.unlink(flacfile)
        wav_files.append(wavfile)
    if len(wav_files) == 1:
        return wav_files[0]
    else:
        return wav_files
开发者ID:rpbaxter,项目名称:psychopy,代码行数:33,代码来源:microphone.py

示例2: _getHgVersion

def _getHgVersion(file):
    """Tries to discover the mercurial (hg) parent and id of a file.
    
    Not thoroughly tested; completely untested on Windows Vista, Win 7, FreeBSD
    
    :Author:
        - 2010 written by Jeremy Gray
    """
    if not os.path.exists(file) or not os.path.isdir(os.path.join(os.path.dirname(file),'.hg')):
        return None
    try:
        hgParentLines,err = shellCall('hg parents "'+file+'"', stderr=True)
        changeset = hgParentLines.splitlines()[0].split()[-1]
    except:
        changeset = ''
    #else: changeset = hgParentLines.splitlines()[0].split()[-1]
    try:
        hgID,err = shellCall('hg id -nibt "'+os.path.dirname(file)+'"', stderr=True)
    except:
        if err: hgID = ''
    
    if len(hgID) or len(changeset):
        return hgID.strip()+' | parent: '+changeset.strip()
    else:
        return None
开发者ID:yvs,项目名称:psychopy,代码行数:25,代码来源:info.py

示例3: _getSvnVersion

def _getSvnVersion(filename):
    """Tries to discover the svn version (revision #) for a file.

    Not thoroughly tested; completely untested on Windows Vista, Win 7, FreeBSD

    :Author:
        - 2010 written by Jeremy Gray
    """
    if not (os.path.exists(filename) and os.path.isdir(os.path.join(os.path.dirname(filename), '.svn'))):
        return None, None, None
    svnRev, svnLastChangedRev, svnUrl = None, None, None
    if sys.platform in ['darwin', 'freebsd'] or sys.platform.startswith('linux'):
        try:
            svninfo = shellCall(['svn', 'info', filename]) # expects a filename, not dir
        except:
            svninfo = ''
        for line in svninfo.splitlines():
            if line.startswith('URL:'):
                svnUrl = line.split()[1]
            elif line.startswith('Revision: '):
                svnRev = line.split()[1]
            elif line.startswith('Last Changed Rev'):
                svnLastChangedRev = line.split()[3]
    else: # worked for me on Win XP sp2 with TortoiseSVN (SubWCRev.exe)
        try:
            stdout = shellCall(['subwcrev', filename])
        except:
            stdout = ''
        for line in stdout.splitlines():
            if line.startswith('Last committed at revision'):
                svnRev = line.split()[4]
            elif line.startswith('Updated to revision'):
                svnLastChangedRev = line.split()[3]
    return svnRev, svnLastChangedRev, svnUrl
开发者ID:alexholcombe,项目名称:psychopy,代码行数:34,代码来源:info.py

示例4: _getHgVersion

def _getHgVersion(filename):
    """Tries to discover the mercurial (hg) parent and id of a file.

    Not thoroughly tested; untested on Windows Vista, Win 7, FreeBSD

    :Author:
        - 2010 written by Jeremy Gray
    """
    dirname = os.path.dirname
    if (not os.path.exists(filename) or
            not os.path.isdir(os.path.join(dirname(filename), '.hg'))):
        return None
    try:
        hgParentLines, err = shellCall(['hg', 'parents', filename],
                                       stderr=True)
        changeset = hgParentLines.splitlines()[0].split()[-1]
    except Exception:
        changeset = ''
    try:
        hgID, err = shellCall(['hg', 'id', '-nibt', dirname(filename)],
                              stderr=True)
    except Exception:
        if err:
            hgID = ''

    if len(hgID) or len(changeset):
        return hgID.strip() + ' | parent: ' + changeset.strip()
    else:
        return None
开发者ID:flipphillips,项目名称:psychopy,代码行数:29,代码来源:info.py

示例5: wav2flac

def wav2flac(path, keep=True):
    """Lossless compression: convert .wav file (on disk) to .flac format.

    If `path` is a directory name, convert all .wav files in the directory.

    `keep` to retain the original .wav file(s), default `True`.
    """
    flac_path = _getFlacPath()
    wav_files = []
    if path.endswith(".wav"):
        wav_files = [path]
    elif type(path) == str and os.path.isdir(path):
        wav_files = glob.glob(os.path.join(path, "*.wav"))
    if len(wav_files) == 0:
        logging.warn("failed to find .wav file(s) from %s" % path)
        return None
    flac_files = []
    for wavfile in wav_files:
        flacfile = wavfile.strip(".wav") + ".flac"
        flac_cmd = [flac_path, "-8", "-f", "--totally-silent", "-o", flacfile, wavfile]
        __, se = core.shellCall(flac_cmd, stderr=True)
        if se or not os.path.isfile(flacfile):  # just try again
            # ~2% incidence when recording for 1s, 650+ trials
            # never got two in a row; core.wait() does not help
            logging.warn("Failed to convert to .flac; trying again")
            __, se = core.shellCall(flac_cmd, stderr=True)
            if se:
                logging.error(se)
        if not keep:
            os.unlink(wavfile)
        flac_files.append(flacfile)
    if len(wav_files) == 1:
        return flac_files[0]
    else:
        return flac_files
开发者ID:rpbaxter,项目名称:psychopy,代码行数:35,代码来源:microphone.py

示例6: test_stdin_and_stderr

    def test_stdin_and_stderr(self):
        echo, se = shellCall([self.cmd, self.msg], stdin='echo', stderr=True)
        assert echo == self.msg
        assert se == ''

        echo, se = shellCall(self.cmd + ' ' + self.msg, stdin='echo',
                             stderr=True)
        assert echo == self.msg
        assert se == ''
开发者ID:dgfitch,项目名称:psychopy,代码行数:9,代码来源:test_core.py

示例7: test_shellCall

def test_shellCall():
    msg = 'echo'
    cmd = ('grep', 'findstr')[sys.platform == 'win32']

    for arg1 in [[cmd, msg],  cmd+' '+msg]:
        echo = shellCall(arg1, stdin=msg)
        assert echo == msg
        echo, se = shellCall(arg1, stdin=msg, stderr=True)
        assert echo == msg
    echo, se = shellCall(12, stdin=msg)
    assert echo == None
开发者ID:9173860,项目名称:psychopy,代码行数:11,代码来源:test_core.py

示例8: __init__

 def __init__(self):
     from psychopy import core
     import os
     # should be writable:
     noopPath = os.path.join(psychopy.prefs.paths['userPrefsDir'], 'showgui_hack.py')
     # code to open & immediately close a gui (= invisibly):
     if not os.path.isfile(noopPath):
         code = """from psychopy import gui
             dlg = gui.Dlg().Show()  # non-blocking
             try: dlg.Destroy()  # might as well
             except: pass""".replace('    ', '')
         with open(noopPath, 'wb') as fd:
             fd.write(code)
     core.shellCall([sys.executable, noopPath])  # append 'w' for pythonw seems not needed
开发者ID:harmadillo,项目名称:psychopy,代码行数:14,代码来源:_psychopyApp.py

示例9: _getFlacPath

def _getFlacPath(flac_exe=''):
    """Return full path to flac binary, using a cached value if possible.
    """
    global FLAC_PATH
    if FLAC_PATH is None:
        if sys.platform == 'win32':
            if os.path.isfile(flac_exe):
                FLAC_PATH = flac_exe
            else:
                FLAC_PATH = core.shellCall(['where', '/r', 'C:\\', 'flac'])
        else:
            FLAC_PATH = core.shellCall(['/usr/bin/which', 'flac'])
        logging.info('set FLAC_PATH to %s' % FLAC_PATH)
    return FLAC_PATH
开发者ID:klq,项目名称:psychopy,代码行数:14,代码来源:microphone.py

示例10: _setSystemUserInfo

 def _setSystemUserInfo(self):
     # machine name
     self['systemHostName'] = platform.node()
     
     # platform name, etc
     if sys.platform in ['darwin']:
         OSXver, junk, architecture = platform.mac_ver()
         platInfo = 'darwin '+OSXver+' '+architecture
         # powerSource = ...
     elif sys.platform in ['linux2']:
         platInfo = 'linux2 '+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()
     
     # is R available (for stats)?
     try:
         Rver,err = shellCall("R --version",stderr=True)
         Rversion = Rver.splitlines()[0]
         if Rversion.find('R version') == 0:
             self['systemRavailable'] = Rversion.strip()
         else: raise
     except:
         self['systemRavailable'] = False
     
     """try:
开发者ID:yvs,项目名称:psychopy,代码行数:50,代码来源:info.py

示例11: _wizard

    def _wizard(self, selector, arg=""):
        from psychopy import core

        wizard = os.path.join(self.prefs.paths["psychopy"], "wizard.py")
        so, se = core.shellCall([sys.executable, wizard, selector, arg], stderr=True)
        if se and self.prefs.app["debugMode"]:
            print se  # stderr contents; sometimes meaningless
开发者ID:virtualtalks,项目名称:psychopy,代码行数:7,代码来源:_psychopyApp.py

示例12: flac2wav

def flac2wav(path, keep=True):
    """Uncompress: convert .flac file (on disk) to .wav format (new file).

    If `path` is a directory name, convert all .flac files in the directory.

    `keep` to retain the original .flac file(s), default `True`.
    """
    flac_path = _getFlacPath()
    flac_files = []
    path = pathToString(path)
    if path.endswith('.flac'):
        flac_files = [path]
    elif type(path) == str and os.path.isdir(path):
        flac_files = glob.glob(os.path.join(path, '*.flac'))
    if len(flac_files) == 0:
        logging.warn('failed to find .flac file(s) from %s' % path)
        return None
    wav_files = []
    for flacfile in flac_files:
        wavname = flacfile.strip('.flac') + '.wav'
        flac_cmd = [flac_path, "-d", "--totally-silent",
                    "-f", "-o", wavname, flacfile]
        _junk, se = core.shellCall(flac_cmd, stderr=True)
        if se:
            logging.error(se)
        if not keep:
            os.unlink(flacfile)
        wav_files.append(wavname)
    if len(wav_files) == 1:
        return wav_files[0]
    else:
        return wav_files
开发者ID:dgfitch,项目名称:psychopy,代码行数:32,代码来源:microphone.py

示例13: test_shellCall

def test_shellCall():
    if PY3:
        # This call to shellCall from tests is failing from Python3
        # but maybe it just isn't a great test anyway?!
        # shellCall is used by PsychoPy Tools>Run and works on Py3 there!
        pytest.xfail(reason="Failing on Py3")
    msg = 'echo'
    cmd = ('grep', 'findstr')[sys.platform == 'win32']

    for arg1 in [[cmd, msg],  cmd+' '+msg]:
        echo = shellCall(arg1, stdin=msg)
        assert echo == msg
        echo, se = shellCall(arg1, stdin=msg, stderr=True)
        assert echo == msg
    echo, se = shellCall(12, stdin=msg)
    assert echo is None
开发者ID:bergwiesel,项目名称:psychopy,代码行数:16,代码来源:test_core.py

示例14: _getUserNameUID

def _getUserNameUID():
    """Return user name, UID.
    
    UID values can be used to infer admin-level:
    -1=undefined, 0=full admin/root, >499=assume non-admin/root (>999 on debian-based)
    
    :Author:
        - 2010 written by Jeremy Gray
    """
    try:
        user = os.environ['USER']
    except KeyError:
        user = os.environ['USERNAME']
    uid = '-1' 
    try:
        if sys.platform not in ['win32']:
            uid = shellCall('id -u')
        else:
            try:
                uid = '1000'
                if ctypes.windll.shell32.IsUserAnAdmin():
                    uid = '0'
            except:
                raise
    except:
        pass
    return str(user), int(uid)
开发者ID:MattIBall,项目名称:psychopy,代码行数:27,代码来源:info.py

示例15: _wizard

 def _wizard(self, selector, arg=''):
     from psychopy import core
     wizard = os.path.join(
         self.prefs.paths['psychopy'], 'tools', 'wizard.py')
     so, se = core.shellCall(
         [sys.executable, wizard, selector, arg], stderr=True)
     if se and self.prefs.app['debugMode']:
         print(se)  # stderr contents; sometimes meaningless
开发者ID:tstenner,项目名称:psychopy,代码行数:8,代码来源:_psychopyApp.py


注:本文中的psychopy.core.shellCall函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。