modulitiz-micro 2.26.0__py311-none-any.whl → 2.27.0__py311-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.
- modulitiz_micro/ModuloBase64.py +61 -61
- modulitiz_micro/ModuloColorText.py +35 -35
- modulitiz_micro/ModuloDate.py +295 -295
- modulitiz_micro/ModuloFunzioni.py +58 -58
- modulitiz_micro/ModuloListe.py +150 -150
- modulitiz_micro/ModuloMeteo.py +72 -72
- modulitiz_micro/ModuloNumeri.py +130 -130
- modulitiz_micro/ModuloPyinstaller.py +29 -29
- modulitiz_micro/ModuloSeriale.py +61 -61
- modulitiz_micro/ModuloStatistiche.py +31 -31
- modulitiz_micro/ModuloStringhe.py +180 -180
- modulitiz_micro/ModuloTarghe.py +46 -46
- modulitiz_micro/android/ModuloAndroid.py +18 -18
- modulitiz_micro/android/ModuloAndroidAdb.py +48 -48
- modulitiz_micro/android/ModuloAndroidSim.py +130 -130
- modulitiz_micro/android/beans/SmsBean.py +12 -12
- modulitiz_micro/android/enums/AndroidSmsTypeEnum.py +17 -17
- modulitiz_micro/database/AbstractDatabaseService.py +13 -13
- modulitiz_micro/database/AbstractSql.py +49 -49
- modulitiz_micro/database/ModuloSqlOracle.py +19 -19
- modulitiz_micro/database/ModuloSqlServer.py +50 -50
- modulitiz_micro/database/eccezioni/EccezioneDbNoData.py +6 -6
- modulitiz_micro/database/mysql/AbstractBasicMysql.py +114 -114
- modulitiz_micro/database/mysql/ModuloMysql.py +151 -151
- modulitiz_micro/database/mysql/MysqlCommonConverter.py +47 -47
- modulitiz_micro/database/mysql/eccezioni/EccezioneMysqlOffline.py +6 -6
- modulitiz_micro/database/sqlite/AbstractBasicSQLite.py +114 -114
- modulitiz_micro/database/sqlite/ModuloSQLite.py +82 -82
- modulitiz_micro/eccezioni/EccezioneBase.py +7 -7
- modulitiz_micro/eccezioni/EccezioneCtrlC.py +7 -7
- modulitiz_micro/eccezioni/EccezioneRuntime.py +7 -7
- modulitiz_micro/eccezioni/EccezioneScheduler.py +7 -7
- modulitiz_micro/eccezioni/EccezioneSoNonSupportato.py +7 -7
- modulitiz_micro/eccezioni/http/EccezioneHttp.py +8 -8
- modulitiz_micro/eccezioni/http/EccezioneHttp404.py +7 -7
- modulitiz_micro/eccezioni/http/EccezioneHttpGeneric.py +7 -7
- modulitiz_micro/files/ModuloFiles.py +173 -173
- modulitiz_micro/files/ModuloLogging.py +69 -69
- modulitiz_micro/files/ModuloZip.py +42 -42
- modulitiz_micro/files/cache/CacheBean.py +5 -5
- modulitiz_micro/files/cache/CacheRam.py +29 -29
- modulitiz_micro/files/cache/DatabaseCache.py +91 -91
- modulitiz_micro/files/cache/decorators/cacheRam.py +26 -26
- modulitiz_micro/files/git/ModuloGit.py +15 -15
- modulitiz_micro/gestionedom/GestioneDom.py +44 -44
- modulitiz_micro/init/AbstractBasicInit.py +27 -27
- modulitiz_micro/init/AbstractInit.py +11 -11
- modulitiz_micro/keylogger/EccezioneKeyLogger.py +7 -7
- modulitiz_micro/keylogger/ModuloKeylogger.py +73 -73
- modulitiz_micro/multithreading/ModuloThread.py +26 -26
- modulitiz_micro/multithreading/ModuloThreadLogger.py +8 -8
- modulitiz_micro/multithreading/ModuloThreadWithCallbackError.py +25 -25
- modulitiz_micro/nlp/ModuloNlp.py +36 -36
- modulitiz_micro/nlp/ModuloNlpDateAndTime.py +59 -59
- modulitiz_micro/rete/ModuloNetworking.py +64 -64
- modulitiz_micro/rete/ModuloOpenVpn.py +15 -15
- modulitiz_micro/rete/email/EmailBean.py +5 -0
- modulitiz_micro/rete/{ModuloEmail.py → email/ModuloEmail.py} +90 -69
- modulitiz_micro/rete/http/ModuloHttp.py +114 -114
- modulitiz_micro/rete/http/ModuloHttpConnectionSafe.py +91 -91
- modulitiz_micro/rete/http/ModuloHttpUtils.py +66 -66
- modulitiz_micro/rete/http/beans/HttpResponseBean.py +5 -5
- modulitiz_micro/rete/http/decorators/catchAndRaiseHttpExceptions.py +22 -22
- modulitiz_micro/rete/ntp/AbstractModuloNtp.py +73 -73
- modulitiz_micro/rete/ntp/ModuloNtpIt.py +8 -8
- modulitiz_micro/rete/socketserver/AbstractBasicGetSocketServer.py +35 -35
- modulitiz_micro/rete/socketserver/AbstractSocketServer.py +267 -267
- modulitiz_micro/rete/ssl/ModuloSsl.py +56 -56
- modulitiz_micro/sistema/EnvVarsEnum.py +9 -9
- modulitiz_micro/sistema/ModuloEnvVars.py +34 -34
- modulitiz_micro/sistema/ModuloSystem.py +298 -298
- modulitiz_micro/sistema/ModuloSystemPipe.py +67 -67
- modulitiz_micro/social/telegram/ModuloTelegram.py +52 -52
- modulitiz_micro/social/telegram/ModuloTelegramSimple.py +26 -26
- modulitiz_micro/util/beans/conf/AbstractBasicConfBean.py +11 -11
- modulitiz_micro/util/beans/conf/AbstractConfBean.py +16 -16
- modulitiz_micro/util/beans/fileconf/AbstractBasicFileConfBean.py +11 -11
- modulitiz_micro/util/beans/fileconf/AbstractFileConfBean.py +13 -13
- modulitiz_micro/util/beans/globalvar/AbstractBasicGlobalVarBean.py +15 -15
- modulitiz_micro/util/beans/globalvar/AbstractGlobalVarBean.py +34 -34
- modulitiz_micro/util/decorators/noAwait.py +23 -23
- modulitiz_micro/util/pip/AbstractModuloPip.py +41 -41
- modulitiz_micro/util/pip/ModuloPip.py +49 -49
- modulitiz_micro/util/scheduler/AbstractScheduler.py +32 -32
- modulitiz_micro/util/spooler/AbstractSpooler.py +14 -14
- modulitiz_micro/util/spooler/Spooler.py +18 -18
- modulitiz_micro/util/spooler/beans/QueueBean.py +8 -8
- modulitiz_micro/util/spooler/decorators/spooler.py +49 -49
- modulitiz_micro/util/spooler/eccezioni/EccezioneSpooler.py +7 -7
- modulitiz_micro/util/spooler/eccezioni/EccezioneSpoolerFull.py +7 -7
- modulitiz_micro/util/unittesting/AbstractOverrideTestUtil.py +18 -18
- modulitiz_micro/util/unittesting/AbstractTestUtil.py +11 -11
- modulitiz_micro/util/unittesting/ModuloRunUnitTest.py +25 -25
- modulitiz_micro/util/wheel/ModuloBuildWheel.py +118 -118
- modulitiz_micro/util/wheel/ModuloToml.py +40 -40
- modulitiz_micro/util/wheel/ModuloWheel.py +12 -12
- {modulitiz_micro-2.26.0.dist-info → modulitiz_micro-2.27.0.dist-info}/LICENSE +20 -20
- {modulitiz_micro-2.26.0.dist-info → modulitiz_micro-2.27.0.dist-info}/METADATA +63 -63
- modulitiz_micro-2.27.0.dist-info/RECORD +101 -0
- modulitiz_micro-2.26.0.dist-info/RECORD +0 -100
- {modulitiz_micro-2.26.0.dist-info → modulitiz_micro-2.27.0.dist-info}/WHEEL +0 -0
- {modulitiz_micro-2.26.0.dist-info → modulitiz_micro-2.27.0.dist-info}/top_level.txt +0 -0
@@ -1,173 +1,173 @@
|
|
1
|
-
import glob
|
2
|
-
import os
|
3
|
-
import shutil
|
4
|
-
|
5
|
-
from modulitiz_micro.ModuloDate import ModuloDate
|
6
|
-
from modulitiz_micro.ModuloListe import ModuloListe
|
7
|
-
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
8
|
-
from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
|
9
|
-
|
10
|
-
|
11
|
-
class ModuloFiles(object):
|
12
|
-
@staticmethod
|
13
|
-
def open(*args,**kwargs):
|
14
|
-
return open(newline="\n",*args,**kwargs)
|
15
|
-
|
16
|
-
@classmethod
|
17
|
-
def readFileBinary(cls,filename:str)->str:
|
18
|
-
"""
|
19
|
-
Convert digital data to binary format
|
20
|
-
Puo' essere usato, ad esempio, per inserire un file di tipo BLOB su sqlite
|
21
|
-
"""
|
22
|
-
return cls.readFile(filename,'rb',None)
|
23
|
-
@classmethod
|
24
|
-
def readFileText(cls,filename:str,useUtf8:bool|None)->str:
|
25
|
-
return cls.readFile(filename,'rt',useUtf8)
|
26
|
-
@staticmethod
|
27
|
-
def readFile(filename:str,mode:str,useUtf8:bool|None):
|
28
|
-
codifica=None
|
29
|
-
if useUtf8 is not None:
|
30
|
-
if useUtf8 is True:
|
31
|
-
codifica=ModuloStringhe.CODIFICA_UTF8
|
32
|
-
else:
|
33
|
-
codifica='latin-1'
|
34
|
-
with open(filename,mode,encoding=codifica) as fp:
|
35
|
-
cont=fp.read()
|
36
|
-
return cont
|
37
|
-
|
38
|
-
@staticmethod
|
39
|
-
def getFileSize(nomefile:str)->int:
|
40
|
-
"""
|
41
|
-
Se non trova nessun file ritorna -1
|
42
|
-
"""
|
43
|
-
try:
|
44
|
-
statinfo=os.stat(nomefile)
|
45
|
-
return statinfo.st_size
|
46
|
-
except FileNotFoundError:
|
47
|
-
return -1
|
48
|
-
|
49
|
-
@classmethod
|
50
|
-
def getFolderSize(cls, path:str)->int:
|
51
|
-
if not os.path.exists(path) or os.path.isfile(path):
|
52
|
-
return -1
|
53
|
-
count=0
|
54
|
-
for root,cartelle,filenames in os.walk(path):
|
55
|
-
for filename in filenames:
|
56
|
-
count+=cls.getFileSize(os.path.join(root,filename))
|
57
|
-
return count
|
58
|
-
|
59
|
-
@staticmethod
|
60
|
-
def getTimestampUtcUltimaModifica(nomefile:str)->int:
|
61
|
-
return int(os.path.getmtime(nomefile))
|
62
|
-
|
63
|
-
@staticmethod
|
64
|
-
def normalizzaSlashPath(percorso:str)->str:
|
65
|
-
percorso=os.path.normpath(percorso)
|
66
|
-
return percorso.replace("\\","/")
|
67
|
-
|
68
|
-
@classmethod
|
69
|
-
def pathJoin(cls,path1:str|None,path2:str|None)->str|None:
|
70
|
-
if ModuloStringhe.isEmpty(path1):
|
71
|
-
return path2
|
72
|
-
if ModuloStringhe.isEmpty(path2):
|
73
|
-
return path1
|
74
|
-
# normalizzazione
|
75
|
-
path1=cls.normalizzaSlashPath(path1)
|
76
|
-
path2=cls.normalizzaSlashPath(path2)
|
77
|
-
# concatenazione
|
78
|
-
path=os.path.join(path1,path2)
|
79
|
-
path=cls.normalizzaSlashPath(path)
|
80
|
-
return path
|
81
|
-
|
82
|
-
@classmethod
|
83
|
-
def pathAbsToRel(cls,percorso:str,root:str):
|
84
|
-
percorso=percorso.replace(root,"")
|
85
|
-
percorso=cls.normalizzaSlashPath(percorso)
|
86
|
-
if percorso.startswith("/"):
|
87
|
-
percorso=percorso[1:]
|
88
|
-
return percorso
|
89
|
-
|
90
|
-
@staticmethod
|
91
|
-
def normalizzaPercorsoLocale(percorso:str):
|
92
|
-
percorso=os.path.normpath(os.path.abspath(percorso))
|
93
|
-
return percorso
|
94
|
-
@classmethod
|
95
|
-
def normalizzaPercorsoRemoto(cls,percorso:str):
|
96
|
-
return cls.normalizzaSlashPath(percorso)
|
97
|
-
|
98
|
-
@classmethod
|
99
|
-
def rinominaConTimestamp(cls,nomefile:str):
|
100
|
-
nomefileSenzaEstensione,ext=cls.getNomefileEdEstensione(nomefile)
|
101
|
-
nomefileNew=nomefileSenzaEstensione+"_"+ModuloDate.dateToString(None, ModuloDate.FORMATO_DATA_ORA_NOMEFILE)+ext
|
102
|
-
os.rename(nomefile,nomefileNew)
|
103
|
-
|
104
|
-
@staticmethod
|
105
|
-
def sposta(sourceFilename:str,destFilename:str):
|
106
|
-
shutil.move(sourceFilename,destFilename)
|
107
|
-
|
108
|
-
@staticmethod
|
109
|
-
def copia(sourceFilename:str,destFilename:str):
|
110
|
-
try:
|
111
|
-
shutil.copy2(sourceFilename,destFilename)
|
112
|
-
except Exception:
|
113
|
-
raise EccezioneRuntime("Errore copia file "+sourceFilename+" in "+destFilename)
|
114
|
-
|
115
|
-
@classmethod
|
116
|
-
def eliminaContenutoCartella(cls,percorso:str):
|
117
|
-
"""
|
118
|
-
elimina tutto il contenuto di una cartella ma non la cartella
|
119
|
-
"""
|
120
|
-
for root,cartelle,nomefiles in os.walk(percorso):
|
121
|
-
for nomefile in nomefiles:
|
122
|
-
os.unlink(cls.pathJoin(root, nomefile))
|
123
|
-
for cartella in cartelle:
|
124
|
-
shutil.rmtree(cls.pathJoin(root, cartella))
|
125
|
-
|
126
|
-
@staticmethod
|
127
|
-
def deleteByPattern(pattern:str):
|
128
|
-
filesDaElim=glob.glob(pattern)
|
129
|
-
for fileDaElim in filesDaElim:
|
130
|
-
os.remove(fileDaElim)
|
131
|
-
|
132
|
-
@staticmethod
|
133
|
-
def getNomefileEdEstensione(nomefile:str)->tuple:
|
134
|
-
arr=nomefile.split(".")
|
135
|
-
nomefileSenzaEstensione=".".join(arr[0:-1])
|
136
|
-
ext="."+arr[-1]
|
137
|
-
return nomefileSenzaEstensione,ext
|
138
|
-
|
139
|
-
@classmethod
|
140
|
-
def walk(cls,root:str,excludeFiles:list|tuple,excludeDirs:list|tuple,minByteSize:int|None,maxByteSize:int|None):
|
141
|
-
"""
|
142
|
-
Questa funzione e' uguale a os.walk() ma restituisce anche il path relativo oltre a quello assoluto.
|
143
|
-
"""
|
144
|
-
root=cls.normalizzaPercorsoLocale(root)
|
145
|
-
for result in os.walk(root):
|
146
|
-
yield from cls.__walk(root,excludeFiles,excludeDirs,minByteSize,maxByteSize,result)
|
147
|
-
|
148
|
-
@classmethod
|
149
|
-
def __walk(cls,root: str,excludeFiles: list|tuple,excludeDirs: list|tuple,minByteSize: int|None,maxByteSize: int|None,
|
150
|
-
result:tuple[str, list[str], list[str]]):
|
151
|
-
percorso,cartelle,nomefiles=result
|
152
|
-
percorsoRel=cls.pathAbsToRel(percorso,root)
|
153
|
-
# elaboro i file
|
154
|
-
for index,nomefile in enumerate(nomefiles):
|
155
|
-
nomefileRelPath=cls.pathJoin(percorsoRel,nomefile)
|
156
|
-
# escludo i file che sono nella blacklist
|
157
|
-
if nomefileRelPath in excludeFiles:
|
158
|
-
nomefiles[index]=""
|
159
|
-
continue
|
160
|
-
# controllo dimensione file
|
161
|
-
if maxByteSize is not None or minByteSize is not None:
|
162
|
-
bytesFile=cls.getFileSize(cls.pathJoin(root,nomefileRelPath))
|
163
|
-
if(maxByteSize is not None and bytesFile>maxByteSize) or (minByteSize is not None and bytesFile<minByteSize):
|
164
|
-
nomefiles[index]=""
|
165
|
-
nomefiles=ModuloListe.eliminaElementiVuoti(nomefiles)
|
166
|
-
#elaboro le cartelle
|
167
|
-
for index,cartella in enumerate(cartelle):
|
168
|
-
cartellaRelPath=cls.normalizzaPercorsoRemoto(cls.pathJoin(percorsoRel,cartella))
|
169
|
-
#escludo le cartelle che sono nella blacklist
|
170
|
-
if cartellaRelPath in excludeDirs:
|
171
|
-
cartelle[index]=""
|
172
|
-
cartelle=ModuloListe.eliminaElementiVuoti(cartelle)
|
173
|
-
yield percorsoRel,percorso,cartelle,nomefiles
|
1
|
+
import glob
|
2
|
+
import os
|
3
|
+
import shutil
|
4
|
+
|
5
|
+
from modulitiz_micro.ModuloDate import ModuloDate
|
6
|
+
from modulitiz_micro.ModuloListe import ModuloListe
|
7
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
8
|
+
from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
|
9
|
+
|
10
|
+
|
11
|
+
class ModuloFiles(object):
|
12
|
+
@staticmethod
|
13
|
+
def open(*args,**kwargs):
|
14
|
+
return open(newline="\n",*args,**kwargs)
|
15
|
+
|
16
|
+
@classmethod
|
17
|
+
def readFileBinary(cls,filename:str)->str:
|
18
|
+
"""
|
19
|
+
Convert digital data to binary format
|
20
|
+
Puo' essere usato, ad esempio, per inserire un file di tipo BLOB su sqlite
|
21
|
+
"""
|
22
|
+
return cls.readFile(filename,'rb',None)
|
23
|
+
@classmethod
|
24
|
+
def readFileText(cls,filename:str,useUtf8:bool|None)->str:
|
25
|
+
return cls.readFile(filename,'rt',useUtf8)
|
26
|
+
@staticmethod
|
27
|
+
def readFile(filename:str,mode:str,useUtf8:bool|None):
|
28
|
+
codifica=None
|
29
|
+
if useUtf8 is not None:
|
30
|
+
if useUtf8 is True:
|
31
|
+
codifica=ModuloStringhe.CODIFICA_UTF8
|
32
|
+
else:
|
33
|
+
codifica='latin-1'
|
34
|
+
with open(filename,mode,encoding=codifica) as fp:
|
35
|
+
cont=fp.read()
|
36
|
+
return cont
|
37
|
+
|
38
|
+
@staticmethod
|
39
|
+
def getFileSize(nomefile:str)->int:
|
40
|
+
"""
|
41
|
+
Se non trova nessun file ritorna -1
|
42
|
+
"""
|
43
|
+
try:
|
44
|
+
statinfo=os.stat(nomefile)
|
45
|
+
return statinfo.st_size
|
46
|
+
except FileNotFoundError:
|
47
|
+
return -1
|
48
|
+
|
49
|
+
@classmethod
|
50
|
+
def getFolderSize(cls, path:str)->int:
|
51
|
+
if not os.path.exists(path) or os.path.isfile(path):
|
52
|
+
return -1
|
53
|
+
count=0
|
54
|
+
for root,cartelle,filenames in os.walk(path):
|
55
|
+
for filename in filenames:
|
56
|
+
count+=cls.getFileSize(os.path.join(root,filename))
|
57
|
+
return count
|
58
|
+
|
59
|
+
@staticmethod
|
60
|
+
def getTimestampUtcUltimaModifica(nomefile:str)->int:
|
61
|
+
return int(os.path.getmtime(nomefile))
|
62
|
+
|
63
|
+
@staticmethod
|
64
|
+
def normalizzaSlashPath(percorso:str)->str:
|
65
|
+
percorso=os.path.normpath(percorso)
|
66
|
+
return percorso.replace("\\","/")
|
67
|
+
|
68
|
+
@classmethod
|
69
|
+
def pathJoin(cls,path1:str|None,path2:str|None)->str|None:
|
70
|
+
if ModuloStringhe.isEmpty(path1):
|
71
|
+
return path2
|
72
|
+
if ModuloStringhe.isEmpty(path2):
|
73
|
+
return path1
|
74
|
+
# normalizzazione
|
75
|
+
path1=cls.normalizzaSlashPath(path1)
|
76
|
+
path2=cls.normalizzaSlashPath(path2)
|
77
|
+
# concatenazione
|
78
|
+
path=os.path.join(path1,path2)
|
79
|
+
path=cls.normalizzaSlashPath(path)
|
80
|
+
return path
|
81
|
+
|
82
|
+
@classmethod
|
83
|
+
def pathAbsToRel(cls,percorso:str,root:str):
|
84
|
+
percorso=percorso.replace(root,"")
|
85
|
+
percorso=cls.normalizzaSlashPath(percorso)
|
86
|
+
if percorso.startswith("/"):
|
87
|
+
percorso=percorso[1:]
|
88
|
+
return percorso
|
89
|
+
|
90
|
+
@staticmethod
|
91
|
+
def normalizzaPercorsoLocale(percorso:str):
|
92
|
+
percorso=os.path.normpath(os.path.abspath(percorso))
|
93
|
+
return percorso
|
94
|
+
@classmethod
|
95
|
+
def normalizzaPercorsoRemoto(cls,percorso:str):
|
96
|
+
return cls.normalizzaSlashPath(percorso)
|
97
|
+
|
98
|
+
@classmethod
|
99
|
+
def rinominaConTimestamp(cls,nomefile:str):
|
100
|
+
nomefileSenzaEstensione,ext=cls.getNomefileEdEstensione(nomefile)
|
101
|
+
nomefileNew=nomefileSenzaEstensione+"_"+ModuloDate.dateToString(None, ModuloDate.FORMATO_DATA_ORA_NOMEFILE)+ext
|
102
|
+
os.rename(nomefile,nomefileNew)
|
103
|
+
|
104
|
+
@staticmethod
|
105
|
+
def sposta(sourceFilename:str,destFilename:str):
|
106
|
+
shutil.move(sourceFilename,destFilename)
|
107
|
+
|
108
|
+
@staticmethod
|
109
|
+
def copia(sourceFilename:str,destFilename:str):
|
110
|
+
try:
|
111
|
+
shutil.copy2(sourceFilename,destFilename)
|
112
|
+
except Exception:
|
113
|
+
raise EccezioneRuntime("Errore copia file "+sourceFilename+" in "+destFilename)
|
114
|
+
|
115
|
+
@classmethod
|
116
|
+
def eliminaContenutoCartella(cls,percorso:str):
|
117
|
+
"""
|
118
|
+
elimina tutto il contenuto di una cartella ma non la cartella
|
119
|
+
"""
|
120
|
+
for root,cartelle,nomefiles in os.walk(percorso):
|
121
|
+
for nomefile in nomefiles:
|
122
|
+
os.unlink(cls.pathJoin(root, nomefile))
|
123
|
+
for cartella in cartelle:
|
124
|
+
shutil.rmtree(cls.pathJoin(root, cartella))
|
125
|
+
|
126
|
+
@staticmethod
|
127
|
+
def deleteByPattern(pattern:str):
|
128
|
+
filesDaElim=glob.glob(pattern)
|
129
|
+
for fileDaElim in filesDaElim:
|
130
|
+
os.remove(fileDaElim)
|
131
|
+
|
132
|
+
@staticmethod
|
133
|
+
def getNomefileEdEstensione(nomefile:str)->tuple:
|
134
|
+
arr=nomefile.split(".")
|
135
|
+
nomefileSenzaEstensione=".".join(arr[0:-1])
|
136
|
+
ext="."+arr[-1]
|
137
|
+
return nomefileSenzaEstensione,ext
|
138
|
+
|
139
|
+
@classmethod
|
140
|
+
def walk(cls,root:str,excludeFiles:list|tuple,excludeDirs:list|tuple,minByteSize:int|None,maxByteSize:int|None):
|
141
|
+
"""
|
142
|
+
Questa funzione e' uguale a os.walk() ma restituisce anche il path relativo oltre a quello assoluto.
|
143
|
+
"""
|
144
|
+
root=cls.normalizzaPercorsoLocale(root)
|
145
|
+
for result in os.walk(root):
|
146
|
+
yield from cls.__walk(root,excludeFiles,excludeDirs,minByteSize,maxByteSize,result)
|
147
|
+
|
148
|
+
@classmethod
|
149
|
+
def __walk(cls,root: str,excludeFiles: list|tuple,excludeDirs: list|tuple,minByteSize: int|None,maxByteSize: int|None,
|
150
|
+
result:tuple[str, list[str], list[str]]):
|
151
|
+
percorso,cartelle,nomefiles=result
|
152
|
+
percorsoRel=cls.pathAbsToRel(percorso,root)
|
153
|
+
# elaboro i file
|
154
|
+
for index,nomefile in enumerate(nomefiles):
|
155
|
+
nomefileRelPath=cls.pathJoin(percorsoRel,nomefile)
|
156
|
+
# escludo i file che sono nella blacklist
|
157
|
+
if nomefileRelPath in excludeFiles:
|
158
|
+
nomefiles[index]=""
|
159
|
+
continue
|
160
|
+
# controllo dimensione file
|
161
|
+
if maxByteSize is not None or minByteSize is not None:
|
162
|
+
bytesFile=cls.getFileSize(cls.pathJoin(root,nomefileRelPath))
|
163
|
+
if(maxByteSize is not None and bytesFile>maxByteSize) or (minByteSize is not None and bytesFile<minByteSize):
|
164
|
+
nomefiles[index]=""
|
165
|
+
nomefiles=ModuloListe.eliminaElementiVuoti(nomefiles)
|
166
|
+
#elaboro le cartelle
|
167
|
+
for index,cartella in enumerate(cartelle):
|
168
|
+
cartellaRelPath=cls.normalizzaPercorsoRemoto(cls.pathJoin(percorsoRel,cartella))
|
169
|
+
#escludo le cartelle che sono nella blacklist
|
170
|
+
if cartellaRelPath in excludeDirs:
|
171
|
+
cartelle[index]=""
|
172
|
+
cartelle=ModuloListe.eliminaElementiVuoti(cartelle)
|
173
|
+
yield percorsoRel,percorso,cartelle,nomefiles
|
@@ -1,69 +1,69 @@
|
|
1
|
-
import logging
|
2
|
-
import os
|
3
|
-
import sys
|
4
|
-
|
5
|
-
from modulitiz_micro.ModuloDate import ModuloDate
|
6
|
-
from modulitiz_micro.files.ModuloFiles import ModuloFiles
|
7
|
-
|
8
|
-
|
9
|
-
class ModuloLogging(logging.Logger):
|
10
|
-
CARTELLA_LOG="logs"
|
11
|
-
NOMEFILE_PREFIX="log"
|
12
|
-
NOMEFILE_EXT=".txt"
|
13
|
-
# dimensione massima del file di log in byte
|
14
|
-
MAX_FILE_SIZE=10*1024*1024
|
15
|
-
|
16
|
-
def __init__(self,nomefileFullPath:str|None=None,cartellaBase:str|None=None,isDebug:bool=False):
|
17
|
-
super().__init__("modulitiz")
|
18
|
-
logFormatterConsole = self.__getOutputFormatter(False)
|
19
|
-
logLevel=logging.INFO if not isDebug else logging.DEBUG
|
20
|
-
# imposto livello
|
21
|
-
self.setLevel(logLevel)
|
22
|
-
# creo console logger
|
23
|
-
consoleHandler=logging.StreamHandler(sys.stdout)
|
24
|
-
consoleHandler.setLevel(logLevel)
|
25
|
-
consoleHandler.setFormatter(logFormatterConsole)
|
26
|
-
self.addHandler(consoleHandler)
|
27
|
-
# creo file logger
|
28
|
-
self.__addFileHandler(nomefileFullPath,cartellaBase,isDebug)
|
29
|
-
|
30
|
-
def close(self):
|
31
|
-
self.handlers.clear()
|
32
|
-
|
33
|
-
@staticmethod
|
34
|
-
def exceptionToString(eccezione)->str:
|
35
|
-
formatter=logging.Formatter()
|
36
|
-
lastEccezione=sys.exc_info()
|
37
|
-
try:
|
38
|
-
msg=formatter.formatException(eccezione)
|
39
|
-
except TypeError:
|
40
|
-
msg=formatter.formatException(lastEccezione)
|
41
|
-
return msg
|
42
|
-
|
43
|
-
@staticmethod
|
44
|
-
def __getOutputFormatter(isDebug:bool)->logging.Formatter:
|
45
|
-
formato='%(asctime)s '+('[%(filename)s:%(lineno)s]\t' if isDebug is True else '')+'[%(levelname)s]\t%(message)s'
|
46
|
-
return logging.Formatter(formato)
|
47
|
-
|
48
|
-
def __addFileHandler(self,nomefileFullPath:str|None,cartellaBase:str|None,isDebug:bool):
|
49
|
-
# controllo se loggare anche su file
|
50
|
-
if nomefileFullPath is None and cartellaBase is None:
|
51
|
-
return
|
52
|
-
# controllo che la cartella dei log esista
|
53
|
-
if cartellaBase is None:
|
54
|
-
cartellaBase=self.CARTELLA_LOG
|
55
|
-
else:
|
56
|
-
cartellaBase=ModuloFiles.pathJoin(cartellaBase,self.CARTELLA_LOG)
|
57
|
-
if not os.path.exists(cartellaBase):
|
58
|
-
os.makedirs(cartellaBase,exist_ok=True)
|
59
|
-
|
60
|
-
# creo il nome del file
|
61
|
-
if nomefileFullPath is None:
|
62
|
-
nomefileFullPath=ModuloFiles.pathJoin(cartellaBase,self.NOMEFILE_PREFIX+self.NOMEFILE_EXT)
|
63
|
-
# se il file e' troppo grande ne creo uno nuovo
|
64
|
-
if ModuloFiles.getFileSize(nomefileFullPath)>=self.MAX_FILE_SIZE:
|
65
|
-
os.rename(nomefileFullPath,nomefileFullPath+"_"+ModuloDate.dateToString(None,ModuloDate.FORMATO_DATA_ORA_NOMEFILE))
|
66
|
-
# file handler
|
67
|
-
fileHandler=logging.FileHandler(nomefileFullPath)
|
68
|
-
fileHandler.setFormatter(self.__getOutputFormatter(isDebug))
|
69
|
-
self.addHandler(fileHandler)
|
1
|
+
import logging
|
2
|
+
import os
|
3
|
+
import sys
|
4
|
+
|
5
|
+
from modulitiz_micro.ModuloDate import ModuloDate
|
6
|
+
from modulitiz_micro.files.ModuloFiles import ModuloFiles
|
7
|
+
|
8
|
+
|
9
|
+
class ModuloLogging(logging.Logger):
|
10
|
+
CARTELLA_LOG="logs"
|
11
|
+
NOMEFILE_PREFIX="log"
|
12
|
+
NOMEFILE_EXT=".txt"
|
13
|
+
# dimensione massima del file di log in byte
|
14
|
+
MAX_FILE_SIZE=10*1024*1024
|
15
|
+
|
16
|
+
def __init__(self,nomefileFullPath:str|None=None,cartellaBase:str|None=None,isDebug:bool=False):
|
17
|
+
super().__init__("modulitiz")
|
18
|
+
logFormatterConsole = self.__getOutputFormatter(False)
|
19
|
+
logLevel=logging.INFO if not isDebug else logging.DEBUG
|
20
|
+
# imposto livello
|
21
|
+
self.setLevel(logLevel)
|
22
|
+
# creo console logger
|
23
|
+
consoleHandler=logging.StreamHandler(sys.stdout)
|
24
|
+
consoleHandler.setLevel(logLevel)
|
25
|
+
consoleHandler.setFormatter(logFormatterConsole)
|
26
|
+
self.addHandler(consoleHandler)
|
27
|
+
# creo file logger
|
28
|
+
self.__addFileHandler(nomefileFullPath,cartellaBase,isDebug)
|
29
|
+
|
30
|
+
def close(self):
|
31
|
+
self.handlers.clear()
|
32
|
+
|
33
|
+
@staticmethod
|
34
|
+
def exceptionToString(eccezione)->str:
|
35
|
+
formatter=logging.Formatter()
|
36
|
+
lastEccezione=sys.exc_info()
|
37
|
+
try:
|
38
|
+
msg=formatter.formatException(eccezione)
|
39
|
+
except TypeError:
|
40
|
+
msg=formatter.formatException(lastEccezione)
|
41
|
+
return msg
|
42
|
+
|
43
|
+
@staticmethod
|
44
|
+
def __getOutputFormatter(isDebug:bool)->logging.Formatter:
|
45
|
+
formato='%(asctime)s '+('[%(filename)s:%(lineno)s]\t' if isDebug is True else '')+'[%(levelname)s]\t%(message)s'
|
46
|
+
return logging.Formatter(formato)
|
47
|
+
|
48
|
+
def __addFileHandler(self,nomefileFullPath:str|None,cartellaBase:str|None,isDebug:bool):
|
49
|
+
# controllo se loggare anche su file
|
50
|
+
if nomefileFullPath is None and cartellaBase is None:
|
51
|
+
return
|
52
|
+
# controllo che la cartella dei log esista
|
53
|
+
if cartellaBase is None:
|
54
|
+
cartellaBase=self.CARTELLA_LOG
|
55
|
+
else:
|
56
|
+
cartellaBase=ModuloFiles.pathJoin(cartellaBase,self.CARTELLA_LOG)
|
57
|
+
if not os.path.exists(cartellaBase):
|
58
|
+
os.makedirs(cartellaBase,exist_ok=True)
|
59
|
+
|
60
|
+
# creo il nome del file
|
61
|
+
if nomefileFullPath is None:
|
62
|
+
nomefileFullPath=ModuloFiles.pathJoin(cartellaBase,self.NOMEFILE_PREFIX+self.NOMEFILE_EXT)
|
63
|
+
# se il file e' troppo grande ne creo uno nuovo
|
64
|
+
if ModuloFiles.getFileSize(nomefileFullPath)>=self.MAX_FILE_SIZE:
|
65
|
+
os.rename(nomefileFullPath,nomefileFullPath+"_"+ModuloDate.dateToString(None,ModuloDate.FORMATO_DATA_ORA_NOMEFILE))
|
66
|
+
# file handler
|
67
|
+
fileHandler=logging.FileHandler(nomefileFullPath)
|
68
|
+
fileHandler.setFormatter(self.__getOutputFormatter(isDebug))
|
69
|
+
self.addHandler(fileHandler)
|
@@ -1,42 +1,42 @@
|
|
1
|
-
import os
|
2
|
-
import zipfile
|
3
|
-
|
4
|
-
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
5
|
-
from modulitiz_micro.files.ModuloFiles import ModuloFiles
|
6
|
-
|
7
|
-
|
8
|
-
class ModuloZip(object):
|
9
|
-
|
10
|
-
@classmethod
|
11
|
-
def zip(cls,dirIn: str,fileOut: str,includeRootDir: bool):
|
12
|
-
fh=zipfile.ZipFile(fileOut,'w',zipfile.ZIP_DEFLATED)
|
13
|
-
if not os.path.isfile(dirIn):
|
14
|
-
cls.__fromFolder(fh,dirIn,includeRootDir)
|
15
|
-
else:
|
16
|
-
fh.write(dirIn)
|
17
|
-
fh.close()
|
18
|
-
|
19
|
-
@staticmethod
|
20
|
-
def unzip(fileIn: str,dirOut: str|None = None):
|
21
|
-
if dirOut is None:
|
22
|
-
dirOut="./"
|
23
|
-
elif dirOut=="":
|
24
|
-
dirOut=fileIn.split("/")[-1].split(".")[0]
|
25
|
-
zipRef=zipfile.ZipFile(fileIn,'r')
|
26
|
-
zipRef.extractall(dirOut)
|
27
|
-
zipRef.close()
|
28
|
-
|
29
|
-
@staticmethod
|
30
|
-
def __fromFolder(fh,dirIn: str,includeRootDir: bool):
|
31
|
-
pathOutRootRel=os.path.basename(dirIn) if includeRootDir else ""
|
32
|
-
for pathRel,pathAbs,cartelle,nomefiles in ModuloFiles.walk(dirIn,(),(),None,None):
|
33
|
-
# controllo se devo scrivere anche la cartella principale
|
34
|
-
if not ModuloStringhe.isEmpty(pathOutRootRel):
|
35
|
-
pathOutRel=ModuloFiles.pathJoin(pathOutRootRel,pathRel)
|
36
|
-
fh.write(pathAbs,pathOutRel)
|
37
|
-
else:
|
38
|
-
pathOutRel=pathRel
|
39
|
-
for nomefile in nomefiles:
|
40
|
-
percorsoFile=ModuloFiles.pathJoin(pathAbs,nomefile)
|
41
|
-
percorsoFileRel=ModuloFiles.pathJoin(pathOutRel,nomefile)
|
42
|
-
fh.write(percorsoFile,percorsoFileRel)
|
1
|
+
import os
|
2
|
+
import zipfile
|
3
|
+
|
4
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
5
|
+
from modulitiz_micro.files.ModuloFiles import ModuloFiles
|
6
|
+
|
7
|
+
|
8
|
+
class ModuloZip(object):
|
9
|
+
|
10
|
+
@classmethod
|
11
|
+
def zip(cls,dirIn: str,fileOut: str,includeRootDir: bool):
|
12
|
+
fh=zipfile.ZipFile(fileOut,'w',zipfile.ZIP_DEFLATED)
|
13
|
+
if not os.path.isfile(dirIn):
|
14
|
+
cls.__fromFolder(fh,dirIn,includeRootDir)
|
15
|
+
else:
|
16
|
+
fh.write(dirIn)
|
17
|
+
fh.close()
|
18
|
+
|
19
|
+
@staticmethod
|
20
|
+
def unzip(fileIn: str,dirOut: str|None = None):
|
21
|
+
if dirOut is None:
|
22
|
+
dirOut="./"
|
23
|
+
elif dirOut=="":
|
24
|
+
dirOut=fileIn.split("/")[-1].split(".")[0]
|
25
|
+
zipRef=zipfile.ZipFile(fileIn,'r')
|
26
|
+
zipRef.extractall(dirOut)
|
27
|
+
zipRef.close()
|
28
|
+
|
29
|
+
@staticmethod
|
30
|
+
def __fromFolder(fh,dirIn: str,includeRootDir: bool):
|
31
|
+
pathOutRootRel=os.path.basename(dirIn) if includeRootDir else ""
|
32
|
+
for pathRel,pathAbs,cartelle,nomefiles in ModuloFiles.walk(dirIn,(),(),None,None):
|
33
|
+
# controllo se devo scrivere anche la cartella principale
|
34
|
+
if not ModuloStringhe.isEmpty(pathOutRootRel):
|
35
|
+
pathOutRel=ModuloFiles.pathJoin(pathOutRootRel,pathRel)
|
36
|
+
fh.write(pathAbs,pathOutRel)
|
37
|
+
else:
|
38
|
+
pathOutRel=pathRel
|
39
|
+
for nomefile in nomefiles:
|
40
|
+
percorsoFile=ModuloFiles.pathJoin(pathAbs,nomefile)
|
41
|
+
percorsoFileRel=ModuloFiles.pathJoin(pathOutRel,nomefile)
|
42
|
+
fh.write(percorsoFile,percorsoFileRel)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class CacheBean(object):
|
2
|
-
def __init__(self,valore,dataLastUpdate):
|
3
|
-
self.valore=valore
|
4
|
-
self.dataLastUpdate=dataLastUpdate
|
5
|
-
|
1
|
+
class CacheBean(object):
|
2
|
+
def __init__(self,valore,dataLastUpdate):
|
3
|
+
self.valore=valore
|
4
|
+
self.dataLastUpdate=dataLastUpdate
|
5
|
+
|
@@ -1,29 +1,29 @@
|
|
1
|
-
from modulitiz_micro.ModuloDate import ModuloDate
|
2
|
-
from modulitiz_micro.ModuloListe import ModuloListe
|
3
|
-
from modulitiz_micro.files.cache.CacheBean import CacheBean
|
4
|
-
|
5
|
-
|
6
|
-
class CacheRam(object):
|
7
|
-
def __init__(self):
|
8
|
-
self.__mappa={}
|
9
|
-
|
10
|
-
def get(self,tipo: str,chiave: str,minsBeforeExpiry: int|None) -> CacheBean|None:
|
11
|
-
# controllo se esiste in ram
|
12
|
-
bean: CacheBean=ModuloListe.collectionSafeGet(self.__mappa,tipo,chiave)
|
13
|
-
if bean is None:
|
14
|
-
return None
|
15
|
-
# controllo se non e' scaduto
|
16
|
-
if minsBeforeExpiry is not None and ModuloDate.now()>ModuloDate.plusMinusMinutes(bean.dataLastUpdate,minsBeforeExpiry):
|
17
|
-
del self.__mappa[tipo][chiave]
|
18
|
-
return None
|
19
|
-
return bean
|
20
|
-
|
21
|
-
def insertOrUpdate(self,tipo: str,chiave: str,valore):
|
22
|
-
if tipo not in self.__mappa:
|
23
|
-
self.__mappa[tipo]={}
|
24
|
-
if chiave not in self.__mappa[tipo]:
|
25
|
-
self.__mappa[tipo][chiave]={}
|
26
|
-
self.__mappa[tipo][chiave]=CacheBean(valore,ModuloDate.now())
|
27
|
-
|
28
|
-
def clear(self):
|
29
|
-
self.__mappa.clear()
|
1
|
+
from modulitiz_micro.ModuloDate import ModuloDate
|
2
|
+
from modulitiz_micro.ModuloListe import ModuloListe
|
3
|
+
from modulitiz_micro.files.cache.CacheBean import CacheBean
|
4
|
+
|
5
|
+
|
6
|
+
class CacheRam(object):
|
7
|
+
def __init__(self):
|
8
|
+
self.__mappa={}
|
9
|
+
|
10
|
+
def get(self,tipo: str,chiave: str,minsBeforeExpiry: int|None) -> CacheBean|None:
|
11
|
+
# controllo se esiste in ram
|
12
|
+
bean: CacheBean=ModuloListe.collectionSafeGet(self.__mappa,tipo,chiave)
|
13
|
+
if bean is None:
|
14
|
+
return None
|
15
|
+
# controllo se non e' scaduto
|
16
|
+
if minsBeforeExpiry is not None and ModuloDate.now()>ModuloDate.plusMinusMinutes(bean.dataLastUpdate,minsBeforeExpiry):
|
17
|
+
del self.__mappa[tipo][chiave]
|
18
|
+
return None
|
19
|
+
return bean
|
20
|
+
|
21
|
+
def insertOrUpdate(self,tipo: str,chiave: str,valore):
|
22
|
+
if tipo not in self.__mappa:
|
23
|
+
self.__mappa[tipo]={}
|
24
|
+
if chiave not in self.__mappa[tipo]:
|
25
|
+
self.__mappa[tipo][chiave]={}
|
26
|
+
self.__mappa[tipo][chiave]=CacheBean(valore,ModuloDate.now())
|
27
|
+
|
28
|
+
def clear(self):
|
29
|
+
self.__mappa.clear()
|