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)
def removeDisutils(sudoFound=None): # get site-packages dirs absolute file path sitePkgAthena = os.path.join(osTools.findSitePackages(), 'athenaCL') if os.path.exists(sitePkgAthena): osTools.rmSudo(sitePkgAthena, sudoFound) else: environment.printWarn('no distutuls install')
def removePthLoader(sudoFound=None): """remove old pth loader""" environment.printWarn('removing outdated pth file') dst = os.path.join(osTools.findSitePackages(), 'athenaCL.pth') if os.path.exists(dst): osTools.rmSudo(dst, sudoFound) else: environment.printWarn('no pth file exists')
def removeUnixLauncher(sudoFound=None): """only remove if it is found within /usr/local/bin""" environment.printWarn('removing athenacl unix launcher') dst = osTools.findAthBinPath() if os.path.exists(dst): osTools.rmSudo(dst, sudoFound) else: environment.printWarn('no athenacl unix launcher exists (%s)' % dst)
def removeMan(sudoFound=None): """removing man file""" environment.printWarn('removing manual-page file') manDir = osTools.findManPath(info.MANGROUP) # assumes group 1 of man pages if manDir == None: return None dst = os.path.join(manDir, info.MANFILE) if os.path.exists(dst): osTools.rmSudo(dst, sudoFound) else: environment.printWarn('no athenacl manual-page exists (%s)' % dst)