kmisc 2.1.100__tar.gz → 2.1.103__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.
- {kmisc-2.1.100 → kmisc-2.1.103}/PKG-INFO +1 -1
- {kmisc-2.1.100 → kmisc-2.1.103}/kmisc/__init__.py +80 -46
- {kmisc-2.1.100 → kmisc-2.1.103}/kmisc.egg-info/PKG-INFO +1 -1
- {kmisc-2.1.100 → kmisc-2.1.103}/LICENSE +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/README.md +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/kmisc.egg-info/SOURCES.txt +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/kmisc.egg-info/dependency_links.txt +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/kmisc.egg-info/top_level.txt +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/pyproject.toml +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/setup.cfg +0 -0
- {kmisc-2.1.100 → kmisc-2.1.103}/setup.py +0 -0
@@ -1859,14 +1859,8 @@ def cut_string(string,max_len=None,sub_len=None,new_line='\n',front_space=False,
|
|
1859
1859
|
def FirstKey(src,default=None):
|
1860
1860
|
return Next(src,default=default)
|
1861
1861
|
|
1862
|
-
def code_error(
|
1863
|
-
|
1864
|
-
if log_msg != default:
|
1865
|
-
if log: log('\n!!ERROR!!: {}'.format(log_msg),log_level=1)
|
1866
|
-
if email_func and email and email_title:
|
1867
|
-
a=email_func(email,email_title,log_msg,dj_ip=email_server)
|
1868
|
-
TIME().Sleep(5)
|
1869
|
-
return default
|
1862
|
+
def code_error(log_msg=None,**opts):
|
1863
|
+
return ExceptMessage(msg=log_msg,default=opts.get('default'))
|
1870
1864
|
|
1871
1865
|
def DirName(src,default=None):
|
1872
1866
|
dirname=Path(src,default=default)
|
@@ -1938,7 +1932,7 @@ def Keys(src,find=None,start=None,end=None,sym='\n',default=[],word=False,patter
|
|
1938
1932
|
return rt
|
1939
1933
|
return default
|
1940
1934
|
|
1941
|
-
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None):
|
1935
|
+
def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_opt=None,find_all=False):
|
1942
1936
|
#<Menu name="Security">
|
1943
1937
|
# <Setting name="Administrator Password" type="Password">
|
1944
1938
|
# <Information>
|
@@ -1948,6 +1942,9 @@ def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_
|
|
1948
1942
|
#</Menu>
|
1949
1943
|
#findXML(cfg_file,find_name='Administrator Password',find_path='./Information/HasPassword',out='data'))
|
1950
1944
|
# => False
|
1945
|
+
# find_name : for finding XML root with maching data of tag name 'name'
|
1946
|
+
# find_path : it searching item keys(ex: Setting/Information/HasPassword) from found XML root
|
1947
|
+
# get_opt : tag name (ex: name, type)
|
1951
1948
|
if os.path.isfile(xmlfile):
|
1952
1949
|
try:
|
1953
1950
|
tree=ET.parse(xmlfile)
|
@@ -1959,53 +1956,90 @@ def findXML(xmlfile,find_name=None,find_path=None,default=None,out='xmlobj',get_
|
|
1959
1956
|
root=ET.fromstring(xmlfile)
|
1960
1957
|
except:
|
1961
1958
|
return default
|
1962
|
-
def
|
1959
|
+
def find_root(tr,find_name):
|
1963
1960
|
for x in tr:
|
1964
1961
|
if x.attrib.get('name') == find_name:
|
1965
1962
|
return x,x.tag
|
1966
|
-
rt,pp=
|
1963
|
+
rt,pp=find_root(x,find_name)
|
1967
1964
|
if rt:
|
1968
1965
|
return rt,'{}/{}'.format(x.tag,pp)
|
1969
1966
|
return None,None
|
1970
|
-
|
1967
|
+
def find_item(tr,find_path):
|
1968
|
+
for x in tr:
|
1969
|
+
if x.tag == find_path[0]:
|
1970
|
+
if find_path[1:]:
|
1971
|
+
a,p=find_item(x,find_path[1:])
|
1972
|
+
if a is not None:
|
1973
|
+
return a,'{}/{}'.format(find_path[0],p)
|
1974
|
+
else:
|
1975
|
+
return x,find_path[0]
|
1976
|
+
return None,None
|
1977
|
+
def find_all_items(tr,find_path):
|
1978
|
+
out=[]
|
1979
|
+
for i in tr:
|
1980
|
+
a=i.findall(find_path)
|
1981
|
+
if a:
|
1982
|
+
out=out+a
|
1983
|
+
o=find_all_items(i,find_path)
|
1984
|
+
if o:
|
1985
|
+
out=out+o
|
1986
|
+
return out
|
1987
|
+
found_root=None,None
|
1988
|
+
#find XML root with name tag information or root's tag name
|
1971
1989
|
if find_name:
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
rt=[]
|
1981
|
-
if out in ['tag','name']:
|
1982
|
-
for ii in found_result:
|
1983
|
-
rt.append(ii.tag)
|
1984
|
-
elif out in ['text','data']:
|
1985
|
-
for ii in found_result:
|
1990
|
+
found_root=find_root(root,find_name)
|
1991
|
+
if found_root[0] is None: found_root=root,None
|
1992
|
+
if find_all:
|
1993
|
+
o=[]
|
1994
|
+
for i in find_all_items(found_root[0],find_path):
|
1995
|
+
if IsIn(out,['tag','name']):
|
1996
|
+
o.append(i.tag)
|
1997
|
+
elif IsIn(out,['text','data','value']):
|
1986
1998
|
if get_opt:
|
1987
|
-
|
1999
|
+
o.append(i.get(get_opt,default))
|
1988
2000
|
else:
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
else:
|
1996
|
-
return found_result
|
2001
|
+
o.append(i.text)
|
2002
|
+
elif IsIn(out,['attrib','att','attr']):
|
2003
|
+
o.append(i.attrib)
|
2004
|
+
else:
|
2005
|
+
o.append(i)
|
2006
|
+
return o
|
1997
2007
|
else:
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2008
|
+
# Searching path from found root or original root
|
2009
|
+
if find_path and isinstance(find_path,str):
|
2010
|
+
if find_path[0] == '/': find_path=find_path[1:]
|
2011
|
+
#ex: root.findall('./Menu/Setting/[@name="Administrator Password"]/Information/HasPassword'):
|
2012
|
+
found_path=find_item(found_root[0],find_path.split('/'))
|
2013
|
+
# <element>.tag: name, .text: data, .attrib: dict
|
2014
|
+
if found_path[0] is not None:
|
2015
|
+
if IsIn(out,['tag','name']):
|
2016
|
+
return found_path[0].tag
|
2017
|
+
elif IsIn(out,['text','data','value']):
|
2018
|
+
if get_opt:
|
2019
|
+
return found_path[0].get(get_opt,default)
|
2020
|
+
return found_path[0].text
|
2021
|
+
elif IsIn(out,['attrib','att','attr']):
|
2022
|
+
return found_path[0].attrib
|
2023
|
+
elif IsIn(out,['path','key','keys']):
|
2024
|
+
print('>>',found_root[1],':',found_path[1])
|
2025
|
+
if found_root[1] is None:
|
2026
|
+
return found_path[1]
|
2027
|
+
return os.path.join(found_root[1],found_path[1])
|
2028
|
+
return found_root[0]
|
2029
|
+
else:
|
2030
|
+
if found_root[0] is not None:
|
2031
|
+
if IsIn(out,['tag','name']):
|
2032
|
+
return found_root[0].tag
|
2033
|
+
elif IsIn(out,['text','data','value']):
|
2034
|
+
if get_opt:
|
2035
|
+
return found_root[0].get(get_opt,default)
|
2036
|
+
else:
|
2037
|
+
return found_root[0].text
|
2038
|
+
elif IsIn(out,['attrib','att','attr']):
|
2039
|
+
return found_root[0].attrib
|
2040
|
+
elif IsIn(out,['path','key','keys']):
|
2041
|
+
return found_root[1]
|
2042
|
+
return found_root[0]
|
2009
2043
|
return default
|
2010
2044
|
|
2011
2045
|
def Compress(data,mode='lz4'):
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|