예제 #1
0
def process_info_schema(dtp_config, pygm_yaml):
    output = []

    for index_label, station_profile in enumerate(pygm_yaml['erddap']):
        dtp_logger.info('Processing YAML for %s' % (station_profile))

        file_name = '%s/%s.xml' % (dtp_config['output']['target_dir'],
                                   station_profile)

        try:
            iso_xml = render_template(
                pygm_yaml['erddap'][station_profile],
                schema_local=dtp_config['output']['target_schema'])
            output.append(iso_xml)
            with open(file_name, 'w') as file_writer:
                file_writer.write(iso_xml)

        except Exception as ex:
            dtp_logger.exception(
                'PyGeoMeta render_template() failed for station: %s' %
                (station_profile),
                exc_info=ex)
            dtp_logger.debug('Dumping Station YAML: %s' %
                             (yaml.dump(pygm_yaml['erddap'][station_profile])))

    return output
예제 #2
0
    def test_pretty_print(self):
        """Test pretty-printing"""

        xml = render_template(get_abspath('../sample.yml'), 'iso19139')
        xml2 = pretty_print(xml)

        self.assertIsInstance(xml2, text_type, 'Expected unicode string')
        self.assertEqual(xml2[-1], '>', 'Expected closing bracket')
        self.assertTrue(xml2.startswith('<?xml'), 'Expected XML declaration')
예제 #3
0
    def test_pretty_print(self):
        """Test pretty-printing"""

        xml = render_template(get_abspath('../sample.yml'), 'iso19139')
        xml2 = pretty_print(xml)

        self.assertIsInstance(xml2, text_type, 'Expected unicode string')
        self.assertEqual(xml2[-1], '>', 'Expected closing bracket')
        self.assertTrue(xml2.startswith('<?xml'), 'Expected XML declaration')
예제 #4
0
    def test_render_template(self):
        """test template rendering"""

        test_mcf_paths = [
            '../sample.yml',
            'unilingual.yml',
            'nil-identification-language.yml'
        ]

        for mcf_path in test_mcf_paths:
            xml = render_template(get_abspath(mcf_path), 'iso19139')
            self.assertIsInstance(xml, text_type, 'Expected unicode string')

            # no schema provided
            with self.assertRaises(RuntimeError):
                render_template(get_abspath(mcf_path))

            # bad schema provided
            with self.assertRaises(RuntimeError):
                xml = render_template(get_abspath(mcf_path), 'bad_schema')

            # bad schema_local provided
            with self.assertRaises(RuntimeError):
                xml = render_template(get_abspath(mcf_path),
                                      schema_local='/bad_schema/path')

            # good schema_local provided
            xml = render_template(get_abspath(mcf_path),
                                  schema_local=get_abspath('sample_schema'))
예제 #5
0
    def test_render_template(self):
        """test template rendering"""

        test_mcf_paths = [
            '../sample.yml', 'unilingual.yml',
            'nil-identification-language.yml'
        ]

        for mcf_path in test_mcf_paths:
            xml = render_template(get_abspath(mcf_path), 'iso19139')
            self.assertIsInstance(xml, text_type, 'Expected unicode string')

            # no schema provided
            with self.assertRaises(RuntimeError):
                render_template(get_abspath(mcf_path))

            # bad schema provided
            with self.assertRaises(RuntimeError):
                xml = render_template(get_abspath(mcf_path), 'bad_schema')

            # bad schema_local provided
            with self.assertRaises(RuntimeError):
                xml = render_template(get_abspath(mcf_path),
                                      schema_local='/bad_schema/path')

            # good schema_local provided
            xml = render_template(get_abspath(mcf_path),
                                  schema_local=get_abspath('sample_schema'))
예제 #6
0
def main():

    template_dataset_srb_cyr = 'pygeometa/templates/dts_template_srb_cyr/'
    template_dataset_srb_lat = 'pygeometa/templates/dts_template_srb_lat/'
    template_dataset_eng = 'pygeometa/templates/dts_template_eng/'
    xml_input_dir = 'xml_input_dir/'
    xml_output_dir = 'xml_output_dir/'
    ymls_dts_dir = 'ymls_dts_dir/'
    faill_dts_dir = 'faill_dts_dir/'
    #print(glob.glob(xml_input_dir + "*.xml"))
    xmlfiles = glob.glob(xml_input_dir + "*.xml")
    data = []
    for fxml in xmlfiles:
        fxml_path = xml_input_dir + fxml
        #print(fxml_path)
        makeyml(fxml, ymls_dts_dir)
    ymlfiles = glob.glob(ymls_dts_dir + "*.yml")
    for fyml in ymlfiles:
        mcf_string = fyml
        fyml_path = xml_output_dir + fyml
        base = os.path.basename(fyml_path)
        base = os.path.splitext(base)[0]
        xml_file_name = base + '.xml'
        xml_file_path = xml_output_dir + xml_file_name
        print(fyml)
        try:
            xml_string = render_template(mcf_string,
                                         schema_local=template_dataset_eng)
            with open(xml_file_path, 'w') as ff:
                ff.write(xml_string)
                print('Uspeh!')
        except ValueError:
            print("Oops! " + base + ' That was no valid file.  Try again...')
            continue

    #with open(r'DOF10_metapodaci za Geoportal.xml') as metadata:
    #with open(r'md_CORINE_SRP_lat.xml') as metadata:
    #with open(r'md_Census_2002_SRP_lat.xml') as metadata:
    #with open(r'md_DOFtrue_BeogradNaVodi_ENG.xml') as metadata:
    #with open(r'md_Vlasina_climbing-touristic_ENG.xml') as metadata:
    #with open(r'md_Suva planina_climbing-touristic_ENG.xml') as metadata:
    #with open(r'md_Flood_water_area_TerraSAR-X_2011_2014_SRP_cyr.xml') as metadata
    #with open(r'md_SPOT5 Mosaic_2005-2007_SRP_cyr.xml') as metadata:
    #with open(r'md_ODK_ENG.xml') as metadata:
    #with open(r'md_Stari Begej-Carska bara_special nature reserve_ENG.xml') as metadata:
    #with open(r'md_Address_SRP_cyr.xml') as metadata:
    #with open(r'md_SREF_SRP_lat.xml') as metadata:
    '''mcf_string = 'data.yml'
예제 #7
0
def main():

    template_dataset_srb_cyr = 'pygeometa/templates/dts_template_srb_cyr/'
    template_dataset_srb_lat = 'pygeometa/templates/dts_template_srb_lat/'
    template_dataset_eng = 'pygeometa/templates/dts_template_eng/'
    xml_input_dir = 'xml_input_dir/'
    xml_output_dir = 'xml_output_dir/'
    ymls_dts_dir = 'ymls_dts_dir/'
    fail_dts_dir = 'fail_dts_dir/'
    #print(glob.glob(xml_input_dir + "*.xml"))
    xmlfiles = glob.glob(xml_input_dir + "*.xml")
    data = []
    for fxml in xmlfiles:
        makeyml(fxml, ymls_dts_dir)
    ymlfiles = glob.glob(ymls_dts_dir + "*.yml")
    for fyml in ymlfiles:
        mcf_string = fyml
        base = os.path.basename(fyml)
        base = os.path.splitext(base)[0]
        xml_file_name = base + '.xml'
        xml_file_path = xml_output_dir + xml_file_name
        print(fyml)
        try:
            xml_string = render_template(mcf_string,
                                         schema_local=template_dataset_srb_lat)
            with open(xml_file_path, 'w') as ff:
                ff.write(xml_string)
                print('Uspeh!')
        except:
            os.rename(fyml, fail_dts_dir + base + '.yml')
            os.rename(xml_input_dir + base + '.xml',
                      fail_dts_dir + xml_file_name)
            print("Oops! " + base + ' That was no valid file.  Try again...')
            continue

    print("--- %s seconds ---" % (time.time() - start_time))
예제 #8
0
    def test_broken_yaml(self):
        """test against broken YAML"""

        with self.assertRaises(MCFReadError):
            render_template(get_abspath('broken-yaml.yml'), 'iso19139')
예제 #9
0
    def test_pre1900_dates(self):
        """test datestrings that are pre-1900"""

        xml = render_template(get_abspath('dates-pre-1900.yml'), 'iso19139')
        self.assertIsInstance(xml, text_type, 'Expected unicode string')
예제 #10
0
    def test_broken_yaml(self):
        """test against broken YAML"""

        with self.assertRaises(MCFReadError):
            render_template(get_abspath('broken-yaml.yml'), 'iso19139')
예제 #11
0
    def test_pre1900_dates(self):
        """test datestrings that are pre-1900"""

        xml = render_template(get_abspath('dates-pre-1900.yml'), 'iso19139')
        self.assertIsInstance(xml, text_type, 'Expected unicode string')
예제 #12
0
def yamlToXml(yaml, schemapath, output):
    xml_string = render_template(yaml, schema_local=schemapath)
    with open(output, 'xb') as ff:
        ff.write(xml_string.encode('utf-8'))