29
29
get_logger
30
30
)
31
31
32
- from wechaty .exceptions import WechatyConfigurationError
33
32
34
33
log = get_logger ('Config' )
35
34
36
35
# log.debug('test logging debug')
37
36
# log.info('test logging info')
38
37
39
38
39
+ # TODO(wj-Mcat): there is no reference usage, so need to be removed
40
40
_FILE_PATH = os .path .dirname (os .path .realpath (__file__ ))
41
41
DATA_PATH = os .path .realpath (
42
42
os .path .join (
@@ -90,40 +90,23 @@ def valid_api_host(api_host: str) -> bool:
90
90
91
91
class Config :
92
92
"""
93
- store python-wechaty configuration
93
+ get the configuration from the environment variables
94
94
"""
95
- # pylint: disable=R0913
96
- def __init__ (self ,
97
- api_host : Optional [str ] = None ,
98
- token : Optional [str ] = None ,
99
- protocol : Optional [str ] = None ,
100
- http_port : Optional [int ] = None ,
101
- name : str = 'python-wechaty' ,
102
- debug : bool = True ,
103
- docker : bool = False ):
104
- """
105
- initialize the configuration
106
- """
107
- self .default = DefaultSetting
108
-
109
- self .api_host = api_host if api_host is not None \
110
- else DefaultSetting .default_api_host
111
-
112
- self .http_port = http_port if http_port is not None \
113
- else DefaultSetting .default_port
114
-
115
- self .protocol = protocol if protocol is not None \
116
- else DefaultSetting .default_protocol
95
+ def __init__ (self ) -> None :
96
+ self ._cache_dir : Optional [str ] = None
117
97
118
- if token is None :
119
- raise WechatyConfigurationError ('token can"t be None' )
98
+ @property
99
+ def cache_dir (self ) -> str :
100
+ """get the cache dir in the lazy loading mode
120
101
121
- self .name = name
122
- self .debug = debug
123
- self .docker = docker
124
-
125
- if self .api_host is not None and not valid_api_host (self .api_host ):
126
- raise WechatyConfigurationError (f'api host %s is not valid { self .api_host } ' )
102
+ Returns:
103
+ str: the path of cache dir
104
+ """
105
+ if self ._cache_dir is not None :
106
+ return self ._cache_dir
107
+ self ._cache_dir = os .environ .get ("CACHE_DIR" , '.wechaty' )
108
+ assert self ._cache_dir is not None
109
+ return self ._cache_dir
127
110
128
111
129
112
# export const CHATIE_OFFICIAL_ACCOUNT_ID = 'gh_051c89260e5d'
@@ -141,3 +124,6 @@ def qr_code_for_chatie() -> FileBox:
141
124
chatie_official_account_qr_code : str = \
142
125
'http://weixin.qq.com/r/qymXj7DEO_1ErfTs93y5'
143
126
return FileBox .from_qr_code (chatie_official_account_qr_code )
127
+
128
+
129
+ config = Config ()
0 commit comments