wwpdb.utils.config 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wwpdb/utils/config/ConfigInfo.py +87 -0
- wwpdb/utils/config/ConfigInfoApp.py +739 -0
- wwpdb/utils/config/ConfigInfoData.py +824 -0
- wwpdb/utils/config/ConfigInfoDataSet.py +243 -0
- wwpdb/utils/config/ConfigInfoDataSetExec.py +178 -0
- wwpdb/utils/config/ConfigInfoFile.py +476 -0
- wwpdb/utils/config/ConfigInfoFileExec.py +512 -0
- wwpdb/utils/config/ConfigInfoGroupDataSet.py +84 -0
- wwpdb/utils/config/ConfigInfoShellExec.py +680 -0
- wwpdb/utils/config/ConfigInfoSiteAccess.py +194 -0
- wwpdb/utils/config/ProjectVersionInfo.py +61 -0
- wwpdb/utils/config/__init__.py +5 -0
- wwpdb/utils/config/py.typed +0 -0
- wwpdb_utils_config-1.0.0.dist-info/METADATA +57 -0
- wwpdb_utils_config-1.0.0.dist-info/RECORD +18 -0
- wwpdb_utils_config-1.0.0.dist-info/WHEEL +4 -0
- wwpdb_utils_config-1.0.0.dist-info/entry_points.txt +3 -0
- wwpdb_utils_config-1.0.0.dist-info/licenses/LICENSE +12 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
##
|
|
2
|
+
# File: ConfigInfo.py
|
|
3
|
+
# Date: 28-Mar-2010
|
|
4
|
+
#
|
|
5
|
+
# Updates:
|
|
6
|
+
#
|
|
7
|
+
# 27-Apr-2010 jdw Allow site Id to be set in the constructor.
|
|
8
|
+
# 29-Jun-2011 jdw Print configuration error if site id is neither provided in the constructor
|
|
9
|
+
# or provided in the environment
|
|
10
|
+
# 18-Jun-2012 jdw add function to set site id from the environment
|
|
11
|
+
# 25-Feb-2013 jdw correct typo in diagnostic message
|
|
12
|
+
# 11-Jul-2016 jdw add optional default return value for get()
|
|
13
|
+
#
|
|
14
|
+
##
|
|
15
|
+
"""
|
|
16
|
+
Provides access to shared and site-specific configuration information for the common deposition and annotation
|
|
17
|
+
system.
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
__docformat__ = "restructuredtext en"
|
|
22
|
+
__author__ = "John Westbrook"
|
|
23
|
+
__email__ = "jwest@rcsb.rutgers.edu"
|
|
24
|
+
__license__ = "Creative Commons Attribution 3.0 Unported"
|
|
25
|
+
__version__ = "V0.01"
|
|
26
|
+
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
from typing import Any, Dict, Optional, TextIO
|
|
30
|
+
|
|
31
|
+
from wwpdb.utils.config.ConfigInfoData import ConfigInfoData
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def getSiteId(defaultSiteId: Optional[str] = None) -> str:
|
|
35
|
+
"""Obtain the site information from the environment or failover to the development site id."""
|
|
36
|
+
siteId = str(os.getenv("WWPDB_SITE_ID", defaultSiteId))
|
|
37
|
+
if siteId is None: # str used above - this will never happen
|
|
38
|
+
siteId = "WWPDB_DEPLOY"
|
|
39
|
+
return siteId
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ConfigInfo:
|
|
43
|
+
"""Provides access to site-specific configuration information for the common
|
|
44
|
+
deposition and annotation system.
|
|
45
|
+
|
|
46
|
+
Configuration data is stored in a dictionary of key value pairs.
|
|
47
|
+
|
|
48
|
+
Configuration data is defined in class ConfigInfoData().
|
|
49
|
+
|
|
50
|
+
SiteId provided in the constructor overrides any value in the environment.
|
|
51
|
+
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
__siteId: Optional[str]
|
|
55
|
+
__verbose: bool
|
|
56
|
+
__lfh: TextIO
|
|
57
|
+
__sI: ConfigInfoData
|
|
58
|
+
__D: Dict[str, Any]
|
|
59
|
+
|
|
60
|
+
def __init__(self, siteId: Optional[str] = None, verbose: bool = True, log: TextIO = sys.stderr) -> None:
|
|
61
|
+
self.__siteId = siteId
|
|
62
|
+
self.__verbose = verbose
|
|
63
|
+
self.__lfh = log
|
|
64
|
+
|
|
65
|
+
if self.__siteId is None:
|
|
66
|
+
self.__siteId = str(os.getenv("WWPDB_SITE_ID", None)).upper()
|
|
67
|
+
"""The site identification is obtained from the environmental variable `WWPDB_SITE_ID`
|
|
68
|
+
"""
|
|
69
|
+
if self.__siteId is None: # str() above ensure will be a string...
|
|
70
|
+
self.__lfh.write(
|
|
71
|
+
"++ERROR - ConfigInfo() no site identifier in constructor or WWPDB_SITE_ID in environment.\n"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
self.__sI = ConfigInfoData(siteId=self.__siteId, verbose=self.__verbose)
|
|
75
|
+
self.__D = self.__sI.getConfigDictionary()
|
|
76
|
+
|
|
77
|
+
def get(self, keyWord: str, default: Any = None) -> Any:
|
|
78
|
+
"""Returns the site-specific value assigned to the input keyword or the default value -"""
|
|
79
|
+
if keyWord is not None and keyWord in self.__D:
|
|
80
|
+
return self.__D[keyWord]
|
|
81
|
+
return default
|
|
82
|
+
|
|
83
|
+
def dump(self, ofh: TextIO) -> None:
|
|
84
|
+
"""Print the current configuration dictionary ."""
|
|
85
|
+
ofh.writelines(
|
|
86
|
+
"+ConfigInfo.dump() key: %-40s value: %s\n" % (ky, self.__D[ky]) for ky in sorted(self.__D.keys())
|
|
87
|
+
)
|