modulitiz-mini 2.6.0__py311-none-any.whl → 2.7.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_mini/ModuloRsa.py +84 -84
- modulitiz_mini/django/ModuloDjango.py +20 -20
- modulitiz_mini/django/MyMiddleware.py +10 -10
- modulitiz_mini/django/settings.py +132 -132
- modulitiz_mini/files/pdf/AbstractPdf.py +9 -9
- modulitiz_mini/files/pdf/ReadPdf.py +27 -27
- modulitiz_mini/files/pdf/WritePdf.py +14 -14
- modulitiz_mini/rete/ModuloTor.py +46 -46
- modulitiz_mini/rete/ftp/FtpReturnBean.py +9 -9
- modulitiz_mini/rete/ftp/ModuloFtp.py +212 -212
- {modulitiz_mini-2.6.0.dist-info → modulitiz_mini-2.7.0.dist-info}/METADATA +50 -50
- modulitiz_mini-2.7.0.dist-info/RECORD +15 -0
- {modulitiz_mini-2.6.0.dist-info → modulitiz_mini-2.7.0.dist-info}/WHEEL +1 -1
- {modulitiz_mini-2.6.0.dist-info → modulitiz_mini-2.7.0.dist-info/licenses}/LICENSE +20 -20
- modulitiz_mini-2.6.0.dist-info/RECORD +0 -15
- {modulitiz_mini-2.6.0.dist-info → modulitiz_mini-2.7.0.dist-info}/top_level.txt +0 -0
modulitiz_mini/rete/ModuloTor.py
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
import time
|
2
|
-
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
|
7
|
-
from
|
8
|
-
|
9
|
-
|
10
|
-
class ModuloTor(object):
|
11
|
-
COMMAND="tor"
|
12
|
-
HTTP_PORT=9050
|
13
|
-
MAX_RETRIES_CHECK_PORT_OPEN=100
|
14
|
-
|
15
|
-
def __init__(self,dirTor:str):
|
16
|
-
self.dirTor=dirTor
|
17
|
-
self.pid=0
|
18
|
-
|
19
|
-
def start(self)->int:
|
20
|
-
cmd=ModuloFiles.pathJoin(self.dirTor, self.COMMAND)
|
21
|
-
# avvio e aspetto che il servizio si avvii
|
22
|
-
for riga in ModuloSystem.systemCallYieldOutput(cmd, None):
|
23
|
-
if ModuloStringhe.contains(riga,"100%"):
|
24
|
-
break
|
25
|
-
# controllo che la porta sia stata aperta
|
26
|
-
maxRetries=self.MAX_RETRIES_CHECK_PORT_OPEN
|
27
|
-
while maxRetries>0:
|
28
|
-
if ModuloNetworking.isHttpPortOpen(None, self.HTTP_PORT):
|
29
|
-
maxRetries=-1
|
30
|
-
else:
|
31
|
-
maxRetries-=1
|
32
|
-
time.sleep(0.1)
|
33
|
-
if maxRetries==0:
|
34
|
-
raise EccezioneRuntime("Tor non ha la porta aperta.")
|
35
|
-
# ricavo il pid
|
36
|
-
pid=ModuloSystem.findPidByName(self.COMMAND)
|
37
|
-
return pid
|
38
|
-
|
39
|
-
def stop(self):
|
40
|
-
if self.pid==0:
|
41
|
-
return
|
42
|
-
ModuloSystem.sendCtrlcProcess(self.pid)
|
43
|
-
|
44
|
-
def restart(self):
|
45
|
-
self.stop()
|
46
|
-
self.start()
|
1
|
+
import time
|
2
|
+
|
3
|
+
from modulitiz_nano.ModuloStringhe import ModuloStringhe
|
4
|
+
from modulitiz_nano.eccezioni.EccezioneRuntime import EccezioneRuntime
|
5
|
+
from modulitiz_nano.files.ModuloFiles import ModuloFiles
|
6
|
+
from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
|
7
|
+
from modulitiz_nano.sistema.ModuloSystem import ModuloSystem
|
8
|
+
|
9
|
+
|
10
|
+
class ModuloTor(object):
|
11
|
+
COMMAND="tor"
|
12
|
+
HTTP_PORT=9050
|
13
|
+
MAX_RETRIES_CHECK_PORT_OPEN=100
|
14
|
+
|
15
|
+
def __init__(self,dirTor:str):
|
16
|
+
self.dirTor=dirTor
|
17
|
+
self.pid=0
|
18
|
+
|
19
|
+
def start(self)->int:
|
20
|
+
cmd=ModuloFiles.pathJoin(self.dirTor, self.COMMAND)
|
21
|
+
# avvio e aspetto che il servizio si avvii
|
22
|
+
for riga in ModuloSystem.systemCallYieldOutput(cmd, None):
|
23
|
+
if ModuloStringhe.contains(riga,"100%"):
|
24
|
+
break
|
25
|
+
# controllo che la porta sia stata aperta
|
26
|
+
maxRetries=self.MAX_RETRIES_CHECK_PORT_OPEN
|
27
|
+
while maxRetries>0:
|
28
|
+
if ModuloNetworking.isHttpPortOpen(None, self.HTTP_PORT):
|
29
|
+
maxRetries=-1
|
30
|
+
else:
|
31
|
+
maxRetries-=1
|
32
|
+
time.sleep(0.1)
|
33
|
+
if maxRetries==0:
|
34
|
+
raise EccezioneRuntime("Tor non ha la porta aperta.")
|
35
|
+
# ricavo il pid
|
36
|
+
pid=ModuloSystem.findPidByName(self.COMMAND)
|
37
|
+
return pid
|
38
|
+
|
39
|
+
def stop(self):
|
40
|
+
if self.pid==0:
|
41
|
+
return
|
42
|
+
ModuloSystem.sendCtrlcProcess(self.pid)
|
43
|
+
|
44
|
+
def restart(self):
|
45
|
+
self.stop()
|
46
|
+
self.start()
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class FtpReturnBean(object):
|
2
|
-
|
3
|
-
def __init__(self,percorso_remoto,nomefile,isFile,countFiles,countDirs):
|
4
|
-
self.percorso_remoto=percorso_remoto
|
5
|
-
self.nomefile=nomefile
|
6
|
-
self.isFile=isFile
|
7
|
-
self.countFiles=countFiles
|
8
|
-
self.countDirs=countDirs
|
9
|
-
|
1
|
+
class FtpReturnBean(object):
|
2
|
+
|
3
|
+
def __init__(self,percorso_remoto,nomefile,isFile,countFiles,countDirs):
|
4
|
+
self.percorso_remoto=percorso_remoto
|
5
|
+
self.nomefile=nomefile
|
6
|
+
self.isFile=isFile
|
7
|
+
self.countFiles=countFiles
|
8
|
+
self.countDirs=countDirs
|
9
|
+
|
@@ -1,212 +1,212 @@
|
|
1
|
-
import ftplib
|
2
|
-
import os
|
3
|
-
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from modulitiz_mini.rete.ftp.FtpReturnBean import FtpReturnBean
|
8
|
-
|
9
|
-
|
10
|
-
class ModuloFtp(object):
|
11
|
-
DEFAULT_FTP_PORT=ftplib.FTP_PORT
|
12
|
-
|
13
|
-
def __init__(self,host,username,password):
|
14
|
-
self.host=host
|
15
|
-
self.porta=self.DEFAULT_FTP_PORT
|
16
|
-
self.username=username
|
17
|
-
self.password=password
|
18
|
-
self.conn=None
|
19
|
-
self.msgBenvenuto=None
|
20
|
-
|
21
|
-
def connect(self):
|
22
|
-
conn=ftplib.FTP(encoding=ModuloStringhe.CODIFICA_LATIN1)
|
23
|
-
try:
|
24
|
-
conn.connect(self.host,self.porta)
|
25
|
-
self.msgBenvenuto=conn.welcome
|
26
|
-
except UnicodeDecodeError as udError:
|
27
|
-
self.msgBenvenuto=udError.object.decode(ModuloStringhe.CODIFICA_ASCII,'ignore')
|
28
|
-
conn.login(self.username,self.password)
|
29
|
-
self.conn=conn
|
30
|
-
|
31
|
-
def uploadCartella(self,root_locale,rootRemota,excludeFiles,excludeDirs,min_byte_size,max_byte_size):
|
32
|
-
root_locale=ModuloFiles.normalizzaPercorsoLocale(root_locale)
|
33
|
-
rootRemota=ModuloFiles.normalizzaPercorsoRemoto(rootRemota)
|
34
|
-
countFiles=
|
35
|
-
|
36
|
-
for percorsoLocaleRel,percorsoLocaleAbs,folders,nomefiles in ModuloFiles.walk(root_locale,excludeFiles,excludeDirs,min_byte_size,max_byte_size):
|
37
|
-
percorso_remoto_abs=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(rootRemota,percorsoLocaleRel))
|
38
|
-
# carico i file contenuti nella cartella corrente
|
39
|
-
for nomefile in nomefiles:
|
40
|
-
self.uploadFile(percorsoLocaleAbs,percorso_remoto_abs,nomefile,False)
|
41
|
-
countFiles+=1
|
42
|
-
yield FtpReturnBean(percorso_remoto_abs,nomefile,True,countFiles,
|
43
|
-
# upload folders
|
44
|
-
for cartella in folders:
|
45
|
-
cartella=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_remoto_abs,cartella))
|
46
|
-
try:
|
47
|
-
self.conn.mkd(cartella)
|
48
|
-
except Exception:
|
49
|
-
pass
|
50
|
-
|
51
|
-
yield FtpReturnBean(percorso_remoto_abs,cartella,False,countFiles,
|
52
|
-
|
53
|
-
def uploadFile(self,percorso_locale,percorso_remoto,nomefile,renameIfExist)->str:
|
54
|
-
nomefile_locale=ModuloFiles.pathJoin(percorso_locale,nomefile)
|
55
|
-
nomefile_remoto=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_remoto,nomefile))
|
56
|
-
if renameIfExist is True:
|
57
|
-
# se il file esiste gia' sul server gli aggiungo il timestamp
|
58
|
-
if self.isFile(nomefile_remoto):
|
59
|
-
nomefile_remoto=ModuloStringhe.aggiungiTimestamp(nomefile_remoto)
|
60
|
-
# carico il file
|
61
|
-
with open(nomefile_locale,'rb') as fp:
|
62
|
-
self.conn.storbinary("STOR "+nomefile_remoto,fp)
|
63
|
-
return nomefile_remoto
|
64
|
-
|
65
|
-
def downloadCartella(self,percorso_remoto,percorso_locale,excludeFiles,excludeDirs):
|
66
|
-
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
67
|
-
return self.__downloadCartella(percorso_remoto,percorso_locale,excludeFiles,excludeDirs)
|
68
|
-
|
69
|
-
def downloadFile(self,nomefile_server,nomefile_locale):
|
70
|
-
nomefile_server=ModuloFiles.normalizzaPercorsoRemoto(nomefile_server)
|
71
|
-
nomefile_locale=ModuloFiles.normalizzaPercorsoLocale(nomefile_locale)
|
72
|
-
# creo le cartelle locali
|
73
|
-
cartella_locale=os.path.dirname(nomefile_locale)
|
74
|
-
os.makedirs(cartella_locale,exist_ok=True)
|
75
|
-
# scarico il file
|
76
|
-
with open(nomefile_locale,"wb") as fp:
|
77
|
-
self.conn.retrbinary("RETR "+nomefile_server,fp.write)
|
78
|
-
|
79
|
-
def eliminaCartella(self,percorso_remoto,excludeFiles,excludeDirs):
|
80
|
-
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
81
|
-
return self.__eliminaCartella(percorso_remoto,'.',excludeFiles,excludeDirs)
|
82
|
-
|
83
|
-
def listaContenutoCartella(self,percorso_remoto):
|
84
|
-
elementi = []
|
85
|
-
if self.isFile(percorso_remoto) is True:
|
86
|
-
return elementi
|
87
|
-
if percorso_remoto.startswith(('.','/')) is False:
|
88
|
-
percorso_remoto="./"+percorso_remoto
|
89
|
-
cmd = "NLST -a "+percorso_remoto
|
90
|
-
try:
|
91
|
-
self.conn.retrlines(cmd, elementi.append)
|
92
|
-
elementi.sort()
|
93
|
-
# elimino . e ..
|
94
|
-
elementi=elementi[2:]
|
95
|
-
except ftplib.error_perm:
|
96
|
-
pass
|
97
|
-
return elementi
|
98
|
-
|
99
|
-
def mkdirs(self,percorso_remoto):
|
100
|
-
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
101
|
-
dirs=ModuloListe.eliminaElementiVuoti(percorso_remoto.split("/"))
|
102
|
-
percorso_corrente=""
|
103
|
-
for cartella in dirs:
|
104
|
-
percorso_corrente=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_corrente,cartella))
|
105
|
-
try:
|
106
|
-
self.conn.mkd(percorso_corrente)
|
107
|
-
except Exception:
|
108
|
-
pass
|
109
|
-
|
110
|
-
def chiudi(self):
|
111
|
-
"""
|
112
|
-
chiude la connessione
|
113
|
-
"""
|
114
|
-
if self.conn is None:
|
115
|
-
return
|
116
|
-
try:
|
117
|
-
self.conn.quit()
|
118
|
-
except Exception:
|
119
|
-
self.conn.close()
|
120
|
-
self.conn=None
|
121
|
-
|
122
|
-
|
123
|
-
def getFileSize(self,nomefile):
|
124
|
-
try:
|
125
|
-
self.conn.voidcmd('TYPE I')
|
126
|
-
size=self.conn.size(nomefile)
|
127
|
-
return size
|
128
|
-
except Exception:
|
129
|
-
return
|
130
|
-
|
131
|
-
def isFile(self,elemento):
|
132
|
-
"""
|
133
|
-
controlla se un oggetto e' un file o una cartella
|
134
|
-
"""
|
135
|
-
return self.getFileSize(elemento) is not None
|
136
|
-
|
137
|
-
def goParentDir(self):
|
138
|
-
# bisogna per forza usare 2 punti, se c'e' anche lo slash finale non funziona
|
139
|
-
self.conn.cwd("..")
|
140
|
-
|
141
|
-
'''
|
142
|
-
FUNZIONI PRIVATE
|
143
|
-
'''
|
144
|
-
|
145
|
-
def __downloadCartella(self,percorso_remoto,percorso_locale,excludeFiles,excludeDirs,
|
146
|
-
countFiles:int=0,
|
147
|
-
"""
|
148
|
-
funzione ricorsiva
|
149
|
-
"""
|
150
|
-
# ciclo ogni elemento
|
151
|
-
elementi=self.listaContenutoCartella(percorso_remoto)
|
152
|
-
for elemento in elementi:
|
153
|
-
elemento_rel_path=elemento
|
154
|
-
if elemento_rel_path.startswith("/"):
|
155
|
-
elemento_rel_path=elemento_rel_path[1:]
|
156
|
-
elemento_remoto=ModuloFiles.normalizzaPercorsoRemoto(elemento)
|
157
|
-
elemento_locale=ModuloFiles.pathJoin(percorso_locale,elemento_rel_path)
|
158
|
-
# controllo se l'elemento e' un file o una cartella
|
159
|
-
if self.isFile(elemento_remoto):
|
160
|
-
os.makedirs(os.path.dirname(elemento_locale),exist_ok=True)
|
161
|
-
if elemento_remoto not in excludeFiles:
|
162
|
-
self.downloadFile(elemento_remoto,elemento_locale)
|
163
|
-
countFiles+=1
|
164
|
-
yield FtpReturnBean(percorso_remoto,elemento,True,countFiles,
|
165
|
-
else:
|
166
|
-
|
167
|
-
# creo la cartella
|
168
|
-
if ModuloListe.stringContainsCollection(elemento_remoto,excludeDirs) is True:
|
169
|
-
yield FtpReturnBean(percorso_remoto,elemento,True,countFiles,
|
170
|
-
break
|
171
|
-
os.makedirs(elemento_locale,exist_ok=True)
|
172
|
-
yield FtpReturnBean(percorso_remoto,elemento,False,countFiles,
|
173
|
-
# entro ed elaboro la sottocartella
|
174
|
-
for bean in self.__downloadCartella(elemento_remoto,percorso_locale,excludeFiles,excludeDirs,
|
175
|
-
countFiles,
|
176
|
-
countFiles=bean.countFiles
|
177
|
-
|
178
|
-
yield bean
|
179
|
-
|
180
|
-
def __eliminaCartella(self,rootRemota,percorsoRemotoRel,excludeFiles,excludeDirs):
|
181
|
-
"""
|
182
|
-
funzione ricorsiva
|
183
|
-
"""
|
184
|
-
# ciclo ogni elemento
|
185
|
-
countFiles=
|
186
|
-
elementi=self.listaContenutoCartella(percorsoRemotoRel)
|
187
|
-
for elemento in elementi:
|
188
|
-
elemento_remoto_rel=elemento
|
189
|
-
elemento_remoto_abs=ModuloFiles.pathJoin("/",elemento)
|
190
|
-
# controllo se e' un file o una cartella
|
191
|
-
if self.isFile(elemento_remoto_abs):
|
192
|
-
if ModuloListe.collectionContainsString(excludeDirs,percorsoRemotoRel) is False and elemento_remoto_rel not in excludeFiles:
|
193
|
-
self.conn.delete(elemento_remoto_abs)
|
194
|
-
countFiles+=1
|
195
|
-
yield FtpReturnBean(percorsoRemotoRel,elemento,True,countFiles,
|
196
|
-
else:
|
197
|
-
# entro ed elaboro la sottocartella
|
198
|
-
if ModuloListe.collectionContainsString(excludeDirs,elemento_remoto_rel) is False:
|
199
|
-
countFilesSubDir=
|
200
|
-
for bean in self.__eliminaCartella(rootRemota,elemento_remoto_rel,excludeFiles,excludeDirs):
|
201
|
-
countFilesSubDir=bean.countFiles+countFiles
|
202
|
-
|
203
|
-
bean.countFiles=countFilesSubDir
|
204
|
-
bean.
|
205
|
-
yield bean
|
206
|
-
countFiles=countFilesSubDir
|
207
|
-
|
208
|
-
# cancello la cartella dopo aver cancellato i file al suo interno
|
209
|
-
if ModuloListe.collectionContainsString(excludeDirs,elemento_remoto_rel) is False:
|
210
|
-
self.conn.rmd(elemento_remoto_abs)
|
211
|
-
|
212
|
-
yield FtpReturnBean(percorsoRemotoRel,elemento,False,countFiles,
|
1
|
+
import ftplib
|
2
|
+
import os
|
3
|
+
|
4
|
+
from modulitiz_nano.ModuloListe import ModuloListe
|
5
|
+
from modulitiz_nano.ModuloStringhe import ModuloStringhe
|
6
|
+
from modulitiz_nano.files.ModuloFiles import ModuloFiles
|
7
|
+
from modulitiz_mini.rete.ftp.FtpReturnBean import FtpReturnBean
|
8
|
+
|
9
|
+
|
10
|
+
class ModuloFtp(object):
|
11
|
+
DEFAULT_FTP_PORT=ftplib.FTP_PORT
|
12
|
+
|
13
|
+
def __init__(self,host,username,password):
|
14
|
+
self.host=host
|
15
|
+
self.porta=self.DEFAULT_FTP_PORT
|
16
|
+
self.username=username
|
17
|
+
self.password=password
|
18
|
+
self.conn=None
|
19
|
+
self.msgBenvenuto=None
|
20
|
+
|
21
|
+
def connect(self):
|
22
|
+
conn=ftplib.FTP(encoding=ModuloStringhe.CODIFICA_LATIN1)
|
23
|
+
try:
|
24
|
+
conn.connect(self.host,self.porta)
|
25
|
+
self.msgBenvenuto=conn.welcome
|
26
|
+
except UnicodeDecodeError as udError:
|
27
|
+
self.msgBenvenuto=udError.object.decode(ModuloStringhe.CODIFICA_ASCII,'ignore')
|
28
|
+
conn.login(self.username,self.password)
|
29
|
+
self.conn=conn
|
30
|
+
|
31
|
+
def uploadCartella(self,root_locale,rootRemota,excludeFiles,excludeDirs,min_byte_size,max_byte_size):
|
32
|
+
root_locale=ModuloFiles.normalizzaPercorsoLocale(root_locale)
|
33
|
+
rootRemota=ModuloFiles.normalizzaPercorsoRemoto(rootRemota)
|
34
|
+
countFiles=countDirs=0
|
35
|
+
|
36
|
+
for percorsoLocaleRel,percorsoLocaleAbs,folders,nomefiles in ModuloFiles.walk(root_locale,excludeFiles,excludeDirs,min_byte_size,max_byte_size):
|
37
|
+
percorso_remoto_abs=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(rootRemota,percorsoLocaleRel))
|
38
|
+
# carico i file contenuti nella cartella corrente
|
39
|
+
for nomefile in nomefiles:
|
40
|
+
self.uploadFile(percorsoLocaleAbs,percorso_remoto_abs,nomefile,False)
|
41
|
+
countFiles+=1
|
42
|
+
yield FtpReturnBean(percorso_remoto_abs,nomefile,True,countFiles,countDirs)
|
43
|
+
# upload folders
|
44
|
+
for cartella in folders:
|
45
|
+
cartella=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_remoto_abs,cartella))
|
46
|
+
try:
|
47
|
+
self.conn.mkd(cartella)
|
48
|
+
except Exception:
|
49
|
+
pass
|
50
|
+
countDirs+=1
|
51
|
+
yield FtpReturnBean(percorso_remoto_abs,cartella,False,countFiles,countDirs)
|
52
|
+
|
53
|
+
def uploadFile(self,percorso_locale,percorso_remoto,nomefile,renameIfExist)->str:
|
54
|
+
nomefile_locale=ModuloFiles.pathJoin(percorso_locale,nomefile)
|
55
|
+
nomefile_remoto=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_remoto,nomefile))
|
56
|
+
if renameIfExist is True:
|
57
|
+
# se il file esiste gia' sul server gli aggiungo il timestamp
|
58
|
+
if self.isFile(nomefile_remoto):
|
59
|
+
nomefile_remoto=ModuloStringhe.aggiungiTimestamp(nomefile_remoto)
|
60
|
+
# carico il file
|
61
|
+
with open(nomefile_locale,'rb') as fp:
|
62
|
+
self.conn.storbinary("STOR "+nomefile_remoto,fp)
|
63
|
+
return nomefile_remoto
|
64
|
+
|
65
|
+
def downloadCartella(self,percorso_remoto,percorso_locale,excludeFiles,excludeDirs):
|
66
|
+
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
67
|
+
return self.__downloadCartella(percorso_remoto,percorso_locale,excludeFiles,excludeDirs)
|
68
|
+
|
69
|
+
def downloadFile(self,nomefile_server,nomefile_locale):
|
70
|
+
nomefile_server=ModuloFiles.normalizzaPercorsoRemoto(nomefile_server)
|
71
|
+
nomefile_locale=ModuloFiles.normalizzaPercorsoLocale(nomefile_locale)
|
72
|
+
# creo le cartelle locali
|
73
|
+
cartella_locale=os.path.dirname(nomefile_locale)
|
74
|
+
os.makedirs(cartella_locale,exist_ok=True)
|
75
|
+
# scarico il file
|
76
|
+
with open(nomefile_locale,"wb") as fp:
|
77
|
+
self.conn.retrbinary("RETR "+nomefile_server,fp.write)
|
78
|
+
|
79
|
+
def eliminaCartella(self,percorso_remoto,excludeFiles,excludeDirs):
|
80
|
+
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
81
|
+
return self.__eliminaCartella(percorso_remoto,'.',excludeFiles,excludeDirs)
|
82
|
+
|
83
|
+
def listaContenutoCartella(self,percorso_remoto):
|
84
|
+
elementi = []
|
85
|
+
if self.isFile(percorso_remoto) is True:
|
86
|
+
return elementi
|
87
|
+
if percorso_remoto.startswith(('.','/')) is False:
|
88
|
+
percorso_remoto="./"+percorso_remoto
|
89
|
+
cmd = "NLST -a "+percorso_remoto
|
90
|
+
try:
|
91
|
+
self.conn.retrlines(cmd, elementi.append)
|
92
|
+
elementi.sort()
|
93
|
+
# elimino . e ..
|
94
|
+
elementi=elementi[2:]
|
95
|
+
except ftplib.error_perm:
|
96
|
+
pass
|
97
|
+
return elementi
|
98
|
+
|
99
|
+
def mkdirs(self,percorso_remoto):
|
100
|
+
percorso_remoto=ModuloFiles.normalizzaPercorsoRemoto(percorso_remoto)
|
101
|
+
dirs=ModuloListe.eliminaElementiVuoti(percorso_remoto.split("/"))
|
102
|
+
percorso_corrente=""
|
103
|
+
for cartella in dirs:
|
104
|
+
percorso_corrente=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_corrente,cartella))
|
105
|
+
try:
|
106
|
+
self.conn.mkd(percorso_corrente)
|
107
|
+
except Exception:
|
108
|
+
pass
|
109
|
+
|
110
|
+
def chiudi(self):
|
111
|
+
"""
|
112
|
+
chiude la connessione
|
113
|
+
"""
|
114
|
+
if self.conn is None:
|
115
|
+
return
|
116
|
+
try:
|
117
|
+
self.conn.quit()
|
118
|
+
except Exception:
|
119
|
+
self.conn.close()
|
120
|
+
self.conn=None
|
121
|
+
|
122
|
+
|
123
|
+
def getFileSize(self,nomefile):
|
124
|
+
try:
|
125
|
+
self.conn.voidcmd('TYPE I')
|
126
|
+
size=self.conn.size(nomefile)
|
127
|
+
return size
|
128
|
+
except Exception:
|
129
|
+
return
|
130
|
+
|
131
|
+
def isFile(self,elemento):
|
132
|
+
"""
|
133
|
+
controlla se un oggetto e' un file o una cartella
|
134
|
+
"""
|
135
|
+
return self.getFileSize(elemento) is not None
|
136
|
+
|
137
|
+
def goParentDir(self):
|
138
|
+
# bisogna per forza usare 2 punti, se c'e' anche lo slash finale non funziona
|
139
|
+
self.conn.cwd("..")
|
140
|
+
|
141
|
+
'''
|
142
|
+
FUNZIONI PRIVATE
|
143
|
+
'''
|
144
|
+
|
145
|
+
def __downloadCartella(self,percorso_remoto,percorso_locale,excludeFiles,excludeDirs,
|
146
|
+
countFiles:int=0,countDirs:int=1):
|
147
|
+
"""
|
148
|
+
funzione ricorsiva
|
149
|
+
"""
|
150
|
+
# ciclo ogni elemento
|
151
|
+
elementi=self.listaContenutoCartella(percorso_remoto)
|
152
|
+
for elemento in elementi:
|
153
|
+
elemento_rel_path=elemento
|
154
|
+
if elemento_rel_path.startswith("/"):
|
155
|
+
elemento_rel_path=elemento_rel_path[1:]
|
156
|
+
elemento_remoto=ModuloFiles.normalizzaPercorsoRemoto(elemento)
|
157
|
+
elemento_locale=ModuloFiles.pathJoin(percorso_locale,elemento_rel_path)
|
158
|
+
# controllo se l'elemento e' un file o una cartella
|
159
|
+
if self.isFile(elemento_remoto):
|
160
|
+
os.makedirs(os.path.dirname(elemento_locale),exist_ok=True)
|
161
|
+
if elemento_remoto not in excludeFiles:
|
162
|
+
self.downloadFile(elemento_remoto,elemento_locale)
|
163
|
+
countFiles+=1
|
164
|
+
yield FtpReturnBean(percorso_remoto,elemento,True,countFiles,countDirs)
|
165
|
+
else:
|
166
|
+
countDirs+=1
|
167
|
+
# creo la cartella
|
168
|
+
if ModuloListe.stringContainsCollection(elemento_remoto,excludeDirs) is True:
|
169
|
+
yield FtpReturnBean(percorso_remoto,elemento,True,countFiles,countDirs)
|
170
|
+
break
|
171
|
+
os.makedirs(elemento_locale,exist_ok=True)
|
172
|
+
yield FtpReturnBean(percorso_remoto,elemento,False,countFiles,countDirs)
|
173
|
+
# entro ed elaboro la sottocartella
|
174
|
+
for bean in self.__downloadCartella(elemento_remoto,percorso_locale,excludeFiles,excludeDirs,
|
175
|
+
countFiles,countDirs):
|
176
|
+
countFiles=bean.countFiles
|
177
|
+
countDirs=bean.countDirs
|
178
|
+
yield bean
|
179
|
+
|
180
|
+
def __eliminaCartella(self,rootRemota,percorsoRemotoRel,excludeFiles,excludeDirs):
|
181
|
+
"""
|
182
|
+
funzione ricorsiva
|
183
|
+
"""
|
184
|
+
# ciclo ogni elemento
|
185
|
+
countFiles=countDirs=0
|
186
|
+
elementi=self.listaContenutoCartella(percorsoRemotoRel)
|
187
|
+
for elemento in elementi:
|
188
|
+
elemento_remoto_rel=elemento
|
189
|
+
elemento_remoto_abs=ModuloFiles.pathJoin("/",elemento)
|
190
|
+
# controllo se e' un file o una cartella
|
191
|
+
if self.isFile(elemento_remoto_abs):
|
192
|
+
if ModuloListe.collectionContainsString(excludeDirs,percorsoRemotoRel) is False and elemento_remoto_rel not in excludeFiles:
|
193
|
+
self.conn.delete(elemento_remoto_abs)
|
194
|
+
countFiles+=1
|
195
|
+
yield FtpReturnBean(percorsoRemotoRel,elemento,True,countFiles,countDirs)
|
196
|
+
else:
|
197
|
+
# entro ed elaboro la sottocartella
|
198
|
+
if ModuloListe.collectionContainsString(excludeDirs,elemento_remoto_rel) is False:
|
199
|
+
countFilesSubDir=countDirsSubDir=0
|
200
|
+
for bean in self.__eliminaCartella(rootRemota,elemento_remoto_rel,excludeFiles,excludeDirs):
|
201
|
+
countFilesSubDir=bean.countFiles+countFiles
|
202
|
+
countDirsSubDir=bean.countDirs+countDirs
|
203
|
+
bean.countFiles=countFilesSubDir
|
204
|
+
bean.countDirs=countDirsSubDir
|
205
|
+
yield bean
|
206
|
+
countFiles=countFilesSubDir
|
207
|
+
countDirs=countDirsSubDir
|
208
|
+
# cancello la cartella dopo aver cancellato i file al suo interno
|
209
|
+
if ModuloListe.collectionContainsString(excludeDirs,elemento_remoto_rel) is False:
|
210
|
+
self.conn.rmd(elemento_remoto_abs)
|
211
|
+
countDirs+=1
|
212
|
+
yield FtpReturnBean(percorsoRemotoRel,elemento,False,countFiles,countDirs)
|
@@ -1,50 +1,50 @@
|
|
1
|
-
Metadata-Version: 2.
|
2
|
-
Name: modulitiz_mini
|
3
|
-
Version: 2.
|
4
|
-
Summary: Raccolta dei miei moduli - versione mini
|
5
|
-
Author-email: tiz <sderfo1234@altervista.org>
|
6
|
-
Classifier: Programming Language :: Python :: 3
|
7
|
-
Classifier:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Requires-Dist:
|
13
|
-
Requires-Dist:
|
14
|
-
Requires-Dist:
|
15
|
-
|
16
|
-
|
17
|
-
# modulitiz-mini
|
18
|
-
|
19
|
-
It's a Python library that contains daily use or generic functions.
|
20
|
-
The difference between "micro" is that it requires other dependencies.
|
21
|
-
|
22
|
-
## Installation
|
23
|
-
|
24
|
-
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install:
|
25
|
-
|
26
|
-
```bash
|
27
|
-
pip install modulitiz_mini
|
28
|
-
```
|
29
|
-
The other required dependencies will be installed automatically.
|
30
|
-
|
31
|
-
## Usage
|
32
|
-
|
33
|
-
```python
|
34
|
-
from modulitiz_mini.ModuloRsa import ModuloRsa
|
35
|
-
|
36
|
-
moduloRsa=ModuloRsa()
|
37
|
-
moduloRsa.generateKeys()
|
38
|
-
|
39
|
-
# returns cripted string
|
40
|
-
moduloRsa.encrypt("test")
|
41
|
-
...
|
42
|
-
```
|
43
|
-
|
44
|
-
## Contributing
|
45
|
-
|
46
|
-
If you find any bug you can write me at [sderfo1234@altervista.org](mailto:sderfo1234@altervista.org)
|
47
|
-
|
48
|
-
## License
|
49
|
-
|
50
|
-
[MIT](https://choosealicense.com/licenses/mit/)
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: modulitiz_mini
|
3
|
+
Version: 2.7.0
|
4
|
+
Summary: Raccolta dei miei moduli - versione mini
|
5
|
+
Author-email: tiz <sderfo1234@altervista.org>
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
7
|
+
Classifier: Operating System :: OS Independent
|
8
|
+
Requires-Python: >=3.11
|
9
|
+
Description-Content-Type: text/markdown
|
10
|
+
License-File: LICENSE
|
11
|
+
Requires-Dist: modulitiz-micro>=2
|
12
|
+
Requires-Dist: cryptography>=41.0
|
13
|
+
Requires-Dist: instabot>=0.117
|
14
|
+
Requires-Dist: pypdf==5.0.1
|
15
|
+
Dynamic: license-file
|
16
|
+
|
17
|
+
# modulitiz-mini
|
18
|
+
|
19
|
+
It's a Python library that contains daily use or generic functions.
|
20
|
+
The difference between "micro" is that it requires other dependencies.
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
pip install -U modulitiz_mini
|
28
|
+
```
|
29
|
+
The other required dependencies will be installed automatically.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```python
|
34
|
+
from modulitiz_mini.ModuloRsa import ModuloRsa
|
35
|
+
|
36
|
+
moduloRsa=ModuloRsa()
|
37
|
+
moduloRsa.generateKeys()
|
38
|
+
|
39
|
+
# returns cripted string
|
40
|
+
moduloRsa.encrypt("test")
|
41
|
+
...
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
If you find any bug you can write me at [sderfo1234@altervista.org](mailto:sderfo1234@altervista.org)
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
modulitiz_mini/ModuloRsa.py,sha256=2JYvB6Fo2qIQnTnZqcGFCDZFEQhdYEXQRxFqg5ffKkQ,2496
|
2
|
+
modulitiz_mini/django/ModuloDjango.py,sha256=whME1HR6-42ApBWN4Z8fw9Z3y-_JtNH15-6vQIFYTq4,505
|
3
|
+
modulitiz_mini/django/MyMiddleware.py,sha256=1FhBwNfPHSab_CAFAimsQrRjIsLTIXF1D1IKAcBb_M8,265
|
4
|
+
modulitiz_mini/django/settings.py,sha256=BmDBR83cX5J4MSLw9eUex4CIgcuO85KaHsTEdelyyok,3003
|
5
|
+
modulitiz_mini/files/pdf/AbstractPdf.py,sha256=pKr1U3yt2G5HsMcRtWRC8LLF1smapjYrZIr2Z85Cy9U,129
|
6
|
+
modulitiz_mini/files/pdf/ReadPdf.py,sha256=Qjht5AKrDmut3cTYomvw327a8DWyIbXYMPwTufrimpc,723
|
7
|
+
modulitiz_mini/files/pdf/WritePdf.py,sha256=eZeYtXxi8hqzECqVujxY24sZqfG8WQpVAeK-kejOVD4,288
|
8
|
+
modulitiz_mini/rete/ModuloTor.py,sha256=pxmOnmZAK4EJM_bOtcDkdSnNhD_TTbhsqBFqqYG9ib4,1257
|
9
|
+
modulitiz_mini/rete/ftp/FtpReturnBean.py,sha256=nx63rBQg8ohMUWSS9ggF4Rf6H2OUbH90-gVRQxDExP4,248
|
10
|
+
modulitiz_mini/rete/ftp/ModuloFtp.py,sha256=jmbtZ5yZCUNtVr6xUhFidBycFq1UQBoAzp34Dekrt_M,7899
|
11
|
+
modulitiz_mini-2.7.0.dist-info/licenses/LICENSE,sha256=vKUA7w9jf8zzsgxwXkljKHPYZ1ohoBtqbRyEYDmTp9A,1064
|
12
|
+
modulitiz_mini-2.7.0.dist-info/METADATA,sha256=72fXcuH4Fd1lc3TwYZs8RSzMNnX0roCRZj8uumF8n6E,1201
|
13
|
+
modulitiz_mini-2.7.0.dist-info/WHEEL,sha256=cRWFNt_CJSuf6BnJKAdKunDXUJxjAbWvbt_kstDCs1I,93
|
14
|
+
modulitiz_mini-2.7.0.dist-info/top_level.txt,sha256=OxUbMOvprrGDegA-38GcCVHtPSP3X-d91EseClu8VN4,15
|
15
|
+
modulitiz_mini-2.7.0.dist-info/RECORD,,
|