def openTerminal(self, package): ''' Open bash in `package`'s chroot jail working directory. ''' if package != None: packagePath = self._getPackages().getPackage(package).getPackageSourceDirectory() if packagePath != None: pathScript = self.__chroot.getChrootDirTransfert() + "/runMe.sh" title = "%s project directory" % package f = open(pathScript, 'w') f.write("#!/bin/sh\n") f.write("# Created by obslight\n") f.write("cd " + packagePath + "\n") # control code to change window title f.write('echo -en "\e]2;%s\a"\n' % title) f.write("exec bash\n") f.close() os.chmod(pathScript, 0755) command = ObsLightConfig.getConsole(title) + " " + pathScript command = shlex.split(str(command)) # subprocess.call(command) would wait for the command to finish, # which would cause problem with terminal emulators which don't # fork themselves subprocess.Popen(command)
def dumpError(exceptionType, message, traceback_): timeString = time.strftime("%Y-%m-%d_%Hh%Mm") + str( time.time() % 1).split(".")[1] message2Dump = message if traceback_ is not None: message2Dump += "\n\n" + "".join(traceback.format_tb(traceback_)) typeName = re.findall(".*\'(.*)\'.*", str(exceptionType)) if len(typeName) == 1: exceptionType = typeName[0] logfile = "%s-%s.log" % (timeString, exceptionType) if not os.path.isdir(ObsLightConfig.ERRORLOGDIRECTORY): os.makedirs(ObsLightConfig.ERRORLOGDIRECTORY) logPath = os.path.join(ObsLightConfig.ERRORLOGDIRECTORY, logfile) try: message2Dump = unicode(message2Dump) except UnicodeError: message2Dump = unicode(str(message2Dump), errors="replace") with open(logPath, 'w') as f: print >> f, message2Dump.encode('utf-8') if (ObsLightConfig.getObslightLoggerLevel() == "DEBUG"): print >> sys.stderr, exceptionType, message2Dump else: message += "\n\nlogPath: " + logPath print >> sys.stderr, exceptionType, message return logPath
def mapProcedureWithThreads(parameterList, procedure, progress=None): errList = [] res = [] maxThreads = ObsLightConfig.getMaxNbThread() if maxThreads > 0: sem = threading.BoundedSemaphore(value=maxThreads) aLock = threading.Lock() for p in parameterList: athread = procedureWithThreads(packagePath=p, procedure=procedure, sem=sem, lock=aLock, errList=errList, progress=progress) athread.start() res.append(athread) for th in res: th.join() else: for parameter in parameterList: retVal = procedure(parameter) if retVal != 0: errList.append(parameter) if progress != None: progress() return errList
def __init__(self, workingDirectory): ''' Constructor ''' self.__repositoriesPath = ObsLightConfig.getRepositriesServerPath() self.__workingDirectory = workingDirectory pathDir = os.path.expanduser(self.__repositoriesPath) if not os.path.isdir(pathDir): os.makedirs(pathDir) self.__pathFile = os.path.join(self.__workingDirectory, "ObsLightRepositoriesConfig") self.__dicOBSLightRepositories = {} self.__mySubprocessCrt = SubprocessCrt()
def openFileWithDefaultProgram(filePath): logger = ObsLightPrintManager.getLogger() openCommand = ObsLightConfig.getOpenFileCommand() if openCommand is None: message = u"No 'openFile' command configured." raise ObsLightErr.ConfigurationError(message) logger.info(u"Opening %s", filePath) logger.debug(u"Running command: '%s %s'", openCommand, filePath) try: retVal = call([openCommand, filePath]) return retVal except BaseException: logger.error("Failed to run '%s %s'", openCommand, filePath, exc_info=True) raise
def getLocalRepository(self): return ObsLightConfig.getLocalRepoServer() + "/" + self.__projectName
Created on 24 oct. 2011 @author: meego ''' import logging import logging.handlers import ObsLightConfig QUIET = 0 DEBUG = 0 logger = logging.getLogger('obslight') spLogger = logging.getLogger('subprocess') streamHandler = logging.StreamHandler() fileHandler = logging.handlers.RotatingFileHandler( ObsLightConfig.getObsLightLogFilePath(), maxBytes=10 * 2**20, backupCount=1) def obsLightPrint(text, isDebug=False, isVerbose=False): ''' ''' if (isDebug == False) or (DEBUG > 0): logger.info(text) else: logger.debug(text) def setLoggerLevel(level):
def __init__(self): ''' Constructor ''' self.__mySubprocessCrt = SubprocessCrt() self.__serverPath = ObsLightConfig.getImageServerPath()