def parse(self): """ parse options from command line """ parser = optparse.OptionParser() parser.add_option("-V", "--version", dest="version", action="store_true", help="print version of the program and quit", metavar="FILE", default=False) parser.add_option("-v", "--verbose", action="store_true", dest="debug", default=False, help="switch to debug/verbose mode") parser.add_option("-m", "--mask", dest="mask", help="file containing the mask (for image reconstruction)", default=None) parser.add_option("-M", "--mode", dest="mode", help="Mode can be online/offline/all", default="offline") parser.add_option("-o", "--out", dest="output", help="file for log", default=None) parser.add_option("-w", "--wavelength", dest="wavelength", type="float", help="wavelength of the X-Ray beam in Angstrom", default=None) parser.add_option("-e", "--energy", dest="energy", type="float", help="energy of the X-Ray beam in keV (hc=%skeV.A)" % self.hc, default=None) parser.add_option("-t", "--template", dest="template", type="str", help="template XML file", default=None) parser.add_option("-n", "--nbcpu", dest="nbcpu", type="int", help="template XML file", default=self.nbcpu) (options, args) = parser.parse_args() # Analyse aruments and options if options.version: print("BioSaxs Azimuthal integration version %s" % __version__) sys.exit(0) if options.debug: EDVerbose.setVerboseDebugOn() self.debug = True if options.output: EDVerbose.setLogFileName(options.output) if options.mask and os.path.isfile(options.mask): self.maskfile = options.mask if options.template and os.path.isfile(options.template): self.xml = open(options.template).read() if options.wavelength: self.wavelength = 1e-10 * options.wavelength elif options.energy: self.wavelength = 1e-10 * self.hc / options.energy if options.mode=="offline": self.mode = "offline" self.newerOnly = False elif options.mode=="online": self.mode = "dirwarch" self.newerOnly = True elif options.mode=="dirwatch": self.mode = "dirwarch" self.newerOnly = False self.cpu_sem = Semaphore(options.nbcpu) self.nbcpu = options.nbcpu self.dataFiles = [f for f in args if os.path.isfile(f)] if not self.dataFiles: raise RuntimeError("Please provide datafiles or read the --help")
def __init__(self, _strPluginName, _functXMLin, \ _functXMLout=None, _functXMLerr=None, \ _iNbThreads=None, _fDelay=1.0, _bVerbose=None, _bDebug=None): """ This is the constructor of the edna plugin launcher. @param _strPluginName: the name of the ENDA plugin @type _strPluginName: python string @param _functXMLin: a function taking a path in input and returning the XML string for input in the EDNA plugin. @type _functXMLin: python function @param _functXMLOut: a function to be called each time a plugin gas finished his job sucessfully, it should take two option: strXMLin an strXMLout @type _functXMLOut: python function @param _functXMLErr: a function to be called each time a plugin gas finished his job and crashed, it should take ONE option: strXMLin @type _functXMLErr: python function @param _iNbThreads: The number of parallel threads to be used by EDNA, usually the number of Cores of the computer. If 0 or None, the number of cores will be auto-detected. @type _iNbThreads: python integer @param _fDelay: The delay in seconds between two directories analysis @type _fDelay: python float @param _bVerbose: Do you want the EDNA plugin execution to be verbose ? @type _bVerbose: boolean @param _bDebug: Do you want EDNA plugin execution debug output (OBS! very verbose) ? @type _bDebug: boolean """ self.__iNbThreads = EDUtilsParallel.detectNumberOfCPUs(_iNbThreads) EDUtilsParallel.initializeNbThread(self.__iNbThreads) self.__semaphoreOut = threading.Semaphore() self.__semaphoreErr = threading.Semaphore() self.__strPluginName = _strPluginName self.__functXMLin = _functXMLin self.__functXMLout = _functXMLout self.__functXMLerr = _functXMLerr self.__strCurrWorkDir = os.getcwd() self.__strTempDir = None self.__listInputPaths = [] if _bVerbose is not None: if _bVerbose: EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseOff() if _bDebug is not None: if _bDebug: EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseDebugOff() self.__fDelay = _fDelay #default delay between two directory checks. self.__bQuit = False # To check if we should quit the application self.__bIsFirstExecute = True signal.signal(signal.SIGTERM, self.handleKill) signal.signal(signal.SIGINT, self.handleKill)
def __init__(self, _strPluginName, _functXMLin, \ _functXMLout=None, _functXMLerr=None, \ _iNbThreads=None, _fDelay=1.0, _bVerbose=None, _bDebug=None): """ This is the constructor of the edna plugin launcher. @param _strPluginName: the name of the ENDA plugin @type _strPluginName: python string @param _functXMLin: a function taking a path in input and returning the XML string for input in the EDNA plugin. @type _functXMLin: python function @param _functXMLOut: a function to be called each time a plugin gas finished his job sucessfully, it should take two option: strXMLin an strXMLout @type _functXMLOut: python function @param _functXMLErr: a function to be called each time a plugin gas finished his job and crashed, it should take ONE option: strXMLin @type _functXMLErr: python function @param _iNbThreads: The number of parallel threads to be used by EDNA, usually the number of Cores of the computer. If 0 or None, the number of cores will be auto-detected. @type _iNbThreads: python integer @param _fDelay: The delay in seconds between two directories analysis @type _fDelay: python float @param _bVerbose: Do you want the EDNA plugin execution to be verbose ? @type _bVerbose: boolean @param _bDebug: Do you want EDNA plugin execution debug output (OBS! very verbose) ? @type _bDebug: boolean """ self.__iNbThreads = EDUtilsParallel.detectNumberOfCPUs(_iNbThreads) EDUtilsParallel.initializeNbThread(self.__iNbThreads) self.__semaphoreOut = threading.Semaphore() self.__semaphoreErr = threading.Semaphore() self.__strPluginName = _strPluginName self.__functXMLin = _functXMLin self.__functXMLout = _functXMLout self.__functXMLerr = _functXMLerr self.__strCurrWorkDir = os.getcwd() self.__strTempDir = None self.__listInputPaths = [] if _bVerbose is not None: if _bVerbose: EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseOff() if _bDebug is not None: if _bDebug: EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseDebugOff() self.__fDelay = _fDelay #default delay between two directory checks. self.__bQuit = False # To check if we should quit the application self.__bIsFirstExecute = True signal.signal(signal.SIGTERM, self.handleKill) signal.signal(signal.SIGINT, self.handleKill)
def processCommandLineDebugVerboseLogFile(self): EDVerbose.DEBUG("EDApplication.processCommandLineDebugVerboseLogFile") EDVerbose.setVerboseOff() # Check if no log file if (self.__edCommandLine.existCommand(EDApplication.NO_LOG_LABEL)): EDVerbose.setLogFileOff() EDVerbose.DEBUG("Log file output switched off") # Check if debug mode if (self.__edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_1) or self.__edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_2)): EDVerbose.setVerboseDebugOn() EDVerbose.DEBUG("Debug Mode [ON]") # Check if verbose if (self.__edCommandLine.existCommand(EDApplication.VERBOSE_MODE_LABEL)): EDVerbose.setVerboseOn()
def preProcess(self): """ Scans the command line. """ EDVerbose.DEBUG("EDTestLauncher.preProcess") edCommandLine = EDCommandLine(sys.argv) EDVerbose.log(self.getEdCommandLine().getCommandLine()) self.processCommandLineDebugVerboseLogFile() bContinue = True strTestName = edCommandLine.getArgument(EDTestLauncher.TEST_LABEL) EDVerbose.DEBUG("EDTestLauncher.preProcess: test name = %r" % strTestName) if (strTestName is None): EDVerbose.screen("ERROR - no --test argument found") bContinue = False else: self.__edTestCase = EDUtilsTest.getFactoryPluginTest().loadPlugin(strTestName) if (bContinue): # Determine the base directory if(self.getBaseDir() is None): self.processCommandLineBaseDirectory() # Create the application working directory strApplicationInstanceName = strTestName + "_" + time.strftime("%Y%m%d-%H%M%S", time.localtime()) if(self.getWorkingDir() is None): self.setWorkingDir(strApplicationInstanceName) self.createApplicationWorkingDirectory() # Set the name of the log file EDVerbose.setLogFileName(os.path.join(self.getBaseDir(), strApplicationInstanceName + ".log")) # The check for --quiet and --DEBUG should ideally be placed elsewhere, # for example in EDApplication. if (edCommandLine.existCommand(EDTestLauncher.QUIET_LABEL)): EDVerbose.setVerboseOff() EDVerbose.setTestOff() if (edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_1) or \ edCommandLine.existCommand(EDApplication.DEBUG_PARAM_LABEL_2)): EDVerbose.setVerboseDebugOn() EDVerbose.DEBUG("EDTestLauncher.preProcess: Debug mode")
from EDVerbose import EDVerbose from EDFactoryPluginStatic import EDFactoryPluginStatic EDFactoryPluginStatic.loadModule("EDPluginControlPyarchThumbnailGeneratorv1_0") from XSDataCommon import XSDataFile from XSDataCommon import XSDataString from XSDataCommon import XSDataInteger from XSDataCommon import XSDataTime from EDPluginControlPyarchThumbnailGeneratorv1_0 import EDPluginControlPyarchThumbnailGeneratorv1_0 from XSDataPyarchThumbnailGeneratorv1_0 import XSDataInputPyarchThumbnailGenerator if __name__ == '__main__': EDVerbose.setVerboseDebugOn() # Sleep a random time 0-2s in order to avoid problems if many instances started at the same time fSleepTime = random.random()*2.0 EDVerbose.DEBUG("Sleeping for %.2f s" % fSleepTime) time.sleep(fSleepTime) # Popolate input data EDVerbose.screen("Starting id29_create_thumbnail") # If no arguments stop if len(sys.argv) <= 2: EDVerbose.screen("Usage: id29_create_thumbnail image_directory_path image1 [image2]" ) sys.exit(1) EDVerbose.screen("Arguments: %r" % sys.argv) strPathToTempDir = tempfile.mkdtemp(prefix="id29_create_thumbnail_") os.chdir(strPathToTempDir) EDVerbose.setLogFileName(os.path.join(strPathToTempDir, "id29_create_thumbnail.log")) strImageDirectory = sys.argv[1]
# """EDNA external libraries builder and installer, useful for PIL, numpy, scipy, Fabio, ... """ __contact__ = "*****@*****.**" __author__ = "Jerome Kieffer" __license__ = "GPLv3+" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" import os, shutil, sys, zipfile, tarfile, urllib2, threading from EDVerbose import EDVerbose from EDUtilsPlatform import EDUtilsPlatform from EDUtilsPath import EDUtilsPath for strOneArg in sys.argv: if strOneArg.lower() in ["-d", "--debug"]: EDVerbose.setVerboseDebugOn() class EDUtilsLibraryInstaller: """ This class helps to install to install an external library within EDNA """ iMAX_DOWNLOAD_TIME = 60 #in seconds def __init__(self, _strLibraryDirectory, _strArchiveName=None, _strSourceDir=None): """ Constructor of the class EDUtilsLibraryInstaller,
def __init__(self, cl, name): PyTango.Device_3Impl.__init__(self, cl, name) EDTangoServer.init_device(self) # Initialise the plugin factory self.m_edFactoryPlugin = EDApplication.getFactoryPlugin() EDVerbose.setVerboseDebugOn()
def runEdnaPlugin(execPath, pluginName, isDebug, xml, additionalPaths=None): ''' execPath - path to run plugin in pluginName - plugin name isDebug - True if should run edna in debug mode xml - xml input to edna additionalPaths - list of other python path locations You must set EDNA_HOME to use this method This method blocks until the EDJob has reached a final status ''' if (not 'EDNA_HOME' in os.environ): raise Exception("Cannot locate EDNA_HOME. Please set before running Edna plugins.") if (not 'EDNA_SITE' in os.environ): raise Exception(" Please set EDNA_SITE before running Edna plugins.") ''' Add edna to path ''' ednaKernelPath = os.environ['EDNA_HOME']+"/kernel/src" sys.path.insert(0, ednaKernelPath) ''' If there are any additional paths such as fabio, add these ''' if (not additionalPaths is None and len(additionalPaths)>0): for path in additionalPaths: sys.path.append(path) os.chdir(execPath) from EDVerbose import EDVerbose if (isDebug): EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseOn() EDVerbose.setVerboseDebugOff() from EDJob import EDJob EDVerbose.setLogFileName(execPath+"/"+pluginName+".log") edJob = EDJob(pluginName) edJob.setDataInput(xml) edJob.execute() edJob.synchronize() # In theory should mean that the following loop is not needed # Unhelpful way of waiting for EDJob to be finished # TODO Fix this in EDJob some time while(True): status = edJob.getStatus() if (status is None): time.sleep(0.2) # 200 ms continue if ("failure" == status): raise Exception("EDJob failed! ") if ("success" == status): break ret = edJob.getDataOutput() return str(ret)
def __init__(self, cl, name): PyTango.Device_3Impl.__init__(self, cl, name) EDTangoServer.init_device(self) # Initialise the plugin factory self.m_edFactoryPlugin = EDApplication.getFactoryPlugin() EDVerbose.setVerboseDebugOn()
def runEdnaPlugin(execPath, pluginName, isDebug, xml, additionalPaths=None): ''' execPath - path to run plugin in pluginName - plugin name isDebug - True if should run edna in debug mode xml - xml input to edna additionalPaths - list of other python path locations You must set EDNA_HOME to use this method This method blocks until the EDJob has reached a final status ''' if (not 'EDNA_HOME' in os.environ): raise Exception( "Cannot locate EDNA_HOME. Please set before running Edna plugins.") if (not 'EDNA_SITE' in os.environ): raise Exception(" Please set EDNA_SITE before running Edna plugins.") ''' Add edna to path ''' ednaKernelPath = os.environ['EDNA_HOME'] + "/kernel/src" sys.path.insert(0, ednaKernelPath) ''' If there are any additional paths such as fabio, add these ''' if (not additionalPaths is None and len(additionalPaths) > 0): for path in additionalPaths: sys.path.append(path) os.chdir(execPath) from EDVerbose import EDVerbose if (isDebug): EDVerbose.setVerboseDebugOn() else: EDVerbose.setVerboseOn() EDVerbose.setVerboseDebugOff() from EDJob import EDJob EDVerbose.setLogFileName(execPath + "/" + pluginName + ".log") edJob = EDJob(pluginName) edJob.setDataInput(xml) edJob.execute() edJob.synchronize( ) # In theory should mean that the following loop is not needed # Unhelpful way of waiting for EDJob to be finished # TODO Fix this in EDJob some time while (True): status = edJob.getStatus() if (status is None): time.sleep(0.2) # 200 ms continue if ("failure" == status): raise Exception("EDJob failed! ") if ("success" == status): break ret = edJob.getDataOutput() return str(ret)