modulitiz-mini 2.6.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 -0
- modulitiz_mini/django/ModuloDjango.py +20 -0
- modulitiz_mini/django/MyMiddleware.py +10 -0
- modulitiz_mini/django/settings.py +132 -0
- modulitiz_mini/files/pdf/AbstractPdf.py +9 -0
- modulitiz_mini/files/pdf/ReadPdf.py +27 -0
- modulitiz_mini/files/pdf/WritePdf.py +14 -0
- modulitiz_mini/rete/ModuloTor.py +46 -0
- modulitiz_mini/rete/ftp/FtpReturnBean.py +9 -0
- modulitiz_mini/rete/ftp/ModuloFtp.py +212 -0
- modulitiz_mini-2.6.0.dist-info/LICENSE +21 -0
- modulitiz_mini-2.6.0.dist-info/METADATA +50 -0
- modulitiz_mini-2.6.0.dist-info/RECORD +15 -0
- modulitiz_mini-2.6.0.dist-info/WHEEL +5 -0
- modulitiz_mini-2.6.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
from cryptography.hazmat.backends import default_backend
|
2
|
+
from cryptography.hazmat.primitives import hashes
|
3
|
+
from cryptography.hazmat.primitives import serialization
|
4
|
+
from cryptography.hazmat.primitives.asymmetric import padding
|
5
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
6
|
+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
|
7
|
+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
|
8
|
+
|
9
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
10
|
+
|
11
|
+
|
12
|
+
class ModuloRsa(object):
|
13
|
+
DEFAULT_HASH_TYPE=hashes.SHA256()
|
14
|
+
KEY_SIZE=4096
|
15
|
+
|
16
|
+
NOMEFILE_PUBLIC_KEY="public.key"
|
17
|
+
NOMEFILE_PRIVATE_KEY="private.key"
|
18
|
+
|
19
|
+
def __init__(self):
|
20
|
+
self.publicKey:RSAPublicKey|None=None
|
21
|
+
self.privateKey:RSAPrivateKey|None=None
|
22
|
+
|
23
|
+
def generateKeys(self):
|
24
|
+
self.privateKey = rsa.generate_private_key(
|
25
|
+
public_exponent=65537, key_size=self.KEY_SIZE, backend=default_backend()
|
26
|
+
)
|
27
|
+
self.publicKey = self.privateKey.public_key()
|
28
|
+
|
29
|
+
#
|
30
|
+
# save
|
31
|
+
#
|
32
|
+
def savePublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
|
33
|
+
pem = self.publicKey.public_bytes(
|
34
|
+
encoding=serialization.Encoding.PEM,
|
35
|
+
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
36
|
+
)
|
37
|
+
with open(nomefile, 'wb') as fp:
|
38
|
+
fp.write(pem)
|
39
|
+
|
40
|
+
def savePrivateKey(self, nomefile=NOMEFILE_PRIVATE_KEY):
|
41
|
+
pem = self.privateKey.private_bytes(
|
42
|
+
encoding=serialization.Encoding.PEM,
|
43
|
+
format=serialization.PrivateFormat.TraditionalOpenSSL,
|
44
|
+
encryption_algorithm=serialization.NoEncryption()
|
45
|
+
)
|
46
|
+
with open(nomefile, 'wb') as fp:
|
47
|
+
fp.write(pem)
|
48
|
+
|
49
|
+
#
|
50
|
+
# read
|
51
|
+
#
|
52
|
+
def readPublicKey(self,nomefile=NOMEFILE_PUBLIC_KEY):
|
53
|
+
with open(nomefile, "rb") as fp:
|
54
|
+
pem=fp.read()
|
55
|
+
self.publicKey = serialization.load_pem_public_key(pem, backend=default_backend())
|
56
|
+
|
57
|
+
def readPrivateKey(self,nomefile=NOMEFILE_PRIVATE_KEY):
|
58
|
+
with open(nomefile, "rb") as fp:
|
59
|
+
pem=fp.read()
|
60
|
+
self.privateKey = serialization.load_pem_private_key(pem, password=None, backend=default_backend())
|
61
|
+
|
62
|
+
|
63
|
+
def encrypt(self,messaggio):
|
64
|
+
encryptedMsg = self.publicKey.encrypt(
|
65
|
+
messaggio.encode(ModuloStringhe.CODIFICA_UTF8),
|
66
|
+
self.__generatePadding()
|
67
|
+
)
|
68
|
+
return encryptedMsg
|
69
|
+
|
70
|
+
def decrypt(self,encryptedMsg):
|
71
|
+
originalMessage = self.privateKey.decrypt(
|
72
|
+
encryptedMsg,
|
73
|
+
self.__generatePadding()
|
74
|
+
).decode(ModuloStringhe.CODIFICA_UTF8)
|
75
|
+
return originalMessage
|
76
|
+
|
77
|
+
def __generatePadding(self):
|
78
|
+
hashType=self.DEFAULT_HASH_TYPE
|
79
|
+
paddingObj=padding.OAEP(
|
80
|
+
mgf=padding.MGF1(algorithm=hashType),
|
81
|
+
algorithm=hashType,
|
82
|
+
label=None
|
83
|
+
)
|
84
|
+
return paddingObj
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"""
|
2
|
+
python manage.py collectstatic
|
3
|
+
python manage.py runserver 0.0.0.0:80
|
4
|
+
"""
|
5
|
+
|
6
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
7
|
+
|
8
|
+
|
9
|
+
class ModuloDjango(object):
|
10
|
+
@staticmethod
|
11
|
+
def isLocalhost(request)->bool:
|
12
|
+
return ModuloStringhe.contains(request.path, 'localhost') or ModuloStringhe.contains(request.path, '127.0.0.1')
|
13
|
+
|
14
|
+
@classmethod
|
15
|
+
def init_modelmap(cls,request,pageTitle:str)->dict:
|
16
|
+
modelMap = {
|
17
|
+
'page_title': pageTitle,
|
18
|
+
'is_localhost': cls.isLocalhost(request)
|
19
|
+
}
|
20
|
+
return modelMap
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class MyMiddleware(object):
|
2
|
+
|
3
|
+
def __init__(self, getResponse):
|
4
|
+
self.getResponse = getResponse
|
5
|
+
|
6
|
+
def __call__(self, request):
|
7
|
+
response = self.getResponse(request)
|
8
|
+
# allow iframe tag to be loaded
|
9
|
+
response['X-Frame-Options'] = 'SAMEORIGIN'
|
10
|
+
return response
|
@@ -0,0 +1,132 @@
|
|
1
|
+
"""
|
2
|
+
Django settings.
|
3
|
+
|
4
|
+
Generated by 'django-admin startproject' using Django 3.0.8.
|
5
|
+
|
6
|
+
For more information on this file, see
|
7
|
+
https://docs.djangoproject.com/en/3.0/topics/settings/
|
8
|
+
|
9
|
+
For the full list of settings and their values, see
|
10
|
+
https://docs.djangoproject.com/en/3.0/ref/settings/
|
11
|
+
"""
|
12
|
+
|
13
|
+
import os
|
14
|
+
|
15
|
+
from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
|
16
|
+
|
17
|
+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
18
|
+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
19
|
+
|
20
|
+
|
21
|
+
# Quick-start development settings - unsuitable for production
|
22
|
+
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
23
|
+
|
24
|
+
ALLOWED_HOSTS = ['localhost', '127.0.0.1', ModuloNetworking.getLocalIp()]
|
25
|
+
|
26
|
+
|
27
|
+
# Application definition
|
28
|
+
|
29
|
+
INSTALLED_APPS = [
|
30
|
+
'django.contrib.admin',
|
31
|
+
'django.contrib.auth',
|
32
|
+
'django.contrib.contenttypes',
|
33
|
+
'django.contrib.sessions',
|
34
|
+
'django.contrib.messages',
|
35
|
+
'django.contrib.staticfiles',
|
36
|
+
]
|
37
|
+
|
38
|
+
MIDDLEWARE = [
|
39
|
+
'django.middleware.security.SecurityMiddleware',
|
40
|
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
41
|
+
'django.middleware.common.CommonMiddleware',
|
42
|
+
'django.middleware.csrf.CsrfViewMiddleware',
|
43
|
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
44
|
+
'django.contrib.messages.middleware.MessageMiddleware',
|
45
|
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
46
|
+
# custom
|
47
|
+
'modulitiz_mini.django.MyMiddleware.MyMiddleware'
|
48
|
+
]
|
49
|
+
|
50
|
+
ROOT_URLCONF = 'testwebsite.urls'
|
51
|
+
|
52
|
+
TEMPLATE_DIRS = [
|
53
|
+
os.path.join(BASE_DIR,'progetto1','templates')
|
54
|
+
]
|
55
|
+
|
56
|
+
TEMPLATES = [
|
57
|
+
{
|
58
|
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
59
|
+
'DIRS': TEMPLATE_DIRS,
|
60
|
+
'APP_DIRS': True,
|
61
|
+
'OPTIONS': {
|
62
|
+
'context_processors': [
|
63
|
+
'django.template.context_processors.debug',
|
64
|
+
'django.template.context_processors.request',
|
65
|
+
'django.contrib.auth.context_processors.auth',
|
66
|
+
'django.contrib.messages.context_processors.messages',
|
67
|
+
],
|
68
|
+
},
|
69
|
+
},
|
70
|
+
]
|
71
|
+
|
72
|
+
WSGI_APPLICATION = 'testwebsite.wsgi.application'
|
73
|
+
|
74
|
+
|
75
|
+
# Database
|
76
|
+
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
77
|
+
|
78
|
+
DATABASES = {
|
79
|
+
'default': {
|
80
|
+
'ENGINE': 'django.db.backends.sqlite3',
|
81
|
+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
# Password validation
|
87
|
+
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
88
|
+
|
89
|
+
AUTH_PASSWORD_VALIDATORS = [
|
90
|
+
{
|
91
|
+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
92
|
+
},
|
93
|
+
{
|
94
|
+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
95
|
+
},
|
96
|
+
{
|
97
|
+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
98
|
+
},
|
99
|
+
{
|
100
|
+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
101
|
+
},
|
102
|
+
]
|
103
|
+
|
104
|
+
|
105
|
+
# Internationalization
|
106
|
+
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
107
|
+
|
108
|
+
LANGUAGE_CODE = 'en-us'
|
109
|
+
|
110
|
+
TIME_ZONE = 'UTC'
|
111
|
+
|
112
|
+
USE_I18N = True
|
113
|
+
|
114
|
+
USE_L10N = True
|
115
|
+
|
116
|
+
USE_TZ = True
|
117
|
+
|
118
|
+
|
119
|
+
# Static files (CSS, JavaScript, Images)
|
120
|
+
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
121
|
+
STATIC_URL = '/static/'
|
122
|
+
STATICFILES_DIRS = [
|
123
|
+
os.path.normpath(os.path.join(BASE_DIR,'static'))
|
124
|
+
]
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import pypdf
|
2
|
+
|
3
|
+
from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
|
4
|
+
from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
|
5
|
+
|
6
|
+
|
7
|
+
class ReadPdf(AbstractPdf):
|
8
|
+
|
9
|
+
def __init__(self,filename:str):
|
10
|
+
super().__init__()
|
11
|
+
self.filename=filename
|
12
|
+
self.pdfObj=pypdf.PdfReader(open(filename,"rb"))
|
13
|
+
|
14
|
+
def getNumPages(self)->int:
|
15
|
+
return len(self.pdfObj.pages)
|
16
|
+
|
17
|
+
def getPage(self,pageNum:int):
|
18
|
+
"""
|
19
|
+
Read a page from a pdf file.
|
20
|
+
:param pageNum: pages start with 0 and including extremes.
|
21
|
+
"""
|
22
|
+
pageNum-=1
|
23
|
+
maxPages=self.getNumPages()
|
24
|
+
# check if page exist
|
25
|
+
if pageNum<0 or pageNum>=maxPages:
|
26
|
+
raise EccezioneRuntime("Page number {0} not exists.".format(pageNum))
|
27
|
+
return self.pdfObj.pages[pageNum]
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import pypdf
|
2
|
+
|
3
|
+
from modulitiz_mini.files.pdf.AbstractPdf import AbstractPdf
|
4
|
+
|
5
|
+
|
6
|
+
class WritePdf(AbstractPdf):
|
7
|
+
|
8
|
+
def __init__(self):
|
9
|
+
super().__init__()
|
10
|
+
self.pdfObj=pypdf.PdfWriter()
|
11
|
+
|
12
|
+
def write(self,filename:str):
|
13
|
+
with open(filename,"wb") as outStream:
|
14
|
+
self.pdfObj.write(outStream)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import time
|
2
|
+
|
3
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
4
|
+
from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
|
5
|
+
from modulitiz_micro.files.ModuloFiles import ModuloFiles
|
6
|
+
from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
|
7
|
+
from modulitiz_micro.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()
|
@@ -0,0 +1,212 @@
|
|
1
|
+
import ftplib
|
2
|
+
import os
|
3
|
+
|
4
|
+
from modulitiz_micro.ModuloListe import ModuloListe
|
5
|
+
from modulitiz_micro.ModuloStringhe import ModuloStringhe
|
6
|
+
from modulitiz_micro.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=countFolders=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,countFolders)
|
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
|
+
countFolders+=1
|
51
|
+
yield FtpReturnBean(percorso_remoto_abs,cartella,False,countFiles,countFolders)
|
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,countFolders: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,countFolders)
|
165
|
+
else:
|
166
|
+
countFolders+=1
|
167
|
+
# creo la cartella
|
168
|
+
if ModuloListe.stringContainsCollection(elemento_remoto,excludeDirs) is True:
|
169
|
+
yield FtpReturnBean(percorso_remoto,elemento,True,countFiles,countFolders)
|
170
|
+
break
|
171
|
+
os.makedirs(elemento_locale,exist_ok=True)
|
172
|
+
yield FtpReturnBean(percorso_remoto,elemento,False,countFiles,countFolders)
|
173
|
+
# entro ed elaboro la sottocartella
|
174
|
+
for bean in self.__downloadCartella(elemento_remoto,percorso_locale,excludeFiles,excludeDirs,
|
175
|
+
countFiles,countFolders):
|
176
|
+
countFiles=bean.countFiles
|
177
|
+
countFolders=bean.countFolders
|
178
|
+
yield bean
|
179
|
+
|
180
|
+
def __eliminaCartella(self,rootRemota,percorsoRemotoRel,excludeFiles,excludeDirs):
|
181
|
+
"""
|
182
|
+
funzione ricorsiva
|
183
|
+
"""
|
184
|
+
# ciclo ogni elemento
|
185
|
+
countFiles=countFolders=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,countFolders)
|
196
|
+
else:
|
197
|
+
# entro ed elaboro la sottocartella
|
198
|
+
if ModuloListe.collectionContainsString(excludeDirs,elemento_remoto_rel) is False:
|
199
|
+
countFilesSubDir=countFoldersSubDir=0
|
200
|
+
for bean in self.__eliminaCartella(rootRemota,elemento_remoto_rel,excludeFiles,excludeDirs):
|
201
|
+
countFilesSubDir=bean.countFiles+countFiles
|
202
|
+
countFoldersSubDir=bean.countFolders+countFolders
|
203
|
+
bean.countFiles=countFilesSubDir
|
204
|
+
bean.countFolders=countFoldersSubDir
|
205
|
+
yield bean
|
206
|
+
countFiles=countFilesSubDir
|
207
|
+
countFolders=countFoldersSubDir
|
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
|
+
countFolders+=1
|
212
|
+
yield FtpReturnBean(percorsoRemotoRel,elemento,False,countFiles,countFolders)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023-2040 tiz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: modulitiz_mini
|
3
|
+
Version: 2.6.0
|
4
|
+
Summary: Raccolta dei miei moduli - versione mini
|
5
|
+
Author-email: tiz <sderfo1234@altervista.org>
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
8
|
+
Classifier: Operating System :: OS Independent
|
9
|
+
Requires-Python: >=3.11
|
10
|
+
Description-Content-Type: text/markdown
|
11
|
+
License-File: LICENSE
|
12
|
+
Requires-Dist: modulitiz-micro>=2
|
13
|
+
Requires-Dist: cryptography>=41.0
|
14
|
+
Requires-Dist: instabot>=0.117
|
15
|
+
Requires-Dist: pypdf==5.0.1
|
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/)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
modulitiz_mini/ModuloRsa.py,sha256=JTzuLm4lg1LN_ExNQ9pNz4mRqQP5VYlywfejtVBo9vo,2581
|
2
|
+
modulitiz_mini/django/ModuloDjango.py,sha256=oflZF10_XryiahFveb2Mvfulx2MwNsrMdeq6LblvQwk,526
|
3
|
+
modulitiz_mini/django/MyMiddleware.py,sha256=IZvRlYzTr5wRDbVxS-KlLiwEBgtE59FRurQXCyTR_vQ,275
|
4
|
+
modulitiz_mini/django/settings.py,sha256=N-6pi_D6Qp5qBMKkpuPHHyw_ucEOyuPu9q7f7zTfzT4,3135
|
5
|
+
modulitiz_mini/files/pdf/AbstractPdf.py,sha256=JRLeAP8ltO4fV_tC4o-XZGcmtsJYd7KeaOQHeqLzxoI,138
|
6
|
+
modulitiz_mini/files/pdf/ReadPdf.py,sha256=il2lZrghOiaZFAss16T-I5q1yF9QwQQdK8jHVpx7asE,751
|
7
|
+
modulitiz_mini/files/pdf/WritePdf.py,sha256=pRi6DWMq9mDlxEMihEHSFKsrwcHzc1bAurLdOf2KRWk,302
|
8
|
+
modulitiz_mini/rete/ModuloTor.py,sha256=hozFSddJYEd4z9cOxMUpthN4Yk9oXo2qKFK0bocZVBk,1307
|
9
|
+
modulitiz_mini/rete/ftp/FtpReturnBean.py,sha256=WJhv-idDa_L8MeTxDkgjz8D8JxOP3jrwoQAWig-1i50,257
|
10
|
+
modulitiz_mini/rete/ftp/ModuloFtp.py,sha256=b1C9wX7pffjNFZCRcwZ5Ddw25BI1IpN5Pge6r2tLTL4,8186
|
11
|
+
modulitiz_mini-2.6.0.dist-info/LICENSE,sha256=gmuE_3LV2kDZCizi2b9sBBrgQEFi3EFeybDbaTyZ_cc,1084
|
12
|
+
modulitiz_mini-2.6.0.dist-info/METADATA,sha256=LkQlnygpwQHsb4ThG_CAttlU3fVJ1q19DirdmUkM8h4,1277
|
13
|
+
modulitiz_mini-2.6.0.dist-info/WHEEL,sha256=2aRSX09k7pmd4gPs96VOQ860h0v0t30ka6JGHtpC3BY,94
|
14
|
+
modulitiz_mini-2.6.0.dist-info/top_level.txt,sha256=OxUbMOvprrGDegA-38GcCVHtPSP3X-d91EseClu8VN4,15
|
15
|
+
modulitiz_mini-2.6.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
modulitiz_mini
|