Пример #1
0
def getTask(messageQueue, taskQueue, IOLock):
    '''Takes a task from taskQueue, interprets it, loads instructions and data into memory
    
    Args:
        - messageQueue -- queue used for logging
        - taskQueue -- the global task queue from
        - IOLock -- the lock that must be acquired when reading or writing data  
    Returns:
        - task -- the task itself, if there are no tasks, this will be none
        - clientScript -- a python file loaded into memory and compressed with zlib.compress, if there are no tasks, this will be none
        - data -- a zipped file containing data for the client loaded into memory, if there are no tasks, this will be none, if no data folder exists, this will be none
    Raises:
        - Exceptions.NoTasks: if there are no tasks in the task queue
    
    '''
    
    IOLock.acquire()
    
    try:
        while True:
            try:
                task = taskQueue.get(True,0.1)
            except Queue.Empty:
                return None,None,None
            
            try:
                taskName,pathToScript,pathToData = task.split(',')
            except ValueError:
                messageQueue.put(UtilityFunctions.createLogEntry('err','the following task is in the wrong format: '+task))
                continue
            
            try:
                scriptHandle = open(pathToScript,'r')
                clientScript = zlib.compress(scriptHandle.read());
                scriptHandle.close();
            except IOError:
                messageQueue.put(UtilityFunctions.createLogEntry('err','could not read the following clientScript: '+pathToScript))
                continue
            
            if os.path.isdir(pathToData):
                UtilityFunctions.zipDir(pathToData, './server/temp/transferData.zip');
                transferDataHandle = open('./server/temp/transferData.zip');
                data = transferDataHandle.read();
                transferDataHandle.close();
                os.remove('./server/temp/transferData.zip')
            else:
                data = None
            
            break
        
        return task,clientScript,data
                
                
    except:
        messageQueue.put(UtilityFunctions.createLogEntry('deb','error in ServerSideTaskHandler.getTask:\n'+traceback.format_exc() + '\ntask' + task));
        raise            
            
        
    finally:
        IOLock.release()         
Пример #2
0
def getTask(messageQueue, taskQueue, IOLock):
    '''Takes a task from taskQueue, interprets it, loads instructions and data into memory
    
    Args:
        - messageQueue -- queue used for logging
        - taskQueue -- the global task queue from
        - IOLock -- the lock that must be acquired when reading or writing data  
    Returns:
        - task -- the task itself, if there are no tasks, this will be none
        - clientScript -- a python file loaded into memory and compressed with zlib.compress, if there are no tasks, this will be none
        - data -- a zipped file containing data for the client loaded into memory, if there are no tasks, this will be none, if no data folder exists, this will be none
    Raises:
        - Exceptions.NoTasks: if there are no tasks in the task queue
    
    '''
    
    IOLock.acquire()
    
    try:
        while True:
            try:
                task = taskQueue.get(True,0.1)
            except Queue.Empty:
                return None,None,None
            
            try:
                taskName,pathToScript,pathToData = task.split(',')
            except ValueError:
                messageQueue.put(UtilityFunctions.createLogEntry('err','the following task is in the wrong format: '+task))
                continue
            
            try:
                scriptHandle = open(pathToScript,'r')
                clientScript = zlib.compress(scriptHandle.read());
                scriptHandle.close();
            except IOError:
                messageQueue.put(UtilityFunctions.createLogEntry('err','could not read the following clientScript: '+pathToScript))
                continue
            
            if os.path.isdir(pathToData):
                UtilityFunctions.zipDir(pathToData, './server/temp/transferData.zip');
                transferDataHandle = open('./server/temp/transferData.zip');
                data = transferDataHandle.read();
                transferDataHandle.close();
                os.remove('./server/temp/transferData.zip')
            else:
                data = None
            
            break
        
        return task,clientScript,data
                
                
    except:
        messageQueue.put(UtilityFunctions.createLogEntry('deb','error in ServerSideTaskHandler.getTask:\n'+traceback.format_exc() + '\ntask' + task));
        raise            
            
        
    finally:
        IOLock.release()         
Пример #3
0
def loadResult(resultsDirectory):
    '''Zips all data in the results directory in a zip file and returns that zip file loaded into memory. Also removes resultsData from disk '''
    temporaryDirectory = './client/temp'
    UtilityFunctions.zipDir(resultsDirectory,
                            os.path.join(temporaryDirectory, 'result.zip'))
    resultHandle = open(os.path.join(temporaryDirectory, 'result.zip'), 'r')
    resultData = resultHandle.readlines()
    resultHandle.close()
    UtilityFunctions.deleteContentsOfDirectory(temporaryDirectory)
    UtilityFunctions.deleteContentsOfDirectory(resultsDirectory)
    return resultData
Пример #4
0
def loadResult(resultsDirectory):
    '''Zips all data in the results directory in a zip file and returns that zip file loaded into memory. Also removes resultsData from disk '''
    temporaryDirectory = './client/temp'
    UtilityFunctions.zipDir(resultsDirectory, os.path.join(temporaryDirectory,'result.zip'))
    resultHandle = open(os.path.join(temporaryDirectory,'result.zip'),'r')
    resultData = resultHandle.readlines()
    resultHandle.close()
    UtilityFunctions.deleteContentsOfDirectory(temporaryDirectory)
    UtilityFunctions.deleteContentsOfDirectory(resultsDirectory)
    return resultData