Exemple #1
0
def metro_get_execution_sequence():
    """
    Fetch the METRo execution sequence.
    """

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    _("Construct METRo execution sequence:"))
    
    lModule_execution_sequence = metro_config.get_value\
                                 ("INIT_MODULE_EXECUTION_SEQUENCE")

    lObject_sequence = []

    # Creation of an object for each module and add everything
    #  in a list
    for sModule_name in lModule_execution_sequence:
        module = __import__(sModule_name)
        sClass_name = string.capitalize(sModule_name)
        #print sClass_name
        exec "tmp_object =  module." + sClass_name + "()"
        lObject_sequence.append(tmp_object)

    
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                    _("METRo execution sequence ready"))
    return lObject_sequence
Exemple #2
0
def noerr(ctx, str):
    sMessage = _("XML Error!: %s") % str
    if metro_logger.is_initialised():
        metro_logger.print_message(metro_logger.LOGGER_MSG_DEBUG, sMessage)
    else:
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sMessage)
Exemple #3
0
def metro_get_execution_sequence():
    """
    Fetch the METRo execution sequence.
    """

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    _("Construct METRo execution sequence:"))

    lModule_execution_sequence = metro_config.get_value\
                                 ("INIT_MODULE_EXECUTION_SEQUENCE")

    lObject_sequence = []

    # Creation of an object for each module and add everything
    #  in a list
    for sModule_name in lModule_execution_sequence:
        module = __import__(sModule_name)
        sClass_name = string.capitalize(sModule_name)
        #print sClass_name
        exec "tmp_object =  module." + sClass_name + "()"
        lObject_sequence.append(tmp_object)

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                    _("METRo execution sequence ready"))
    return lObject_sequence
Exemple #4
0
def validating_configuration():
    # validation de toute les options
    sMessage = _("Validating configuration")
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE, sMessage)

    metro_config_validation.validate_config(dConfig)

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                    _("METRo configuration validated"))
Exemple #5
0
def write_config_file(sFilename, bFull_config=False):
    plwriter = plist_writer.Plist_writer()
    try:
        plwriter.write(sFilename, dConfig, True, bFull_config)
    except IOError, sError:
        sError =  _("Unable to write to file '%s', the following\n") %(sFilename)+ \
                  _("error occured: %s") % (sError)
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR, sError)
        sys.exit(2)
Exemple #6
0
def validate_string( sXml_content ):
    if metro_xml_lib.get_name() == "Metro_xml_libxml2":
        metro_xml_lib.validate_xml_string(sXml_content)
    else:
        sMessage = _("Validation is only supported with metro_xml_libxml2")
        if metro_logger.is_initialised():
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       sMessage)
        else:
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
Exemple #7
0
def validate_string(sXml_content):
    if metro_xml_lib.get_name() == "Metro_xml_libxml2":
        metro_xml_lib.validate_xml_string(sXml_content)
    else:
        sMessage = _("Validation is only supported with metro_xml_libxml2")
        if metro_logger.is_initialised():
            metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,
                                       sMessage)
        else:
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
Exemple #8
0
def validate_handler(sHandler, iFrom, sDescription):
    #    (sModule_name,sFunction_name) = string.split(sHandler,'.')
    lFunctionPart = string.split(sHandler, '.')
    sFunction_module = string.join(lFunctionPart[:-1], ".")
    sFunction_name = lFunctionPart[-1]
    try:
        metro_util.test_function_existence(sFunction_module, sFunction_name)
    except metro_error.Metro_import_error, inst:
        sMessage = config_error_string(sDescription, iFrom, str(inst))
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sMessage)
        sys.exit(3)
Exemple #9
0
def read_configuration_file(dCmdline_conf):
    if 'FILE_CONFIGMETRO_FILENAME' in dCmdline_conf:
        sConfig_filename = dCmdline_conf['FILE_CONFIGMETRO_FILENAME']
        sMessage = _("Reading and validating configuration file...")
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        sMessage)
        dConfigfile = read_config_file(sConfig_filename)

    else:
        dConfigfile = None

    return dConfigfile
Exemple #10
0
def validate_execution_sequence(dConf):
    sKey = 'INIT_MODULE_EXECUTION_SEQUENCE'
    lExecutionSequence = dConf[sKey]['VALUE']
    iFrom = dConf[sKey]['FROM']
    for sModule in lExecutionSequence:
        try:
            metro_util.test_import(sModule)
        except metro_error.Metro_import_error, inst:
            sConfig_path = "%s module:'%s'" % (sKey, sModule)
            sMessage = config_error_string(sConfig_path, iFrom, str(inst))
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
Exemple #11
0
def init( sMetro_xml_lib = ""):
    global metro_xml_lib
    if sMetro_xml_lib != "":
        try:
            metro_xml_lib = __import__(sMetro_xml_lib)
        except metro_error.Metro_import_error:
            sMessage =  _("Fatal error! Can't import '%s' xml library") \
                       % (sMetro_xml_lib)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
        else:
            metro_logger.print_init_message( \
                    metro_logger.LOGGER_INIT_SUCCESS,
                    _("XML library '%s' will be use.") % (sMetro_xml_lib))
            metro_xml_lib = __import__(sMetro_xml_lib)
        
    else:
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        _("Auto configure METRo XML library"))
        try:
            metro_util.test_import("metro_xml_libxml2")
        except metro_error.Metro_import_error, inst:
            sMessage = _("Fatal error! No METRo XML library can be use. ") +\
                       _("\nMETRo need one of the following XML library ") +\
                       _("installed on the system.\nSupported library:") +\
                       "python-libxml2"
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
        else:
Exemple #12
0
def init(sMetro_xml_lib=""):
    global metro_xml_lib
    if sMetro_xml_lib != "":
        try:
            metro_xml_lib = __import__(sMetro_xml_lib)
        except metro_error.Metro_import_error:
            sMessage =  _("Fatal error! Can't import '%s' xml library") \
                       % (sMetro_xml_lib)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
        else:
            metro_logger.print_init_message( \
                    metro_logger.LOGGER_INIT_SUCCESS,
                    _("XML library '%s' will be use.") % (sMetro_xml_lib))
            metro_xml_lib = __import__(sMetro_xml_lib)

    else:
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        _("Auto configure METRo XML library"))
        try:
            metro_util.test_import("metro_xml_libxml2")
        except metro_error.Metro_import_error, inst:
            sMessage = _("Fatal error! No METRo XML library can be use. ") +\
                       _("\nMETRo need one of the following XML library ") +\
                       _("installed on the system.\nSupported library:") +\
                       "python-libxml2"
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
        else:
Exemple #13
0
def validate_roadcast_start_time(dConf):
    sKey = 'INIT_ROADCAST_START_DATE'
    sStart_time = dConf[sKey]['VALUE']

    if sStart_time != "":
        try:
            metro_date.parse_date_string(sStart_time)
        except metro_error.Metro_date_error, inst:
            sMessage = _("Fatal error, the date string '%s' passed to the\n ")\
                       % (sStart_time)+\
                       _("option '--roadcast-start-date' doesn't conform to ") +\
                       _("ISO 8601")
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
Exemple #14
0
def read_config_file(sFilename):

    try:
        sConfig_file = open(sFilename).read()
    except IOError, sError:
        dConf = {}

        sIOError =  _("Cant open METRo configuration file:'%s' test\n") \
                   % (sFilename) +\
                   _("The following error occured:\n%s") % (sError)

        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sIOError)

        sys.exit(2)
Exemple #15
0
def process_command_line_parameter(dCmdline):

    # si l'usager desire generer un fichier de configuration
    if 'FILE_GENERATE_CONFIGMETRO' in dCmdline:
        sConfig_filename = dCmdline['FILE_GENERATE_CONFIGMETRO']

        sGenerate = _("Generating METRo configuration file...")
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        sGenerate)
        write_config_file(sConfig_filename)
        sSuccess = _("METRo configuration file '%s' created with \n") \
                     % (sConfig_filename) + \
                   _("success. To launch METRo with that configuration\n") + \
                   _("file you need to use the --config option\n")

        metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                        sSuccess)
        sys.exit(0)
Exemple #16
0
def overlay_config(dBase, dNew, iConfig_level):

    for sKey in dNew.keys():
        if sKey in dBase:
            dBase[sKey]['VALUE'] = dNew[sKey]
            dBase[sKey]['FROM'] = iConfig_level
        else:
            sMessage = _(
                "Additionnal configuration value added to METRo config.")
            sComments = "'%s', %s" % (sKey, sMessage)
            dBase[sKey] = {
                'VALUE': dNew[sKey],
                'FROM': iConfig_level,
                'COMMENTS': sMessage
            }

            sWarning = _("%s\nkey='%s'\nvalue='%s'") %\
                       (sMessage, sKey, dNew[sKey])
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                            sWarning)
Exemple #17
0
def generate_dtd_catalog( ):
    sMessage = _("Generating METRo DTD catalog...")
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    sMessage)
    
    sCatalog = genxml_xml_header()
    sCatalog += "\n"

    sCatalog += genxml_public_doctype(
        "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN",
        "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd")
    sCatalog += "\n"

    sCatalog += genxml_tag(
        "catalog",[("xmlns","urn:oasis:names:tc:entity:xmlns:xml:catalog")])
    sCatalog += "\n"

    sMetro_root_path = metro_util.get_metro_root_path()
    sMetro_catalog_path = sMetro_root_path + "/usr/share/metro/data/DTD/"

    sCatalog += genxml_public_catalog_entry(
        "-//Apple Computer//DTD PLIST 1.0//EN",
        sMetro_catalog_path + "plist.dtd")
    
    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD FORECAST 1.0//EN",
        sMetro_catalog_path + "forecast.dtd")

    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD OBSERVATION 1.0//EN",
        sMetro_catalog_path + "observation.dtd")

    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD STATION 1.0//EN",
        sMetro_catalog_path + "station.dtd")

    sCatalog += genxml_close_tag("catalog") + "\n"

    #creation du fichier catalog
    sCatalog_filename = sMetro_catalog_path + "metro_catalog.xml"
    
    try:
        fCatalog = open(sCatalog_filename,'w')
    except IOError:
        fCatalog = None
        sError_message = _("can't create METRo DTD catalog file:'%s'") \
                         % (sCatalog_filename)
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sError_message)
    else:
        #ecrire le header du log
        fCatalog.write(sCatalog)
        fCatalog.close()
        
        sSuccess_message = _("METRo DTD catalog file created with success.\n") +\
                           _("DTD catalog file:'%s'") % (sCatalog_filename)
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                        sSuccess_message)
Exemple #18
0
def validate_xml_itemlist_def(sConfig_path, iFrom, lItems, dData_type):

    # validate child structure
    for dItem in lItems:
        if not 'NAME' in dItem or \
           not 'XML_TAG' in dItem or \
           not 'DATA_TYPE' in dItem:
            sError = _("Some XML definition are not complete.\n") + \
                     _("Each definition must have the following property ") + \
                     _("set:\nNAME, XML_TAG, DATA_TYPE")
            sMessage = config_error_string(sConfig_path, iFrom, sError)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)

    # validate each child
    for dItem in lItems:
        sChild_type = dItem['DATA_TYPE']
        sChild_name = dItem['NAME']

        # si le type du child n'est pas un type valide
        if sChild_type not in dData_type:

            # liste de tout les types valide
            lKeys = dData_type.keys()
            lKeys.sort()
            sType_list = metro_util.list2string(lKeys)

            sError = _("In item %s, '%s' is not a valid METRo data type.") \
                     % (sChild_name, sChild_type)+ \
                     _("\nValid METRo data type are:\n[%s]") \
                     % (sType_list)

            sMessage = config_error_string(sConfig_path, iFrom, sError)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
Exemple #19
0
def generate_dtd_catalog():
    sMessage = _("Generating METRo DTD catalog...")
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE, sMessage)

    sCatalog = genxml_xml_header()
    sCatalog += "\n"

    sCatalog += genxml_public_doctype(
        "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN",
        "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd")
    sCatalog += "\n"

    sCatalog += genxml_tag(
        "catalog", [("xmlns", "urn:oasis:names:tc:entity:xmlns:xml:catalog")])
    sCatalog += "\n"

    sMetro_root_path = metro_util.get_metro_root_path()
    sMetro_catalog_path = sMetro_root_path + "/usr/share/metro/data/DTD/"

    sCatalog += genxml_public_catalog_entry(
        "-//Apple Computer//DTD PLIST 1.0//EN",
        sMetro_catalog_path + "plist.dtd")

    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD FORECAST 1.0//EN", sMetro_catalog_path + "forecast.dtd")

    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD OBSERVATION 1.0//EN",
        sMetro_catalog_path + "observation.dtd")

    sCatalog += genxml_public_catalog_entry(
        "-//METRo//DTD STATION 1.0//EN", sMetro_catalog_path + "station.dtd")

    sCatalog += genxml_close_tag("catalog") + "\n"

    #creation du fichier catalog
    sCatalog_filename = sMetro_catalog_path + "metro_catalog.xml"

    try:
        fCatalog = open(sCatalog_filename, 'w')
    except IOError:
        fCatalog = None
        sError_message = _("can't create METRo DTD catalog file:'%s'") \
                         % (sCatalog_filename)
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sError_message)
    else:
        #ecrire le header du log
        fCatalog.write(sCatalog)
        fCatalog.close()

        sSuccess_message = _("METRo DTD catalog file created with success.\n") +\
                           _("DTD catalog file:'%s'") % (sCatalog_filename)
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                        sSuccess_message)
Exemple #20
0
def metro_init():
    """
    Initialization of configuration.
    """
    metro_config.init()

    # Processing of command line arguments
    dCmdline_conf = metro_config.get_cmdline_conf(sys.argv)
    metro_config.process_command_line_parameter(dCmdline_conf)

    # Start METRo initialization
    sMessage = _("Initialising METRo %s") % (metro_config.CFG_METRO_VERSION)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    sMessage)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_BLANK)

    # XML library initialization
    metro_xml.init()

    # Read the config file
    dFile_conf = metro_config.read_configuration_file(dCmdline_conf)

    # Combine the different configuration levels
    metro_config.overlay_configuration(dFile_conf, dCmdline_conf)

    # Configuration validation
    metro_config.validating_configuration()
    
    # Logger initialisation 
    metro_logger.init()

    # Fetch the module list that constitute de METRo
    #  execution sequence
    lObject_sequence = metro_get_execution_sequence()

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_BLANK)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    _("Initialisation done"))
    return lObject_sequence
Exemple #21
0
def metro_init():
    """
    Initialization of configuration.
    """
    metro_config.init()

    # Processing of command line arguments
    dCmdline_conf = metro_config.get_cmdline_conf(sys.argv)
    metro_config.process_command_line_parameter(dCmdline_conf)

    # Start METRo initialization
    sMessage = _("Initialising METRo %s") % (metro_config.CFG_METRO_VERSION)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE, sMessage)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_BLANK)

    # XML library initialization
    metro_xml.init()

    # Read the config file
    dFile_conf = metro_config.read_configuration_file(dCmdline_conf)

    # Combine the different configuration levels
    metro_config.overlay_configuration(dFile_conf, dCmdline_conf)

    # Configuration validation
    metro_config.validating_configuration()

    # Logger initialisation
    metro_logger.init()

    # Fetch the module list that constitute de METRo
    #  execution sequence
    lObject_sequence = metro_get_execution_sequence()

    metro_logger.print_init_message(metro_logger.LOGGER_INIT_BLANK)
    metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                    _("Initialisation done"))
    return lObject_sequence
Exemple #22
0
        sys.exit(2)
    else:

        plreader = plist_reader.Plist_reader()
        try:
            dConf = plreader.read(sConfig_file)
        except:
            dConf = {}
            sError = _("Error when reading METRo configuration\n") + \
                     _("file:'%s'. Please make sure that the file\nhave ") % (sFilename)+ \
                     _("valid XML synthax and is not corrupted. You can ") + \
                     _("check it with the command 'xmllint %s'. You can\n") % (sFilename)+ \
                     _("also generated a new one with the option: %s.\n") \
                     % ("--generate-config",)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sError)
            sys.exit(2)
        else:
            sSuccess = _("Configuration file:'%s' loaded with success") \
                       % (sFilename)
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_SUCCESS,
                                            sSuccess)

    return dConf


def write_config_file(sFilename, bFull_config=False):
    plwriter = plist_writer.Plist_writer()
    try:
        plwriter.write(sFilename, dConfig, True, bFull_config)
    except IOError, sError:
Exemple #23
0
    sKey = 'INIT_ROADCAST_START_DATE'
    sStart_time = dConf[sKey]['VALUE']

    if sStart_time != "":
        try:
            metro_date.parse_date_string(sStart_time)
        except metro_error.Metro_date_error, inst:
            sMessage = _("Fatal error, the date string '%s' passed to the\n ")\
                       % (sStart_time)+\
                       _("option '--roadcast-start-date' doesn't conform to ") +\
                       _("ISO 8601")
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
    else:
        sMessage = _("No roadcast start date provided. The date of the\n") + \
                   _("last observation will be used as the roadcast ") + \
                   _("start date\n")
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                        sMessage)


def validate_config(dConf):
    """
    Execution of the validation of the configuration files.
    """
    validate_datatype(dConf)
    validate_execution_sequence(dConf)
    validate_xml_file_def(dConf)
    validate_roadcast_start_time(dConf)
Exemple #24
0
    else:
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        _("Auto configure METRo XML library"))
        try:
            metro_util.test_import("metro_xml_libxml2")
        except metro_error.Metro_import_error, inst:
            sMessage = _("Fatal error! No METRo XML library can be use. ") +\
                       _("\nMETRo need one of the following XML library ") +\
                       _("installed on the system.\nSupported library:") +\
                       "python-libxml2"
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
        else:
            metro_logger.print_init_message( \
                    metro_logger.LOGGER_INIT_SUCCESS,
                    _("metro_xml_libxml2 will be used."))
            metro_xml_libxml2 = metro_util.import_name('toolbox',
                                                       "metro_xml_libxml2")
            metro_xml_lib = metro_xml_libxml2.Metro_xml_libxml2()
                
    metro_xml_lib.start()

def stop():
    sMessage = metro_xml_lib.stop()
    if sMessage:
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING,sMessage)

def validate_string( sXml_content ):
    if metro_xml_lib.get_name() == "Metro_xml_libxml2":
        metro_xml_lib.validate_xml_string(sXml_content)
Exemple #25
0
    else:
        metro_logger.print_init_message(metro_logger.LOGGER_INIT_MESSAGE,
                                        _("Auto configure METRo XML library"))
        try:
            metro_util.test_import("metro_xml_libxml2")
        except metro_error.Metro_import_error, inst:
            sMessage = _("Fatal error! No METRo XML library can be use. ") +\
                       _("\nMETRo need one of the following XML library ") +\
                       _("installed on the system.\nSupported library:") +\
                       "python-libxml2"
            metro_logger.print_init_message(metro_logger.LOGGER_INIT_ERROR,
                                            sMessage)
            sys.exit(3)
        else:
            metro_logger.print_init_message( \
                    metro_logger.LOGGER_INIT_SUCCESS,
                    _("metro_xml_libxml2 will be used."))
            metro_xml_libxml2 = metro_util.import_name('toolbox',
                                                       "metro_xml_libxml2")
            metro_xml_lib = metro_xml_libxml2.Metro_xml_libxml2()

    metro_xml_lib.start()


def stop():
    sMessage = metro_xml_lib.stop()
    if sMessage:
        metro_logger.print_message(metro_logger.LOGGER_MSG_WARNING, sMessage)


def validate_string(sXml_content):