modulitiz-mini 2.12.0__py312-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/multimedia/ModuloMultimedia.py +71 -0
- modulitiz_mini/rete/ModuloTor.py +46 -0
- modulitiz_mini/rete/ftp/FtpReturnBean.py +9 -0
- modulitiz_mini/rete/ftp/ModuloFtp.py +211 -0
- modulitiz_mini-2.12.0.dist-info/METADATA +49 -0
- modulitiz_mini-2.12.0.dist-info/RECORD +16 -0
- modulitiz_mini-2.12.0.dist-info/WHEEL +5 -0
- modulitiz_mini-2.12.0.dist-info/licenses/LICENSE +21 -0
- modulitiz_mini-2.12.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_nano.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_nano.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_mini.files.pdf.AbstractPdf import AbstractPdf
|
|
4
|
+
from modulitiz_nano.exceptions.ExceptionRuntime import ExceptionRuntime
|
|
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 ExceptionRuntime("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,71 @@
|
|
|
1
|
+
from modulitiz_binaries.Init import Init
|
|
2
|
+
from modulitiz_nano.ModuloListe import ModuloListe
|
|
3
|
+
from modulitiz_nano.ModuloStringhe import ModuloStringhe
|
|
4
|
+
from modulitiz_nano.files.ModuloFiles import ModuloFiles
|
|
5
|
+
from modulitiz_nano.sistema.ModuloSystem import ModuloSystem
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ModuloMultimedia(object):
|
|
9
|
+
ESTENSIONI_IMMAGINE=(".avif",".jpg",".jpeg",".png",".webp")
|
|
10
|
+
ESTENSIONI_MUSICA=(".wav",".m4a",".opus",".ogg")
|
|
11
|
+
ESTENSIONI_VIDEO=(".webm",".mp4",".mkv",".m4v",".3gp",".mov",".vob")
|
|
12
|
+
|
|
13
|
+
ESTENSIONI=ESTENSIONI_IMMAGINE+ESTENSIONI_MUSICA+ESTENSIONI_VIDEO
|
|
14
|
+
|
|
15
|
+
VIDEO_CODEC__AOMEDIA_VIDEO_1="av1"
|
|
16
|
+
|
|
17
|
+
def __init__(self):
|
|
18
|
+
path=None
|
|
19
|
+
if ModuloSystem.isWindows():
|
|
20
|
+
path=Init.getCartellaFileBinari()
|
|
21
|
+
self.cartellaFileBinari=path
|
|
22
|
+
|
|
23
|
+
def hasAudioTrack(self,nomefile:str)->bool:
|
|
24
|
+
nomefileEseguibile=ModuloFiles.pathJoin(self.cartellaFileBinari, "ffprobe")
|
|
25
|
+
comando=f'"{nomefileEseguibile}" -i "{nomefile}" -show_streams -select_streams a -loglevel error'
|
|
26
|
+
output=ModuloSystem.systemCallReturnOutput(comando,None)
|
|
27
|
+
if ModuloStringhe.isEmpty(output):
|
|
28
|
+
return False
|
|
29
|
+
lines=ModuloStringhe.normalizzaEol(output).split("\n")
|
|
30
|
+
return ModuloListe.collectionContainsString(lines,"channels=")
|
|
31
|
+
|
|
32
|
+
def convertImage(self,nomevecchio:str,nomenuovo:str):
|
|
33
|
+
return self.convertFile(nomevecchio, nomenuovo, None,None,None,None)
|
|
34
|
+
|
|
35
|
+
def convertFile(self,nomevecchio:str,nomenuovo:str,fps:int|None,larghezzaMax:int|None,altezzaMax:int|None,bitrate:str|None):
|
|
36
|
+
cmdFps=""
|
|
37
|
+
if fps is not None:
|
|
38
|
+
cmdFps="-filter:v fps=fps="+str(fps)
|
|
39
|
+
cmdDimensioni=""
|
|
40
|
+
if larghezzaMax is not None:
|
|
41
|
+
cmdDimensioni=f"-vf scale={larghezzaMax}:-2"
|
|
42
|
+
elif altezzaMax is not None:
|
|
43
|
+
cmdDimensioni=f"-vf scale=-2:{altezzaMax}"
|
|
44
|
+
cmdBitrate=""
|
|
45
|
+
if bitrate is not None:
|
|
46
|
+
cmdBitrate="-b:a "+bitrate
|
|
47
|
+
# comando
|
|
48
|
+
nomefileEseguibile=ModuloFiles.pathJoin(self.cartellaFileBinari, "ffmpeg")
|
|
49
|
+
comando=f'"{nomefileEseguibile}" -i "{nomevecchio}" {cmdFps} {cmdDimensioni} {cmdBitrate} "{nomenuovo}"'
|
|
50
|
+
output=ModuloSystem.systemCallReturnOutput(comando,None)
|
|
51
|
+
return output
|
|
52
|
+
|
|
53
|
+
def getCodecName(self,nomefile:str):
|
|
54
|
+
nomefileEseguibile=ModuloFiles.pathJoin(self.cartellaFileBinari, "ffprobe")
|
|
55
|
+
comando=f'"{nomefileEseguibile}" -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "{nomefile}"'
|
|
56
|
+
output=ModuloSystem.systemCallReturnOutput(comando,None)
|
|
57
|
+
output=ModuloStringhe.normalizzaEol(output).replace("\n","")
|
|
58
|
+
return output
|
|
59
|
+
|
|
60
|
+
def getLengthOfVideo(self,nomefile:str):
|
|
61
|
+
nomefileEseguibile=ModuloFiles.pathJoin(self.cartellaFileBinari, "ffprobe")
|
|
62
|
+
comando=f'"{nomefileEseguibile}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "{nomefile}"'
|
|
63
|
+
output=ModuloSystem.systemCallReturnOutput(comando,None)
|
|
64
|
+
output=ModuloStringhe.normalizzaEol(output).replace("\n","")
|
|
65
|
+
return float(output)
|
|
66
|
+
|
|
67
|
+
def imagesToVideo(self,filesImmaginiPattern:str,nomefileVideoOut:str,fpsIn:int,fpsOut:int):
|
|
68
|
+
nomefileEseguibile=ModuloFiles.pathJoin(self.cartellaFileBinari, "ffmpeg")
|
|
69
|
+
comando=f'"{nomefileEseguibile}" -r {fpsIn} -pattern_type glob -i "{filesImmaginiPattern}" -vf "fps={fpsOut}" -c:v libx265 "{nomefileVideoOut}"'
|
|
70
|
+
output=ModuloSystem.systemCallReturnOutput(comando,None)
|
|
71
|
+
return output
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
from modulitiz_micro.rete.ModuloNetworking import ModuloNetworking
|
|
4
|
+
from modulitiz_nano.ModuloStringhe import ModuloStringhe
|
|
5
|
+
from modulitiz_nano.exceptions.ExceptionRuntime import ExceptionRuntime
|
|
6
|
+
from modulitiz_nano.files.ModuloFiles import ModuloFiles
|
|
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 ExceptionRuntime("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,211 @@
|
|
|
1
|
+
import ftplib
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from modulitiz_mini.rete.ftp.FtpReturnBean import FtpReturnBean
|
|
5
|
+
from modulitiz_nano.ModuloListe import ModuloListe
|
|
6
|
+
from modulitiz_nano.ModuloStringhe import ModuloStringhe
|
|
7
|
+
from modulitiz_nano.files.ModuloFiles import ModuloFiles
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ModuloFtp(object):
|
|
11
|
+
DEFAULT_FTP_PORT=ftplib.FTP_PORT
|
|
12
|
+
|
|
13
|
+
def __init__(self,host:str,username:str,password:str):
|
|
14
|
+
self.host=host
|
|
15
|
+
self.port=self.DEFAULT_FTP_PORT
|
|
16
|
+
self.username=username
|
|
17
|
+
self.password=password
|
|
18
|
+
self.conn:ftplib.FTP|None=None
|
|
19
|
+
self.isConnected=False
|
|
20
|
+
|
|
21
|
+
def connect(self)->str:
|
|
22
|
+
conn=ftplib.FTP(encoding=ModuloStringhe.CODIFICA_LATIN1)
|
|
23
|
+
try:
|
|
24
|
+
conn.connect(self.host,self.port)
|
|
25
|
+
welcomeMsg=conn.welcome
|
|
26
|
+
except UnicodeDecodeError as udError:
|
|
27
|
+
welcomeMsg=udError.object.decode(ModuloStringhe.CODIFICA_ASCII,'ignore')
|
|
28
|
+
conn.login(self.username,self.password)
|
|
29
|
+
self.conn=conn
|
|
30
|
+
self.isConnected=True
|
|
31
|
+
return welcomeMsg
|
|
32
|
+
|
|
33
|
+
def uploadCartella(self,rootLocal:str,rootRemote:str,
|
|
34
|
+
excludeFiles:list|tuple,excludeDirs:list|tuple,
|
|
35
|
+
minByteSize:int|None,maxByteSize:int|None):
|
|
36
|
+
rootLocal=ModuloFiles.normalizzaPercorsoLocale(rootLocal)
|
|
37
|
+
rootRemote=ModuloFiles.normalizzaPercorsoRemoto(rootRemote)
|
|
38
|
+
countFiles=countDirs=0
|
|
39
|
+
|
|
40
|
+
for percorsoLocaleRel,percorsoLocaleAbs,folders,nomefiles in ModuloFiles.walk(rootLocal,excludeFiles,excludeDirs,minByteSize,maxByteSize):
|
|
41
|
+
percorso_remoto_abs=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(rootRemote,percorsoLocaleRel))
|
|
42
|
+
# carico i file contenuti nella cartella corrente
|
|
43
|
+
for nomefile in nomefiles:
|
|
44
|
+
self.uploadFile(percorsoLocaleAbs,percorso_remoto_abs,nomefile,False)
|
|
45
|
+
countFiles+=1
|
|
46
|
+
yield FtpReturnBean(percorso_remoto_abs,nomefile,True,countFiles,countDirs)
|
|
47
|
+
# upload folders
|
|
48
|
+
for cartella in folders:
|
|
49
|
+
cartella=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(percorso_remoto_abs,cartella))
|
|
50
|
+
try:
|
|
51
|
+
self.conn.mkd(cartella)
|
|
52
|
+
except Exception:
|
|
53
|
+
pass
|
|
54
|
+
countDirs+=1
|
|
55
|
+
yield FtpReturnBean(percorso_remoto_abs,cartella,False,countFiles,countDirs)
|
|
56
|
+
|
|
57
|
+
def uploadFile(self,pathLocal:str,pathRemote:str,filename:str,renameIfExist:bool)->str:
|
|
58
|
+
filenameLocal=ModuloFiles.pathJoin(pathLocal,filename)
|
|
59
|
+
filenameRemote=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(pathRemote,filename))
|
|
60
|
+
if renameIfExist is True and self.isFile(filenameRemote):
|
|
61
|
+
filenameRemote=ModuloStringhe.addTimestamp(filenameRemote)
|
|
62
|
+
# carico il file
|
|
63
|
+
with open(filenameLocal,'rb') as fp:
|
|
64
|
+
self.conn.storbinary("STOR "+filenameRemote,fp)
|
|
65
|
+
return filenameRemote
|
|
66
|
+
|
|
67
|
+
def downloadCartella(self,pathRemote:str,pathLocal:str,excludeFiles: list|tuple,excludeDirs: list|tuple):
|
|
68
|
+
pathRemote=ModuloFiles.normalizzaPercorsoRemoto(pathRemote)
|
|
69
|
+
return self.__downloadCartella(pathRemote,pathLocal,excludeFiles,excludeDirs)
|
|
70
|
+
|
|
71
|
+
def downloadFile(self,filePathRemote:str,filePathLocal:str):
|
|
72
|
+
filePathRemote=ModuloFiles.normalizzaPercorsoRemoto(filePathRemote)
|
|
73
|
+
filePathLocal=ModuloFiles.normalizzaPercorsoLocale(filePathLocal)
|
|
74
|
+
# creo le cartelle locali
|
|
75
|
+
pathDirLocal=os.path.dirname(filePathLocal)
|
|
76
|
+
os.makedirs(pathDirLocal,exist_ok=True)
|
|
77
|
+
# scarico il file
|
|
78
|
+
with open(filePathLocal,"wb") as fp:
|
|
79
|
+
self.conn.retrbinary("RETR "+filePathRemote,fp.write)
|
|
80
|
+
|
|
81
|
+
def eliminaCartella(self,pathRemote:str,excludeFiles: list|tuple,excludeDirs: list|tuple):
|
|
82
|
+
pathRemote=ModuloFiles.normalizzaPercorsoRemoto(pathRemote)
|
|
83
|
+
return self.__eliminaCartella(pathRemote,'.',excludeFiles,excludeDirs)
|
|
84
|
+
|
|
85
|
+
def listaContenutoCartella(self,pathRemote:str)->list:
|
|
86
|
+
elements = []
|
|
87
|
+
if self.isFile(pathRemote):
|
|
88
|
+
return elements
|
|
89
|
+
if not pathRemote.startswith(('.','/')):
|
|
90
|
+
pathRemote="./"+pathRemote
|
|
91
|
+
cmd = "NLST -a "+pathRemote
|
|
92
|
+
try:
|
|
93
|
+
self.conn.retrlines(cmd, elements.append)
|
|
94
|
+
elements.sort()
|
|
95
|
+
# elimino . e ..
|
|
96
|
+
elements=elements[2:]
|
|
97
|
+
except ftplib.error_perm:
|
|
98
|
+
pass
|
|
99
|
+
return elements
|
|
100
|
+
|
|
101
|
+
def mkdirs(self,pathRemote:str):
|
|
102
|
+
pathRemote=ModuloFiles.normalizzaPercorsoRemoto(pathRemote)
|
|
103
|
+
folders=ModuloListe.eliminaElementiVuoti(pathRemote.split("/"))
|
|
104
|
+
pathCurrent=""
|
|
105
|
+
for folder in folders:
|
|
106
|
+
pathCurrent=ModuloFiles.normalizzaPercorsoRemoto(ModuloFiles.pathJoin(pathCurrent,folder))
|
|
107
|
+
try:
|
|
108
|
+
self.conn.mkd(pathCurrent)
|
|
109
|
+
except Exception:
|
|
110
|
+
pass
|
|
111
|
+
|
|
112
|
+
def chiudi(self):
|
|
113
|
+
"""
|
|
114
|
+
chiude la connessione
|
|
115
|
+
"""
|
|
116
|
+
if not self.isConnected:
|
|
117
|
+
return
|
|
118
|
+
try:
|
|
119
|
+
self.conn.quit()
|
|
120
|
+
except Exception:
|
|
121
|
+
self.conn.close()
|
|
122
|
+
finally:
|
|
123
|
+
self.isConnected = False
|
|
124
|
+
|
|
125
|
+
def getFileSize(self,filePathRemote:str)->int:
|
|
126
|
+
try:
|
|
127
|
+
self.conn.voidcmd('TYPE I')
|
|
128
|
+
size=self.conn.size(filePathRemote)
|
|
129
|
+
return size
|
|
130
|
+
except Exception:
|
|
131
|
+
return -1
|
|
132
|
+
|
|
133
|
+
def isFile(self,element:str)->bool:
|
|
134
|
+
"""
|
|
135
|
+
controlla se un oggetto e' un file o una cartella
|
|
136
|
+
"""
|
|
137
|
+
return self.getFileSize(element)>=0
|
|
138
|
+
|
|
139
|
+
def goParentDir(self):
|
|
140
|
+
# bisogna per forza usare 2 punti, se c'e' anche lo slash finale non funziona
|
|
141
|
+
self.conn.cwd("..")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def __downloadCartella(self,pathRemote:str,pathLocal:str,
|
|
145
|
+
excludeFiles: list|tuple,excludeDirs: list|tuple,
|
|
146
|
+
countFiles:int=0,countDirs:int=1):
|
|
147
|
+
"""
|
|
148
|
+
funzione ricorsiva
|
|
149
|
+
"""
|
|
150
|
+
elements=self.listaContenutoCartella(pathRemote)
|
|
151
|
+
for element in elements:
|
|
152
|
+
elementRelPath=element
|
|
153
|
+
if elementRelPath.startswith("/"):
|
|
154
|
+
elementRelPath=elementRelPath[1:]
|
|
155
|
+
elementRemote=ModuloFiles.normalizzaPercorsoRemoto(element)
|
|
156
|
+
elementLocal=ModuloFiles.pathJoin(pathLocal,elementRelPath)
|
|
157
|
+
# controllo se l'elemento e' un file o una cartella
|
|
158
|
+
if self.isFile(elementRemote):
|
|
159
|
+
os.makedirs(os.path.dirname(elementLocal),exist_ok=True)
|
|
160
|
+
if elementRemote not in excludeFiles:
|
|
161
|
+
self.downloadFile(elementRemote,elementLocal)
|
|
162
|
+
countFiles+=1
|
|
163
|
+
yield FtpReturnBean(pathRemote,element,True,countFiles,countDirs)
|
|
164
|
+
else:
|
|
165
|
+
countDirs+=1
|
|
166
|
+
# creo la cartella
|
|
167
|
+
if ModuloListe.stringContainsCollection(elementRemote,excludeDirs):
|
|
168
|
+
yield FtpReturnBean(pathRemote,element,True,countFiles,countDirs)
|
|
169
|
+
break
|
|
170
|
+
os.makedirs(elementLocal,exist_ok=True)
|
|
171
|
+
yield FtpReturnBean(pathRemote,element,False,countFiles,countDirs)
|
|
172
|
+
# entro ed elaboro la sottocartella
|
|
173
|
+
for bean in self.__downloadCartella(elementRemote,pathLocal,excludeFiles,excludeDirs,
|
|
174
|
+
countFiles,countDirs):
|
|
175
|
+
countFiles=bean.countFiles
|
|
176
|
+
countDirs=bean.countDirs
|
|
177
|
+
yield bean
|
|
178
|
+
|
|
179
|
+
def __eliminaCartella(self,rootRemote:str,pathRemoteRel:str,
|
|
180
|
+
excludeFiles: list|tuple,excludeDirs: list|tuple):
|
|
181
|
+
"""
|
|
182
|
+
funzione ricorsiva
|
|
183
|
+
"""
|
|
184
|
+
countFiles=countDirs=0
|
|
185
|
+
elements=self.listaContenutoCartella(pathRemoteRel)
|
|
186
|
+
for element in elements:
|
|
187
|
+
elementRemoteRel=element
|
|
188
|
+
elementRemoteAbs=ModuloFiles.pathJoin("/",element)
|
|
189
|
+
# controllo se e' un file o una cartella
|
|
190
|
+
if self.isFile(elementRemoteAbs):
|
|
191
|
+
if ModuloListe.collectionContainsString(excludeDirs,pathRemoteRel) is False and elementRemoteRel not in excludeFiles:
|
|
192
|
+
self.conn.delete(elementRemoteAbs)
|
|
193
|
+
countFiles+=1
|
|
194
|
+
yield FtpReturnBean(pathRemoteRel,element,True,countFiles,countDirs)
|
|
195
|
+
else:
|
|
196
|
+
# entro ed elaboro la sottocartella
|
|
197
|
+
if not ModuloListe.collectionContainsString(excludeDirs,elementRemoteRel):
|
|
198
|
+
countFilesSubDir=countDirsSubDir=0
|
|
199
|
+
for bean in self.__eliminaCartella(rootRemote,elementRemoteRel,excludeFiles,excludeDirs):
|
|
200
|
+
countFilesSubDir=bean.countFiles+countFiles
|
|
201
|
+
countDirsSubDir=bean.countDirs+countDirs
|
|
202
|
+
bean.countFiles=countFilesSubDir
|
|
203
|
+
bean.countDirs=countDirsSubDir
|
|
204
|
+
yield bean
|
|
205
|
+
countFiles=countFilesSubDir
|
|
206
|
+
countDirs=countDirsSubDir
|
|
207
|
+
# cancello la cartella dopo aver cancellato i file al suo interno
|
|
208
|
+
if not ModuloListe.collectionContainsString(excludeDirs,elementRemoteRel):
|
|
209
|
+
self.conn.rmd(elementRemoteAbs)
|
|
210
|
+
countDirs+=1
|
|
211
|
+
yield FtpReturnBean(pathRemoteRel,element,False,countFiles,countDirs)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modulitiz_mini
|
|
3
|
+
Version: 2.12.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.12
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: modulitiz-binaries>=2
|
|
12
|
+
Requires-Dist: cryptography>=41.0
|
|
13
|
+
Requires-Dist: pypdf==6.8.0
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# modulitiz-mini
|
|
17
|
+
|
|
18
|
+
It's a Python library that contains daily use or generic functions.
|
|
19
|
+
The difference between "micro" is that it requires other dependencies.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install -U modulitiz_mini
|
|
27
|
+
```
|
|
28
|
+
The other required dependencies will be installed automatically.
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from modulitiz_mini.ModuloRsa import ModuloRsa
|
|
34
|
+
|
|
35
|
+
moduloRsa=ModuloRsa()
|
|
36
|
+
moduloRsa.generateKeys()
|
|
37
|
+
|
|
38
|
+
# returns cripted string
|
|
39
|
+
moduloRsa.encrypt("test")
|
|
40
|
+
...
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Contributing
|
|
44
|
+
|
|
45
|
+
If you find any bug you can write me at [sderfo1234@altervista.org](mailto:sderfo1234@altervista.org)
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
modulitiz_mini/ModuloRsa.py,sha256=YVgr4GATmyZ1-Xz597CdlXf7jflmxpovZQRqSbu9grw,2580
|
|
2
|
+
modulitiz_mini/django/ModuloDjango.py,sha256=RGocBue9Rr9HbaxxDnx23gtdOsNUV9DM9aT5KKqJ5NI,525
|
|
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=CjIs7UU9mqebmmVlJSzdPnXWWp4CCB-bHKcXgl2arGo,751
|
|
7
|
+
modulitiz_mini/files/pdf/WritePdf.py,sha256=pRi6DWMq9mDlxEMihEHSFKsrwcHzc1bAurLdOf2KRWk,302
|
|
8
|
+
modulitiz_mini/multimedia/ModuloMultimedia.py,sha256=GFR1fB3DojMEnaygyxKi7NzfgkfMKVIeOof5GtPz61U,3294
|
|
9
|
+
modulitiz_mini/rete/ModuloTor.py,sha256=tfiyxCCJIjE6OoADBayzGbPdJrSHvVSffJCVzQqQVeU,1304
|
|
10
|
+
modulitiz_mini/rete/ftp/FtpReturnBean.py,sha256=WJhv-idDa_L8MeTxDkgjz8D8JxOP3jrwoQAWig-1i50,257
|
|
11
|
+
modulitiz_mini/rete/ftp/ModuloFtp.py,sha256=Y3DTJrxA8kXLVefgiB8IN4exIB2-0x7lM33F8LaeNZ0,7931
|
|
12
|
+
modulitiz_mini-2.12.0.dist-info/licenses/LICENSE,sha256=gmuE_3LV2kDZCizi2b9sBBrgQEFi3EFeybDbaTyZ_cc,1084
|
|
13
|
+
modulitiz_mini-2.12.0.dist-info/METADATA,sha256=Zwo1clgxtyQTiCfaf9UuIeBhzuGprn6fPB2egAz9kHQ,1223
|
|
14
|
+
modulitiz_mini-2.12.0.dist-info/WHEEL,sha256=d5yzEvgM0c12ABT3toN2kBv6KW3qPo4KmF0bmVLQeZY,93
|
|
15
|
+
modulitiz_mini-2.12.0.dist-info/top_level.txt,sha256=OxUbMOvprrGDegA-38GcCVHtPSP3X-d91EseClu8VN4,15
|
|
16
|
+
modulitiz_mini-2.12.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
modulitiz_mini
|