def test_logging(self): logger = UtilsLogging.getLogger('DEBUG') logger.debug("Test message debug") logger.info("Test message info") logger.warning("Test message warning") logger.error("Test message error") logger.critical("Test message critical") logger.fatal("Test message fatal")
def setImageQualityIndicatorsPlot(dataCollectionId, plotFile, csvFile): logger = UtilsLogging.getLogger() client = getCollectionWebService() if client is None: logger.error( "No web service client available, cannot contact setImageQualityIndicatorsPlot web service." ) returnDataCollectionId = client.service.setImageQualityIndicatorsPlot( dataCollectionId, plotFile, csvFile) return returnDataCollectionId
def getTransport(): transport = None logger = UtilsLogging.getLogger() if not "ISPyB_user" in os.environ: logger.error("No ISPyB user name defined as environment variable!") elif not "ISPyB_pass" in os.environ: logger.error("No ISPyB password defined as environment variable!") else: ispybUserName = os.environ["ISPyB_user"] ispybPassword = os.environ["ISPyB_pass"] transport = HttpAuthenticated(username=ispybUserName, password=ispybPassword) return transport
def getCollectionWebService(): logger = UtilsLogging.getLogger() collectionWdsl = getToolsForCollectionWebService() transport = getTransport() if transport is None: logger.error( "No transport defined, ISPyB web service client cannot be instantiated." ) collectionWSClient = None else: collectionWSClient = Client(collectionWdsl, transport=transport, cache=None) return collectionWSClient
def findDataCollectionFromFileLocationAndFileName(imagePath, client=None): logger = UtilsLogging.getLogger() dataCollectionWS3VO = None noTrials = 10 fileLocation = os.path.dirname(imagePath) fileName = os.path.basename(imagePath) if fileName.endswith(".h5"): prefix = UtilsImage.getPrefix(fileName) imageNumber = UtilsImage.getImageNumber(fileName) fileName = "{0}_{1:04d}.h5".format(prefix, imageNumber) try: if client is None: client = getCollectionWebService() if client is None: logger.error( "No web service client available, cannot contact findDataCollectionFromFileLocationAndFileName web service." ) elif fileLocation is None: logger.error( "No fileLocation given, cannot contact findDataCollectionFromFileLocationAndFileName web service." ) elif fileName is None: logger.error( "No fileName given, cannot contact findDataCollectionFromFileLocationAndFileName web service." ) else: dataCollectionWS3VO = client.service.findDataCollectionFromFileLocationAndFileName( fileLocation, fileName) except Exception as e: logger.error( "ISPyB error for findDataCollectionFromFileLocationAndFileName: {0}, {1} trials left" .format(e, noTrials)) raise e if dataCollectionWS3VO is None: time.sleep(1) if noTrials == 0: raise RuntimeError( "ISPyB error for findDataCollectionFromFileLocationAndFileName - no data collections found for path {0}" .format(imagePath)) else: logger.warning( "Cannot find {0} in ISPyB - retrying, {1} trials left".format( imagePath, noTrials)) return dataCollectionWS3VO
def findDataCollection(dataCollectionId, client=None): e = None dataCollectionWS3VO = None noTrials = 5 logger = UtilsLogging.getLogger() try: if client is None: client = getCollectionWebService() if client is None: logger.error( "No web service client available, cannot contact findDataCollection web service." ) elif dataCollectionId is None: logger.error( "No dataCollectionId given, cannot contact findDataCollection web service." ) else: dataCollectionWS3VO = client.service.findDataCollection( dataCollectionId) except Exception as e: logger.error( "ISPyB error for findDataCollection: {0}, {1} trials left".format( e, noTrials)) return dataCollectionWS3VO
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # __authors__ = ['O. Svensson'] __license__ = 'MIT' __date__ = '21/04/2019' from edna2.utils import UtilsLogging from edna2.tasks.AbstractTask import AbstractTask from edna2.tasks.test.ParallelTasks.ExampleTask import ExampleTask logger = UtilsLogging.getLogger() class ControlTestTask(AbstractTask): """ Control task for testing parallel execution """ def run(self, inData): numberOfTasks = inData['numberOfTasks'] startNumber = inData['startNumber'] listTasks = [] for taskNumber in range(startNumber, startNumber + numberOfTasks): testTaskInData = {'taskNumber': taskNumber} testTask = ExampleTask(inData=testTaskInData) logger.info(testTask) listTasks.append(testTask)
if taskName is None: parser.print_help() sys.exit(1) elif inData is None and inDataFile is not None: with open(inDataFile) as fd: inData = fd.read() else: print("Error - no indata provided!") parser.print_help() sys.exit(1) # Set up logging if errorLogLevel: logger = UtilsLogging.getLogger('ERROR') elif warningLogLevel: logger = UtilsLogging.getLogger('WARNING') elif debugLogLevel: logger = UtilsLogging.getLogger('DEBUG') else: logger = UtilsLogging.getLogger('INFO') # Load and run EDNA2 task edna2 = __import__('edna2.tasks.{0}'.format(taskName)) tasks = getattr(edna2, "tasks") tasksModule = getattr(tasks, taskName) TaskClass = getattr(tasksModule, taskName) task = TaskClass(inData=json.loads(inData)) task.execute()