iniUts 1.1.9__tar.gz → 1.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iniUts
3
- Version: 1.1.9
3
+ Version: 1.2.0
4
4
  Summary: Ini file manipulator
5
5
  Home-page:
6
6
  Author: Melque Lima
@@ -2,6 +2,23 @@ import configparser as cp
2
2
  from dataclasses import dataclass
3
3
  from datetime import datetime
4
4
  import re
5
+ import os
6
+
7
+ class envar():
8
+ def __init__(self,key:str,default:str=None):
9
+ self.key = key
10
+ self.default = default
11
+
12
+ def get_value(self):
13
+ if self.default != None:
14
+ return os.getenv(self.key,self.default)
15
+ else:
16
+ value = os.getenv(self.key)
17
+ if not value:
18
+ raise Exception(f"envar '{self.key}' not found!")
19
+ return value
20
+
21
+
5
22
 
6
23
 
7
24
  class IniUts():
@@ -112,9 +129,19 @@ class IniUts():
112
129
  v = cls(v)
113
130
  return v
114
131
 
132
+ def setup_initial_values(self,dtClass):
133
+ for k in dtClass.__annotations__:
134
+ if not hasattr(dtClass, k):
135
+ setattr(dtClass, k, None)
136
+ return dtClass
137
+
115
138
  def section2DataClass(self,section,dtClass,skip_missing=False,empty_as_null=False):
116
139
  dt = self.Section2Dict(section,empty_as_null=empty_as_null)
117
140
  dt2 = self.Section2Dict(section,empty_as_null=empty_as_null,fileIni=self.prd_file)
141
+
142
+ dtClass = self.setup_initial_values(dtClass)
143
+
144
+ #VALIDA AS KEYS NO INI DE DEV
118
145
  for k, v in dt.items():
119
146
  if not k in dtClass.__annotations__:
120
147
  if not skip_missing:
@@ -122,20 +149,22 @@ class IniUts():
122
149
  else:
123
150
  continue
124
151
  v = self.format_data(dtClass,k,v)
125
-
126
-
127
-
128
152
  setattr(dtClass, k, v)
129
153
 
154
+ class_keys = [x for x in dtClass.__annotations__ if getattr(dtClass,x) != envar]
130
155
 
131
- MissingKeysFromClass = lambda x:list(set(dtClass.__annotations__.keys()) - set(x.keys()))
156
+ MissingKeysFromClass = lambda x:list(set(class_keys) - set(x.keys()))
132
157
 
133
158
  #VERIFICA SE AS KEYS NAO ENCONTRADAS ESTAO NO ARQUIVO DE PRD:
134
159
  if not self.in_prd:
135
160
  for k in MissingKeysFromClass(dt):
136
161
  if not k in dt2.keys():
162
+ if isinstance(getattr(dtClass,k),envar):
163
+ v = getattr(dtClass,k).get_value()
164
+ setattr(dtClass, k, v)
165
+ continue
137
166
  if not skip_missing:
138
- raise Exception(f"Cound not find '{MissingKeysFromClass(dt)}' keys at section '{section}' in ini file")
167
+ raise Exception(f"Cound not find '{k}' keys at section '{section}' in ini file")
139
168
  continue
140
169
  v = self.format_data(dtClass,k,dt2[k])
141
170
  setattr(dtClass, k, v)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: iniUts
3
- Version: 1.1.9
3
+ Version: 1.2.0
4
4
  Summary: Ini file manipulator
5
5
  Home-page:
6
6
  Author: Melque Lima
@@ -14,12 +14,15 @@ ini = IniUts('prd_config.ini','dev_config.ini',in_prd=False)
14
14
 
15
15
  @ini.link('PERSON')
16
16
  class Person():
17
+ USERNAME: str = envar("USERNAME")
17
18
  NAME : str
18
19
  age : int
19
20
  amount : float
20
21
  friends: tuple = ','
21
22
  dob : datetime = "%Y-%m-%d"
22
23
 
24
+
25
+ pass
23
26
  # pass
24
27
  # a = 1
25
28
 
@@ -10,7 +10,7 @@ classifiers = [
10
10
 
11
11
  setup(
12
12
  name='iniUts',
13
- version='1.1.9',
13
+ version='1.2.0',
14
14
  description='Ini file manipulator',
15
15
  long_description=open('README.md').read() + '\n\n' + open('CHANGELOG.txt').read(),
16
16
  long_description_content_type='text/markdown',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes