Beispiel #1
0
def load_submission_file(dataset_, path_, fname_=""):
    if len(fname_) > 0:
        path_ = path_ + "/" + fname_
    data = open_yaml_file(path_)
    dataset_properties = data[0]
    msg.info("HEP_data_utils.helpers.load_submission_file",
             "submission file with the following metadata:",
             _verbose_level=1)
    msg.check_verbosity_and_print(yaml.safe_dump(dataset_properties),
                                  _verbose_level=1)
    dataset_._description = dataset_properties["additional_resources"][0][
        "description"]
    dataset_._location = dataset_properties["additional_resources"][0][
        "location"]
    dataset_._comment = dataset_properties["comment"]
    dataset_._hepdata_doi = dataset_properties["hepdata_doi"]
    for idx in range(1, len(data)):
        datum = data[idx]
        msg.info("HEP_data_utils.helpers.load_submission_file",
                 "submission file entry with the following definitions:",
                 _verbose_level=1)
        msg.check_verbosity_and_print(yaml.safe_dump(datum), _verbose_level=1)
        filename = hlp.get_directory(path_) + "/" + datum["data_file"]
        if not os.path.isfile(filename):
            msg.fatal(
                "HEP_data_utils.helpers.load_submission_file",
                "submission file asks for a yaml file called {0} but none exists"
                .format(filename))
        msg.info("HEP_data_utils.helpers.load_submission_file",
                 "opening yaml file {0}".format(filename),
                 _verbose_level=0)
        load_yaml_file(dataset_, filename, metadata_global_=datum)
Beispiel #2
0
def open_yaml_file(path_):
    yaml_file = open(path_, 'r')
    data = []
    try:
        for datum in yaml.safe_load_all(yaml_file):
            msg.info("HEP_data_utils.helpers.open_yaml_file",
                     "yaml file opened with entries:",
                     _verbose_level=1)
            msg.check_verbosity_and_print(yaml.safe_dump(datum),
                                          _verbose_level=1)
            data.append(datum)
    except yaml.YAMLError as exc:
        print(exc)
        msg.fatal(
            "HEP_data_utils.helpers.open_yaml_file",
            "Exception thrown when opening the yaml file (see previous messages)"
        )
    return data
Beispiel #3
0
 def load_keys(self, filename_):
     config = configparser.ConfigParser()
     config.optionxform = str
     try:
         config.read(filename_)
     except:
         msg.check_verbosity_and_print(str(sys.exc_info()[0]),
                                       _verbose_level=-1)
         msg.error(
             "HEP_data_utils.data_structures.Distribution_store",
             "an exception occured when parsing the config file... Continuing with nothing done"
         )
         return
     if "KEYS" not in config.sections():
         msg.error(
             "HEP_data_utils.data_structures.Distribution_store",
             "no section titled \"KEYS\" in file {0}".format(filename_))
         return
     keys = config["KEYS"]
     for old_key in keys:
         self.rename(old_key, keys[old_key])
     self.print_keys()