Пример #1
0
def writeUnixLauncher(pathLaunchScript, pathShellScript, optInstallTool=0,
                             sudoFound=None):
    """used to create shell scripts that act as application launcher
    creates file in local directory first, using paths in args
    will optional move to /usr/local/bin if optInstallTool is 1
    pathLaunchScript is the path to the python file
    pathShellScript is the path to the shell script to be written\
    if optInstallTool == 2; case were to assume already root
    """
    environment.printWarn('writing launcher script:\n%s' % pathLaunchScript)
    pythonExe = sys.executable
    # get name of shell script
    dir, name = os.path.split(pathShellScript)
    # sets command line options: -O for optimized 
    # sets -u for unbuffered standard out
    launchScript = '#!/bin/sh \n%s -O -u %s $*\n\n' % (pythonExe, 
                                                      pathLaunchScript)
    # erase if already exists
    if os.path.exists(pathShellScript):
        if optInstallTool <= 1:   # use sudo
            osTools.rmSudo(pathShellScript, sudoFound)
        elif optInstallTool == 2: # do not use sudo
            osTools.rm(pathShellScript)
    # touch a file first
    # always write a basic script in local dirs
    try:
        f = open(pathShellScript, 'w')  # test opening the file
        f.close()
        permissionError = 0
    except IOError:
        permissionError = 1

    if permissionError: # try to change mod of parent dir
        dir, name = os.path.split(pathShellScript)
        osTools.chmodSudo(775, dir, sudoFound)
    # try again w/ changed permissions
    try:
        f = open(pathShellScript, 'w')      
        f.write(launchScript)
        f.close()
        osTools.chmod(775, pathShellScript)
    except IOError:
        environment.printWarn(lang.msgFileIoError % pathShellScript)

    # optionally move this script to /usr/local/bin
    if optInstallTool >= 1: # install tool into /usr/local/bin
        binPath = osTools.findBinPath()
        flagStr = '-p' # create intermediate dirs as required
        dstPath = os.path.join(binPath, name)
        print _MOD, 'installing launcher script:\n%s' % dstPath
        if not os.path.exists(binPath): # create directory
            if optInstallTool == 1: # use sudo
                osTools.mkdirSudo(binPath, sudoFound, flagStr)
            if optInstallTool == 2: # already root
                osTools.mkdir(binPath, flagStr)
        # mv launcher script to dir
        if optInstallTool == 1: # use sudo, get permissioin
            osTools.mvSudo(pathShellScript, dstPath, sudoFound)
        elif optInstallTool == 2: # already root
            osTools.mv(pathShellScript, dstPath)
Пример #2
0
def soxSpeed(src, dst=None, speed=.5):
    # this is destructive if dst id none
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s speed %s' % (src, dst, speed)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Пример #3
0
def soxSpeed(src, dst=None, speed=.5):
    # this is destructive if dst id none
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s speed %s' % (src, dst, speed)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Пример #4
0
def soxFade(src, dst=None, timeIn=.01, timeOut=.01):
    # add a fade in and fade out to sound file
    # need total time 
    # this is destructive if dst id none
    timeTotal = fileDur(src)
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s fade t %s %s %s' % (src, dst, timeIn, timeTotal, timeOut)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src
Пример #5
0
def soxFade(src, dst=None, timeIn=.01, timeOut=.01):
    # add a fade in and fade out to sound file
    # need total time 
    # this is destructive if dst id none
    timeTotal = fileDur(src)
    if dst == None: # replace original
        nameStub, ext = osTools.extSplit(src)
        dst = '%s-temp%s' % (nameStub, ext)
    #print 'in, out, total:', timeIn, timeOut, timeTotal
    # t is a linear slope
    cmd = 'sox %s %s fade t %s %s %s' % (src, dst, timeIn, timeTotal, timeOut)
    os.system(cmd)
    if dst == '%s-temp%s' % (nameStub, ext):
        osTools.mv(dst, src)
        #osTools.rm(dst)
    return src