From d9f313da55973969d415cb2904e358240975693a Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 30 Jun 2020 14:43:17 +0200 Subject: [PATCH] =?UTF-8?q?illustrations:=20mise=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- illustrations/1_tester/test_integration.py | 3 +- illustrations/1_tester/test_intelligents.py | 1 + illustrations/1_tester/test_paradoxe.py | 1 + illustrations/2_deployer/exemple.py | 31 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/illustrations/1_tester/test_integration.py b/illustrations/1_tester/test_integration.py index 40f0b79..5c8a619 100644 --- a/illustrations/1_tester/test_integration.py +++ b/illustrations/1_tester/test_integration.py @@ -8,7 +8,7 @@ class UnixFS: # Sans intégration def test_monkeypatche(mocker): - mocker.patch('os.remove') + mocker.patch('os.remove') # Se renseigner sur les mocks dans les tests UnixFS.rm('contrôle complet') os.remove.assert_called_once_with('contrôle complet') @@ -22,4 +22,5 @@ def test_db_with_db(): UnixFS.rm(fp.name) # Exercice: assert que le fichier a été supprimé. # assert not os.access(fp.name)? + # Regarder os.path aussi. # https://docs.python.org/fr/3/library/os.html diff --git a/illustrations/1_tester/test_intelligents.py b/illustrations/1_tester/test_intelligents.py index 7f3ce53..497c0ff 100644 --- a/illustrations/1_tester/test_intelligents.py +++ b/illustrations/1_tester/test_intelligents.py @@ -8,6 +8,7 @@ def encode(input_string): count = 1 prev = '' lst = [] + if not input_string: return ([], 0) diff --git a/illustrations/1_tester/test_paradoxe.py b/illustrations/1_tester/test_paradoxe.py index 1aec162..74ea32f 100644 --- a/illustrations/1_tester/test_paradoxe.py +++ b/illustrations/1_tester/test_paradoxe.py @@ -2,6 +2,7 @@ from hypothesis import given, assume from hypothesis.strategies import lists, permutations from collections import Counter, defaultdict +# Wikipedia: Paradoxe de Condorcet / Scrutin de Condorcet. # Ici, on va observer un paradoxe classique en théorie des votes juste en utilisant Hypothesis. # Imaginez, ici que vous fabriquez un algorithme de couplage, type APB/Admissions Parallèles/Parcoursup. diff --git a/illustrations/2_deployer/exemple.py b/illustrations/2_deployer/exemple.py index 072ab3a..0bfba8d 100644 --- a/illustrations/2_deployer/exemple.py +++ b/illustrations/2_deployer/exemple.py @@ -5,7 +5,38 @@ utilisateur = "raito" # À remplacer avec root ou votre nom d'utilisateur. c = Connection(nom_hote, user=utilisateur) + +def generer_nix(): + squelette = """ + # This file is managed by Fabric, do not edit. + { pkgs, ... }: + { + %s + } + """ + + nix_conf = """ + # On se lance un petit service de courses à la maison. + services.grocy = { + enable = true; + hostName = "votre.tld"; # Vous pouvez utiliser un DynDNS ! e.g. https://dns.he.net/ + }; + security.acme.acceptTerms = true; # On accepte les termes du contrat de Let's Encrypt. + security.acme.email = "vous@mail.tld"; # Email pour les alertes de Let's Encrypt. + networking.firewall.allowedTCPPorts = [ 80 443 ]; # Ports à ouvrir! + """ + + return squelette % nix_conf + print('[+] Regardons le nom d\'hôte') c.run('hostname') print('[+] Regardons les informations du noyau et de la machine') c.run('uname -a') + + +fabric_managed_contents = generer_nix() +with open("/tmp/fabric.nix", "w") as f: + f.write(fabric_managed_contents) +c.put('/tmp/fabric.nix', '/tmp/fabric.nix') +c.run('sudo mv /tmp/fabric.nix /etc/nixos/fabric-managed.nix', pty=True) +c.run('sudo nixos-rebuild switch', pty=True)