From 0904bce7ada7fba29c111d5e6a6b5ee5f4d2b50e Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 30 Sep 2021 16:36:58 +0200 Subject: [PATCH] sisr-11-python3 --- sio2/sisr/11-python/creatusr.py | 32 +++++++++++++++++++++++++ sio2/sisr/11-python/delusr.py | 33 ++++++++++++++++++++++++++ sio2/sisr/11-python/ex1.py | 8 +++++++ sio2/sisr/11-python/ex2.py | 28 ++++++++++++++++++++++ sio2/sisr/11-python/ex3.py | 14 +++++++++++ sio2/sisr/11-python/ex4.py | 34 ++++++++++++++++++++++++++ sio2/sisr/11-python/passusr.py | 42 +++++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+) create mode 100755 sio2/sisr/11-python/creatusr.py create mode 100644 sio2/sisr/11-python/delusr.py create mode 100755 sio2/sisr/11-python/ex1.py create mode 100755 sio2/sisr/11-python/ex2.py create mode 100755 sio2/sisr/11-python/ex3.py create mode 100755 sio2/sisr/11-python/ex4.py create mode 100755 sio2/sisr/11-python/passusr.py diff --git a/sio2/sisr/11-python/creatusr.py b/sio2/sisr/11-python/creatusr.py new file mode 100755 index 0000000..125346b --- /dev/null +++ b/sio2/sisr/11-python/creatusr.py @@ -0,0 +1,32 @@ +#!/usr/lib/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ no$ + res = os.system ("getent passwd "+login) + if res != 0: + passw = "pwgen 4 1" + os.system (cmd) + os.system ("pwgen 4 1") + os.system ("echo "+login+passw"|chpasswd) + os.system ("echo "login+passw" >> "+filename+".p$ + else: + print ("Utilisateur "+login+" déjà éxistant") + line = fh.readline() + + fh.close() diff --git a/sio2/sisr/11-python/delusr.py b/sio2/sisr/11-python/delusr.py new file mode 100644 index 0000000..410cfb0 --- /dev/null +++ b/sio2/sisr/11-python/delusr.py @@ -0,0 +1,33 @@ +#!/usr/lib/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ no$ + res = os.system ("getent passwd "+login) + if res != 0: + passw = "pwgen 4 1" + os.system (cmd) + os.system ("pwgen 4 1") + os.system ("echo "+login+passw+"|chpasswd") + os.system ("echo "+login+passw+" >> "+filename+"$ + else: + print ("Utilisateur "+login+" déjà éxistant") + os.system ("sudo userdel -r "+login) + line = fh.readline() + + fh.close() diff --git a/sio2/sisr/11-python/ex1.py b/sio2/sisr/11-python/ex1.py new file mode 100755 index 0000000..ec348f7 --- /dev/null +++ b/sio2/sisr/11-python/ex1.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 + +p = 3.141592 +rayon = int(input("Quel est le diametre du cercle ?")) + +resultat = 2*p*rayon + +print("Le rayon du cercle est de " , resultat) diff --git a/sio2/sisr/11-python/ex2.py b/sio2/sisr/11-python/ex2.py new file mode 100755 index 0000000..52d4cb5 --- /dev/null +++ b/sio2/sisr/11-python/ex2.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +i = 0 +maxi = i +mini = i +total = 0 +tab = [] + +for i in range (5) : + valeur = int(input("Quelle sont les valeurs du tableau ?")) + tab.append(valeur) + maxi = valeur + mini = valeur + +for valeur in tab : + if valeur < mini : + mini = valeur + if valeur > maxi : + maxi = valeur + total = total + valeur + +moyenne = total/5 + +print("Le plus grand element est :" , maxi) +print("Le plus petit element est :" , mini) +print("La moyenne est : " , moyenne) +for valeur in tab : + print (valeur) diff --git a/sio2/sisr/11-python/ex3.py b/sio2/sisr/11-python/ex3.py new file mode 100755 index 0000000..b2383f2 --- /dev/null +++ b/sio2/sisr/11-python/ex3.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +phrase = input("Phrase : ") +tabmot=phrase.split (' ') +cptmot={} + +for mot in tabmot: + if mot in cptmot: + cptmot[mot]=cptmot[mot]+1 + else : + cptmot[mot]=1 + +for cle in cptmot.keys(): + print(cle, cptmot[cle]) diff --git a/sio2/sisr/11-python/ex4.py b/sio2/sisr/11-python/ex4.py new file mode 100755 index 0000000..8b55572 --- /dev/null +++ b/sio2/sisr/11-python/ex4.py @@ -0,0 +1,34 @@ +#!/usr/lib/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login + res = os.system ("getent passwd "+login) + if res != 0: + passw = "pwgen 4 1" + os.system (cmd) + mdp = string(os.system ("pwgen 4 1")) + os.system ("echo "+login+mdp+"|chpasswd") + os.system ("echo "+login+mdp+" > "+filename+".pwd") + else: + print ("Utilisateur "+login+" déjà éxistant") + os.system ("sudo userdel -r "+login) + line = fh.readline() + + fh.close() + diff --git a/sio2/sisr/11-python/passusr.py b/sio2/sisr/11-python/passusr.py new file mode 100755 index 0000000..182df26 --- /dev/null +++ b/sio2/sisr/11-python/passusr.py @@ -0,0 +1,42 @@ +#!/usr/lib/python3 +import sys +import subprocess +import os +nbarg = len(sys.argv) +if nbarg != 2: + print ("Nombre d'argument invalide") + exit (1) +filename = sys.argv[1] +try: + fh = open(filename, "r") +except: + print ("Fichier ", filename," inconnu") + exit (2) +else: + line = fh.readline () + while line: + nouvline = line.rstrip() + login,nomlong = nouvline.split(':') + cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ no$ + res = os.system ("getent passwd "+login) + if res != 0: + passw = ["pwgen", "4","1"] + #passw = "pwgen 4 1" + os.system (cmd) + #mdp = str(os.system (passw)) + #print (mdp) + mdp = subprocess.run(passw,capture_output=True) + mdp2 = mdp.stdout.decode("utf-8") + mdp3 = mdp2.rstrip() + print (mdp3) + ch3 = "echo "+login+":"+mdp3+"|sudo chpasswd" + print (ch3) + os.system (ch3) + os.system ("sudo echo "+login+":"+mdp3+" >> "+fi$ + else: + print ("Utilisateur "+login+" déjà éxistant") + os.system ("sudo userdel -r "+login) + line = fh.readline() + + fh.close() +