modulitiz-micro 2.38.0__py311-none-any.whl → 2.39.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.
@@ -0,0 +1,8 @@
1
+ class ModuleEnum(object):
2
+ @staticmethod
3
+ def isValueIn(value, enumClass)->bool:
4
+ try:
5
+ enumClass(value)
6
+ except ValueError:
7
+ return False
8
+ return True
@@ -38,6 +38,7 @@ class ModuloFunzioni(object):
38
38
  def getClassesFromFileSource(filename:str)->list[str]:
39
39
  """
40
40
  Reads content of file, then finds all classes in it.
41
+ Also counts inner classes.
41
42
  """
42
43
  module=ast.parse(ModuloFiles.readFileText(filename,True))
43
44
  classes=[node.name for node in ast.walk(module) if isinstance(node,ast.ClassDef)]
@@ -3,7 +3,7 @@ import json
3
3
  from modulitiz_micro.ModuloDate import ModuloDate
4
4
  from modulitiz_micro.ModuloListe import ModuloListe
5
5
  from modulitiz_micro.eccezioni.http.EccezioneHttpGeneric import EccezioneHttpGeneric
6
- from modulitiz_micro.files import ModuloLogging
6
+ from modulitiz_micro.files.ModuloLogging import ModuloLogging
7
7
  from modulitiz_micro.rete.http.ModuloHttp import ModuloHttp
8
8
  from modulitiz_micro.rete.http.ModuloHttpUtils import ModuloHttpUtils
9
9
 
@@ -52,8 +52,7 @@ class ModuloNumeri(object):
52
52
  Converte una stringa in numero intero.
53
53
  """
54
54
  try:
55
- ris=int(valore)
56
- return ris
55
+ return int(valore)
57
56
  except ValueError:
58
57
  return None
59
58
 
@@ -62,9 +61,7 @@ class ModuloNumeri(object):
62
61
  """
63
62
  Converte un numero intero in valore booleano (o binario).
64
63
  """
65
- if int(valore)==1:
66
- return True
67
- return False
64
+ return int(valore)==1
68
65
 
69
66
  @staticmethod
70
67
  def boolToInt(valore:bool)->int:
@@ -0,0 +1,46 @@
1
+ from modulitiz_micro.ModuloNumeri import ModuloNumeri
2
+ from modulitiz_micro.ModuloStringhe import ModuloStringhe
3
+ from modulitiz_micro.eccezioni.EccezioneRuntime import EccezioneRuntime
4
+ from modulitiz_micro.eccezioni.http.EccezioneHttp import EccezioneHttp
5
+ from modulitiz_micro.files.ModuloLogging import ModuloLogging
6
+ from modulitiz_micro.iot.beans.IotDeviceBean import IotDeviceBean
7
+ from modulitiz_micro.iot.enums.IotOSEnum import IotOSEnum
8
+ from modulitiz_micro.iot.espurna.ModuleEspurna import ModuleEspurna
9
+ from modulitiz_micro.rete.http.ModuloHttp import ModuloHttp
10
+
11
+
12
+ class ModuleIotDevice(object):
13
+ def __init__(self, logger:ModuloLogging|None, deviceBean:IotDeviceBean):
14
+ self.__logger=logger
15
+ self.__deviceBean=deviceBean
16
+
17
+ def getRelayStatus(self, relayNum:int)->bool:
18
+ """
19
+ @param relayNum: Depending on which OS you choose, can be relative (0, 1, ...) or GPIO
20
+ """
21
+ if self.__deviceBean.os==IotOSEnum.ESPURNA:
22
+ url=ModuleEspurna.URL_GET_RELAY.format(ip=self.__deviceBean.ip,relayNum=relayNum,apiKey=self.__deviceBean.key)
23
+ else:
24
+ raise EccezioneRuntime("Iot os '%s' not known"%(self.__deviceBean.os,))
25
+ return ModuloNumeri.intToBool(ModuloNumeri.strToInt(self.__sendRequest(url)))
26
+
27
+ def setRelayStatus(self, relayNum:int, status:bool):
28
+ """
29
+ @param relayNum: Depending on which OS you choose, can be relative (0, 1, ...) or GPIO
30
+ @param status: value to set, can only be false or true
31
+ """
32
+ if self.__deviceBean.os==IotOSEnum.ESPURNA:
33
+ statusStr=str(ModuloNumeri.boolToInt(status))# TODO check if works or if u have to use value 2 (toggle)
34
+ url=ModuleEspurna.URL_SET_RELAY.format(ip=self.__deviceBean.ip,relayNum=relayNum,apiKey=self.__deviceBean.key,status=statusStr)
35
+ else:
36
+ raise EccezioneRuntime("Iot os '%s' not known"%(self.__deviceBean.os,))
37
+ # TODO: check output
38
+ self.__sendRequest(url)
39
+
40
+ def __sendRequest(self, url:str)->str:
41
+ http=ModuloHttp(url,self.__logger,False)
42
+ http.setUserAgent()
43
+ bean=http.doGet(0, False)
44
+ if bean.status!=ModuloHttp.STATUS_OK:
45
+ raise EccezioneHttp(bean.status)
46
+ return bean.responseBody.decode(ModuloStringhe.CODIFICA_UTF8)
@@ -0,0 +1,13 @@
1
+ from modulitiz_micro.iot.enums.IotOSEnum import IotOSEnum
2
+
3
+
4
+ class IotDeviceBean(object):
5
+ """
6
+ Classe che definisce la struttura di una voce complessa del file di configurazione del programma.
7
+ Elenca le proprietà che identificano un dispositivo/sensore Internet Of Things.
8
+ """
9
+
10
+ def __init__(self,ip:str, os:IotOSEnum, key:str):
11
+ self.ip=ip
12
+ self.os=os
13
+ self.key=key
@@ -0,0 +1,12 @@
1
+ from enum import StrEnum
2
+ from enum import unique
3
+
4
+
5
+ @unique
6
+ class IotOSEnum(StrEnum):
7
+ """
8
+ Supported operating systems for Iot devices
9
+ """
10
+ ESPURNA="ESPURNA"
11
+ TASMOTA="TASMOTA"
12
+ TIZS="TIZS"
@@ -0,0 +1,3 @@
1
+ class ModuleEspurna(object):
2
+ URL_GET_RELAY="http://{ip}/api/relay/{relayNum}?apikey={apiKey}"
3
+ URL_SET_RELAY=URL_GET_RELAY+"&value={status}"
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import re
2
3
  import socket
3
4
  from contextlib import closing
4
5
  from uuid import getnode
@@ -46,22 +47,26 @@ class ModuloNetworking(object):
46
47
  return False
47
48
 
48
49
  @staticmethod
49
- def checkPing(indirizzoIp:str)->bool:
50
- # costruisco il comando a seconda del sistema operativo
51
- comando="ping "
50
+ def checkPing(ipAddress:str)->bool:
51
+ # build command
52
+ cmd="ping "
53
+ regexPercPacketsLost=r"(\d{1,3})\% "
52
54
  if ModuloSystem.isWindows():
53
- comando+="-n"
55
+ cmd+="-n"
56
+ regexPercPacketsLost=r"\("+regexPercPacketsLost
54
57
  elif os.name=='posix':
55
- comando+="-c"
58
+ cmd+="-c"
59
+ regexPercPacketsLost=r", "+regexPercPacketsLost
56
60
  else:
57
61
  raise EccezioneRuntime("Tipologia del sistema operativo non riconosciuta: "+os.name)
58
- comando+=" 1 " + indirizzoIp
59
- # eseguo il comando
60
- outputComando=ModuloStringhe.normalizzaEol(ModuloSystem.systemCallReturnOutput(comando,None))
61
- righe=outputComando.split("\n")
62
- righe=ModuloListe.eliminaElementiVuoti(righe)
63
- for riga in righe:
64
- if ModuloStringhe.contains(riga, "%"):
65
- numPacchettiPersi=int(riga.split("=")[1].split("(")[0].strip())
66
- return numPacchettiPersi==0
62
+ cmd+=" 1 "+ipAddress
63
+ # execute command
64
+ outputComando=ModuloStringhe.normalizzaEol(ModuloSystem.systemCallReturnOutput(cmd,None))
65
+ rows=outputComando.split("\n")
66
+ rows=ModuloListe.eliminaElementiVuoti(rows)
67
+ for row in rows:
68
+ if ModuloStringhe.contains(row, "%"):
69
+ regexOutput=re.search(regexPercPacketsLost,row)
70
+ if regexOutput is not None:
71
+ return int(regexOutput.group(1).strip())==0
67
72
  return False
@@ -83,6 +83,7 @@ class ModuloHttp(object):
83
83
  ctx=ssl.create_default_context()
84
84
  ctx.check_hostname=False
85
85
  ctx.verify_mode=ssl.CERT_NONE
86
+ # send request
86
87
  with urllib.request.urlopen(self.__requestObj,context=ctx) as response:
87
88
  responseBody=response.read()
88
89
  responseHeaders=response.info()
@@ -47,15 +47,15 @@ class ModuloBuildWheel(object):
47
47
  {}""".format(ModuloColorText.GRASSETTO,msg,self.versionOld,ModuloColorText.DEFAULT))
48
48
  # change dir
49
49
  os.chdir(self.percorsoCartellaSource)
50
- if self.__doUnitTests() is True:
50
+ if self.__doUnitTests():
51
51
  return
52
52
  # aggiorno versione
53
53
  self.moduloToml.updateVersion(self.versionNew)
54
54
  # building wheel
55
55
  ModuloSystem.systemCallPrintOutput(f'{self.CMD_PYTHON} -m pip install -U build twine==6.0.1',None)
56
56
  print()
57
- percorsoCartellaOut=ModuloFiles.pathJoin(self.percorsoCartellaRoot,"wheel")
58
- cmd='{} -m build --wheel --outdir "{}"'.format(self.CMD_PYTHON,percorsoCartellaOut)
57
+ pathFolderWheel=ModuloFiles.pathJoin(self.percorsoCartellaRoot,"wheel")
58
+ cmd='{} -m build --wheel --outdir "{}"'.format(self.CMD_PYTHON,pathFolderWheel)
59
59
  ModuloSystem.systemCallPrintOutput(cmd,None)
60
60
  # deleting temporary dirs
61
61
  print()
@@ -63,15 +63,16 @@ class ModuloBuildWheel(object):
63
63
  shutil.rmtree(ModuloFiles.pathJoin(self.percorsoCartellaSource,self.moduleName+".egg-info"))
64
64
  # install wheel
65
65
  self.filenameWheel=self.PATTERN_NOMEFILE_WHEEL.format(self.moduleName,self.versionNew,self.moduloToml.retrieveMinPyVersion())
66
- percorsoWheel=ModuloFiles.pathJoin(percorsoCartellaOut,self.filenameWheel)
66
+ percorsoWheel=ModuloFiles.pathJoin(pathFolderWheel,self.filenameWheel)
67
67
  cmd='{} -m pip install -U "{}"'.format(self.CMD_PYTHON,percorsoWheel)
68
68
  ModuloSystem.systemCallPrintOutput(cmd,None)
69
+ # upload to web
69
70
  print()
70
71
  print("Uploading to Pypi")
71
72
  cmd='{} -m twine upload "{}"'.format(self.CMD_PYTHON,percorsoWheel)
72
73
  ModuloSystem.systemCallPrintOutput(cmd,None)
73
74
  # delete wheel
74
- os.remove(percorsoWheel)
75
+ shutil.rmtree(pathFolderWheel)
75
76
 
76
77
  def __doUnitTests(self) -> bool:
77
78
  if self.skipUnitTest:
@@ -51,11 +51,14 @@ class ModuloCheckTestNamingConvention(object):
51
51
  return
52
52
  # file name must match class name
53
53
  testClasses=ModuloFunzioni.getClassesFromFileSource(filenameAbs)
54
+ if len(testClasses)==0:
55
+ self.errors.append("File must contain at least 1 class: %s"%(filenameRel,))
56
+ return
54
57
  if len(testClasses)>1:
55
58
  self.errors.append("File must not contain more than 1 class: %s"%(filenameRel,))
56
59
  return
57
60
  baseFilename=ModuloFiles.getBaseFileNameAndExtension(filename)[0]
58
- testClassName=None
61
+ testClassName:str|None=None
59
62
  if not isDecorator:
60
63
  testClassName=testClasses[0]
61
64
  if testClassName!=baseFilename:
@@ -68,6 +71,9 @@ class ModuloCheckTestNamingConvention(object):
68
71
  return
69
72
  # source class name must equals class test
70
73
  if not isDecorator:
74
+ if ModuloStringhe.isEmpty(testClassName):
75
+ self.errors.append("Test class name doesn't match source class name: %s"%(filenameRel,))
76
+ return
71
77
  sourceClassName=ModuloFunzioni.getClassesFromFileSource(ModuloFiles.pathJoin(self.pathSource,sourceFilenameRel))[0]
72
78
  if not testClassName.startswith(sourceClassName):
73
79
  self.errors.append("Test class name doesn't match source class name: %s"%(filenameRel,))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: modulitiz_micro
3
- Version: 2.38.0
3
+ Version: 2.39.0
4
4
  Summary: Raccolta dei miei moduli - versione micro
5
5
  Author-email: tiz <sderfo1234@altervista.org>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,10 +1,11 @@
1
+ modulitiz_micro/ModuleEnum.py,sha256=1HVhYspeTyE8nEuYSDkQXuRUISEggR_Cejqn3uGMOPQ,159
1
2
  modulitiz_micro/ModuloBase64.py,sha256=dW1TP8TkIuOqAbbJcvTAo4xEurHl8NBs8lQTuHY_HaU,1866
2
3
  modulitiz_micro/ModuloColorText.py,sha256=_sMSh9xZ-qbpa35oaSGdzQJKpFiGLsCHtM4P1HQWcTE,828
3
4
  modulitiz_micro/ModuloDate.py,sha256=niDdyhWUkRNOfxK7G-RkvvuGJdPCCJRpL3-TFZiuUOE,7997
4
- modulitiz_micro/ModuloFunzioni.py,sha256=K-8rwVeSEgKCCLQSIXVHZ69YhLRCy3ILYxZXZOy95eI,1947
5
+ modulitiz_micro/ModuloFunzioni.py,sha256=n2wNRCLg-l2EvUtZu2K2yT-oE9XJN8nYSDjzECYVqNw,1977
5
6
  modulitiz_micro/ModuloListe.py,sha256=aWqnJX2JAk_LApUQvObkc6P89qXJzFviljJeKa39KC8,3581
6
- modulitiz_micro/ModuloMeteo.py,sha256=Tr3lRW-lvk9XKm_M-ZvohJ6ueA9oA4TbP6BaZVeCl60,2310
7
- modulitiz_micro/ModuloNumeri.py,sha256=aWTKRwVzFSXKZ7GGwJjl6xFZIE3xgAgq6cezVLw1qwM,2806
7
+ modulitiz_micro/ModuloMeteo.py,sha256=uiENrmpkRVFX-qaFoxH5BfuEkob-1KqiVmXd734qeCk,2324
8
+ modulitiz_micro/ModuloNumeri.py,sha256=0r2t8QHM_e-8GpFg_jvPEnb2QWlwJ0eVTMKDnak9nV0,2765
8
9
  modulitiz_micro/ModuloPyinstaller.py,sha256=TiDtOsDAYkK1EVXNC0qWVCgBoCo2puH6HIVL6gMLqAw,845
9
10
  modulitiz_micro/ModuloSeriale.py,sha256=k9po45AFiYc4d-j4BHQsaQFakW8Vs-ZlHu5Bxk7AaDg,1895
10
11
  modulitiz_micro/ModuloStatistiche.py,sha256=ANDTatAfDxGfxN5ZusQxWZnqjUCA8z_kPyQR69sCJ_w,1316
@@ -47,6 +48,10 @@ modulitiz_micro/files/git/exceptions/EccezioneGit.py,sha256=SfBBBvfo7XXJeUYpF61I
47
48
  modulitiz_micro/gestionedom/GestioneDom.py,sha256=LjmFKiBLNc0yn9m7Z27u2rpU4UcF9778Ljm8aYhdBcY,1350
48
49
  modulitiz_micro/init/AbstractBasicInit.py,sha256=hp2U5ZSIaWtwMuohlsk2WHjPRKxJrQyavPsLPlbejtQ,582
49
50
  modulitiz_micro/init/AbstractInit.py,sha256=0dxk2o6Sx3Ii4UzYvIMeWOClxdbmctO3M4XoMpk2v7k,228
51
+ modulitiz_micro/iot/ModuleIotDevice.py,sha256=O9rciBfaE7ImrbCoCvJfEampwK7J_ntKuxIkf40DW70,2108
52
+ modulitiz_micro/iot/beans/IotDeviceBean.py,sha256=lSxK80JW3PmhlbKMNX8-U1fjwciFp_MaxH8jYtJLGas,374
53
+ modulitiz_micro/iot/enums/IotOSEnum.py,sha256=jMGWbPo0gafFdog7f9VBX_vJQ86XiXYUcxVg-RM9-s8,191
54
+ modulitiz_micro/iot/espurna/ModuleEspurna.py,sha256=ueL-hDpaGzmU7mUvpLmu3YerJCJqrfTzATfOVeasD9I,142
50
55
  modulitiz_micro/keylogger/EccezioneKeyLogger.py,sha256=BEhO2y8haOBfuboJHkZI_FyTmFsVw_uHKkQvjyBFkbk,212
51
56
  modulitiz_micro/keylogger/ModuloKeylogger.py,sha256=7envuMiJVPGWDTzy9iq8tc9fPj1UKuaOfFz6viR8eDQ,1939
52
57
  modulitiz_micro/multithread/ModuloThread.py,sha256=BB9t6tCGjDT4JuoEQ61AJmYiqY-oycjub3zq9gFVI_E,982
@@ -54,11 +59,11 @@ modulitiz_micro/multithread/ModuloThreadLogger.py,sha256=oQql4C3qrqOUksvcdrgZxgW
54
59
  modulitiz_micro/multithread/ModuloThreadWithCallbackError.py,sha256=RQWfLDssdVmXoewrWaCdVSrySjbElh2iNBqlSslg0W8,724
55
60
  modulitiz_micro/nlp/ModuloNlp.py,sha256=h7ca9kVLKRcqHMK6rCVOambdpPfh-ehVSppP2nYGxVA,799
56
61
  modulitiz_micro/nlp/ModuloNlpDateAndTime.py,sha256=QCURYksP4-z_u03CVzcESLp5EtdIx2GNXDNYgYOPGuU,1851
57
- modulitiz_micro/rete/ModuloNetworking.py,sha256=ouaArJo-sc_eKrTaJW3rzk6zLtNtpfI8YGHQboi_urE,1999
62
+ modulitiz_micro/rete/ModuloNetworking.py,sha256=3tatSHP4s2AeBBZM4nsyZFHdhlXhNIG16C1SsCb6xYk,2114
58
63
  modulitiz_micro/rete/ModuloOpenVpn.py,sha256=t99ofIYhM7q3HnQrvzQbx-6JeyDQqOc1wvg7pxvYo8U,627
59
64
  modulitiz_micro/rete/email/EmailBean.py,sha256=EOKLfBVqwBEkbWfywiUmk2iB5K2uVlykxsh4zB9red8,168
60
65
  modulitiz_micro/rete/email/ModuloEmail.py,sha256=6roT23q15xmo_olXORF19PRwss81tQg-71gGquvs28A,2956
61
- modulitiz_micro/rete/http/ModuloHttp.py,sha256=4IPwfUjwYHHBTavLxnAULOVetKpcE_kFLESWUFgO3w4,4693
66
+ modulitiz_micro/rete/http/ModuloHttp.py,sha256=i7Zfu9aYT14AQpggW2GBdcGRtyHnBfxyjcuuWshPS5s,4711
62
67
  modulitiz_micro/rete/http/ModuloHttpConnectionSafe.py,sha256=w1cLQrnPJXltUeJ4OOtFOTPv5k0J6uNqlrXUzO0UbX4,2936
63
68
  modulitiz_micro/rete/http/ModuloHttpUtils.py,sha256=9r6Z4eT4j4ZH-UyjOQXz_vUaltW-oH9gyyQLZDgVf7s,2350
64
69
  modulitiz_micro/rete/http/beans/HttpResponseBean.py,sha256=7JVywcWURv1I9rYKj4Kt9XLt7387wMZGTMefcsm7E3I,202
@@ -93,12 +98,12 @@ modulitiz_micro/util/spooler/eccezioni/EccezioneSpoolerFull.py,sha256=KEcDisixOS
93
98
  modulitiz_micro/util/unittesting/AbstractOverrideTestUtil.py,sha256=5YX20I-rhl6TpRrqSdNafI1cqBAdTs2sgtOTDjzDn5k,754
94
99
  modulitiz_micro/util/unittesting/AbstractTestUtil.py,sha256=AW9mCj8i_qHrigcXcvvjgdLxa-4Ce0jrwJEZqpPVBxY,297
95
100
  modulitiz_micro/util/unittesting/ModuloRunUnitTest.py,sha256=_YHxjTk_t9wvlCYgS4HSQ657ht7ekSRQsH7i1aKw1LY,774
96
- modulitiz_micro/util/wheel/ModuloBuildWheel.py,sha256=eEnozE5OZGXEMQq9fujhS5tHrzSIQ25lkFTtAt5DAoo,4781
97
- modulitiz_micro/util/wheel/ModuloCheckTestNamingConvention.py,sha256=2J3yE6Ba2EyhXSzH5gcmxHnEUOSGOin9dW_Q6dADsXM,3606
101
+ modulitiz_micro/util/wheel/ModuloBuildWheel.py,sha256=OtZdKTiiU0XhrIjWaFlBx8denZXwWIe-V794YUi8WcE,4786
102
+ modulitiz_micro/util/wheel/ModuloCheckTestNamingConvention.py,sha256=ZGwMtVexRscwVEtiwxgU5ENsItcfsV2NEAcyclcLFgA,3885
98
103
  modulitiz_micro/util/wheel/ModuloToml.py,sha256=774GQ8y6lyhOrT0edJPlLq4TBU7Nq4699q74deGlFW4,1205
99
104
  modulitiz_micro/util/wheel/ModuloWheel.py,sha256=VRS_6kSt62qubBYzkGm91_GWzcIiD0KlSnaqhM_aQnE,338
100
- modulitiz_micro-2.38.0.dist-info/LICENSE,sha256=b-Ia9Hv3N_FviXoFAXG44lDGbk4tCC0fBdduccm8nl0,1086
101
- modulitiz_micro-2.38.0.dist-info/METADATA,sha256=DC7-csHBAdlOGvjt3FXixzhQkp9DlaMdXF7gOFc9ETg,1690
102
- modulitiz_micro-2.38.0.dist-info/WHEEL,sha256=2aRSX09k7pmd4gPs96VOQ860h0v0t30ka6JGHtpC3BY,94
103
- modulitiz_micro-2.38.0.dist-info/top_level.txt,sha256=ESJE0qtNJp3tbKPrffbFVjH511NSjJHxscfpdLjTpA8,16
104
- modulitiz_micro-2.38.0.dist-info/RECORD,,
105
+ modulitiz_micro-2.39.0.dist-info/LICENSE,sha256=b-Ia9Hv3N_FviXoFAXG44lDGbk4tCC0fBdduccm8nl0,1086
106
+ modulitiz_micro-2.39.0.dist-info/METADATA,sha256=nWExoZuR-JAq9R53bpezFLNMOe86Mktd2P0MNxbAF0I,1690
107
+ modulitiz_micro-2.39.0.dist-info/WHEEL,sha256=2aRSX09k7pmd4gPs96VOQ860h0v0t30ka6JGHtpC3BY,94
108
+ modulitiz_micro-2.39.0.dist-info/top_level.txt,sha256=ESJE0qtNJp3tbKPrffbFVjH511NSjJHxscfpdLjTpA8,16
109
+ modulitiz_micro-2.39.0.dist-info/RECORD,,