Refacere repo
This commit is contained in:
27
Python_module_2/python_001.py
Normal file
27
Python_module_2/python_001.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/home/andrei/it_school/bin/python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def gestioneaza_fiesere(director):
|
||||
# Verificam daca directorul exista
|
||||
if os.path.exists(director):
|
||||
print(f"Directorul '{director}' exista. Fisierele din acest director sunt:")
|
||||
# Listam fisierele din director
|
||||
for nume_fisier in os.listdir(director):
|
||||
cale_fisier = os.path.join(director, nume_fisier)
|
||||
if os.path.isfile(cale_fisier):
|
||||
dimensiune_kb = os.path.getsize(cale_fisier) / 1024
|
||||
print(f"- {nume_fisier} ({dimensiune_kb:.2f} KB)")
|
||||
else:
|
||||
print(f"Directorul '{nume_fisier}' nu este un fisier.")
|
||||
else:
|
||||
os.mkdir(director)
|
||||
print(f"Directorul '{director}' nu exista. A fost creat.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
director_de_gestionat = sys.argv[1]
|
||||
gestioneaza_fiesere(director_de_gestionat)
|
||||
else:
|
||||
print("Va rugam sa specficati un director ca argument la linia de comanda.")
|
||||
24
Python_module_2/python_002.py
Executable file
24
Python_module_2/python_002.py
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/home/andrei/it_school/bin/python3
|
||||
|
||||
import sys
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 4:
|
||||
print("Eroare: Trebuie sa furnizati cel putin trei argumente numerice.")
|
||||
|
||||
numbers = []
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
try:
|
||||
num = float(arg)
|
||||
numbers.append(num)
|
||||
except ValueError:
|
||||
print(f"Eroare: '{arg}' nu este un numar valid.")
|
||||
return
|
||||
total = sum(numbers)
|
||||
average = total / len(numbers)
|
||||
print(f"Suma: {total}")
|
||||
print(f"Media: {average}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
14
Python_module_2/python_003.py
Executable file
14
Python_module_2/python_003.py
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/home/andrei/it_school/bin/python3
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def check_service_status(service_name):
|
||||
try:
|
||||
# Run the systemctl command to check the service status
|
||||
result = subprocess.run(['systemctl', 'is-active', service_name], capture_output=True, text=True)
|
||||
return result.stdout.strip() == 'active'
|
||||
except Exception as e:
|
||||
print(f"Error checking service status: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user