From cab654e58b46b7a29f867a5caa076f07130b60cd Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 7 May 2020 19:58:08 -0700 Subject: nice simple hack for config loading --- chocula/config.py | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/chocula/config.py b/chocula/config.py index 1835478..2237404 100644 --- a/chocula/config.py +++ b/chocula/config.py @@ -1,30 +1,21 @@ -class ChoculaConfig: +from types import SimpleNamespace +import toml - ISSNL_FILE = 'data/20200323.ISSN-to-ISSN-L.txt' +class ChoculaConfig(SimpleNamespace): - ENTREZ_FILE = 'data/entrez-journals.csv' - ROAD_FILE = 'data/road-2018-01-24.tsv' - ROAD_DATE = '2018-01-24' - DOAJ_FILE = 'data/journalcsv__doaj_20191221_0135_utf8.csv' - DOAJ_DATE = '2019-12-21' - CROSSREF_FILE = 'data/doi_titles_file_2019-12-20.csv' - SHERPA_ROMEO_JOURNAL_FILE = 'data/romeo-journals.csv' - SHERPA_ROMEO_POLICY_FILE = 'data/romeo-policies.csv' - NORWEGIAN_FILE = 'data/2019-12-21 Norwegian Register for Scientific Journals and Series.csv' - NORWEGIAN_DATE = '2019-12-21' - LOCKSS_FILE = 'data/kbart_LOCKSS.txt' - CLOCKSS_FILE = 'data/kbart_CLOCKSS.txt' - PORTICO_FILE = 'data/Portico_Holding_KBart.txt' - JSTOR_FILE = 'data/JSTOR_Global_AllArchiveTitles_2019-12-21.txt' - SIM_FILE = 'data/MASTER TITLE_METADATA_LIST_20171019.converted.csv' - SZCZEPANSKI_DATE = '2018' - SZCZEPANSKI_FILE = 'data/Jan-Szczepanski-Open-Access-Journals-2018_0.fixed.json' - EZB_FILE = 'data/ezb_metadata.json' - GOLD_OA_FILE = 'data/ISSN_Gold-OA_3.0.csv' - WIKIDATA_SPARQL_FILE = 'data/wikidata_journals_sparql.2019-12-20.tsv' - OPENAPC_FILE = 'data/apc_de.2019-12-20.csv' - FATCAT_CONTAINER_FILE = 'data/container_export.2019-12-13.json' + @classmethod + def from_file(cls, file_path="sources.toml", sources_dir="data/"): - IA_CRAWL_FILE = 'data/url_status.20191223.json' - FATCAT_STATS_FILE = 'data/container_stats.20191213.json' + # TODO: can we just pass _dict=SimpleNamespace here? + sources = toml.load(file_path) + + # convert all sub-tables to SimpleNamespace + for k in list(sources.keys()): + if isinstance(sources[k], dict): + if "filename" in sources[k]: + sources[k]["filepath"] = sources_dir + sources[k]["filename"] + sources[k] = SimpleNamespace(**sources[k]) + + # conver the whole thing to SimpleNamespace + return ChoculaConfig(**sources) -- cgit v1.2.3