15-03-2019
This commit is contained in:
7
build_and_upload.sh
Executable file
7
build_and_upload.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /Users/bruno/project
|
||||||
|
mkdocs build
|
||||||
|
scp -P42666 -r ./central_docs bruno@192.168.1.7:/volume1/web
|
||||||
|
#scp -P42666 -r ./central_docs bruno@clicclac.synology.me:/volume1/web
|
||||||
|
#rsync -rav -e ssh ./central_docs bruno@192.168.1.7:/volume1/web/tt
|
||||||
BIN
docs/Divers/.DS_Store
vendored
BIN
docs/Divers/.DS_Store
vendored
Binary file not shown.
402
docs/Divers/Vagrant/Vagrant.md
Normal file
402
docs/Divers/Vagrant/Vagrant.md
Normal file
@@ -0,0 +1,402 @@
|
|||||||
|
# Vagrant
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew cask install vagrant
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Test installation
|
||||||
|
```bash
|
||||||
|
$ vagrant
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Nouveau projet
|
||||||
|
```bash
|
||||||
|
$ mkdir vagrant_1
|
||||||
|
$ cd vagrant_1/
|
||||||
|
$ vagrant init
|
||||||
|
A `Vagrantfile` has been placed in this directory. You are now
|
||||||
|
ready to `vagrant up` your first virtual environment! Please read
|
||||||
|
the comments in the Vagrantfile as well as documentation on
|
||||||
|
`vagrantup.com` for more information on using Vagrant.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Installer une Box
|
||||||
|
Linux Mint 18.2 Fr: https://app.vagrantup.com/mazenovi/boxes/linuxmint
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant box add mazenovi/linuxmint
|
||||||
|
==> box: Loading metadata for box 'mazenovi/linuxmint'
|
||||||
|
box: URL: https://vagrantcloud.com/mazenovi/linuxmint
|
||||||
|
==> box: Adding box 'mazenovi/linuxmint' (v18.2) for provider: virtualbox
|
||||||
|
box: Downloading: https://vagrantcloud.com/mazenovi/boxes/linuxmint/versions/18.2/providers/virtualbox.box
|
||||||
|
box: Progress: 0% (Rate: 667k/s, Estimated time remaining: 5:23:24)
|
||||||
|
==> box: Successfully added box 'mazenovi/linuxmint' (v18.2) for 'virtualbox'!
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant up
|
||||||
|
Bringing machine 'default' up with 'virtualbox' provider...
|
||||||
|
==> default: Importing base box 'mazenovi/linuxmint'...
|
||||||
|
==> default: Matching MAC address for NAT networking...
|
||||||
|
==> default: Checking if box 'mazenovi/linuxmint' is up to date...
|
||||||
|
==> default: Setting the name of the VM: vagrant_1_default_1535283084230_82301
|
||||||
|
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
|
||||||
|
==> default: Clearing any previously set network interfaces...
|
||||||
|
==> default: Preparing network interfaces based on configuration...
|
||||||
|
default: Adapter 1: nat
|
||||||
|
==> default: Forwarding ports...
|
||||||
|
default: 22 (guest) => 2200 (host) (adapter 1)
|
||||||
|
==> default: Running 'pre-boot' VM customizations...
|
||||||
|
==> default: Booting VM...
|
||||||
|
==> default: Waiting for machine to boot. This may take a few minutes...
|
||||||
|
default: SSH address: 127.0.0.1:2200
|
||||||
|
default: SSH username: vagrant
|
||||||
|
default: SSH auth method: private key
|
||||||
|
default:
|
||||||
|
default: Vagrant insecure key detected. Vagrant will automatically replace
|
||||||
|
default: this with a newly generated keypair for better security.
|
||||||
|
default:
|
||||||
|
default: Inserting generated public key within guest...
|
||||||
|
default: Removing insecure key from the guest if it's present...
|
||||||
|
default: Key inserted! Disconnecting and reconnecting using new SSH key...
|
||||||
|
==> default: Machine booted and ready!
|
||||||
|
==> default: Checking for guest additions in VM...
|
||||||
|
default: The guest additions on this VM do not match the installed version of
|
||||||
|
default: VirtualBox! In most cases this is fine, but in rare cases it can
|
||||||
|
default: prevent things such as shared folders from working properly. If you see
|
||||||
|
default: shared folder errors, please make sure the guest additions within the
|
||||||
|
default: virtual machine match the version of VirtualBox you have installed on
|
||||||
|
default: your host and reload your VM.
|
||||||
|
default:
|
||||||
|
default: Guest Additions Version: 5.1.26
|
||||||
|
default: VirtualBox Version: 5.2
|
||||||
|
==> default: Mounting shared folders...
|
||||||
|
default: /vagrant => /Users/bruno/vagrant_1
|
||||||
|
==> default: Running provisioner: shell...
|
||||||
|
default: Running: /var/folders/s5/zy63nf3953sb_4k0ppcy16sw0000gn/T/vagrant-shell20180826-50764-3ev96e.sh
|
||||||
|
default: Lecture des listes de paquets…
|
||||||
|
default: Construction de l'arbre des dépendances…
|
||||||
|
default: Lecture des informations d'état…
|
||||||
|
default: The following additional packages will be installed:
|
||||||
|
default: apache2-bin apache2-data apache2-utils libapr1 libaprutil1
|
||||||
|
default: libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
|
||||||
|
default: Paquets suggérés :
|
||||||
|
default: apache2-doc apache2-suexec-pristine | apache2-suexec-custom
|
||||||
|
default: Les NOUVEAUX paquets suivants seront installés :
|
||||||
|
default: apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
|
||||||
|
default: libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
|
||||||
|
default: 0 mis à jour, 9 nouvellement installés, 0 à enlever et 10 non mis à jour.
|
||||||
|
default: Il est nécessaire de prendre 1 540 ko dans les archives.
|
||||||
|
default: Après cette opération, 6 369 ko d'espace disque supplémentaires seront utilisés.
|
||||||
|
default: Réception de:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libapr1 amd64 1.5.2-3 [86,0 kB]
|
||||||
|
default: Réception de:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1 amd64 1.5.4-1build1 [77,1 kB]
|
||||||
|
default: Réception de:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1-dbd-sqlite3 amd64 1.5.4-1build1 [10,6 kB]
|
||||||
|
default: Réception de:4 http://archive.ubuntu.com/ubuntu xenial/main amd64 libaprutil1-ldap amd64 1.5.4-1build1 [8 720 B]
|
||||||
|
default: Réception de:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 liblua5.1-0 amd64 5.1.5-8ubuntu1 [102 kB]
|
||||||
|
default: Err:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2-bin amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: Ign:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2-utils amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: Ign:8 http://archive.ubuntu.com/ubuntu xenial-updates/main i386 apache2-data all 2.4.18-2ubuntu3.4
|
||||||
|
default: Ign:9 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2 amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: Ign:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2-data all 2.4.18-2ubuntu3.4
|
||||||
|
default: Err:6 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2-bin amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: Err:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2-utils amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: Err:9 http://security.ubuntu.com/ubuntu xenial-security/main amd64 apache2 amd64 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: Err:8 http://security.ubuntu.com/ubuntu xenial-security/main i386 apache2-data all 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: Err:8 http://security.ubuntu.com/ubuntu xenial-security/main i386 apache2-data all 2.4.18-2ubuntu3.4
|
||||||
|
default: 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: 285 ko réceptionnés en 0s (431 ko/s)
|
||||||
|
default: E
|
||||||
|
default: :
|
||||||
|
default: Impossible de récupérer http://security.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-bin_2.4.18-2ubuntu3.4_amd64.deb 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: E
|
||||||
|
default: :
|
||||||
|
default: Impossible de récupérer http://security.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-utils_2.4.18-2ubuntu3.4_amd64.deb 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: E
|
||||||
|
default: :
|
||||||
|
default: Impossible de récupérer http://security.ubuntu.com/ubuntu/pool/main/a/apache2/apache2-data_2.4.18-2ubuntu3.4_all.deb 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default: E: Impossible de récupérer http://security.ubuntu.com/ubuntu/pool/main/a/apache2/apache2_2.4.18-2ubuntu3.4_amd64.deb 404 Not Found [IP : 91.189.88.162 80]
|
||||||
|
default:
|
||||||
|
default: E: Impossible de récupérer certaines archives, peut-être devrez-vous lancer apt-get update ou essayer avec --fix-missing ?
|
||||||
|
The SSH command responded with a non-zero exit status. Vagrant
|
||||||
|
assumes that this means the command failed. The output for this command
|
||||||
|
should be in the log above. Please read the output to determine what
|
||||||
|
went wrong.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Mettre à jour la box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ apt-get update
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Démarrer la box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant up
|
||||||
|
Bringing machine 'default' up with 'virtualbox' provider...
|
||||||
|
==> default: Checking if box 'mazenovi/linuxmint' is up to date...
|
||||||
|
==> default: Clearing any previously set forwarded ports...
|
||||||
|
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
|
||||||
|
==> default: Clearing any previously set network interfaces...
|
||||||
|
==> default: Preparing network interfaces based on configuration...
|
||||||
|
default: Adapter 1: nat
|
||||||
|
==> default: Forwarding ports...
|
||||||
|
default: 22 (guest) => 2200 (host) (adapter 1)
|
||||||
|
==> default: Running 'pre-boot' VM customizations...
|
||||||
|
==> default: Booting VM...
|
||||||
|
==> default: Waiting for machine to boot. This may take a few minutes...
|
||||||
|
default: SSH address: 127.0.0.1:2200
|
||||||
|
default: SSH username: vagrant
|
||||||
|
default: SSH auth method: private key
|
||||||
|
==> default: Machine booted and ready!
|
||||||
|
==> default: Checking for guest additions in VM...
|
||||||
|
default: The guest additions on this VM do not match the installed version of
|
||||||
|
default: VirtualBox! In most cases this is fine, but in rare cases it can
|
||||||
|
default: prevent things such as shared folders from working properly. If you see
|
||||||
|
default: shared folder errors, please make sure the guest additions within the
|
||||||
|
default: virtual machine match the version of VirtualBox you have installed on
|
||||||
|
default: your host and reload your VM.
|
||||||
|
default:
|
||||||
|
default: Guest Additions Version: 5.1.26
|
||||||
|
default: VirtualBox Version: 5.2
|
||||||
|
==> default: Mounting shared folders...
|
||||||
|
default: /vagrant => /Users/bruno/vagrant_1
|
||||||
|
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
|
||||||
|
==> default: flag to force provisioning. Provisioners marked to run always will still run.
|
||||||
|
bruno@silverbook:~/vagrant_1$ vagrant provision
|
||||||
|
==> default: Running provisioner: shell...
|
||||||
|
default: Running: /var/folders/s5/zy63nf3953sb_4k0ppcy16sw0000gn/T/vagrant-shell20180826-51048-16o6i4q.sh
|
||||||
|
default: Lecture des listes de paquets…
|
||||||
|
default: Construction de l'arbre des dépendances…
|
||||||
|
default: Lecture des informations d'état…
|
||||||
|
default: The following additional packages will be installed:
|
||||||
|
default: apache2-bin apache2-data apache2-utils libapr1 libaprutil1
|
||||||
|
default: libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
|
||||||
|
default: Paquets suggérés :
|
||||||
|
default: apache2-doc apache2-suexec-pristine | apache2-suexec-custom
|
||||||
|
default: Les NOUVEAUX paquets suivants seront installés :
|
||||||
|
default: apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
|
||||||
|
default: libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.1-0
|
||||||
|
default: 0 mis à jour, 9 nouvellement installés, 0 à enlever et 441 non mis à jour.
|
||||||
|
default: Il est nécessaire de prendre 1 255 ko/1 540 ko dans les archives.
|
||||||
|
default: Après cette opération, 6 373 ko d'espace disque supplémentaires seront utilisés.
|
||||||
|
default: Réception de:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-bin amd64 2.4.18-2ubuntu3.9 [925 kB]
|
||||||
|
default: Réception de:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-utils amd64 2.4.18-2ubuntu3.9 [81,8 kB]
|
||||||
|
default: Réception de:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2-data all 2.4.18-2ubuntu3.9 [162 kB]
|
||||||
|
default: Réception de:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 apache2 amd64 2.4.18-2ubuntu3.9 [86,6 kB]
|
||||||
|
default: dpkg-preconfigure: impossible de réouvrir stdin : No such file or directory
|
||||||
|
default: 1 255 ko réceptionnés en 0s (2 062 ko/s)
|
||||||
|
default: Sélection du paquet libapr1:amd64 précédemment désélectionné.
|
||||||
|
default: (Lecture de la base de données...
|
||||||
|
default: (Lecture de la base de données... 5%
|
||||||
|
default: (Lecture de la base de données... 10%
|
||||||
|
default: (Lecture de la base de données... 15%
|
||||||
|
default: (Lecture de la base de données... 20%
|
||||||
|
default: (Lecture de la base de données... 25%
|
||||||
|
default: (Lecture de la base de données... 30%
|
||||||
|
default: (Lecture de la base de données... 35%
|
||||||
|
default: (Lecture de la base de données... 40%
|
||||||
|
default: (Lecture de la base de données... 45%
|
||||||
|
default: (Lecture de la base de données... 50%
|
||||||
|
default: (Lecture de la base de données... 55%
|
||||||
|
default: (Lecture de la base de données... 60%
|
||||||
|
default: (Lecture de la base de données... 65%
|
||||||
|
default: (Lecture de la base de données... 70%
|
||||||
|
default: (Lecture de la base de données... 75%
|
||||||
|
default: (Lecture de la base de données... 80%
|
||||||
|
default: (Lecture de la base de données... 85%
|
||||||
|
default: (Lecture de la base de données... 90%
|
||||||
|
default: (Lecture de la base de données... 95%
|
||||||
|
default: (Lecture de la base de données... 100%
|
||||||
|
default: (Lecture de la base de données...
|
||||||
|
default: 203928 fichiers et répertoires déjà installés.)
|
||||||
|
default: Préparation du dépaquetage de .../libapr1_1.5.2-3_amd64.deb ...
|
||||||
|
default: Dépaquetage de libapr1:amd64 (1.5.2-3) ...
|
||||||
|
default: Sélection du paquet libaprutil1:amd64 précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../libaprutil1_1.5.4-1build1_amd64.deb ...
|
||||||
|
default: Dépaquetage de libaprutil1:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Sélection du paquet libaprutil1-dbd-sqlite3:amd64 précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../libaprutil1-dbd-sqlite3_1.5.4-1build1_amd64.deb ...
|
||||||
|
default: Dépaquetage de libaprutil1-dbd-sqlite3:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Sélection du paquet libaprutil1-ldap:amd64 précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../libaprutil1-ldap_1.5.4-1build1_amd64.deb ...
|
||||||
|
default: Dépaquetage de libaprutil1-ldap:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Sélection du paquet liblua5.1-0:amd64 précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../liblua5.1-0_5.1.5-8ubuntu1_amd64.deb ...
|
||||||
|
default: Dépaquetage de liblua5.1-0:amd64 (5.1.5-8ubuntu1) ...
|
||||||
|
default: Sélection du paquet apache2-bin précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../apache2-bin_2.4.18-2ubuntu3.9_amd64.deb ...
|
||||||
|
default: Dépaquetage de apache2-bin (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Sélection du paquet apache2-utils précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../apache2-utils_2.4.18-2ubuntu3.9_amd64.deb ...
|
||||||
|
default: Dépaquetage de apache2-utils (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Sélection du paquet apache2-data précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../apache2-data_2.4.18-2ubuntu3.9_all.deb ...
|
||||||
|
default: Dépaquetage de apache2-data (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Sélection du paquet apache2 précédemment désélectionné.
|
||||||
|
default: Préparation du dépaquetage de .../apache2_2.4.18-2ubuntu3.9_amd64.deb ...
|
||||||
|
default: Dépaquetage de apache2 (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour libc-bin (2.23-0ubuntu9) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour man-db (2.7.5-1) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour systemd (229-4ubuntu19) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour ureadahead (0.100.0-19) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour ufw (0.35-0ubuntu2) ...
|
||||||
|
default: Paramétrage de libapr1:amd64 (1.5.2-3) ...
|
||||||
|
default: Paramétrage de libaprutil1:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Paramétrage de libaprutil1-dbd-sqlite3:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Paramétrage de libaprutil1-ldap:amd64 (1.5.4-1build1) ...
|
||||||
|
default: Paramétrage de liblua5.1-0:amd64 (5.1.5-8ubuntu1) ...
|
||||||
|
default: Paramétrage de apache2-bin (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Paramétrage de apache2-utils (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Paramétrage de apache2-data (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Paramétrage de apache2 (2.4.18-2ubuntu3.9) ...
|
||||||
|
default: Enabling module mpm_event.
|
||||||
|
default: Enabling module authz_core.
|
||||||
|
default: Enabling module authz_host.
|
||||||
|
default: Enabling module authn_core.
|
||||||
|
default: Enabling module auth_basic.
|
||||||
|
default: Enabling module access_compat.
|
||||||
|
default: Enabling module authn_file.
|
||||||
|
default: Enabling module authz_user.
|
||||||
|
default: Enabling module alias.
|
||||||
|
default: Enabling module dir.
|
||||||
|
default: Enabling module autoindex.
|
||||||
|
default: Enabling module env.
|
||||||
|
default: Enabling module mime.
|
||||||
|
default: Enabling module negotiation.
|
||||||
|
default: Enabling module setenvif.
|
||||||
|
default: Enabling module filter.
|
||||||
|
default: Enabling module deflate.
|
||||||
|
default: Enabling module status.
|
||||||
|
default: Enabling conf charset.
|
||||||
|
default: Enabling conf localized-error-pages.
|
||||||
|
default: Enabling conf other-vhosts-access-log.
|
||||||
|
default: Enabling conf security.
|
||||||
|
default: Enabling conf serve-cgi-bin.
|
||||||
|
default: Enabling site 000-default.
|
||||||
|
default: Traitement des actions différées (« triggers ») pour libc-bin (2.23-0ubuntu9) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour systemd (229-4ubuntu19) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour ureadahead (0.100.0-19) ...
|
||||||
|
default: Traitement des actions différées (« triggers ») pour ufw (0.35-0ubuntu2) ...
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Se connecter à la box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant ssh
|
||||||
|
Welcome to Linux Mint 18.2 Sonya (GNU/Linux 4.8.0-53-generic x86_64)
|
||||||
|
|
||||||
|
- Documentation: https://www.linuxmint.com
|
||||||
|
vagrant@vagrant-VirtualBox ~ $ ls
|
||||||
|
Bureau Documents Images Modèles Musique Public Téléchargements Vidéos
|
||||||
|
|
||||||
|
CTRL + D => déconnexion ssh
|
||||||
|
|
||||||
|
vagrant@vagrant-VirtualBox ~ $ déconnexion
|
||||||
|
Connection to 127.0.0.1 closed.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Supprimer la box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant destroy
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Supprimer les fichiers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant box remove (supprime les fichiers)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Synced folders:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant@vagrant-VirtualBox /vagrant $ ls
|
||||||
|
foo provision.sh Vagrantfile
|
||||||
|
et
|
||||||
|
bruno@silverbook:~/vagrant_1$ ls
|
||||||
|
Vagrantfile foo provision.sh
|
||||||
|
sont synchronisés
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Provisionning:
|
||||||
|
|
||||||
|
Créer un fichier bootstrap.sh dans le même répertoire que Vagrantfile
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# !/usr/bin/env bash
|
||||||
|
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y apache2
|
||||||
|
if ! [ -L /var/www ]; then
|
||||||
|
rm -rf /var/www
|
||||||
|
ln -fs /vagrant /var/www
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
et ajouter la ligne suivante à `Vagrantfile`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
config.vm.provision :shell, path: "bootstrap.sh"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Redémarrer la box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant up
|
||||||
|
Redémarrer la VM et relancer les provisions (lancer uniquement au 1er lancement de vagrant up)
|
||||||
|
$ vagrant reload --provision
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Liens:
|
||||||
|
|
||||||
|
[Plusieurs Vagrant MV dans un fichier Vagrantfile](http://www.thisprogrammingthing.com/2015/multiple-vagrant-vms-in-one-vagrantfile/)
|
||||||
|
|
||||||
|
[Utiliser Vagrant et Packer pour créer des VM](https://www.rubix.nl/blogs/utilizing-vagrant-and-packer-provisioning-development-environments)
|
||||||
|
|
||||||
|
[Créer une VagrantBox](https://www.engineyard.com/blog/building-a-vagrant-box)
|
||||||
|
|
||||||
|
[Vagrant Boxes](https://app.vagrantup.com/boxes/search)
|
||||||
|
|
||||||
|
[Vagrant docs](https://www.vagrantup.com/intro/getting-started/index.html)
|
||||||
|
|
||||||
|
[Bootstrap PHP7](https://github.com/spiritix/vagrant-php7)
|
||||||
|
|
||||||
|
[How To Provision A LEMP Stack In Vagrant](https://kenfavors.com/code/how-to-provision-a-lemp-stack-in-vagrant/)
|
||||||
|
|
||||||
218
docs/Divers/Vagrant/creer_une_vagrant_box.md
Normal file
218
docs/Divers/Vagrant/creer_une_vagrant_box.md
Normal file
@@ -0,0 +1,218 @@
|
|||||||
|
# Créer une Vagrant box
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## VirtualBox
|
||||||
|
|
||||||
|
https://www.engineyard.com/blog/building-a-vagrant-box
|
||||||
|
https://www.ceos3c.com/open-source/install-linux-mint-19-virtualbox/
|
||||||
|
|
||||||
|
1. #### Créer une nouvelle machine virtuelle
|
||||||
|
|
||||||
|
Nom: Linux Mint 19 xfce
|
||||||
|
Type: Linux
|
||||||
|
Version: Ubuntu (64-bit)
|
||||||
|
|
||||||
|
- mémoire: 2Go
|
||||||
|
- disque dur: créer un disque dur maintenant
|
||||||
|
- type: VMDK VDI (VirtualBox Disk Image)
|
||||||
|
- stockage: Dynamiquement alloué
|
||||||
|
- emplacement et taille: /Users/bruno/VirtualBox VMs/Linux Mint 19 xfce/Linux Mint 19 xfce.vdi 20Go
|
||||||
|
|
||||||
|
2. #### Configurer le hardware
|
||||||
|
|
||||||
|
- désactiver audio et USB
|
||||||
|
- la carte réseau 1 doit être réglée sur NAT
|
||||||
|
- ajouter cette règle de redirection de ports:
|
||||||
|
Nom: SSH Protocole: TCP IP Hote: <blanc> Port hôte: 2222 IP invité <blanc> Port invité: 22
|
||||||
|
|
||||||
|
3. #### Installer Linux Mint 19
|
||||||
|
|
||||||
|
- Démarrer la machine
|
||||||
|
- Choisir l'ISO: linuxmint-19-xfce-64bit-v2.iso
|
||||||
|
- Linux Mint 19 démarre dans son environnement Live. Double-clic sur Install Linux Mint
|
||||||
|
- Choisir le language
|
||||||
|
- Choisir le clavier
|
||||||
|
- Ne pas installer les logiciels tiers
|
||||||
|
- Effacer le disque et installer Linux Mint
|
||||||
|
- Installer maintenant
|
||||||
|
- Choisir le fuseau horaire
|
||||||
|
- Utilisateur: vagrant Mot de passe: vagrant
|
||||||
|
|
||||||
|
4. #### Redémarrer:
|
||||||
|
|
||||||
|
- Régler le mot de passe root:
|
||||||
|
`sudo passwd root (vagrant)`
|
||||||
|
|
||||||
|
- Régler le super utilisateur: sudo visudo -f /etc/sudoers.d/vagrant
|
||||||
|
Ajouter:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
add vagrant user
|
||||||
|
vagrant ALL=(ALL) NOPASSWD:ALL
|
||||||
|
```
|
||||||
|
|
||||||
|
- Sauver et quitter.
|
||||||
|
|
||||||
|
- Tester:
|
||||||
|
`sudo pwd`
|
||||||
|
|
||||||
|
5. #### Mettre à jour l'OS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get update -y
|
||||||
|
sudo apt-get upgrade -y
|
||||||
|
#et redémarrer
|
||||||
|
sudo shutdown -r now
|
||||||
|
```
|
||||||
|
|
||||||
|
6. #### Reconfigurer le clavier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get install keyboard-configuration
|
||||||
|
sudo dpkg-reconfigure keyboard-configuration
|
||||||
|
Keyboard-configuration choices for MackBookPro French keyboard:
|
||||||
|
|
||||||
|
-> MacBook / MacBookPro (Intl)
|
||||||
|
-> French
|
||||||
|
-> French (again)
|
||||||
|
-> Right Alt (AltGr)
|
||||||
|
-> No Compose Key
|
||||||
|
```
|
||||||
|
|
||||||
|
7. #### Installer la Clé Vagrant:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p /home/vagrant/.ssh
|
||||||
|
chmod 0700 /home/vagrant/.ssh
|
||||||
|
wget --no-check-certificate \
|
||||||
|
https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
|
||||||
|
-O /home/vagrant/.ssh/authorized_keys
|
||||||
|
chmod 0600 /home/vagrant/.ssh/authorized_keys
|
||||||
|
chown -R vagrant /home/vagrant/.ssh
|
||||||
|
```
|
||||||
|
|
||||||
|
8. #### Installer le serveur OpenSSH:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get install -y openssh-server
|
||||||
|
sudo nano /etc/ssh/sshd_config
|
||||||
|
# Décommenter la ligne AuthorizedKeysFile %h/.ssh/authorized_keys
|
||||||
|
# Redémarrer ssh
|
||||||
|
sudo service ssh restart
|
||||||
|
```
|
||||||
|
|
||||||
|
9. #### Installer Guest Tools:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get install -y gcc build-essential linux-headers-server
|
||||||
|
#Dans VirtualBox, menu Périphériques, cliquer sur Insérer l'image CD des Additions Invité
|
||||||
|
sudo mount /dev/cdrom /mnt
|
||||||
|
cd /mnt
|
||||||
|
sudo ./VBoxLinuxAdditions.run
|
||||||
|
```
|
||||||
|
|
||||||
|
10. #### Finaliser la Box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
“zero out” the drive.
|
||||||
|
sudo dd if=/dev/zero of=/EMPTY bs=1M
|
||||||
|
sudo rm -f /EMPTY
|
||||||
|
```
|
||||||
|
|
||||||
|
11. #### Créer un dossier pour les Box:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir ~/vagrant_boxes
|
||||||
|
cd ~/vagrant_boxes
|
||||||
|
```
|
||||||
|
|
||||||
|
12. #### Créer le paquet (tar.gz et fichiers Vagrantfile , metadata.json
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant package --base Linux\ Mint\ 19\ xfce
|
||||||
|
==> Linux Mint 19 xfce: Attempting graceful shutdown of VM...
|
||||||
|
==> Linux Mint 19 xfce: Clearing any previously set forwarded ports...
|
||||||
|
==> Linux Mint 19 xfce: Exporting VM...
|
||||||
|
==> Linux Mint 19 xfce: Compressing package to: /Users/bruno/vagrant_boxes/package.box
|
||||||
|
```
|
||||||
|
|
||||||
|
13. #### Tester la box
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant box add mint19-64 package.box
|
||||||
|
==> box: Box file was not detected as metadata. Adding it directly...
|
||||||
|
==> box: Adding box 'mint19-64' (v0) for provider:
|
||||||
|
box: Unpacking necessary files from: file:///Users/bruno/vagrant_boxes/package.box
|
||||||
|
==> box: Successfully added box 'mint19-64' (v0) for 'virtualbox'!
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant init mint19-64
|
||||||
|
A `Vagrantfile` has been placed in this directory. You are now
|
||||||
|
ready to `vagrant up` your first virtual environment! Please read
|
||||||
|
the comments in the Vagrantfile as well as documentation on
|
||||||
|
`vagrantup.com` for more information on using Vagrant.
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant up
|
||||||
|
Bringing machine 'default' up with 'virtualbox' provider...
|
||||||
|
==> default: Importing base box 'mint19-64'...
|
||||||
|
==> default: Matching MAC address for NAT networking...
|
||||||
|
==> default: Setting the name of the VM: vagrant_boxes_default_1535276878752_78916
|
||||||
|
Vagrant is currently configured to create VirtualBox synced folders with
|
||||||
|
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
|
||||||
|
guest is not trusted, you may want to disable this option. For more
|
||||||
|
information on this option, please refer to the VirtualBox manual:
|
||||||
|
|
||||||
|
https://www.virtualbox.org/manual/ch04.html#sharedfolders
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
This option can be disabled globally with an environment variable:
|
||||||
|
|
||||||
|
VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
|
||||||
|
|
||||||
|
or on a per folder basis within the Vagrantfile:
|
||||||
|
|
||||||
|
config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
|
||||||
|
==> default: Clearing any previously set network interfaces...
|
||||||
|
==> default: Preparing network interfaces based on configuration...
|
||||||
|
default: Adapter 1: nat
|
||||||
|
==> default: Forwarding ports...
|
||||||
|
default: 22 (guest) => 2222 (host) (adapter 1)
|
||||||
|
==> default: Booting VM...
|
||||||
|
==> default: Waiting for machine to boot. This may take a few minutes...
|
||||||
|
default: SSH address: 127.0.0.1:2222
|
||||||
|
default: SSH username: vagrant
|
||||||
|
default: SSH auth method: private key
|
||||||
|
default:
|
||||||
|
default: Vagrant insecure key detected. Vagrant will automatically replace
|
||||||
|
default: this with a newly generated keypair for better security.
|
||||||
|
default:
|
||||||
|
default: Inserting generated public key within guest...
|
||||||
|
default: Removing insecure key from the guest if it's present...
|
||||||
|
default: Key inserted! Disconnecting and reconnecting using new SSH key...
|
||||||
|
==> default: Machine booted and ready!
|
||||||
|
==> default: Checking for guest additions in VM...
|
||||||
|
==> default: Mounting shared folders...
|
||||||
|
default: /vagrant => /Users/bruno/vagrant_boxes
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vagrant ssh
|
||||||
|
vagrant@vagrant-VirtualBox:~$ ls
|
||||||
|
Bureau Documents Images Modèles Musique Public Téléchargements Vidéos
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant@vagrant-VirtualBox:~$ exit
|
||||||
|
déconnexion
|
||||||
|
Connection to 127.0.0.1 closed.
|
||||||
|
```
|
||||||
|
|
||||||
@@ -125,6 +125,69 @@ Crée un clone du depot dans le dossier mondossier
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Tirer un seul fichier d'un repo git:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mkdir rpi_py
|
||||||
|
$ git init
|
||||||
|
Dépôt Git vide initialisé dans /home/pi/git/rpi_py/.git/
|
||||||
|
$ git remote add origin bruno@dsm916e:/volume1/Repositories/rpi_py.git
|
||||||
|
$ git fetch
|
||||||
|
bruno@clicclac.synology.me's password:
|
||||||
|
remote: Enumerating objects: 38, done.
|
||||||
|
remote: Counting objects: 100% (38/38), done.
|
||||||
|
remote: Compressing objects: 100% (38/38), done.
|
||||||
|
remote: Total 38 (delta 5), reused 0 (delta 0)
|
||||||
|
Dépaquetage des objets: 100% (38/38), fait.
|
||||||
|
Depuis dsm916e:/volume1/Repositories/rpi_py
|
||||||
|
* [nouvelle branche] master -> origin/master
|
||||||
|
$ git checkout origin/master -- Camera/camera_2.py
|
||||||
|
|
||||||
|
pi@litePi:~/git/rpi_py $ cd Camera/
|
||||||
|
total 12
|
||||||
|
drwxr-xr-x 2 pi pi 4096 févr. 4 16:45 .
|
||||||
|
drwxr-xr-x 4 pi pi 4096 févr. 4 16:45 ..
|
||||||
|
-rw-r--r-- 1 pi pi 238 févr. 4 16:45 camera_2.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Autre solution (juste le fichier, pas l'historique):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git archive --format=tar --remote=ssh://bruno@dsm916e/volume1/Repositories/rpi_py.git heads/master -- Camera/camera_2.py | tar xf -
|
||||||
|
|
||||||
|
# affiche le fichier sur la sortie stdout (tar -xO)
|
||||||
|
$ git archive --format=tar --remote=ssh://bruno@dsm916e/volume1/Repositories/rpi_py.git heads/master -- Camera/camera_2.py | tar -xO
|
||||||
|
bruno@clicclac.synology.me's password:
|
||||||
|
import time
|
||||||
|
import picamera
|
||||||
|
|
||||||
|
with picamera.PiCamera() as camera:
|
||||||
|
camera.resolution = (1024, 768)
|
||||||
|
camera.start_preview()
|
||||||
|
# Camera warm-up time
|
||||||
|
time.sleep(2)
|
||||||
|
camera.capture('/home/pi/Desktop/foo.jpg', resize=(320, 240))
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
# -n : No checkout of HEAD is performed after the clone is complete.
|
||||||
|
# --depth 1 : juste la dernière révision
|
||||||
|
$ git clone -n ssh://bruno@dsm916e/volume1/Repositories/rpi_py.git --depth 1
|
||||||
|
Clonage dans 'rpi_py'...
|
||||||
|
...
|
||||||
|
$ cd rpi_py/
|
||||||
|
$ git checkout HEAD Camera/camera_2.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Voir aussi https://gist.github.com/ssp/1663093
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Enregistrer des modifications dans le dépôt:
|
### Enregistrer des modifications dans le dépôt:
|
||||||
|
|
||||||
#### [Vérifier l'état des fichiers](https://git-scm.com/book/fr/v1/Les-bases-de-Git-Enregistrer-des-modifications-dans-le-d%C3%A9p%C3%B4t#V%C3%A9rifier-l'%C3%A9tat-des-fichiers)
|
#### [Vérifier l'état des fichiers](https://git-scm.com/book/fr/v1/Les-bases-de-Git-Enregistrer-des-modifications-dans-le-d%C3%A9p%C3%B4t#V%C3%A9rifier-l'%C3%A9tat-des-fichiers)
|
||||||
|
|||||||
71
docs/Divers/markdown.md
Normal file
71
docs/Divers/markdown.md
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
Normal
|
||||||
|
|
||||||
|
**Gras**
|
||||||
|
|
||||||
|
*Italique*
|
||||||
|
|
||||||
|
<u>Souligné</u>
|
||||||
|
|
||||||
|
~~Barré~~
|
||||||
|
|
||||||
|
`Code`
|
||||||
|
|
||||||
|
<!--Commentaire-->
|
||||||
|
|
||||||
|
$Math en ligne$
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Bloc de code:
|
||||||
|
|
||||||
|
$ cd
|
||||||
|
$ ls
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
> Citation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Titre 1
|
||||||
|
|
||||||
|
## Titre 2
|
||||||
|
|
||||||
|
### Titre 3
|
||||||
|
|
||||||
|
#### Titre 4
|
||||||
|
|
||||||
|
##### Titre 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1. Un
|
||||||
|
2. Deux
|
||||||
|
3. Trois
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- Un
|
||||||
|
- Deux
|
||||||
|
- Trois
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- [ ] Un
|
||||||
|
- [ ] Deux
|
||||||
|
- [ ] Trois
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
@@ -88,7 +88,9 @@ Plug-in [MultiPlex](https://github.com/JayTheHatWearer/MultiPLEX.bundle)
|
|||||||
|
|
||||||
Le paquet pour NAS Synology se trouve [ici](https://github.com/ukdtom/WTInstaller/releases/latest).
|
Le paquet pour NAS Synology se trouve [ici](https://github.com/ukdtom/WTInstaller/releases/latest).
|
||||||
|
|
||||||
WebTools se lance depuis [DSM](http://192.168.1.7:33400/#!/uas) (et pas depuis Plex)
|
WebTools se lance depuis [DSM](http://192.168.1.7:33400/#!/uas) (et pas depuis Plex). Il est dispo ici http://192.168.1.7:33400/login (on se loggue avec les identifiants Plex).
|
||||||
|
|
||||||
|
Si WebTools ne fonctionne plus, il faut le [resetter](https://github.com/ukdtom/WebTools.bundle/wiki/Reset).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
https://ss64.com/vi.html
|
https://ss64.com/vi.html
|
||||||
|
|
||||||
:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ awk 'NR!=1{print $1}' test.txt
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
mojave
|
||||||
|
sierra
|
||||||
|
tiger
|
||||||
|
snowleopard
|
||||||
|
|
||||||
|
# NR!=n° de ligne
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher le fichier entier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ awk '{print $0}' test.txt
|
||||||
|
ubuntu Linux
|
||||||
|
mint Linux
|
||||||
|
debian Linux
|
||||||
|
raspbian Linux
|
||||||
|
mojave macOS
|
||||||
|
sierra macOS
|
||||||
|
tiger macOS
|
||||||
|
snowleopard macOS
|
||||||
|
|
||||||
|
# commande identique:
|
||||||
|
$ awk '1' test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Fichier avec séparateur:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat test.csv
|
||||||
|
ubuntu,Linux
|
||||||
|
mint,Linux
|
||||||
|
debian,Linux
|
||||||
|
raspbian,Linux
|
||||||
|
mojave,macOS
|
||||||
|
sierra,macOS
|
||||||
|
tiger,macOS
|
||||||
|
snowleopard,macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher la 1ere colonne d'un fichier:
|
||||||
|
|
||||||
|
il faut spécifier le séparateur:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ awk -F"," '{print $1}' test.csv
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
mojave
|
||||||
|
sierra
|
||||||
|
tiger
|
||||||
|
snowleopard
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# idem, autre commande:
|
||||||
|
# FS (Field Separator)
|
||||||
|
$ awk '{print $2}' FS="," test.csv
|
||||||
|
Linux
|
||||||
|
Linux
|
||||||
|
Linux
|
||||||
|
Linux
|
||||||
|
macOS
|
||||||
|
macOS
|
||||||
|
macOS
|
||||||
|
macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les colonnes 1 et 2:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ awk -F"," '{print $1, $2}' test.csv
|
||||||
|
ubuntu Linux
|
||||||
|
mint Linux
|
||||||
|
debian Linux
|
||||||
|
raspbian Linux
|
||||||
|
mojave macOS
|
||||||
|
sierra macOS
|
||||||
|
tiger macOS
|
||||||
|
snowleopard macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les colonnes 1 et 2, avec un séparateur:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# OFS (Output Field Separator)
|
||||||
|
|
||||||
|
$ awk -F"," '{print $1, $2}' OFS=";" test.csv
|
||||||
|
ubuntu;Linux
|
||||||
|
mint;Linux
|
||||||
|
debian;Linux
|
||||||
|
raspbian;Linux
|
||||||
|
mojave;macOS
|
||||||
|
sierra;macOS
|
||||||
|
tiger;macOS
|
||||||
|
snowleopard;macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Passer un argument à awk:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ x=3
|
||||||
|
|
||||||
|
$ awk '{print $0,val}' OFS=, val=$x test.csv
|
||||||
|
ubuntu,Linux,3
|
||||||
|
mint,Linux,3
|
||||||
|
debian,Linux,3
|
||||||
|
raspbian,Linux,3
|
||||||
|
mojave,macOS,3
|
||||||
|
sierra,macOS,3
|
||||||
|
tiger,macOS,3
|
||||||
|
snowleopard,macOS,3
|
||||||
|
|
||||||
|
$ export x
|
||||||
|
$ awk '{print $0,ENVIRON["x"]}' OFS=, test.csv
|
||||||
|
ubuntu,Linux,3
|
||||||
|
mint,Linux,3
|
||||||
|
debian,Linux,3
|
||||||
|
raspbian,Linux,3
|
||||||
|
mojave,macOS,3
|
||||||
|
sierra,macOS,3
|
||||||
|
tiger,macOS,3
|
||||||
|
snowleopard,macOS,3
|
||||||
|
```
|
||||||
|
|
||||||
@@ -40,6 +40,9 @@ then
|
|||||||
elif [ $foo -eq 2 ]
|
elif [ $foo -eq 2 ]
|
||||||
then
|
then
|
||||||
echo "Two"
|
echo "Two"
|
||||||
|
elif [ $foo -eq 3 ]
|
||||||
|
then
|
||||||
|
echo "Three"
|
||||||
else
|
else
|
||||||
echo "Bigger than two"
|
echo "Bigger than two"
|
||||||
fi
|
fi
|
||||||
@@ -63,6 +66,12 @@ then
|
|||||||
echo "Either you didn't give me a value or file is unreadable"
|
echo "Either you didn't give me a value or file is unreadable"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [ $num -gt 100 ] && [ $num -lt 200 ]
|
||||||
|
then
|
||||||
|
echo "The number lies between 100 and 200"
|
||||||
|
fi
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -243,7 +252,7 @@ if [ olderfile -ot newerfile ]; then
|
|||||||
if [ /mnt/remote/remotefile -ot localfile ]; then
|
if [ /mnt/remote/remotefile -ot localfile ]; then
|
||||||
```
|
```
|
||||||
|
|
||||||
Si les fichiers <u>*same et file font référence au même device / inode*</u>
|
Si les fichiers <u>*same et file font référence au même device / inode*</u>.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if [ same -ef file ]; then
|
if [ same -ef file ]; then
|
||||||
@@ -251,7 +260,15 @@ if [ same -ef file ]; then
|
|||||||
if [ /dev/cdrom -ef /dev/dvd ]; then
|
if [ /dev/cdrom -ef /dev/dvd ]; then
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Si un fichier a été <u>modifié durant les 5 dernières minutes</u>.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dir="/usr/local/etc/httpd"
|
||||||
|
name="httpd.conf"
|
||||||
|
|
||||||
|
test=$(find $dir -name "$name" -mmin -5 -maxdepth 1)
|
||||||
|
[ ! -z $test ] && echo -e "\033[1;31m❗️ ️$name was modified in the last 5 minutes\033[0m"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -266,19 +283,19 @@ if [ “$1” == “moo” ]; then
|
|||||||
Si les chaines sont <u>*différentes*</u> [ STRING1 != STRING2 ]
|
Si les chaines sont <u>*différentes*</u> [ STRING1 != STRING2 ]
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if [ “$userinput” != “$password” ];
|
if [ “$userinput” != “$password” ]; then
|
||||||
```
|
```
|
||||||
|
|
||||||
Si la chaine 1 <u>*est triée après*</u> la chaine 2 [ STRING1 > STRING2 ]
|
Si la chaine 1 <u>*est triée après*</u> la chaine 2 [ STRING1 > STRING2 ]
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if [ “$userinput” > “$password” ];
|
if [ “$userinput” > “$password” ]; then
|
||||||
```
|
```
|
||||||
|
|
||||||
Si la chaine 1 <u>*est triée avant*</u> la chaine 2 [ STRING1 < STRING2 ]
|
Si la chaine 1 <u>*est triée avant*</u> la chaine 2 [ STRING1 < STRING2 ]
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
if [ “$userinput” < “$password” ];
|
if [ “$userinput” < “$password” ]; then
|
||||||
```
|
```
|
||||||
|
|
||||||
Si la chaine <u>*NONEMPTYSTRING a une longueur > 0*</u> (contient 1 ou plusieurs caractères)
|
Si la chaine <u>*NONEMPTYSTRING a une longueur > 0*</u> (contient 1 ou plusieurs caractères)
|
||||||
|
|||||||
14
docs/Linux/divers.md
Normal file
14
docs/Linux/divers.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Divers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Calculer la taille d'un dossier et des ses sous-dossiers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ du -hcs folder/*
|
||||||
|
8,0K folder/Camera
|
||||||
|
8,0K total
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
44
docs/Linux/format_ext4.md
Normal file
44
docs/Linux/format_ext4.md
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Formater un disque externe au format ext4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1. Ouvrir Gparted (Système->Administration dans Debian)
|
||||||
|
2. Sélectionner le disque dans le menu déroulant à droite (/dev/sdg 698Gio)
|
||||||
|
3. Cliquer sur la bande du disque
|
||||||
|
4. Partition > Demonter
|
||||||
|
5. Partition -> Supprimer -> Appliquer
|
||||||
|
6. Tout l'espace est non alloué
|
||||||
|
7. Partition -> Nouvelle
|
||||||
|
Créer comme: Partiiton primaire
|
||||||
|
Système de fichier: ext4
|
||||||
|
Nouvelle taille: en Mio
|
||||||
|
Ajouter une étiquette
|
||||||
|
8. Ajouter -> Appliquer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Le disque est formaté ext4
|
||||||
|
|
||||||
|
Pour ce type de système de fichier (ext4, ext3...) les droits sont automatiquement donné à root (ce n'est pas le cas pour fat, ntfs...). L'utilisateur courant ne peut pas y écrire.
|
||||||
|
|
||||||
|
Il faut donc modifier les droits:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bruno@debian:~$ cd /media/bruno/
|
||||||
|
bruno@debian:/media/bruno$ ls -la
|
||||||
|
total 12
|
||||||
|
drwxr-x---+ 3 root root 4096 févr. 2 09:02 .
|
||||||
|
drwxr-xr-x 4 root root 4096 janv. 22 20:50 ..
|
||||||
|
drwxrwxr-x 5 root root 4096 févr. 2 08:15 RPi
|
||||||
|
|
||||||
|
bruno@debian:/media/bruno$ sudo chown bruno:bruno -R RPi/
|
||||||
|
[sudo] Mot de passe de bruno :
|
||||||
|
|
||||||
|
bruno@debian:/media/bruno$ ls -la
|
||||||
|
total 12
|
||||||
|
drwxr-x---+ 3 root root 4096 févr. 2 09:02 .
|
||||||
|
drwxr-xr-x 4 root root 4096 janv. 22 20:50 ..
|
||||||
|
drwxrwxr-x 5 bruno bruno 4096 févr. 2 08:15 RPi
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
174
docs/Linux/read.md
Normal file
174
docs/Linux/read.md
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
# Lire un fichier
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat test.txt
|
||||||
|
ubuntu Linux
|
||||||
|
mint Linux
|
||||||
|
debian Linux
|
||||||
|
raspbian Linux
|
||||||
|
mojave macOS
|
||||||
|
sierra macOS
|
||||||
|
tiger macOS
|
||||||
|
snowleopard macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Lire un fichier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat read.sh
|
||||||
|
#!/bin/bash
|
||||||
|
while read line
|
||||||
|
do
|
||||||
|
echo "Line is : $line"
|
||||||
|
done < test.txt
|
||||||
|
|
||||||
|
$ ./read.sh
|
||||||
|
Line is : ubuntu Linux
|
||||||
|
Line is : mint Linux
|
||||||
|
Line is : debian Linux
|
||||||
|
Line is : raspbian Linux
|
||||||
|
Line is : mojave macOS
|
||||||
|
Line is : sierra macOS
|
||||||
|
Line is : tiger macOS
|
||||||
|
Line is : snowleopard macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Lire un fichier tabulé:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat read.sh
|
||||||
|
#!/bin/bash
|
||||||
|
while read f1 f2
|
||||||
|
do
|
||||||
|
echo "Distrib : $f1"
|
||||||
|
echo "OS : $f2"
|
||||||
|
done < test.txt
|
||||||
|
|
||||||
|
$ ./read.sh
|
||||||
|
Distrib : ubuntu
|
||||||
|
OS : Linux
|
||||||
|
Distrib : mint
|
||||||
|
OS : Linux
|
||||||
|
Distrib : debian
|
||||||
|
OS : Linux
|
||||||
|
Distrib : raspbian
|
||||||
|
OS : Linux
|
||||||
|
Distrib : mojave
|
||||||
|
OS : macOS
|
||||||
|
Distrib : sierra
|
||||||
|
OS : macOS
|
||||||
|
Distrib : tiger
|
||||||
|
OS : macOS
|
||||||
|
Distrib : snowleopard
|
||||||
|
OS : macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Changer le séparateur:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat read.sh
|
||||||
|
#!/bin/bash
|
||||||
|
while read f1 f2
|
||||||
|
do
|
||||||
|
echo $f1:$f2
|
||||||
|
done < test.txt > test2.txt
|
||||||
|
|
||||||
|
$ cat test2.txt
|
||||||
|
ubuntu:Linux
|
||||||
|
mint:Linux
|
||||||
|
debian:Linux
|
||||||
|
raspbian:Linux
|
||||||
|
mojave:macOS
|
||||||
|
sierra:macOS
|
||||||
|
tiger:macOS
|
||||||
|
snowleopard:macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Lire un fichier .csv:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat test.csv
|
||||||
|
ubuntu,Linux
|
||||||
|
mint,Linux
|
||||||
|
debian,Linux
|
||||||
|
raspbian,Linux
|
||||||
|
mojave,macOS
|
||||||
|
sierra,macOS
|
||||||
|
tiger,macOS
|
||||||
|
snowleopard,macOS
|
||||||
|
|
||||||
|
$ cat read.sh
|
||||||
|
# !/bin/bash
|
||||||
|
IFS=","
|
||||||
|
while read f1 f2
|
||||||
|
do
|
||||||
|
echo "Distrib : $f1"
|
||||||
|
echo "OS : $f2"
|
||||||
|
done < test.csv
|
||||||
|
|
||||||
|
$ ./read.sh
|
||||||
|
Distrib : ubuntu
|
||||||
|
OS : Linux
|
||||||
|
Distrib : mint
|
||||||
|
OS : Linux
|
||||||
|
Distrib : debian
|
||||||
|
OS : Linux
|
||||||
|
Distrib : raspbian
|
||||||
|
OS : Linux
|
||||||
|
Distrib : mojave
|
||||||
|
OS : macOS
|
||||||
|
Distrib : sierra
|
||||||
|
OS : macOS
|
||||||
|
Distrib : tiger
|
||||||
|
OS : macOS
|
||||||
|
Distrib : snowleopard
|
||||||
|
OS : macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Ne pas changer le séparateur définitivement:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat read.sh
|
||||||
|
|
||||||
|
# !/bin/bash
|
||||||
|
OLDIFS=$IFS
|
||||||
|
IFS=","
|
||||||
|
while read f1 f2
|
||||||
|
do
|
||||||
|
echo "Distrib : $f1"
|
||||||
|
echo "OS : $f2"
|
||||||
|
done < test.csv
|
||||||
|
IFS=$OLDIFS
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat read.sh
|
||||||
|
|
||||||
|
# !/bin/bash
|
||||||
|
while IFS="," read f1 f2 f3
|
||||||
|
do
|
||||||
|
echo "Distrib : $f1"
|
||||||
|
echo "OS : $f2"
|
||||||
|
done < test.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Multiples séparateurs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
IFS=":/"
|
||||||
|
```
|
||||||
|
|
||||||
@@ -18,11 +18,14 @@ funnymac@ssh funnymac@ftp.cluster011.ovh.net:/www/backup/
|
|||||||
Copie d'un fichier depuis le répertoire courant vers un répertoire du serveur:
|
Copie d'un fichier depuis le répertoire courant vers un répertoire du serveur:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
~ scp Fichier login@serveur:Chemin
|
$ scp Fichier login@serveur:Chemin
|
||||||
~ scp /home/mickael/data/Ficher2 root@192.168.10.131:/var/www/
|
$ scp /home/mickael/data/Ficher2 root@192.168.10.131:/var/www/
|
||||||
~ scp /Users/bruno/test-copy-scp-2.txt root@192.168.1.8:/root/
|
$ scp /Users/bruno/test-copy-scp-2.txt root@192.168.1.8:/root/
|
||||||
root@DiskStation:~ # scp /root/.profile funnymac@ftp.cluster011.ovh.net:www/backup/.profile_syno_root
|
root@DiskStation:~ # scp /root/.profile funnymac@ftp.cluster011.ovh.net:www/backup/.profile_syno_root
|
||||||
.profile 100% 497 0.5KB/s 0.5KB/s 00:00
|
.profile 100% 497 0.5KB/s 0.5KB/s 00:00
|
||||||
|
$ scp .bashrc pi@framboise.local:/home/pi/Desktop/
|
||||||
|
.bashrc 100% 3640 401.7KB/s 00:00
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Copie d'un répertoire, avec éventuellement ses sous-répertoires, vers un répertoire du serveur:
|
Copie d'un répertoire, avec éventuellement ses sous-répertoires, vers un répertoire du serveur:
|
||||||
|
|||||||
674
docs/Linux/sed.md
Normal file
674
docs/Linux/sed.md
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
# sed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Suppression de ligne:
|
||||||
|
|
||||||
|
Supprimer la <u>1ere ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '1d' test.txt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
|
||||||
|
# le fichier test.txt n'est pas modifié
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -i .bak '1d' test.txt
|
||||||
|
$ cat test.txt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
$ cat test.txt.bak
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
|
||||||
|
# le fichier test.txt est sauvegardé en test.txt.bak
|
||||||
|
# le fichier test.txt est modifié
|
||||||
|
# Sinon pour masOS
|
||||||
|
$ sed -i '' '1d' test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer la <u>3eme ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '3d' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer la <u>dernière ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '$d' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer <u>de la 2eme à 4eme ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '2,4d' test.txt
|
||||||
|
red hat
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les <u>lignes autres que de la 2eme à 4eme</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '2,4!d' test.txt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer la <u>1ere ET la dernière ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '1d;$d' test.txt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes <u>commençant par le caractère 'u'</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/^u/d' test.txt
|
||||||
|
red hat
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes se <u>terminant par le caractère 'n'</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/n$/d' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes se <u>terminant par les caractères 'T', t', 'U' ou 'u'</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/[TtUu]$/d' test.txt
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes <u>vides</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/^$/d' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes <u>contenant l'expression 'red hat'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/red hat/d' test.txt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes <u>ne contenant pas l'expression 'red hat'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/red hat/!d' test.txt
|
||||||
|
red hat
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les lignes <u>contenant les expressions 'ubuntu' OU 'mint'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/ubuntu\|mint/d' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS ???
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer de la <u>1ere ligne à la ligne contenant l'expression 'ubuntu'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '1,/ubuntu/d' test.txt
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer de la <u>ligne contenant l'expression 'ubuntu' jusqu'à la dernière ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/ubuntu/,$d' test.txt
|
||||||
|
red hat
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer la <u>dernière ligne uniquement si elle contient l'expression 'raspbian'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '${/raspbian/d;}' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer la <u>dernière ligne uniquement si elle contient les expressions 'raspbian' ou 'debian'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '${/raspbian\|debian/d;}' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS ???
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la ligne <u>contenant l'expression 'debian' uniquement. si elle est présente dans les lignes 1 à 4</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '1,4{/debian/d;}' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la <u>contenant l'expression 'mint' ET la ligne suivante</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/mint/{N;d;}' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la <u>ligne suivante celle contenant l'expression 'mint'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '/mint/{N;s/\n.*//;}' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la <u>ligne contenant l'expression 'mint' ET la ligne précédente</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/mint/{s/.*//;x;d;};x;p;${x;p;}' test.txt | sed '/^$/d'
|
||||||
|
red hat
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la <u>ligne précedent celle contenant l'expression 'mint'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/mint/{x;d;};1h;1!{x;p;};${x;p;}' test.txt
|
||||||
|
red hat
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprime la <u>ligne contenant l'expression 'mint', ainsi que la précédente et la suivante</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/mint/{N;s/.*//;x;d;};x;p;${x;p;}' test.txt | sed '/^$/d'
|
||||||
|
red hat
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Affichage de ligne:
|
||||||
|
|
||||||
|
Afficher uniquement la <u>1ere ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '1p' test.txt
|
||||||
|
red hat
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher la <u>dernière ligne</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '$p' test.txt
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les lignes qui <u>ne contiennent pas 'b'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/b/!p' test.txt
|
||||||
|
red hat
|
||||||
|
mint
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les lignes qui <u>contiennent 'h' ou 't'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/[ht]/p' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les lignes <u>se terminant par 'n' ou 'N'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/[nN]$/p' test.txt
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher les lignes qui <u>commencent par 'm' ou 'u'</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -n '/^m\|^u/p' test.txt
|
||||||
|
# Ne marche pas sous macOS ???
|
||||||
|
```
|
||||||
|
|
||||||
|
Afficher <u>1 ligne sur 2</u>:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 'n;d' test.txt
|
||||||
|
red hat
|
||||||
|
mint
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Suprression de caractères:
|
||||||
|
|
||||||
|
Commande:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/find/replace/' file
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer le caractère 'a'
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# supprimer le 1er caractère trouvé
|
||||||
|
$ sed 's/a//' test.txt
|
||||||
|
red ht
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debin
|
||||||
|
rspbian
|
||||||
|
|
||||||
|
# supprimer tous les caractères
|
||||||
|
$ sed 's/a//g' test.txt
|
||||||
|
red ht
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debin
|
||||||
|
rspbin
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer le 1er caractère de chaque ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/^.//' test.txt
|
||||||
|
ed hat
|
||||||
|
buntu
|
||||||
|
int
|
||||||
|
ebian
|
||||||
|
aspbian
|
||||||
|
|
||||||
|
# autre commande identique
|
||||||
|
$ sed 's/.//' test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer le dernier caractère de chaque ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/.$//' test.txt
|
||||||
|
red ha
|
||||||
|
ubunt
|
||||||
|
min
|
||||||
|
debia
|
||||||
|
raspbia
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les 1er et dernier caractères de chaque ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/.//;s/.$//' test.txt
|
||||||
|
ed ha
|
||||||
|
bunt
|
||||||
|
in
|
||||||
|
ebia
|
||||||
|
aspbia
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer le 1er caractère de chaque ligne, mais seulement celui spécifié (ici le 'u'):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/^u//' test.txt
|
||||||
|
red hat
|
||||||
|
buntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer le dernier caractère de chaque ligne, mais seulement celui spécifié (ici le 'u'):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/n$//' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debia
|
||||||
|
raspbia
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les 3 premiers caractères de chaque ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/...//' test.txt
|
||||||
|
hat
|
||||||
|
ntu
|
||||||
|
t
|
||||||
|
ian
|
||||||
|
pbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les n premiers caractères de chaque ligne (ici 3):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -r 's/.{3}//' test.txt
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les n derniers caractères de chaque ligne (ici 3):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -r 's/.{3}$//'
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Tout supprimer sauf les n premiers caractères de chaque ligne (ici 3):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -r 's/(.{3}).*/\1/' test.txt
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Tout supprimer sauf les n derniers caractères de chaque ligne (ici 3):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -r 's/.*(.{3})/\1/' test.txt
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer plusieurs caractères (ici toutes les voyelles):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[aeiou]//g' test.txt
|
||||||
|
rd ht
|
||||||
|
bnt
|
||||||
|
mnt
|
||||||
|
dbn
|
||||||
|
rspbn
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer une expression ('bia'):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/bia//g' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
den
|
||||||
|
raspn
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer seulement la n ième occurence d'un caractère:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/u//2' test.txt
|
||||||
|
red hat
|
||||||
|
ubntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Tout supprimer après le caractère spécifié ('b'):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/b.*//' test.txt
|
||||||
|
red hat
|
||||||
|
u
|
||||||
|
mint
|
||||||
|
de
|
||||||
|
rasp
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer tous les nombres:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[0-9]//g' test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer toutes les minuscules:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[a-z]//g' test.txt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$
|
||||||
|
# supprime les caractères mais laisse des lignes vides
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer tout sauf les minuscules:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[^a-z]//g' test.txt
|
||||||
|
redhat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer tous les caractères alpha-numériques:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[a-zA-Z0-9]//g' test.txt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$
|
||||||
|
# supprime les caractères mais laisse des lignes vides
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer minuscule et majuscule d'un caractère:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/[uU]//g' test.txt
|
||||||
|
red hat
|
||||||
|
bnt
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Remplacement de caractères:
|
||||||
|
|
||||||
|
Ajouter une expression en début de ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/^/Distrib: /' test.txt
|
||||||
|
Distrib: red hat
|
||||||
|
Distrib: ubuntu
|
||||||
|
Distrib: mint
|
||||||
|
Distrib: debian
|
||||||
|
Distrib: raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouter une expression en fin de ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/$/ Tux ruleeeeez/' test.txt
|
||||||
|
red hat Tux ruleeeeez
|
||||||
|
ubuntu Tux ruleeeeez
|
||||||
|
mint Tux ruleeeeez
|
||||||
|
debian Tux ruleeeeez
|
||||||
|
raspbian Tux ruleeeeez
|
||||||
|
```
|
||||||
|
|
||||||
|
Substituer un caractère (le 1er trouvé de chaque ligne):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/a/A/' test.txt
|
||||||
|
red hAt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debiAn
|
||||||
|
rAspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Substituer tous les caractères:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/a/A/g' test.txt
|
||||||
|
red hAt
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debiAn
|
||||||
|
rAspbiAn
|
||||||
|
```
|
||||||
|
|
||||||
|
Subsituer uniquement la 2nde occurence:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/a/A/2' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
mint
|
||||||
|
debian
|
||||||
|
raspbiAn
|
||||||
|
```
|
||||||
|
|
||||||
|
Subsituer toutes les occurences à partir de la 2nde:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/u/U/2g' test.txt
|
||||||
|
|
||||||
|
# ne fonctionne pas sous macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Substituer uniquement sur le n eme ligne (3eme):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '3s/n/N/g' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
miNt
|
||||||
|
debian
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Subtituer uniquement de la 3e à la 4e ligne:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '3,4s/n/N/g' test.txt
|
||||||
|
red hat
|
||||||
|
ubuntu
|
||||||
|
miNt
|
||||||
|
debiaN
|
||||||
|
raspbian
|
||||||
|
```
|
||||||
|
|
||||||
|
Remplacer la ligne entière:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/.*/& is a distrib Linux/' test.txt
|
||||||
|
red hat is a distrib Linux
|
||||||
|
ubuntu is a distrib Linux
|
||||||
|
mint is a distrib Linux
|
||||||
|
debian is a distrib Linux
|
||||||
|
raspbian is a distrib Linux
|
||||||
|
```
|
||||||
|
|
||||||
|
Multiples substitutions:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed 's/a/A/g; s/u/uUu/g' test.txt
|
||||||
|
red hAt
|
||||||
|
uUubuUuntuUu
|
||||||
|
mint
|
||||||
|
debiAn
|
||||||
|
rAspbiAn
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Ajouter une ligne (à voir pour macOS):
|
||||||
|
|
||||||
|
Ajouter une ligne d'entête:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed '1i Employee, EmpId' test.txt
|
||||||
|
# GNU sed, ne marche pas pour macOS
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouter '————————' après la ligne d'entête:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -i '1a ---------------' test.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouter une ligne tout à la fin:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sed -i '$a ---------------' test.txt
|
||||||
|
```
|
||||||
77
docs/Linux/string.md
Normal file
77
docs/Linux/string.md
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# String
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Supprimer la 1ere ligne d'un fichier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm ls | sed '1,1d'
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer les 2 premières lignes d'un fichier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm ls | sed '1,2d'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Supprimer les lignes contenant un motif:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ npm ls | grep -v 'motif'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Récupérer la 1ere sous-chaine d'une chaine:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ string='924782627 GPX Editor (2.96.10)'
|
||||||
|
|
||||||
|
$ echo "$string" | awk '{print $1}'
|
||||||
|
924782627
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Récupérer tout sauf la 1ere sous-chaine d'une chaine:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ string='924782627 GPX Editor (2.96.10)'
|
||||||
|
|
||||||
|
$ echo "$string" | awk {'first = $1; $1=""; print $0'}
|
||||||
|
GPX Editor (2.96.10)
|
||||||
|
|
||||||
|
# Supprimer le 1er espace
|
||||||
|
$ echo "$string" | awk {'first = $1; $1=""; print $0'}| sed 's/^ //g'
|
||||||
|
GPX Editor (2.96.10)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
awk:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ string='924782627 GPX Editor (2.96.10)'
|
||||||
|
|
||||||
|
$ echo "$string"
|
||||||
|
924782627 GPX Editor (2.96.10)
|
||||||
|
# Par défaut le séparateur de awk est l'espace
|
||||||
|
$ echo "$string" | awk '{print $1}'
|
||||||
|
924782627
|
||||||
|
$ echo "$string" | awk '{print $2}'
|
||||||
|
GPX
|
||||||
|
$ echo "$string" | awk '{print $4}'
|
||||||
|
(2.96.10)
|
||||||
|
# On met '(' comme séparateur
|
||||||
|
$ echo "$string" | awk -F "(" '{print $1}'
|
||||||
|
924782627 GPX Editor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
355
docs/Programmation/Python/Python.md
Normal file
355
docs/Programmation/Python/Python.md
Normal file
@@ -0,0 +1,355 @@
|
|||||||
|
# Python 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1. collections:
|
||||||
|
1. [liste](liste.md)
|
||||||
|
2. [dictionnaire](dictionnaire.md)
|
||||||
|
3. [tuple](tuple.md)
|
||||||
|
4. [set](set.md)
|
||||||
|
2. [class - objet](class.md)
|
||||||
|
3. [date](date.md)
|
||||||
|
4. [fichiers](fichiers.md)
|
||||||
|
5. [fonctions](fonctions.md)
|
||||||
|
6. [fabric-ssh](fabric-ssh.md)
|
||||||
|
7. [regex](regex.md)
|
||||||
|
8. [strings](string.md)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
https://www.tutorialspoint.com/python3/index.htm
|
||||||
|
|
||||||
|
https://www.w3schools.com/python/default.asp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Instruction de boucles
|
||||||
|
|
||||||
|
##### while:
|
||||||
|
|
||||||
|
```python
|
||||||
|
while n != 1:
|
||||||
|
if n % 2 == 0 : # si un nombre entier modulo 2 vaut 0, il est pair
|
||||||
|
n = n // 2
|
||||||
|
else: # cas où le nombre est impair
|
||||||
|
n = 3*n + 1
|
||||||
|
|
||||||
|
print(n)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### for:
|
||||||
|
|
||||||
|
```python
|
||||||
|
somme = 0
|
||||||
|
for val in range(5): # 0 1 2 3 4
|
||||||
|
somme += val
|
||||||
|
|
||||||
|
print(somme)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Conditions:
|
||||||
|
|
||||||
|
##### if:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> x = 1
|
||||||
|
>>> if x > 5:
|
||||||
|
... x = x + 1
|
||||||
|
... elif x == 5:
|
||||||
|
... x = x + 1000
|
||||||
|
... else:
|
||||||
|
... x = x - 1
|
||||||
|
...
|
||||||
|
>>> x
|
||||||
|
0
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Compréhension de liste:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Soit une liste:
|
||||||
|
>>> a = [1,4,2,7,1,9,0,3,4,6,6,6,8,3]
|
||||||
|
|
||||||
|
# On veut filtrer les nombres > 5
|
||||||
|
>>> b = []
|
||||||
|
>>> for x in a:
|
||||||
|
... if x > 5:
|
||||||
|
... b.append(x)
|
||||||
|
...
|
||||||
|
>>> b
|
||||||
|
[7, 9, 6, 6, 6, 8]
|
||||||
|
|
||||||
|
# La même chose sur une seule ligne
|
||||||
|
>>> [x for x in a if x > 5]
|
||||||
|
[7, 9, 6, 6, 6, 8]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Convertir plusueurs chaines en entiers
|
||||||
|
>>> items = ["5", "10", "15"]
|
||||||
|
>>> items = [int(x) for x in items]
|
||||||
|
>>> print(items)
|
||||||
|
[5, 10, 15]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Collections:
|
||||||
|
|
||||||
|
[liste](liste.md):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1,2,3]
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3]
|
||||||
|
|
||||||
|
# modifiable, ordonée
|
||||||
|
```
|
||||||
|
|
||||||
|
[set](set.md):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"apple", "banana", "cherry"}
|
||||||
|
>>> un_set
|
||||||
|
{'apple', 'cherry', 'banana'}
|
||||||
|
|
||||||
|
# ni ordonnée, ni indexée
|
||||||
|
```
|
||||||
|
|
||||||
|
[tuple](tuple.md):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_tuple = ("alpha","beta","gamma")
|
||||||
|
>>> un_tuple
|
||||||
|
('alpha', 'beta', 'gamma')
|
||||||
|
|
||||||
|
# non modifiable, ordonée
|
||||||
|
```
|
||||||
|
|
||||||
|
[dictionnaire](dictionnaire.md):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = {
|
||||||
|
... "brand": "Ford",
|
||||||
|
... "model": "Mustang",
|
||||||
|
... "year": 1964
|
||||||
|
... }
|
||||||
|
>>> un_dict
|
||||||
|
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
|
||||||
|
|
||||||
|
# modifiable, non ordonée, indexée
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Opérateurs:
|
||||||
|
|
||||||
|
Operateurs relationnels:
|
||||||
|
|
||||||
|
```python
|
||||||
|
<, <=, >, >=, == et !=
|
||||||
|
```
|
||||||
|
|
||||||
|
Opérateurs booléens:
|
||||||
|
|
||||||
|
```python
|
||||||
|
and, or et not
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Instruction `pass`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
if x < 0 :
|
||||||
|
pass # TODO compléter le code (cas où x < 0)
|
||||||
|
else :
|
||||||
|
print('traitement du cas où x est positif')
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Fonction (def):
|
||||||
|
|
||||||
|
```python
|
||||||
|
def pgcd(x, y):
|
||||||
|
"""
|
||||||
|
calcule le pgcd de 2 nombres entiers positifs
|
||||||
|
"""
|
||||||
|
while (y > 0):
|
||||||
|
x, y = y, x % y
|
||||||
|
return x
|
||||||
|
|
||||||
|
>>> pgcd(45, 78)
|
||||||
|
3
|
||||||
|
|
||||||
|
# utiliser une liste pour paramètres
|
||||||
|
>>> param = [45, 78]
|
||||||
|
>>> pgcd(*param)
|
||||||
|
3
|
||||||
|
# * => opérateur splat
|
||||||
|
|
||||||
|
# rendre obligatoire uniquement certains paramètres
|
||||||
|
>>> def fiche(prenom, nom, *reste):
|
||||||
|
... return prenom + " " + nom
|
||||||
|
...
|
||||||
|
>>> fiche("john", "doe")
|
||||||
|
'john doe'
|
||||||
|
|
||||||
|
# utiliser un dictionnaire pour paramèttres
|
||||||
|
>>> param = {"prenom": "john", "nom": "doe"}
|
||||||
|
>>> def fiche(**param):
|
||||||
|
... return param["nom"]
|
||||||
|
...
|
||||||
|
>>> fiche(nom="doe")
|
||||||
|
'doe'
|
||||||
|
|
||||||
|
>>> def fiches(prenom="", nom=""):
|
||||||
|
... return "{} {}".format(prenom, nom)
|
||||||
|
...
|
||||||
|
>>> fiches(*param)
|
||||||
|
'prenom nom'
|
||||||
|
>>> fiches(**param)
|
||||||
|
'john doe'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Importer des fonctions d'autres fichiers
|
||||||
|
|
||||||
|
Le fichier regroupant les fonctions `functions.py` se trouvent dans le même répertoire que le script `test.py`:
|
||||||
|
|
||||||
|
`functions.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
def x2(x):
|
||||||
|
return x * 2
|
||||||
|
```
|
||||||
|
|
||||||
|
`test.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
from functions import *
|
||||||
|
|
||||||
|
nb = int(input("Choisissez un nombre : "))
|
||||||
|
print("Vous avez choisi", nb)
|
||||||
|
|
||||||
|
multiplie = x2(nb)
|
||||||
|
print(nb, " x2 = ", multiplie)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Importer un module:
|
||||||
|
|
||||||
|
L'interpréteur recherche les modules dans
|
||||||
|
|
||||||
|
1. le répertoire courant
|
||||||
|
2. tous les répertoires de la variable `PYTHONPATH`
|
||||||
|
3. dans le chemin par défaut (`/usr/local/lib/python3/`)
|
||||||
|
|
||||||
|
```python
|
||||||
|
import datetime
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# importe uniquement la section time du module datetime
|
||||||
|
from datetime import time
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# importe le module calendar et crée un alias c
|
||||||
|
import calendar as c
|
||||||
|
|
||||||
|
print(c.month_name[1])
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Exécuter un script Python
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python /chemin/script.py
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Exceptions (try / except / finally)
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> a = 0
|
||||||
|
>>> b = 2
|
||||||
|
>>> try:
|
||||||
|
... b/a
|
||||||
|
... print("Ok", b/a)
|
||||||
|
... except:
|
||||||
|
... print("Erreur")
|
||||||
|
...
|
||||||
|
Erreur
|
||||||
|
|
||||||
|
|
||||||
|
>>> try:
|
||||||
|
... b/a
|
||||||
|
... print("Ok", b/a)
|
||||||
|
... except ZeroDivisionError:
|
||||||
|
... print("Erreur: division par 0")
|
||||||
|
... finally:
|
||||||
|
... print("Instructions exécutées quelque soit les erreurs générées")
|
||||||
|
...
|
||||||
|
Erreur: division par 0
|
||||||
|
Instructions exécutées quelque soit les erreurs générées
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### pdb
|
||||||
|
|
||||||
|
pdb est un débugger.
|
||||||
|
|
||||||
|
Ajouter ce qui suit à la ligne à étudier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
```
|
||||||
|
|
||||||
|
Le programme s'arrête à la ligne et donne accès à un shell:
|
||||||
|
|
||||||
|
```python
|
||||||
|
\r\nDNT: 1\r\nAccept-Encoding: gzip, deflate\r\n\r\n'
|
||||||
|
> /Users/bruno/PycharmProjects/webserver/serve2.py(23)<module>()
|
||||||
|
-> client_connection.sendall(http_response)
|
||||||
|
(Pdb) l
|
||||||
|
18 Hello, World!
|
||||||
|
19 """
|
||||||
|
20 import pdb;
|
||||||
|
21
|
||||||
|
22 pdb.set_trace()
|
||||||
|
23 -> client_connection.sendall(http_response)
|
||||||
|
24 client_connection.close()
|
||||||
|
[EOF]
|
||||||
|
(Pdb) n
|
||||||
|
TypeError: a bytes-like object is required, not 'str'
|
||||||
|
> /Users/bruno/PycharmProjects/webserver/serve2.py(23)<module>()
|
||||||
|
-> client_connection.sendall(http_response)
|
||||||
|
(Pdb)
|
||||||
|
```
|
||||||
|
|
||||||
|
Les commandes utiles:
|
||||||
|
|
||||||
|
- `l`: Liste quelques lignes de code avant et après là où vous vous trouver. Utile pour se resituer dans le contexte du programme. ‘l’ pour ‘list’.
|
||||||
|
- `n`: Exécute la ligne suivante. Vous pouvez ainsi continuer l’exécution du programme de bout en bout, ligne par ligne, et le tester en entier. ‘n’ pour ‘next’.
|
||||||
|
- `s`: Si votre ligne contient un appel de fonction ou de méthode, rentre dans à l’intérieur. ‘s’ pour ‘step in’.
|
||||||
|
- `r`: Si vous êtes dans une fonction ou une méthode, celà permet d’en sortir et de passer dans le scope du dessus. ‘r’ pour ‘return’.
|
||||||
|
- `unt`: Si vous êtes à la dernière ligne d’une boucle, permet de reprendre l’exécution jusqu’à la sortie de la boucle. ‘unt’ pour ‘until’.
|
||||||
|
- `q`: Quitte brutalement le programme en le faisant crasher. ‘q’ pour ‘quit’.
|
||||||
|
- `c`: Quitte le debugger et continue l’exécution du programme normalement. Tous les changements que vous avez fait dans le code sont pris en compte. ‘c’ pour ‘continue’.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
70
docs/Programmation/Python/class.md
Normal file
70
docs/Programmation/Python/class.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Créer une class:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class MaClass:
|
||||||
|
x = 5
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Créer un objet:
|
||||||
|
|
||||||
|
```python
|
||||||
|
p1 = MaClass()
|
||||||
|
print(p1.x)
|
||||||
|
|
||||||
|
5
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Fonction \__init__()
|
||||||
|
|
||||||
|
La fonction \__init__() est appelée automatiquement chaque fois que la class est utilisée.
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Person:
|
||||||
|
def __init__(self, name, age):
|
||||||
|
self.name = name
|
||||||
|
self.age = age
|
||||||
|
|
||||||
|
p1 = Person("John", 36)
|
||||||
|
|
||||||
|
print(p1.name)
|
||||||
|
print(p1.age)
|
||||||
|
|
||||||
|
John
|
||||||
|
36
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Méthodes:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Person:
|
||||||
|
def __init__(self, name, age):
|
||||||
|
self.name = name
|
||||||
|
self.age = age
|
||||||
|
|
||||||
|
def myfunc(self):
|
||||||
|
print("Hello my name is " + self.name)
|
||||||
|
|
||||||
|
p1 = Person("John", 36)
|
||||||
|
p1.myfunc()
|
||||||
|
|
||||||
|
Hello my name is John
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Modifier les propiétés de l'objet:
|
||||||
|
|
||||||
|
```python
|
||||||
|
p1.age = 40
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
156
docs/Programmation/Python/date.md
Normal file
156
docs/Programmation/Python/date.md
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
# Date
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
On importe le module `datetime`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from datetime import datetime
|
||||||
|
```
|
||||||
|
|
||||||
|
Obtenir l'heure courante:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> maintenant = datetime.now()
|
||||||
|
>>> maintenant
|
||||||
|
datetime.datetime(2019, 3, 2, 6, 57, 24, 532139)
|
||||||
|
|
||||||
|
# datetime(année, mois, jour, heure, minute, seconde, microseconde, fuseau horaire)
|
||||||
|
|
||||||
|
>>> maintenant.year
|
||||||
|
2019
|
||||||
|
>>> maintenant.month
|
||||||
|
3
|
||||||
|
>>> maintenant.day
|
||||||
|
2
|
||||||
|
>>> maintenant.hour
|
||||||
|
6
|
||||||
|
>>> maintenant.minute
|
||||||
|
57
|
||||||
|
>>> maintenant.second
|
||||||
|
24
|
||||||
|
>>> maintenant.microsecond
|
||||||
|
532139
|
||||||
|
>>> maintenant.isocalendar
|
||||||
|
<built-in method isocalendar of datetime.datetime object at 0x104900b70>
|
||||||
|
|
||||||
|
>>> maintenant.date()
|
||||||
|
datetime.date(2019, 3, 2)
|
||||||
|
>>> maintenant.time()
|
||||||
|
datetime.time(6, 57, 24, 532139)
|
||||||
|
```
|
||||||
|
|
||||||
|
Créer une date:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# année, mois, jour sont obligatoires
|
||||||
|
>>> a = datetime(2001, 1, 1)
|
||||||
|
>>> a.year
|
||||||
|
2001
|
||||||
|
```
|
||||||
|
|
||||||
|
Durée:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> duree = datetime.now() - datetime(2001, 1, 1)
|
||||||
|
>>> duree
|
||||||
|
datetime.timedelta(days=6634, seconds=26875, microseconds=353545)
|
||||||
|
|
||||||
|
>>> duree.days
|
||||||
|
6634
|
||||||
|
>>> duree.total_seconds()
|
||||||
|
573204475.353545
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Format d'affichage:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> maintenant = datetime.now()
|
||||||
|
>>> maintenant
|
||||||
|
datetime.datetime(2019, 3, 2, 7, 50, 30, 756453)
|
||||||
|
|
||||||
|
>>> maintenant_US = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
|
||||||
|
>>> maintenant_US
|
||||||
|
'2019-03-02 07:49:12.627321'
|
||||||
|
|
||||||
|
>>> maintenant_FR = datetime.now().strftime('%d-%m-%Y %H:%M:%S')
|
||||||
|
>>> maintenant_FR
|
||||||
|
'02-03-2019 07:53:05'
|
||||||
|
```
|
||||||
|
|
||||||
|
[Liste des formats](https://docs.python.org/fr/3/library/datetime.html#strftime-and-strptime-behavior)
|
||||||
|
|
||||||
|
### Calendrier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import calendar
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> calendar.mdays # nb de. jours dans le mois
|
||||||
|
[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||||
|
>>> calendar.isleap(2020) # année bisextile ?
|
||||||
|
True
|
||||||
|
>>> calendar.weekday(1966, 8, 31) # jour précis d'une date (2 => mercredi)
|
||||||
|
2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Timestamp:
|
||||||
|
|
||||||
|
Récupérer le timestamp courant:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> from datetime import datetime
|
||||||
|
>>> import calendar
|
||||||
|
>>> d = datetime.now()
|
||||||
|
>>> ts = calendar.timegm(d.utctimetuple())
|
||||||
|
>>> ts
|
||||||
|
1551516334
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import time
|
||||||
|
>>> ts = time.time()
|
||||||
|
>>> ts
|
||||||
|
1551511030.9611452
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import datetime
|
||||||
|
>>> ts = datetime.datetime.now().timestamp()
|
||||||
|
>>> ts
|
||||||
|
1551511138.821511
|
||||||
|
|
||||||
|
# equivalent
|
||||||
|
>>> from datetime import datetime
|
||||||
|
>>> ts = datetime.now().timestamp()
|
||||||
|
>>> ts
|
||||||
|
1551511979.337509
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
import calendar, time
|
||||||
|
>>> ts = calendar.timegm(time.gmtime())
|
||||||
|
>>> ts
|
||||||
|
1551511394
|
||||||
|
```
|
||||||
|
|
||||||
|
Récupérer une date depuis un timestamp:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# heure utc
|
||||||
|
>>> d = datetime.utcfromtimestamp(ts)
|
||||||
|
>>> d
|
||||||
|
datetime.datetime(2019, 3, 2, 8, 53, 3)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# heure LOCALE
|
||||||
|
>>> e = datetime.fromtimestamp(ts)
|
||||||
|
>>> e
|
||||||
|
datetime.datetime(2019, 3, 2, 9, 53, 3)
|
||||||
|
```
|
||||||
|
|
||||||
231
docs/Programmation/Python/dictionnaire.md
Normal file
231
docs/Programmation/Python/dictionnaire.md
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
# Dictionnaire
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Un dictionnaire est une sorte de liste, mais qui utilise des clés à la place des index.
|
||||||
|
C'est une collection **non ordonnée**, **modifiable** et **indexée**.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Créer un dictionnaire:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict = {}
|
||||||
|
|
||||||
|
>>> type(dict)
|
||||||
|
<class 'dict'>
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = {
|
||||||
|
... "marque": "Ford",
|
||||||
|
... "modele": "Mustang",
|
||||||
|
... "annee": 1964
|
||||||
|
... }
|
||||||
|
>>> un_dict
|
||||||
|
{'marque': 'Ford', 'modele': 'Mustang', 'annee': 1964}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Constructor dict()
|
||||||
|
>>> un_dict = dict(marque="Ford", modele="Mustang", annee=1964)
|
||||||
|
>>> un_dict
|
||||||
|
{'marque': 'Ford', 'modele': 'Mustang', 'annee': 1964}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Accéder à un item:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = dict(marque="Ford", modele="Mustang", annee=1964)
|
||||||
|
>>> un_dict
|
||||||
|
{'marque': 'Ford', 'modele': 'Mustang', 'annee': 1964}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> x = un_dict["modele"]
|
||||||
|
>>> x
|
||||||
|
'Mustang'
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> x = un_dict.get("modele")
|
||||||
|
>>> x
|
||||||
|
'Mustang'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Récupérer une valeur (get):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict = {'language': 'python', 'version': '3.7'}
|
||||||
|
>>>
|
||||||
|
>>> dict.get("language")
|
||||||
|
'python'
|
||||||
|
>>> dict.get("os", "pas de clé os")
|
||||||
|
'pas de clé os'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Modifier une valeur:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = dict(marque="Ford", modele="Mustang", annee=1964)
|
||||||
|
>>> un_dict["annee"] = 1965
|
||||||
|
>>> un_dict
|
||||||
|
{'marque': 'Ford', 'modele': 'Mustang', 'annee': 1965}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Y ajouter des valeurs:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict["language"] = "python"
|
||||||
|
>>> dict["version"] = "3.7"
|
||||||
|
>>> dict
|
||||||
|
{'language': 'python', 'version': '3.7'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Vérifier la présence d'une clé (in):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> "language" in dict
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer une entrée (del):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> del dict["version"]
|
||||||
|
>>> print(dict)
|
||||||
|
{'language': 'python'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer une entrée (pop):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict.pop("version")
|
||||||
|
'3.7'
|
||||||
|
>>> dict
|
||||||
|
{'language': 'python'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer la dernière entrée (popitem):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict["version"] = "3.7"
|
||||||
|
>>> dict["type"] = "interpreté"
|
||||||
|
>>> dict
|
||||||
|
{'language': 'python', 'version': '3.7', 'type': 'interprete'}
|
||||||
|
>>> dict.popitem()
|
||||||
|
('type', 'interprete')
|
||||||
|
>>> dict
|
||||||
|
{'language': 'python', 'version': '3.7'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un dictionnaire (del):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = {'language': 'python', 'version': '3.7'}
|
||||||
|
>>> del un_dict
|
||||||
|
>>> un_dict
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
NameError: name 'un_dict' is not defined
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Vider un dictionnaire (clear):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_dict = {'language': 'python', 'version': '3.7'}
|
||||||
|
>>> un_dict.clear()
|
||||||
|
>>> un_dict
|
||||||
|
{}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Récupérer les clés par une boucle (keys):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> for cle in dict.keys():
|
||||||
|
... print(cle)
|
||||||
|
...
|
||||||
|
language
|
||||||
|
version
|
||||||
|
|
||||||
|
>>> for cle in dict:
|
||||||
|
... print(cle)
|
||||||
|
...
|
||||||
|
language
|
||||||
|
version
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Récupérer les valeurs par une boucle (values):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> for valeur in dict.values():
|
||||||
|
... print(valeur)
|
||||||
|
...
|
||||||
|
python
|
||||||
|
3.7
|
||||||
|
|
||||||
|
>>> for val in dict:
|
||||||
|
... print(dict[val])
|
||||||
|
...
|
||||||
|
python
|
||||||
|
3.7
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Récupérer les clés et les valeurs par une boucle (items):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> for cle, valeur in dict.items():
|
||||||
|
... print(cle, valeur)
|
||||||
|
...
|
||||||
|
language python
|
||||||
|
version 3.7
|
||||||
|
```
|
||||||
|
|
||||||
|
Vérifier si une clé existe dans un dictionnaire:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict = {'language': 'python', 'version': '3.7'}
|
||||||
|
>>> if "language" in dict:
|
||||||
|
... print("'language' est dans dict")
|
||||||
|
...
|
||||||
|
'language' est dans dict
|
||||||
|
```
|
||||||
|
|
||||||
|
Longueur d'un dictionnaire:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> dict = {'language': 'python', 'version': '3.7'}
|
||||||
|
>>> print(len(dict))
|
||||||
|
2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Copier un dictionnaire (copy):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> autre_dict = dict.copy()
|
||||||
|
>>> autre_dict
|
||||||
|
{'language': 'python', 'version': '3.7'}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Méthodes:
|
||||||
|
|
||||||
|
| Méthode | Description |
|
||||||
|
| ------------ | ----------- |
|
||||||
|
| clear() | |
|
||||||
|
| copy() | |
|
||||||
|
| fromkeys() | |
|
||||||
|
| get() | |
|
||||||
|
| items() | |
|
||||||
|
| keys() | |
|
||||||
|
| pop() | |
|
||||||
|
| popitem() | |
|
||||||
|
| setdefault() | |
|
||||||
|
| update() | |
|
||||||
|
| values() | |
|
||||||
|
|
||||||
33
docs/Programmation/Python/fabric-ssh.md
Normal file
33
docs/Programmation/Python/fabric-ssh.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Fabric SSH Python
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installer fabric et paramiko:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ pip install fabric
|
||||||
|
$ pip install paramiko
|
||||||
|
|
||||||
|
# CryptographyDeprecationWarning
|
||||||
|
$ pip install cryptography==2.5
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`fabfile.py`
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fabric import Connection
|
||||||
|
c = Connection(host='192.168.1.7', user='bruno', port=42666)
|
||||||
|
|
||||||
|
result = c.run('uname -s')
|
||||||
|
|
||||||
|
result = c.put(local='/Users/bruno/test.csv', remote='/homes/bruno')
|
||||||
|
|
||||||
|
result = c.get(remote='/homes/bruno/httpd-vhost.conf', local='/Users/bruno/Downloads/')
|
||||||
|
result = c.get(remote='/homes/bruno/httpd-vhost.conf')
|
||||||
|
|
||||||
|
# erreur avec '/homes/bruno/hello.py'
|
||||||
|
result = c.run('python hello.py')
|
||||||
|
```
|
||||||
|
|
||||||
208
docs/Programmation/Python/fichiers.md
Normal file
208
docs/Programmation/Python/fichiers.md
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
# Fichiers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Fonction open:
|
||||||
|
|
||||||
|
##### Ouvrir un fichier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
fichier = open("test.py","r")
|
||||||
|
print(fichier)
|
||||||
|
fichier.close()
|
||||||
|
|
||||||
|
>>> <_io.TextIOWrapper name='test.py' mode='r' encoding='UTF-8'>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Ouvrir et afficher un fichier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
fichier = open("test.py","r")
|
||||||
|
print(fichier.read())
|
||||||
|
fichier.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
Autre syntaxe:
|
||||||
|
|
||||||
|
```python
|
||||||
|
with open("test.py","r") as fichier:
|
||||||
|
print(fichier.read())
|
||||||
|
```
|
||||||
|
|
||||||
|
Parcourrir un fichier ligne par ligne:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> fichier = open("serve.py","r")
|
||||||
|
>>> for x in fichier:
|
||||||
|
... print(x)
|
||||||
|
...
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Ecrire dans un fichier (à la suite, sur une nouvelle ligne):
|
||||||
|
|
||||||
|
```python
|
||||||
|
fichier = open("test.py","a")
|
||||||
|
fichier.write("\n\n\"\"\" Commentaire \"\"\"")
|
||||||
|
fichier.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Type d'ouverture:
|
||||||
|
|
||||||
|
```python
|
||||||
|
r, pour une ouverture en lecture (READ).
|
||||||
|
w, pour une ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé. Si le fichier n'existe pas python le crée.
|
||||||
|
a, pour une ouverture en mode ajout à la fin du fichier (APPEND). Si le fichier n'existe pas python le crée.
|
||||||
|
b, pour une ouverture en mode binaire.
|
||||||
|
t, pour une ouverture en mode texte.
|
||||||
|
x, crée un nouveau fichier et l'ouvre pour écriture
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Test si un fichier existe:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
if os.path.exists("serve.py"):
|
||||||
|
print("Le fichier existe")
|
||||||
|
else:
|
||||||
|
print("Le fichier n'existe pas")
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un fichier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
if os.path.exists("zz.py"):
|
||||||
|
os.remove("zz.py")
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un dossier:
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
if os.path.exists("empty_folder"):
|
||||||
|
os.rmdir("empty_folder")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Chemins
|
||||||
|
|
||||||
|
##### Méthodes:
|
||||||
|
|
||||||
|
```
|
||||||
|
>>> help(os.path)
|
||||||
|
|
||||||
|
abspath(path) → Retourne un chemin absolu
|
||||||
|
basename(p) → Retourne le dernier élément d'un chemin
|
||||||
|
commonprefix(list) → Retourne le chemin commun le plus long d'une liste de chemins
|
||||||
|
dirname(p) → Retourne le dossier parent de l'élément
|
||||||
|
exists(path) → Test si un chemin existe
|
||||||
|
getaTime(filename) → Retourne la date du dernier accès au fichier [os.stat()]
|
||||||
|
getctime(filename) → Retourne la date du dernier changement de metadonnées du fichier
|
||||||
|
getmTime(filename) → Retourne la date de la dernière modification du fichier
|
||||||
|
getsize(filename) → Retourne la tailkle d'un fichier (en octets)
|
||||||
|
isabs(s) → Test si un chemin est absolu
|
||||||
|
isdir(s) → Test si le chemin est un dossier
|
||||||
|
isfile(path) → Test si le chemin est un fichier régulier
|
||||||
|
islink(path) → Test si le chemin est un lien symbolique
|
||||||
|
ismount(path) → Test si le chemin est un point de montage
|
||||||
|
join(path, s) → Ajoute un élément au chemin passé en paramètre
|
||||||
|
normcase(s) → Normalise la casse d'un chemin
|
||||||
|
normpath(path) → Normalise le chemin, élimine les doubles barres obliques, etc.
|
||||||
|
realpath(filename) → Retourne le chemin canonique du nom de fichier spécifié (élimine les liens symboliques)
|
||||||
|
samefile(f1, f2) → Test si deux chemins font référence au même fichier réel
|
||||||
|
sameopenfile(f1, f2) → Test si deux objets de fichiers ouverts font référence au même fichier
|
||||||
|
split(p) → Fractionne un chemin d'accès. Retourne un tuple
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Exemples:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import os.path
|
||||||
|
>>> help(os.path)
|
||||||
|
|
||||||
|
>>> path = "/Users/bruno/PycharmProjects/webserver/index.py"
|
||||||
|
|
||||||
|
>>> os.path.dirname(path)
|
||||||
|
'/Users/bruno/PycharmProjects/webserver'
|
||||||
|
>>> os.path.basename(path)
|
||||||
|
'index.py'
|
||||||
|
>>> os.path.split(path)
|
||||||
|
('/Users/bruno/PycharmProjects/webserver', 'index.py')
|
||||||
|
>>> os.path.abspath(".")
|
||||||
|
'/Users/bruno'
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> os.listdir(os.path.dirname(path))
|
||||||
|
['functions.py', 'server.py', 'index.py', 'serve.py', '__pycache__', 'test.py', 'open.py', '.idea']
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# lister récursivement tous les fichiers
|
||||||
|
|
||||||
|
>>> import os
|
||||||
|
>>> folder = '/Users/bruno/PycharmProjects'
|
||||||
|
>>> for path, dirs, files in os.walk(folder):
|
||||||
|
... for filename in files:
|
||||||
|
... print(filename)
|
||||||
|
...
|
||||||
|
.DS_Store
|
||||||
|
pyvenv.cfg
|
||||||
|
pip3.7
|
||||||
|
python3
|
||||||
|
easy_install
|
||||||
|
python
|
||||||
|
.../...
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Connaître le répertoire courante:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import os
|
||||||
|
>>> os.getcwd()
|
||||||
|
'/Users/bruno/PycharmProjects/webserver'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Rechercher des éléments par motif
|
||||||
|
|
||||||
|
```
|
||||||
|
* → n'importe quel séquence de caractères
|
||||||
|
? → n'importe quel caractère
|
||||||
|
[] → n'importe quel caractère listé entre les crochets
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> import glob
|
||||||
|
|
||||||
|
# Methodes:
|
||||||
|
glob.glob(motif) → Liste les dossiers et les fichiers correspondants au motif
|
||||||
|
glob.iglob(motif) → Idem que glob mais retourne un itérateur
|
||||||
|
|
||||||
|
# Recherche des fichiers python:
|
||||||
|
>>> glob.glob("/Users/bruno/PycharmProjects/webserver/*.py")
|
||||||
|
['/Users/bruno/PycharmProjects/webserver/functions.py', '/Users/bruno/PycharmProjects/webserver/server.py', '/Users/bruno/PycharmProjects/webserver/index.py', '/Users/bruno/PycharmProjects/webserver/serve.py', '/Users/bruno/PycharmProjects/webserver/test.py', '/Users/bruno/PycharmProjects/webserver/open.py']
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Manipuler les éléments
|
||||||
|
|
||||||
|
```python
|
||||||
|
os.makedirs(path) → Créer récursivement tous les dossiers d'un path si ceux-ci n'existent pas
|
||||||
|
os.mkdir(path) → Créer le dernier dossier d'un path. Si un des dossiers n'existe pas une erreur est retournée
|
||||||
|
os.remove(path) → Supprime le fichier / dossier indiqué
|
||||||
|
os.rename(old, new) → Renomme le fichier / dossier indiqué
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
414
docs/Programmation/Python/fonctions.md
Normal file
414
docs/Programmation/Python/fonctions.md
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
# Fonctions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Fonctions natives:
|
||||||
|
|
||||||
|
##### abs(x)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la valeur absolue
|
||||||
|
>>> abs(-3)
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
##### all(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les éléments d'un élément itérable sont True
|
||||||
|
>>> liste = [True, True, True, 1]
|
||||||
|
>>> all(liste)
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
##### any(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si au moins un élément d'un élément itérable est True
|
||||||
|
>>> liste = [True, False, True, 1]
|
||||||
|
>>> any(liste)
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### bin(x)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -convertit un entier en chaine de caractères binaires
|
||||||
|
>>> bin(132)
|
||||||
|
'0b10000100'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### bool()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la valeur boléenne
|
||||||
|
>>> bool(12)
|
||||||
|
True
|
||||||
|
>>> bool(0)
|
||||||
|
False
|
||||||
|
```
|
||||||
|
|
||||||
|
##### callable
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -détermine si un objet est callable (exécutable ou appelable)
|
||||||
|
# -fonctions (user ou builtin), methodes
|
||||||
|
>>> callable("A")
|
||||||
|
False
|
||||||
|
>>> callable(int)
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### chr(n)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la caractère qui correspond à l'unicode n
|
||||||
|
>>> chr(97)
|
||||||
|
'a'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### delattr()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -efface un attribut d'un objet
|
||||||
|
|
||||||
|
class Person:
|
||||||
|
name = "John"
|
||||||
|
age = 36
|
||||||
|
country = "Norway"
|
||||||
|
|
||||||
|
delattr(Person, 'age')
|
||||||
|
```
|
||||||
|
|
||||||
|
##### eval(expression)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -
|
||||||
|
>>> v =101
|
||||||
|
>>> eval('v+1')
|
||||||
|
102
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### format(val, format)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -formatte une valeur selon le format. spécifié
|
||||||
|
>>> x = format(5, 'b') # binaire
|
||||||
|
>>> x
|
||||||
|
'101'
|
||||||
|
>>> x = format(44, 'x') # hexa
|
||||||
|
>>> x
|
||||||
|
'2c'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### getattr(objet, attribut)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la valeur de l'attribut de l'objet spécifié
|
||||||
|
class Person:
|
||||||
|
name = "John"
|
||||||
|
age = 36
|
||||||
|
country = "Norway"
|
||||||
|
|
||||||
|
x = getattr(Person, 'age')
|
||||||
|
36
|
||||||
|
```
|
||||||
|
|
||||||
|
##### hasattr(objet, attribut)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si l'objet spécifié à l'attribut
|
||||||
|
class Person:
|
||||||
|
name = "John"
|
||||||
|
age = 36
|
||||||
|
country = "Norway"
|
||||||
|
|
||||||
|
x = hasattr(Person, 'age')
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
##### help(element)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne l'aide sur l'élément
|
||||||
|
>>> help(tuple)
|
||||||
|
|
||||||
|
Help on class tuple in module builtins:
|
||||||
|
|
||||||
|
class tuple(object)
|
||||||
|
| tuple(iterable=(), /)
|
||||||
|
|
|
||||||
|
| Built-in immutable sequence.
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### hex()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -convertit un nombre en hexa`
|
||||||
|
>>> hex(15)
|
||||||
|
'0xf'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### locals()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne un dictionnaire avec des variables en cours
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### map(function)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -exécute une fonction sur chaque item d'un élément itérable
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### max() / min()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la valeur maxi ou mini
|
||||||
|
|
||||||
|
>>> min([1,3,6,99,125,-3])
|
||||||
|
-3
|
||||||
|
>>> max([1,3,6,99,125,-3])
|
||||||
|
125
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### next(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne l'item suivant d'un itérable
|
||||||
|
>>> mylist = iter(["apple", "banana", "cherry"])
|
||||||
|
>>> x = next(mylist)
|
||||||
|
>>> x
|
||||||
|
'apple'
|
||||||
|
>>> x = next(mylist)
|
||||||
|
>>> x
|
||||||
|
'banana'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### ord(caractère)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne le code unicode du caractère
|
||||||
|
>>> x = ord("€")
|
||||||
|
>>> x
|
||||||
|
8364
|
||||||
|
```
|
||||||
|
|
||||||
|
##### pow(x, y, z)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne x puissance y (modulo z)
|
||||||
|
>>> pow(2,4)
|
||||||
|
16
|
||||||
|
```
|
||||||
|
|
||||||
|
##### print(object(s) separator=separator, end=end, file=file, flush=flush)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -affiche le message à l'écran ou sur une autre sortie
|
||||||
|
# -par défaut, end='\'
|
||||||
|
>>> print("Hello", "how are you?", sep=" --- ")
|
||||||
|
Hello --- how are you?
|
||||||
|
|
||||||
|
fichier = open("test.py","r")
|
||||||
|
print(fichier.read())
|
||||||
|
fichier.close()
|
||||||
|
```
|
||||||
|
|
||||||
|
##### randint()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne un entier aléatoire
|
||||||
|
|
||||||
|
>>> import random
|
||||||
|
>>> random.randint(1,100)
|
||||||
|
76
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### random()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne une valeur aléatoire
|
||||||
|
|
||||||
|
>>> import random
|
||||||
|
>>> random.random()
|
||||||
|
0.893485376651602
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### range(x)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -crée une séquence de nombre de 0 à x (exclu)
|
||||||
|
x = range(4) # de 0 à 3
|
||||||
|
for n in x:
|
||||||
|
print(n)
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
|
||||||
|
x = range(3, 6) # de 3 à 5
|
||||||
|
for n in x:
|
||||||
|
print(n)
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
|
||||||
|
x = range(0,6,2) # de 0 à 5 et un pas de 2
|
||||||
|
for n in x:
|
||||||
|
print(n)
|
||||||
|
0
|
||||||
|
2
|
||||||
|
4
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### reverse()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -inverse l'ordre d'une liste
|
||||||
|
|
||||||
|
>>> x = [1,2,3]
|
||||||
|
>>> x.reverse()
|
||||||
|
>>> x
|
||||||
|
[3, 2, 1]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### reversed()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne un itérateur inversé
|
||||||
|
|
||||||
|
>>> list(reversed([1,2,3,4]))
|
||||||
|
[4, 3, 2, 1]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### round(number)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne l'arrondi d'un nombre
|
||||||
|
|
||||||
|
>>> round(-1.2)
|
||||||
|
-1
|
||||||
|
>>> round(-1.2563679)
|
||||||
|
-1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### set(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -crée un objet set
|
||||||
|
# -un set est une collection non ordonnée et non indexé
|
||||||
|
|
||||||
|
x = set(('apple', 'banana', 'cherry'))
|
||||||
|
>>> x
|
||||||
|
{'apple', 'cherry', 'banana'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### slice(start, end, step)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne un objet slice
|
||||||
|
>>> a = ("a", "b", "c", "d", "e", "f", "g", "h")
|
||||||
|
|
||||||
|
>>> x = slice(2)
|
||||||
|
>>> print(a[x])
|
||||||
|
('a', 'b')
|
||||||
|
|
||||||
|
>>> x = slice(3, 5)
|
||||||
|
>>> print(a[x])
|
||||||
|
('d', 'e')
|
||||||
|
|
||||||
|
>>> x = slice(0, 8, 3)
|
||||||
|
>>> print(a[x])
|
||||||
|
('a', 'd', 'g')
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### shuffle()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -mélange aléatoirement une liste
|
||||||
|
|
||||||
|
>>> import random
|
||||||
|
>>> x = [1,2,3,4,5]
|
||||||
|
>>> random.shuffle(x)
|
||||||
|
>>> x
|
||||||
|
[2, 5, 4, 1, 3]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### list.sort()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -permet de trier une liste
|
||||||
|
|
||||||
|
>>> l = [67,34,89,12,70,345,2,-56]
|
||||||
|
>>> l.sort()
|
||||||
|
>>> l
|
||||||
|
[-56, 2, 12, 34, 67, 70, 89, 345]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### sorted(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -tri un élément itérable
|
||||||
|
|
||||||
|
>>> sorted([3,2,12,1])
|
||||||
|
[1, 2, 3, 12]
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### sum(iterable)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la somme des valeurs d'un élément itérable
|
||||||
|
|
||||||
|
>>> sum([12,24,36])
|
||||||
|
72
|
||||||
|
```
|
||||||
|
|
||||||
|
##### upper()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -met en majuscule la chaine de caractères
|
||||||
|
|
||||||
|
>>> "Python".upper()
|
||||||
|
'PYTHON'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### zip(*iterables)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -permet de regrouper sous la forme d'un tuple les items de listes.
|
||||||
|
# - https://stackoverflow.com/questions/31683959/the-zip-function-in-python-3
|
||||||
|
|
||||||
|
>>> a = ["sharon", "sophie", "halle"]
|
||||||
|
>>> b = ["stone", "marceau", "berry"]
|
||||||
|
>>> zip(a,b)
|
||||||
|
<zip object at 0x10e1009c8>
|
||||||
|
>>> list(zip(a,b))
|
||||||
|
[('sharon', 'stone'), ('sophie', 'marceau'), ('halle', 'berry')]
|
||||||
|
```
|
||||||
|
|
||||||
292
docs/Programmation/Python/liste.md
Normal file
292
docs/Programmation/Python/liste.md
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
# Listes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Une liste est une collection **ordonnée** et **modifiable**. C'est ce qui se rapproche le plus des tableaux (array).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Créer une liste:
|
||||||
|
|
||||||
|
```python
|
||||||
|
liste = []
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Constructor list()
|
||||||
|
liste = list(("alpha", "banana", "cherry"))
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Ajouter une valeur (append):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1,2,3]
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3]
|
||||||
|
|
||||||
|
>>>> liste.append(4)
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4]
|
||||||
|
|
||||||
|
>>> liste.append("Bonjour")
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4, 'Bonjour']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Afficher un item:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour']
|
||||||
|
>>> liste[0]
|
||||||
|
1
|
||||||
|
>>> liste[4]
|
||||||
|
'Bonjour'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Modifier un item:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste[4] = "Hello"
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4, 'Hello']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un item (remove):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Hello']
|
||||||
|
>>> liste.remove(2)
|
||||||
|
>>> liste
|
||||||
|
[1, 3, 4, 'Hello']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un item (pop):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Hello']
|
||||||
|
>>> liste.pop() # supprimer l'index spécifié ou le dernier
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un item (del):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Hello']
|
||||||
|
>>> del liste[1]
|
||||||
|
>>> liste
|
||||||
|
[1, 3, 4, 'Hello']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer la liste (del):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Hello']
|
||||||
|
>>> del liste
|
||||||
|
>>> liste
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
NameError: name 'liste' is not defined
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Vider la liste (clear):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Hello']
|
||||||
|
>>> liste.clear()
|
||||||
|
>>> liste
|
||||||
|
[]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Inverser les items (reverse):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 3, 4, 'Hello']
|
||||||
|
>>> liste.reverse()
|
||||||
|
>>> liste
|
||||||
|
['Hello', 4, 3, 1]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Nb d'items (len):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = ['Hello', 4, 3, 1]
|
||||||
|
>>> len(liste)
|
||||||
|
4
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Nb d'occurences d'une valeur (count):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> liste.index(1)
|
||||||
|
0
|
||||||
|
>>> liste.count(1)
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Index d'une valeur (index):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> liste.index("Bonjour")
|
||||||
|
4
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Manipuler une liste:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> liste
|
||||||
|
[1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
|
||||||
|
# Dernière occurence
|
||||||
|
>>> liste[-1]
|
||||||
|
1
|
||||||
|
|
||||||
|
# 3e occurence en partant de la fin
|
||||||
|
>>> liste[-3]
|
||||||
|
'Bonjour'
|
||||||
|
|
||||||
|
# 2 premières occurences
|
||||||
|
>>> liste[:2]
|
||||||
|
[1, 2]
|
||||||
|
|
||||||
|
# 3 dernières occurences
|
||||||
|
>>> liste[-3:]
|
||||||
|
['Bonjour', 1, 1]
|
||||||
|
|
||||||
|
# vider la liste
|
||||||
|
>>> liste[:] = []
|
||||||
|
>>>
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Boucle:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> for i in liste:
|
||||||
|
... print (i)
|
||||||
|
...
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
Bonjour
|
||||||
|
1
|
||||||
|
1
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Boucle (avec l'index):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = [1, 2, 3, 4, 'Bonjour', 1, 1]
|
||||||
|
>>> for i in enumerate(liste):
|
||||||
|
... print (i)
|
||||||
|
...
|
||||||
|
(0, 1)
|
||||||
|
(1, 2)
|
||||||
|
(2, 3)
|
||||||
|
(3, 4)
|
||||||
|
(4, 'Bonjour')
|
||||||
|
(5, 1)
|
||||||
|
(6, 1)
|
||||||
|
# Les valeurs retournées par la boucle sont des tuples.
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Copier une liste:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> x = [1, 2, 3]
|
||||||
|
>>> y = x[:]
|
||||||
|
>>> y[0] = 0
|
||||||
|
>>> x
|
||||||
|
[1, 2, 3]
|
||||||
|
>>> y
|
||||||
|
[0, 2, 3]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Transformer une string en liste (split):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> string = "Language:Version:OS"
|
||||||
|
>>> z = string.split(":")
|
||||||
|
>>> z
|
||||||
|
['Language', 'Version', 'OS']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Transformer une liste en string (join):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = ['semis','date','lune']
|
||||||
|
>>> ";".join(liste)
|
||||||
|
'semis;date;lune'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Trouver un item dans une liste (in):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> liste = ['semis','date','lune']
|
||||||
|
>>> 'lune' in liste
|
||||||
|
True
|
||||||
|
>>> 'meteo' in liste
|
||||||
|
False
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Range:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> range(0, 10)
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Concaténer 2 listes (extend, +):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> a = [1, 2, 3]
|
||||||
|
>>> b = [4, 5 ,6]
|
||||||
|
>>> a.extend(b)
|
||||||
|
>>> print(a)
|
||||||
|
[1, 2, 3, 4, 5, 6]
|
||||||
|
>>> c = a + b
|
||||||
|
>>> print(c)
|
||||||
|
[1, 2, 3, 4, 5, 6, 4, 5, 6]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Multiplier une liste (utile pour l'initialiser):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> a = [0] * 4
|
||||||
|
>>> print(a)
|
||||||
|
[0, 0, 0, 0]
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Vérifier si un item est présent dans une liste:
|
||||||
|
|
||||||
|
```python
|
||||||
|
thislist = ["alpha", "beta", "gamma"]
|
||||||
|
if "alpha" in thislist:
|
||||||
|
print("Oui, 'alpha' est dans la liste")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Méthodes:
|
||||||
|
|
||||||
|
| Méthode | Description |
|
||||||
|
| --------- | ----------- |
|
||||||
|
| append() | |
|
||||||
|
| clear() | |
|
||||||
|
| copy() | |
|
||||||
|
| count() | |
|
||||||
|
| extend() | |
|
||||||
|
| index() | |
|
||||||
|
| insert() | |
|
||||||
|
| pop() | |
|
||||||
|
| remove() | |
|
||||||
|
| reverse() | |
|
||||||
|
| sort() | |
|
||||||
|
|
||||||
85
docs/Programmation/Python/regex.md
Normal file
85
docs/Programmation/Python/regex.md
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# regex
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
. Le point correspond à n'importe quel caractère.
|
||||||
|
^ Indique un commencement de segment mais signifie aussi "contraire de"
|
||||||
|
$ Fin de segment
|
||||||
|
[xy] Une liste de segment possibble. Exemple [abc] équivaut à : a, b ou c
|
||||||
|
(x|y) Indique un choix multiple type (ps|ump) équivaut à "ps" OU "UMP"
|
||||||
|
\d le segment est composé uniquement de chiffre, ce qui équivaut à [0-9].
|
||||||
|
\D le segment n'est pas composé de chiffre, ce qui équivaut à [^0-9].
|
||||||
|
\s Un espace, ce qui équivaut à [ \t\n\r\f\v].
|
||||||
|
\S Pas d'espace, ce qui équivaut à [^ \t\n\r\f\v].
|
||||||
|
\w Présence alphanumérique, ce qui équivaut à [a-zA-Z0-9_].
|
||||||
|
\W Pas de présence alphanumérique [^a-zA-Z0-9_].
|
||||||
|
\ Est un caractère d'échappement
|
||||||
|
\t\n\r Tab, newline, retour
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Nombre d'occurrences:
|
||||||
|
|
||||||
|
```python
|
||||||
|
A{2} : on attend à ce que la lettre A (en majuscule) se répète 2 fois consécutives.
|
||||||
|
BA{1,9} : on attend à ce que le segment BA se répète de 1 à 9 fois consécutives.
|
||||||
|
BRA{,10} : on attend à ce que le segment BRA ne soit pas présent du tout ou présent jusqu'à 10 fois consécutives.
|
||||||
|
VO{1,} : on attend à ce que le segment VO soit présent au mois une fois.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
| Symbole | Nb caractères attendus | Exemples |
|
||||||
|
| ------- | ---------------------- | --------- |
|
||||||
|
| ? | 0 ou 1 | Pyt(.)?on |
|
||||||
|
| + | 1 ou plus | Pyt(.)+on |
|
||||||
|
| * | 0, 1 ou plus | Pyt(.)*on |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Fonction match():
|
||||||
|
|
||||||
|
```python
|
||||||
|
re.match(pattern, string, flags = 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
import re
|
||||||
|
|
||||||
|
>>> x = re.match(r"Py(.)?hon", "Python")
|
||||||
|
>>> x
|
||||||
|
<re.Match object; span=(0, 6), match='Python'>
|
||||||
|
|
||||||
|
>>> x = re.match(r"Py(.)?hon", "Pithon")
|
||||||
|
>>> x
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Fonction search():
|
||||||
|
|
||||||
|
```python
|
||||||
|
re.search(pattern, string, flags = 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Options flags:
|
||||||
|
|
||||||
|
| | Description |
|
||||||
|
| ---- | ----------- |
|
||||||
|
| 1 | re.I |
|
||||||
|
| 2 | re.L |
|
||||||
|
| 3 | re.M |
|
||||||
|
| 4 | re.S |
|
||||||
|
| 5 | re.U |
|
||||||
|
| 6 | re.X |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Fonction sub():
|
||||||
|
|
||||||
|
```python
|
||||||
|
re.sub(pattern, repl, string, max=0)
|
||||||
|
```
|
||||||
|
|
||||||
131
docs/Programmation/Python/set.md
Normal file
131
docs/Programmation/Python/set.md
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
# Set
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Une liste est une collection **non ordonnée** et **non indexée**. On ne peut pas modifier un item, mais on peut en ajouter.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Créer un set:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set
|
||||||
|
{'alpha', 'beta', 'gamma'}
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Constructor set()
|
||||||
|
>>> un_set = set(("alpha", "beta", "gamma"))
|
||||||
|
>>> un_set
|
||||||
|
{'gamma', 'alpha', 'beta'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Ajouter un item:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set.add("delta")
|
||||||
|
>>> un_set
|
||||||
|
{'gamma', 'alpha', 'beta', 'delta'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Ajouter plusieurs items:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set.update(["delta","zeta","epsilon"])
|
||||||
|
>>> un_set
|
||||||
|
{'zeta', 'alpha', 'beta', 'delta', 'gamma', 'epsilon'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Longueur d'un set:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> print(len(un_set))
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un item (remove):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set.remove("beta")
|
||||||
|
>>> un_set
|
||||||
|
{'gamma', 'alpha'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un item (discard):
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set.discard("beta")
|
||||||
|
>>> un_set
|
||||||
|
{'gamma', 'alpha'}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Vider un set:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_set = {"alpha", "beta", "gamma"}
|
||||||
|
>>> un_set.clear()
|
||||||
|
>>> un_set
|
||||||
|
set()
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Supprimer un set:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> del un_set
|
||||||
|
>>> un_set
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
NameError: name 'un_set' is not defined
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Boucle:
|
||||||
|
|
||||||
|
```python
|
||||||
|
un_set = {"alpha", "beta", "gamma"}
|
||||||
|
for x in un_set:
|
||||||
|
print(x)
|
||||||
|
|
||||||
|
alpha
|
||||||
|
beta
|
||||||
|
gamma
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Test si un item est présent dans le set:
|
||||||
|
|
||||||
|
```python
|
||||||
|
un_set = {"alpha", "beta", "gamma"}
|
||||||
|
print("alpha" in un_set)
|
||||||
|
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Méthodes:
|
||||||
|
|
||||||
|
| Méthodes | Description |
|
||||||
|
| ----------------------------- | ----------- |
|
||||||
|
| add() | |
|
||||||
|
| clear() | |
|
||||||
|
| copy() | |
|
||||||
|
| difference() | |
|
||||||
|
| difference_update() | |
|
||||||
|
| discard() | |
|
||||||
|
| intersection() | |
|
||||||
|
| intersection_update() | |
|
||||||
|
| isdisjoint() | |
|
||||||
|
| issubset() | |
|
||||||
|
| issuperset() | |
|
||||||
|
| pop() | |
|
||||||
|
| remove() | |
|
||||||
|
| symmetric_difference() | |
|
||||||
|
| symmetric_difference_update() | |
|
||||||
|
| union() | |
|
||||||
|
| update() | |
|
||||||
|
|
||||||
210
docs/Programmation/Python/string.md
Normal file
210
docs/Programmation/Python/string.md
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
# Strings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### str.count()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -compte le nombre d'occurence de la chaine demandée
|
||||||
|
>>> "programmation".count("m")
|
||||||
|
2
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.capitalize()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -capitalise la chaine de caractère
|
||||||
|
>>> "pYtHOn".capitalize()
|
||||||
|
'Python'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.endswith(str)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -teste si une chaine se termine par la chaine demandée (sensible à la casse)
|
||||||
|
>>> a = "Python"
|
||||||
|
>>> a.endswith("r")
|
||||||
|
False
|
||||||
|
>>> a.endswith("n")
|
||||||
|
True
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.find()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -trouve la 1ere occurence de la chaine demandée
|
||||||
|
>>> "capitalize".find("i")
|
||||||
|
3
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.isalnum()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont alphanumériques
|
||||||
|
>>> "0xf".isalnum()
|
||||||
|
True
|
||||||
|
>>> "0xf_".isalnum()
|
||||||
|
False
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.isalpha()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont des lettres
|
||||||
|
>>> "0xf".isalpha()
|
||||||
|
False
|
||||||
|
>>> "abcdef".isalpha()
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.isdigit()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont numériques
|
||||||
|
>>> "1234".isalnum()
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.islower()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont en minuscule
|
||||||
|
>>> "python".islower()
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### str.isspace()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont des espaces
|
||||||
|
>>> "".isspace()
|
||||||
|
False
|
||||||
|
>>> " ".isspace()
|
||||||
|
True
|
||||||
|
>>> "un mot".isspace()
|
||||||
|
False
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.istitle()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si la chaine à un format titre
|
||||||
|
>>> "Python".istitle()
|
||||||
|
True
|
||||||
|
>>> "Python Est Un Language De Programmation".istitle()
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.isupper()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si tous les caractères sont en majuscule
|
||||||
|
>>> "PYTHON".isupper()
|
||||||
|
True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.join(liste)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -transforme une liste en chaine
|
||||||
|
|
||||||
|
>>> ":".join(["language", "python"])
|
||||||
|
'language:python'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### len(s)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne le nb d'items d'un objet
|
||||||
|
|
||||||
|
>>> len(["language", "python"])
|
||||||
|
2
|
||||||
|
>>> len("Python")
|
||||||
|
6
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.lower()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne la chaine en minuscule
|
||||||
|
|
||||||
|
>>> "PYTHON".lower()
|
||||||
|
'python'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.replace(str,str)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -remplace un segement de chaine par un autre
|
||||||
|
|
||||||
|
>>> "Python est un language".replace("Python","Perl")
|
||||||
|
'Perl est un language'
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.startswith()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne True si la chaine commence par le préfix indiqué (sensible à la casse)
|
||||||
|
|
||||||
|
>>> a = "Python"
|
||||||
|
>>> a.startswith("P")
|
||||||
|
True
|
||||||
|
>>> a.startswith("y")
|
||||||
|
False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.split(séparateur)
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -transforme une chaine en liste
|
||||||
|
|
||||||
|
>>> "Language:Python".split(":")
|
||||||
|
['Language', 'Python']
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.splitlines()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -retourne une liste des lignes de la chaine
|
||||||
|
|
||||||
|
>>> "language\n\n\Python\n\n3.7".splitlines()
|
||||||
|
['language', '', '\\Python', '', '3.7']
|
||||||
|
>>> "language\nPython\n3.7".splitlines()
|
||||||
|
['language', 'Python', '3.7']
|
||||||
|
>>> "language\n\rPython\n\r3.7".splitlines()
|
||||||
|
['language', '', 'Python', '', '3.7']
|
||||||
|
>>> "language\r\nPython\r\n3.7".splitlines()
|
||||||
|
['language', 'Python', '3.7']
|
||||||
|
>>> "language\r\nPython\r\n\r\n3.7".splitlines()
|
||||||
|
['language', 'Python', '', '3.7']
|
||||||
|
>>> "language\r\nPython\r\n\r\n3.7".splitlines(True)
|
||||||
|
['language\r\n', 'Python\r\n', '\r\n', '3.7']
|
||||||
|
```
|
||||||
|
|
||||||
|
##### str.title()
|
||||||
|
|
||||||
|
```python
|
||||||
|
# -transforme la chaine dans un format Titre
|
||||||
|
|
||||||
|
>>> "Ceci est un titre".title()
|
||||||
|
'Ceci Est Un Titre'
|
||||||
|
```
|
||||||
|
|
||||||
|
#####
|
||||||
78
docs/Programmation/Python/tuple.md
Normal file
78
docs/Programmation/Python/tuple.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
# Tuple
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Un tuple est une liste qui ne peut être modifiée.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##### Créer un tuple
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_tuple = ()
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Y ajouter des valeurs
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_tuple = ("alpha","beta","gamma")
|
||||||
|
>>> print(un_tuple)
|
||||||
|
('alpha', 'beta', 'gamma')
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Si 1 seule valeur, ajouter une virgule, sinon c'est une chaine
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> autre_tuple = ("un",)
|
||||||
|
>>> type(autre_tuple)
|
||||||
|
<class 'tuple'>
|
||||||
|
>>> autre_tuple = ("un")
|
||||||
|
>>> type(autre_tuple)
|
||||||
|
<class 'str'>
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Afficher une valeur d'un tuple
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_tuple[0]
|
||||||
|
'alpha'
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Les tuples ne sont pas modifiables (ni modif, ni ajout, ni suppression)
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> un_tuple[0] = "delta"
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<stdin>", line 1, in <module>
|
||||||
|
TypeError: 'tuple' object does not support item assignment
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Test si un item existe:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> if "alpha" in un_tuple:
|
||||||
|
... print("'alpha' est dans le tuple")
|
||||||
|
...
|
||||||
|
'alpha' est dans le tuple
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Boucle:
|
||||||
|
|
||||||
|
```python
|
||||||
|
>>> for x in un_tuple:
|
||||||
|
... print(x)
|
||||||
|
...
|
||||||
|
alpha
|
||||||
|
beta
|
||||||
|
gamma
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Méthodes:
|
||||||
|
|
||||||
|
| Méthode | Description |
|
||||||
|
| ------- | ----------- |
|
||||||
|
| count() | |
|
||||||
|
| index() | |
|
||||||
|
|
||||||
213
docs/Raspberry/hardware.md
Normal file
213
docs/Raspberry/hardware.md
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
# Hardware
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Version of Debian:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ cat /etc/debian_version
|
||||||
|
9.6
|
||||||
|
```
|
||||||
|
|
||||||
|
#### OS Release Notes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ cat /etc/os-release
|
||||||
|
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
|
||||||
|
NAME="Raspbian GNU/Linux"
|
||||||
|
VERSION_ID="9"
|
||||||
|
VERSION="9 (stretch)"
|
||||||
|
ID=raspbian
|
||||||
|
ID_LIKE=debian
|
||||||
|
HOME_URL="http://www.raspbian.org/"
|
||||||
|
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
|
||||||
|
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Kernel version:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ uname -a
|
||||||
|
Linux framboise 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Harware version:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ cat /proc/cpuinfo
|
||||||
|
processor : 0
|
||||||
|
model name : ARMv7 Processor rev 4 (v7l)
|
||||||
|
BogoMIPS : 38.40
|
||||||
|
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
|
||||||
|
CPU implementer : 0x41
|
||||||
|
CPU architecture: 7
|
||||||
|
CPU variant : 0x0
|
||||||
|
CPU part : 0xd03
|
||||||
|
CPU revision : 4
|
||||||
|
|
||||||
|
processor : 1
|
||||||
|
model name : ARMv7 Processor rev 4 (v7l)
|
||||||
|
BogoMIPS : 38.40
|
||||||
|
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
|
||||||
|
CPU implementer : 0x41
|
||||||
|
CPU architecture: 7
|
||||||
|
CPU variant : 0x0
|
||||||
|
CPU part : 0xd03
|
||||||
|
CPU revision : 4
|
||||||
|
|
||||||
|
processor : 2
|
||||||
|
model name : ARMv7 Processor rev 4 (v7l)
|
||||||
|
BogoMIPS : 38.40
|
||||||
|
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
|
||||||
|
CPU implementer : 0x41
|
||||||
|
CPU architecture: 7
|
||||||
|
CPU variant : 0x0
|
||||||
|
CPU part : 0xd03
|
||||||
|
CPU revision : 4
|
||||||
|
|
||||||
|
processor : 3
|
||||||
|
model name : ARMv7 Processor rev 4 (v7l)
|
||||||
|
BogoMIPS : 38.40
|
||||||
|
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
|
||||||
|
CPU implementer : 0x41
|
||||||
|
CPU architecture: 7
|
||||||
|
CPU variant : 0x0
|
||||||
|
CPU part : 0xd03
|
||||||
|
CPU revision : 4
|
||||||
|
|
||||||
|
Hardware : BCM2835
|
||||||
|
Revision : a02082
|
||||||
|
Serial : 000000004c7a2d11
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Revision: a02082 correspond au Pi3 Model B
|
||||||
|
|
||||||
|
https://elinux.org/RPi_HardwareHistory
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Autres méthodes (Raspian reçent):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ cat /proc/device-tree/model
|
||||||
|
Raspberry Pi 3 Model B Rev 1.2
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ pinout
|
||||||
|
,--------------------------------.
|
||||||
|
| oooooooooooooooooooo J8 +====
|
||||||
|
| 1ooooooooooooooooooo | USB
|
||||||
|
| +====
|
||||||
|
| Pi Model 3B V1.2 |
|
||||||
|
| +----+ +====
|
||||||
|
| |D| |SoC | | USB
|
||||||
|
| |S| | | +====
|
||||||
|
| |I| +----+ |
|
||||||
|
| |C| +======
|
||||||
|
| |S| | Net
|
||||||
|
| pwr |HDMI| |I||A| +======
|
||||||
|
`-| |--------| |----|V|-------'
|
||||||
|
|
||||||
|
Revision : a02082
|
||||||
|
SoC : BCM2837
|
||||||
|
RAM : 1024Mb
|
||||||
|
Storage : MicroSD
|
||||||
|
USB ports : 4 (excluding power)
|
||||||
|
Ethernet ports : 1
|
||||||
|
Wi-fi : True
|
||||||
|
Bluetooth : True
|
||||||
|
Camera ports (CSI) : 1
|
||||||
|
Display ports (DSI): 1
|
||||||
|
|
||||||
|
J8:
|
||||||
|
3V3 (1) (2) 5V
|
||||||
|
GPIO2 (3) (4) 5V
|
||||||
|
GPIO3 (5) (6) GND
|
||||||
|
GPIO4 (7) (8) GPIO14
|
||||||
|
GND (9) (10) GPIO15
|
||||||
|
GPIO17 (11) (12) GPIO18
|
||||||
|
GPIO27 (13) (14) GND
|
||||||
|
GPIO22 (15) (16) GPIO23
|
||||||
|
3V3 (17) (18) GPIO24
|
||||||
|
GPIO10 (19) (20) GND
|
||||||
|
GPIO9 (21) (22) GPIO25
|
||||||
|
GPIO11 (23) (24) GPIO8
|
||||||
|
GND (25) (26) GPIO7
|
||||||
|
GPIO0 (27) (28) GPIO1
|
||||||
|
GPIO5 (29) (30) GND
|
||||||
|
GPIO6 (31) (32) GPIO12
|
||||||
|
GPIO13 (33) (34) GND
|
||||||
|
GPIO19 (35) (36) GPIO16
|
||||||
|
GPIO26 (37) (38) GPIO20
|
||||||
|
GND (39) (40) GPIO21
|
||||||
|
|
||||||
|
For further information, please refer to https://pinout.xyz/
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Version actuelle du firmware:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ vcgencmd version
|
||||||
|
Nov 4 2018 16:35:17
|
||||||
|
Copyright (c) 2012 Broadcom
|
||||||
|
version ed5baf9520a3c4ca82ba38594b898f0c0446da66 (clean) (release)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Télécharger la m-à-j du firmware sans installer:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ sudo JUST_CHECK=1 rpi-update
|
||||||
|
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||||
|
*** Performing self-update
|
||||||
|
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||||
|
Dload Upload Total Spent Left Speed
|
||||||
|
100 13545 100 13545 0 0 43575 0 --:--:-- --:--:-- --:--:-- 43693
|
||||||
|
*** Relaunching after update
|
||||||
|
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||||
|
*** We're running for the first time
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Mettre à jour le firmware:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ sudo rpi-update
|
||||||
|
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||||
|
*** Performing self-update
|
||||||
|
*** Relaunching after update
|
||||||
|
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
|
||||||
|
*** We're running for the first time
|
||||||
|
*** Backing up files (this will take a few minutes)
|
||||||
|
*** Backing up firmware
|
||||||
|
*** Backing up modules 4.14.79-v7+
|
||||||
|
|
||||||
|
###### #######################################################
|
||||||
|
|
||||||
|
This update bumps to rpi-4.14.y linux tree
|
||||||
|
Be aware there could be compatibility issues with some drivers
|
||||||
|
Discussion here:
|
||||||
|
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=197689
|
||||||
|
|
||||||
|
###### ########################################################
|
||||||
|
|
||||||
|
*** Downloading specific firmware revision (this will take a few minutes)
|
||||||
|
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||||
|
Dload Upload Total Spent Left Speed
|
||||||
|
100 168 0 168 0 0 420 0 --:--:-- --:--:-- --:--:-- 421
|
||||||
|
100 56.2M 100 56.2M 0 0 3594k 0 0:00:16 0:00:16 --:--:-- 3192k
|
||||||
|
*** Updating firmware
|
||||||
|
*** Updating kernel modules
|
||||||
|
*** depmod 4.14.94+
|
||||||
|
*** depmod 4.14.94-v7+
|
||||||
|
*** Updating VideoCore libraries
|
||||||
|
*** Using HardFP libraries
|
||||||
|
*** Updating SDK
|
||||||
|
*** Running ldconfig
|
||||||
|
*** Storing current firmware revision
|
||||||
|
*** Deleting downloaded files
|
||||||
|
*** Syncing changes to disk
|
||||||
|
*** If no errors appeared, your firmware was successfully updated to 699879be36d90225232de87e9ae589be7209b14c
|
||||||
|
*** A reboot is needed to activate the new firmware
|
||||||
|
```
|
||||||
|
|
||||||
180
docs/Raspberry/headless.md
Normal file
180
docs/Raspberry/headless.md
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
# Headless
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Télécharger l'image [Raspian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/) et l'installer sur la carte SD avec [Etcher](https://www.balena.io/etcher/).
|
||||||
|
|
||||||
|
Activer et connecter le wifi:
|
||||||
|
|
||||||
|
Il faut créer un fichier `wpa_supplicant.conf` dans /boot
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Depuis macOS
|
||||||
|
cd /Volumes/boot
|
||||||
|
nano wpa_supplicant.conf
|
||||||
|
|
||||||
|
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||||
|
update_config=1
|
||||||
|
country=FR
|
||||||
|
|
||||||
|
network={
|
||||||
|
ssid="SSID"
|
||||||
|
psk="Mot de passe"
|
||||||
|
key_mgmt=WPA-PSK
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Activer SSH:
|
||||||
|
|
||||||
|
Il faut créer un fichier `ssh` dans /boot
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#Depuis macOS
|
||||||
|
cd /Volumes/boot
|
||||||
|
touch ssh
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Démarrer le Raspberry, il va se connecter automatiquement à la Box.
|
||||||
|
Pour trouver l'ip, aller sur la box -> Configuration DHCP -> Baux DHCP valides
|
||||||
|
|
||||||
|
Se connecter au Raspberry en SSH:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ssh pi@ip
|
||||||
|
avec le mot-de-passe Raspberry
|
||||||
|
```
|
||||||
|
|
||||||
|
Changer le mot-de-passe:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ passwd
|
||||||
|
Changing password for pi.
|
||||||
|
(current) UNIX password:
|
||||||
|
Enter new UNIX password:
|
||||||
|
Retype new UNIX password:
|
||||||
|
passwd: password updated successfully
|
||||||
|
```
|
||||||
|
|
||||||
|
Mettre en IP fixe:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano /etc/dhcpcd.conf
|
||||||
|
|
||||||
|
à rajouter à la fin du fichier:
|
||||||
|
interface eth0
|
||||||
|
static ip_address=192.168.1.24/24
|
||||||
|
static routers=192.168.1.1
|
||||||
|
static domain_name_servers=192.168.1.1
|
||||||
|
|
||||||
|
interface wlan0
|
||||||
|
static ip_address=192.168.1.23/24
|
||||||
|
static routers=192.168.1.1
|
||||||
|
static domain_name_servers=192.168.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
Ajouter la clé ssh:
|
||||||
|
|
||||||
|
```
|
||||||
|
bruno@silverbook:~/.ssh$ ssh pi@framboise.local 'mkdir -p ~/.ssh; chmod 0700 ~/.ssh; echo ' $(< ~/.ssh/id_ed25519.pub) ' >> ~/.ssh/authorized_keys ; chmod 0600 ~/.ssh/authorized_keys'
|
||||||
|
```
|
||||||
|
|
||||||
|
Sécuriser ssh:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano /etc/ssh/sshd_config
|
||||||
|
Port 36722
|
||||||
|
PermitRootLogin prohibit-password
|
||||||
|
|
||||||
|
yes (défaut)
|
||||||
|
# without-password (prohibit-password) authentification par mot de passe désactivée, # authentification par clé publique seulement
|
||||||
|
# forced-commands-only avec l'option Commande, authentification par clé publique seulement
|
||||||
|
# no
|
||||||
|
|
||||||
|
$ sudo service ssh restart
|
||||||
|
```
|
||||||
|
|
||||||
|
Configurer le Raspberry:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo raspi-config
|
||||||
|
|
||||||
|
-Network Options -> changer le hostname
|
||||||
|
-Localisations Options -> Change Locale, Change Timezone
|
||||||
|
-Interfacing Options -> enable Camera, SPI, I2C, Serial
|
||||||
|
-Advanced Options -> Expanding filesystem
|
||||||
|
-Update (raspi-config)
|
||||||
|
```
|
||||||
|
|
||||||
|
Installer git:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo apt-get install -y git dirmngr
|
||||||
|
```
|
||||||
|
|
||||||
|
Installer log2ram:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /home/pi
|
||||||
|
git clone https://github.com/azlux/log2ram.git
|
||||||
|
cd log2ram
|
||||||
|
chmod +x install.sh
|
||||||
|
sudo ./install.sh
|
||||||
|
|
||||||
|
#Change the log size value to 128M
|
||||||
|
sudo vi /etc/log2ram.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Vérifier l'installation de log2ram:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ df -h
|
||||||
|
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
|
||||||
|
/dev/root 15G 1,1G 13G 8% /
|
||||||
|
devtmpfs 181M 0 181M 0% /dev
|
||||||
|
tmpfs 186M 0 186M 0% /dev/shm
|
||||||
|
tmpfs 186M 2,7M 183M 2% /run
|
||||||
|
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
|
||||||
|
tmpfs 186M 0 186M 0% /sys/fs/cgroup
|
||||||
|
/dev/mmcblk0p1 44M 23M 22M 51% /boot
|
||||||
|
log2ram 40M 636K 40M 2% /var/log
|
||||||
|
tmpfs 37M 0 37M 0% /run/user/1000
|
||||||
|
```
|
||||||
|
|
||||||
|
Toutes les heures, log2ram copie les logs en mémoire vers les fichiers. On peut modifier pour que ce soit tous les jours.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mv /etc/cron.hourly/log2ram /etc/cron.daily/log2ram
|
||||||
|
sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
Mettre à jour le Raspberry:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo apt-get update && sudo apt-get upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
Créer un alias dans .bashrc:
|
||||||
|
alias update='sudo apt-get update && sudo apt-get upgrade'
|
||||||
|
|
||||||
|
Backup de la carte SD
|
||||||
|
https://raspberrypi.stackexchange.com/questions/311/how-do-i-backup-my-raspberry-pi
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bruno@silverbook:~$ diskutil list
|
||||||
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 of=/Users/bruno/Downloads/litePi_1.img bs=1m
|
||||||
|
# ou
|
||||||
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 bs=1m | gzip > /Users/bruno/Downloads/litePi_1.gz
|
||||||
|
# avec progression:
|
||||||
|
bruno@silverbook:~$ sudo dd if=/dev/rdisk2 bs=1m | pv | gzip > /Users/bruno/Downloads/litePi_1.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
Restaurer:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bruno@silverbook:~$ diskutil list
|
||||||
|
bruno@silverbook:~$ sudo dd if=/Users/bruno/Downloads/litePi_1.img of=/dev/rdisk2 bs=1m
|
||||||
|
# ou
|
||||||
|
bruno@silverbook:~$ gzip -dc /Users/bruno/Downloads/litePi_1.gz | sudo dd of=/dev/rdisk2 bs=1m
|
||||||
|
```
|
||||||
|
|
||||||
@@ -1,13 +1,28 @@
|
|||||||
# Raspberry
|
# Raspberry
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[apt-get & apt-cache](apt-get.md)
|
||||||
|
|
||||||
|
[aptitude](aptitude.md)
|
||||||
|
|
||||||
[Backup](backup.md)
|
[Backup](backup.md)
|
||||||
|
|
||||||
[Commandes apt-get & apt-cache](apt-get.md)
|
[Envoyer un mail depuis le Raspberry](send_mail.md)
|
||||||
|
|
||||||
|
[Hardware](hardware.md)
|
||||||
|
|
||||||
|
[Matériels](materiels/materiels.md)
|
||||||
|
|
||||||
[Réseau](reseau.md)
|
[Réseau](reseau.md)
|
||||||
|
|
||||||
[Boot et clone](boot.md)
|
[Boot et clone](boot.md)
|
||||||
|
|
||||||
[Bouton du Pi Desktop](pi-desktop.md)
|
[Pi Desktop](pi-desktop.md)
|
||||||
|
|
||||||
|
[Divers](divers.md)
|
||||||
|
|
||||||
|
[SiriControl](siri_control.md)
|
||||||
|
|
||||||
|
[Tools](tools.md)
|
||||||
|
|
||||||
[Divers](divers.md)
|
|
||||||
19
docs/Raspberry/materiels/HC-SR04.md
Normal file
19
docs/Raspberry/materiels/HC-SR04.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Capteur à Ultra-sons HC-SR04
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[http://espace-raspberry-francais.fr/Composants/Mesure-de-distance-avec-HC-SR04-Raspberry-Francais/](http://espace-raspberry-francais.fr/Composants/Mesure-de-distance-avec-HC-SR04-Raspberry-Francais/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Autre capteur: SRF06
|
||||||
|
[http://www.yoctopuce.com/FR/article/le-srf06-un-capteur-de-distance-bon-marche](http://www.yoctopuce.com/FR/article/le-srf06-un-capteur-de-distance-bon-marche)
|
||||||
|
|
||||||
33
docs/Raspberry/materiels/HC-SR501.md
Normal file
33
docs/Raspberry/materiels/HC-SR501.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Détecteur de mouvement PIR infrarouge HC-SR501
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[http://espace-raspberry-francais.fr/Composants/Capteur-presence-HC-SR501-Raspberry-Francais/](http://espace-raspberry-francais.fr/Composants/Capteur-presence-HC-SR501-Raspberry-Francais/)
|
||||||
|
[http://www.ihm3d.fr/httpwww-ihm3d-frutilisation-dun-detecteur-de-mouvement-hc-sr501-avec-arduino-raspberry-pi3.html](http://www.ihm3d.fr/httpwww-ihm3d-frutilisation-dun-detecteur-de-mouvement-hc-sr501-avec-arduino-raspberry-pi3.html)
|
||||||
|
|
||||||
|
#### Ordre des broches (côté micro-controleur):
|
||||||
|
|
||||||
|
VCC - Out - GND
|
||||||
|
L'ordre peut varier selon les modèles. <u>Le micro-controleur est toujours côté GND</u>. Sinon déclipser le dome pour vérifier.
|
||||||
|
|
||||||
|
#### PIR (Passive Infrared Sensor)
|
||||||
|
|
||||||
|
|
||||||
|
Le détecteur HC-SR501 fonctionne grâce au rayonnement infrarouge. Il possède deux états, haut et bas. Lorsque quelque chose se trouve en mouvement dans son champ de vision, il passe à l'état haut. Lorsque celui-ci ne détecte aucun mouvements, il passe à l'état bas.
|
||||||
|
|
||||||
|
Le détecteur possède deux potentiomètres qui correspondent:
|
||||||
|
|
||||||
|
- au temps de détection
|
||||||
|
- à la distance de détection.
|
||||||
|
|
||||||
|
Lorsque l'on tourne le <u>potentiomètre du temps de détection</u> dans le sens des aiguilles d'une montre, la durée est plus longue (de 3 secondes à 5 minutes).
|
||||||
|
Lorsque l'on tourne le <u>potentiomètre de la distance de détection</u> dans le sens des aiguilles d'une montre, celle-ci est plus grande (3 mètres à 7 mètres).
|
||||||
|
|
||||||
|
Le détecteur possède aussi un cavalier qui permet de déterminer le <u>mode de détection</u> : un mode de <u>détection unique</u>, et un mode de <u>détection multiple</u>.
|
||||||
|
|
||||||
|
- H (repeat): le capteur continue de sortir un signal Haut tant qu'il continue de détecter un mouvement.
|
||||||
|
- L (no repeat): le capteur continue de sortir un signal Haut pour la période réglée par le potentiomètre Temps.
|
||||||
|
|
||||||
|
A la mise sous tension, le capteur se calibre par rapport à son envirronnement (30-60s).
|
||||||
|
Après une détection, le capteur se reset. Durant cette période (5-6s), il ne détecte aucun mouvement.
|
||||||
|
|
||||||
53
docs/Raspberry/materiels/camera.md
Normal file
53
docs/Raspberry/materiels/camera.md
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Caméra
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Installer la caméra:
|
||||||
|
|
||||||
|
https://www.rs-online.com/designspark/raspberry-pi-camera-setup
|
||||||
|
|
||||||
|
1. Eteindre le Raspberry
|
||||||
|
|
||||||
|
2. Brancher la caméra au connecteur CSI (entre Ethernet et HDMI), la partie alu côté HDMI.
|
||||||
|
|
||||||
|
3. Redémarrer le Raspberry et activer la caméra dans Raspi-config
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo raspi-config
|
||||||
|
# 5 Interfacing Options -> P1 Camera -> enable
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Redémarrer
|
||||||
|
|
||||||
|
#### Capturer une image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# au format jpeg
|
||||||
|
$ raspistill -o image.jpg
|
||||||
|
# largeur 1200px
|
||||||
|
$ raspistill -w 1200 -o image.jpg
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Capturer une video:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 5s au format h264
|
||||||
|
$ raspivid -o video.h264
|
||||||
|
|
||||||
|
# 10s
|
||||||
|
$ raspivid -o video.h264 -t 10000
|
||||||
|
# largeur 1200px
|
||||||
|
$ raspivid -w 1200$ raspivid -o video.h264 -t 10000
|
||||||
|
|
||||||
|
# 10s dans le mode demo
|
||||||
|
$ raspivid -o video.h264 -t 10000 -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour voir la liste des options de **raspivid** ou **raspistill**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ raspivid | less
|
||||||
|
|
||||||
|
$ raspistill | less
|
||||||
|
```
|
||||||
|
|
||||||
30
docs/Raspberry/materiels/materiels.md
Normal file
30
docs/Raspberry/materiels/materiels.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Matériels
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Chargeur USB 5V 1A 1000C PowerBoost 1000
|
||||||
|
TPS61090
|
||||||
|
adafruit
|
||||||
|
|
||||||
|
Module Camera v2 8MP
|
||||||
|
|
||||||
|
Caméra Infrarouge v2 8MP
|
||||||
|
|
||||||
|
Raspberry Pi Camera à vision nocturneFish Eye 5MP avec 2 IR
|
||||||
|
|
||||||
|
Ecran tactile 7" 1024x600 Capacitif HDMI
|
||||||
|
|
||||||
|
Flex cable pour RPi Camera 300mn
|
||||||
|
|
||||||
|
4 Canaux Module 5V DC Relais pour Arduino DSP AVR PIC ARM Raspberry Pi Relay
|
||||||
|
5V 4 canaux Relais carte d'interface, et chacun a besoin 15-20mA actuel du pilote.
|
||||||
|
Equipé de relais à courant élevé, AC250V 10A; DC30V 10A.
|
||||||
|
Interface standard qui peut être contrôlé directement par le microcontrôleur (Arduino, 8051, AVR, PIC, DSP, ARM, ARM, MSP430, logique TTL).
|
||||||
|
Indication des LED pour l'état de sortie de relais.
|
||||||
|
|
||||||
|
RPI RELAY BOARD
|
||||||
|
|
||||||
|
Capteur à Ultra-sons [HC-SR04](HC-SR04.md)
|
||||||
|
|
||||||
|
Détecteur de mouvement PIR infrarouge [HC-SR501](HC-SR501.md)
|
||||||
|
|
||||||
@@ -1,20 +1,78 @@
|
|||||||
# Pi Desktop
|
# Pi Desktop
|
||||||
|
|
||||||
### Télécharger le paquet Pi Desktop:
|
#### Télécharger le paquet Pi Desktop:
|
||||||
|
|
||||||
https://github.com/pi-desktop/deb-make/releases
|
https://github.com/pi-desktop/deb-make/releases
|
||||||
|
|
||||||
|
https://github.com/hoopsurfer/pidesktop (Fork)
|
||||||
|
|
||||||
|
|
||||||
### Installer Pi Desktop:
|
|
||||||
|
#### Installer Pi Desktop:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
Installer Pi Desktop:
|
||||||
|
# Supprimer l'ancienne version
|
||||||
|
$ sudo dpkg -r pidesktop-base
|
||||||
|
# Installer
|
||||||
$ sudo dpkg -i pidesktop-base-1.1.0.deb
|
$ sudo dpkg -i pidesktop-base-1.1.0.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Bouton du Pi Desktop:
|
Le RPi 3+ peut nativement booter depuis un disque USB.
|
||||||
|
|
||||||
|
Il y a 2 méthodes:
|
||||||
|
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/README.md
|
||||||
|
|
||||||
|
1. **Avec une carte une SD:**
|
||||||
|
Cloner la carte SD sur le mSSD avec SD Carte Copier
|
||||||
|
Dans `/boot/cmdline.txt`, changer `root=/dev/mmcblk0p2 par root=/dev/sdx2`.
|
||||||
|
|
||||||
|
2. **Sans carte SD:**
|
||||||
|
|
||||||
|
Dans ce cas, pour le RPi 3, il faut que le bit USB boot soit mis dans le OTP:
|
||||||
|
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md
|
||||||
|
|
||||||
|
On vérifie si le boot USB est actif:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vcgencmd otp_dump | grep 17:
|
||||||
|
17:1020000a
|
||||||
|
La valeur doit être 3020000a
|
||||||
|
```
|
||||||
|
|
||||||
|
On active le boot USB:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
|
||||||
|
$ sudo reboot
|
||||||
|
```
|
||||||
|
|
||||||
|
On vérifie que le boot USB est actif:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ vcgencmd otp_dump | grep 17:
|
||||||
|
17:3020000a
|
||||||
|
```
|
||||||
|
|
||||||
|
On peut supprimer la ligne `program_usb_boot_mode=1` dans le config.txt pour
|
||||||
|
éviter de l'activer par inadvertance si on insère la carte dans un autre Raspberry.
|
||||||
|
L'activation du bit USB boot dans le OTP est définitive (mais n'empêche pas de démarrer sur la SD ultérieurement).
|
||||||
|
|
||||||
|
Cloner la carte SD sur le mSSD avec SD Carte Copier (la commande pd-clonessd ouvre bien SD Carte Copier mais ce dernier reste grisé)
|
||||||
|
Lancer la commande pd-bootssd
|
||||||
|
|
||||||
|
On peut retirer la SD et démarrer sur le mSSD. Perso, j'ai laissé la SD en place qui me sert de backup.
|
||||||
|
|
||||||
|
<u>config.txt (mSSD)</u>
|
||||||
|
`dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=4ad391be-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait`
|
||||||
|
<u>config.txt (SD)</u>
|
||||||
|
`dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Bouton du Pi Desktop:
|
||||||
|
|
||||||
- Lorsque vous appuyez **une fois rapidement (plus de 150mS)** sur le bouton A/M, le Raspberry Pi **démarre**
|
- Lorsque vous appuyez **une fois rapidement (plus de 150mS)** sur le bouton A/M, le Raspberry Pi **démarre**
|
||||||
- Lorsque vous appuyez **plus longuement (plus de 2 secondes)** sur le bouton A/M, le programme de gestion **arrête proprement le Raspberry Pi** (le système s’arrête normalement) puis **coupe l’alimentation**.
|
- Lorsque vous appuyez **plus longuement (plus de 2 secondes)** sur le bouton A/M, le programme de gestion **arrête proprement le Raspberry Pi** (le système s’arrête normalement) puis **coupe l’alimentation**.
|
||||||
|
|||||||
@@ -1,33 +1,105 @@
|
|||||||
# Réseau et partage
|
# Réseau et partage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Configurer le réseau wifi:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nano /etc/wpa_supplicant/wpa_supplicant.conf
|
||||||
|
|
||||||
|
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||||
|
update_config=1
|
||||||
|
country=FR
|
||||||
|
|
||||||
|
network={
|
||||||
|
ssid="Bart_nomap"
|
||||||
|
psk="ma_clef_wifi"
|
||||||
|
key_mgmt=WPA-PSK
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Encoder le mot de passe:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ wpa_passphrase "Bart_nomap"
|
||||||
|
|
||||||
|
# reading passphrase from stdin
|
||||||
|
|
||||||
|
ma_clef_wifi
|
||||||
|
network={
|
||||||
|
ssid="Bart_nomap"
|
||||||
|
#psk="ma_clef_wifi"
|
||||||
|
psk=40e6467b0ab3569a63dfe33001abb3a6b8757989937091f3edf7c9d9bd508ede7
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nano /etc/network/interfaces
|
||||||
|
### (ne pas changer !!!) ###
|
||||||
|
|
||||||
|
# interfaces(5) file used by ifup(8) and ifdown(8)
|
||||||
|
# Please note that this file is written to be used with dhcpcd
|
||||||
|
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
|
||||||
|
# Include files from /etc/network/interfaces.d:
|
||||||
|
source-directory /etc/network/interfaces.d
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Adresses IP:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ip -4 addr | grep global
|
||||||
|
inet 192.168.1.254/24 brd 192.168.1.255 scope global eth0
|
||||||
|
inet 192.168.1.21/24 brd 192.168.1.255 scope global wlan0
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Adresse du routeur (gateway):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ip route | grep default | awk '{print $3}'
|
||||||
|
192.168.1.1
|
||||||
|
192.168.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Adresse du serveur DNS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cat /etc/resolv.conf
|
||||||
|
|
||||||
|
# Generated by resolvconf
|
||||||
|
|
||||||
|
domain home
|
||||||
|
nameserver 192.168.1.1
|
||||||
|
nameserver fe80::4265:a3ff:fec3:8132%eth0
|
||||||
|
nameserver fe80::4265:a3ff:fec3:8132%wlan0
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Liste des noms d'interface
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ls /sys/class/net
|
||||||
|
eth0 lo wlan0
|
||||||
|
```
|
||||||
|
|
||||||
#### Mettre en IP fixe:
|
#### Mettre en IP fixe:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo nano /etc/dhcpcd.conf
|
$ sudo nano /etc/dhcpcd.conf
|
||||||
|
|
||||||
à rajouter à la fin du fichier:
|
# à rajouter à la fin du fichier:
|
||||||
|
|
||||||
interface eth0
|
interface eth0
|
||||||
|
|
||||||
static ip_address=192.168.1.254/24
|
static ip_address=192.168.1.254/24
|
||||||
|
|
||||||
static routers=192.168.1.1
|
static routers=192.168.1.1
|
||||||
|
|
||||||
static domain_name_servers=8.8.8.8
|
static domain_name_servers=8.8.8.8
|
||||||
|
|
||||||
interface wlan0
|
interface wlan0
|
||||||
|
|
||||||
static ip_address=192.168.1.253/24
|
static ip_address=192.168.1.253/24
|
||||||
|
|
||||||
static routers=192.168.1.1
|
static routers=192.168.1.1
|
||||||
|
|
||||||
static domain_name_servers=8.8.8.8
|
static domain_name_servers=8.8.8.8
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### VNC:
|
#### VNC:
|
||||||
|
|
||||||
*VNC Server (Pi):*
|
*VNC Server (Pi):*
|
||||||
@@ -51,6 +123,27 @@ Port 5900
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### SSH:
|
||||||
|
|
||||||
|
Changer le port par défaut (22):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano sshd_config
|
||||||
|
|
||||||
|
#Décommenter la ligne # Port 22 et modifier le port
|
||||||
|
Port 39517
|
||||||
|
|
||||||
|
$ sudo service ssh restart
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Ajouter la clé ssh:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bruno@silverbook:~/.ssh$ ssh pi@framboise.local 'mkdir -p ~/.ssh; chmod 0700 ~/.ssh; echo ' $(< ~/.ssh/id_ed25519.pub) ' >> ~/.ssh/authorized_keys ; chmod 0600 ~/.ssh/authorized_keys'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#### Installer Samba:
|
#### Installer Samba:
|
||||||
|
|
||||||
Installer et créer un répertoire partagé:
|
Installer et créer un répertoire partagé:
|
||||||
@@ -62,7 +155,13 @@ $ sudo chown -hR pi:pi /home/pi/share
|
|||||||
$ sudo chmod 777 /home/pi/share
|
$ sudo chmod 777 /home/pi/share
|
||||||
```
|
```
|
||||||
|
|
||||||
Editer le fichier smb.conf:
|
#### Sauvegarder le fichier de configuration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Editer le fichier smb.conf:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo nano /etc/samba/smb.conf
|
$ sudo nano /etc/samba/smb.conf
|
||||||
@@ -75,6 +174,9 @@ wins support = yes
|
|||||||
####### Authentication #######
|
####### Authentication #######
|
||||||
security = user
|
security = user
|
||||||
|
|
||||||
|
[homes]
|
||||||
|
read only = no
|
||||||
|
|
||||||
[Share]
|
[Share]
|
||||||
comment = Partage Samba sur Raspberry
|
comment = Partage Samba sur Raspberry
|
||||||
path=/home/pi/share
|
path=/home/pi/share
|
||||||
@@ -86,12 +188,116 @@ directory mask=0777
|
|||||||
public=no
|
public=no
|
||||||
```
|
```
|
||||||
|
|
||||||
Créer un utilisateur Samba:
|
#### Créer un utilisateur Samba:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo smbpasswd –a pi
|
$ sudo smbpasswd -a pi
|
||||||
|
New SMB password:
|
||||||
|
Retype new SMB password:
|
||||||
|
Added user pi.
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Tester la config Samba:
|
||||||
|
|
||||||
|
```bash
|
||||||
$ testparm
|
$ testparm
|
||||||
|
Load smb config files from /etc/samba/smb.conf
|
||||||
|
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
|
||||||
|
WARNING: The "syslog" option is deprecated
|
||||||
|
Processing section "[homes]"
|
||||||
|
Processing section "[printers]"
|
||||||
|
Processing section "[print$]"
|
||||||
|
Processing section "[Share]"
|
||||||
|
Loaded services file OK.
|
||||||
|
Server role: ROLE_STANDALONE
|
||||||
|
|
||||||
|
Press enter to see a dump of your service definitions
|
||||||
|
|
||||||
|
# Global parameters
|
||||||
|
[global]
|
||||||
|
log file = /var/log/samba/log.%m
|
||||||
|
max log size = 1000
|
||||||
|
syslog = 0
|
||||||
|
panic action = /usr/share/samba/panic-action %d
|
||||||
|
usershare allow guests = Yes
|
||||||
|
map to guest = Bad User
|
||||||
|
obey pam restrictions = Yes
|
||||||
|
pam password change = Yes
|
||||||
|
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
|
||||||
|
passwd program = /usr/bin/passwd %u
|
||||||
|
server role = standalone server
|
||||||
|
unix password sync = Yes
|
||||||
|
dns proxy = No
|
||||||
|
wins support = Yes
|
||||||
|
idmap config * : backend = tdb
|
||||||
|
|
||||||
|
|
||||||
|
[homes]
|
||||||
|
comment = Home Directories
|
||||||
|
browseable = No
|
||||||
|
create mask = 0700
|
||||||
|
directory mask = 0700
|
||||||
|
valid users = %S
|
||||||
|
|
||||||
|
|
||||||
|
[printers]
|
||||||
|
comment = All Printers
|
||||||
|
path = /var/spool/samba
|
||||||
|
browseable = No
|
||||||
|
printable = Yes
|
||||||
|
create mask = 0700
|
||||||
|
|
||||||
|
|
||||||
|
[print$]
|
||||||
|
comment = Printer Drivers
|
||||||
|
path = /var/lib/samba/printers
|
||||||
|
|
||||||
|
|
||||||
|
[Share]
|
||||||
|
comment = Partage Samba sur Raspberry
|
||||||
|
path = /home/pi/share
|
||||||
|
create mask = 0777
|
||||||
|
directory mask = 0777
|
||||||
|
read only = No
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**Messages d'erreurs:**
|
||||||
|
|
||||||
|
`rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Global files limit:
|
||||||
|
|
||||||
|
$ cat /proc/sys/fs/file-max
|
||||||
|
88603
|
||||||
|
|
||||||
|
# Local files limit:
|
||||||
|
|
||||||
|
$ ulimit -Hn
|
||||||
|
1048576
|
||||||
|
$ ulimit -Sn
|
||||||
|
1024
|
||||||
|
|
||||||
|
# Modifier temporairement les limites:
|
||||||
|
|
||||||
|
ulimit -Hn n
|
||||||
|
ulimit -Sn m
|
||||||
|
|
||||||
|
# Modifier les limites:
|
||||||
|
|
||||||
|
Editer /etc/security/limits.conf et ajouter:
|
||||||
|
samba soft nofile 16384
|
||||||
|
samba hard nofile 32768
|
||||||
|
```
|
||||||
|
|
||||||
|
`WARNING: The "syslog" option is deprecated`
|
||||||
|
commenter la ligne syslog: `#syslog = 0`
|
||||||
|
|
||||||
|
#### Redémarrer Samba:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo /etc/init.d/samba restart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
163
docs/Raspberry/send_mail.md
Normal file
163
docs/Raspberry/send_mail.md
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#### Configurer un compte Gmail:
|
||||||
|
|
||||||
|
Sécurité -> Allow less secure apps
|
||||||
|
|
||||||
|
#### Installer SSMTP
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo apt-get install ssmtp
|
||||||
|
Installer mpack (pour envoyer des PJ)
|
||||||
|
$ sudo apt-get install mpack
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Configurer SSMTP
|
||||||
|
|
||||||
|
https://wiki.archlinux.org/index.php/SSMTP
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano /etc/ssmtp/ssmtp.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
et ajouter ces lignes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
root=username@gmail.com
|
||||||
|
mailhub=smtp.gmail.com:465
|
||||||
|
rewriteDomain=gmail.com
|
||||||
|
AuthUser=username
|
||||||
|
AuthPass=password
|
||||||
|
FromLineOverride=YES
|
||||||
|
UseTLS=YES
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano /etc/ssmtp/revaliases
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Vérifier le log:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ tail -f /var/log/mail.log
|
||||||
|
$ tail -f /var/log/syslog
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Sécuriser ssmtp.conf
|
||||||
|
|
||||||
|
Ajouter le groupe ssmtp
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo groupadd ssmtp
|
||||||
|
```
|
||||||
|
|
||||||
|
Donner le groupe ssmtp au fichier ssmtp.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Donner le groupe ssmtp au fichier à l'exécutable ssmtp
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo chown :ssmtp /usr/sbin/ssmtp
|
||||||
|
```
|
||||||
|
|
||||||
|
S'assurer que juste root et le group ssmtp ont accès au fichier ssmtp.conf
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo chmod 640 /etc/ssmtp/ssmtp.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Mettre le bit SGID à l'exécutable ssmtp
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo chmod g+s /usr/sbin/ssmtp
|
||||||
|
```
|
||||||
|
|
||||||
|
Envoyer un email:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo 'Test text' | mail -s 'Test Mail' username@domaine.com
|
||||||
|
$ ssmtp username@domaine.com
|
||||||
|
subject: ceci est un test !
|
||||||
|
hello world !
|
||||||
|
<CTRL>+D pour envoyer
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ echo "Hello world email body" | mail -s "Test Subject" username@gmail.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Envoyer un fichier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mpack -s 'Test image en PJ' o.jpg username@domaine.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Envoyer un mail et une PJ:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nano mail_template.txt
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
Ci-joint la photo demandée.
|
||||||
|
|
||||||
|
Cordialement.
|
||||||
|
|
||||||
|
$ mpack -s 'Test image en PJ' -d mail_template.txt image.jpg username@gmail.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Changer le from name = 'root'
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo nano /etc/passwd
|
||||||
|
# Remplacer
|
||||||
|
root:x:0:0:root:/root:/bin/bash
|
||||||
|
# par
|
||||||
|
root:x:0:0:RPi3:/root:/bin/bash
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Envoyer un message avec PHP:
|
||||||
|
|
||||||
|
1. Editer le fichier de conf de PHP
|
||||||
|
|
||||||
|
```
|
||||||
|
$ nano /etc/php/apache/php.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Vérifier la ligne sendmail_path
|
||||||
|
|
||||||
|
```
|
||||||
|
sendmail_path = /usr/sbin/sendmail -t -i
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Créer un fichier mailtest.php
|
||||||
|
```php
|
||||||
|
<?php
|
||||||
|
$to = “targetperson@example.com”;
|
||||||
|
$subject = “PHP Test mail”;
|
||||||
|
$message = “This is a test email”;
|
||||||
|
$from = “you@your.domain”;
|
||||||
|
$headers = “From:” . $from;
|
||||||
|
mail($to,$subject,$message,$headers);
|
||||||
|
echo “Mail Sent.”;
|
||||||
|
?>
|
||||||
|
```
|
||||||
|
|
||||||
|
4. puis
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ php mailtest.php
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Envoyer un message avec Python:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
import smtplib
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
https://myhydropi.com/send-email-with-a-raspberry-pi-and-python
|
||||||
59
docs/Raspberry/siri_control.md
Normal file
59
docs/Raspberry/siri_control.md
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# SiriControl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
https://github.com/theraspberryguy/SiriControl-System
|
||||||
|
https://medium.com/@thesanjeetc/want-to-control-something-with-siri-heres-how-bae98aceb586
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Configurer un compte gmail
|
||||||
|
|
||||||
|
- IMAP
|
||||||
|
- Votre compte Google -> Sécurité -> Accès moins sécurisé des applications
|
||||||
|
- Ajouter le compte gmail à Notes (iOS)
|
||||||
|
|
||||||
|
#### Installer SiriControl:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ git clone https://github.com/theraspberryguy/SiriControl-System.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Ouvrir siricontrol.py et renseigner les username et password du compte gmail.
|
||||||
|
|
||||||
|
Rendre le script exécutable (sinon 'compte IMAP inexistant')
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ chmod +x siricontrol.py
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Créer un module:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nano photo.py
|
||||||
|
|
||||||
|
# You can import any required modules here
|
||||||
|
# This can be anything you want
|
||||||
|
moduleName = "photo"
|
||||||
|
|
||||||
|
# All of the words must be heard in order for this module to be executed
|
||||||
|
commandWords = ["prendre","photo"]
|
||||||
|
|
||||||
|
def execute(command):
|
||||||
|
# Write anything you want to be executed when the commandWords are heard
|
||||||
|
# The 'command' parameter is the command you speak
|
||||||
|
|
||||||
|
scrot
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Utilisation:
|
||||||
|
|
||||||
|
Dis Siris
|
||||||
|
|
||||||
|
> Oui
|
||||||
|
|
||||||
|
Note **Prendre** une **photo**
|
||||||
|
|
||||||
42
docs/Raspberry/tools.md
Normal file
42
docs/Raspberry/tools.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Tools
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Prendre une copie d'écran
|
||||||
|
|
||||||
|
- Appuyer sur la touch ImprimEcran ouvre **Scrot**
|
||||||
|
|
||||||
|
- Installer GNOME Screenshot
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update && sudo apt upgrade
|
||||||
|
sudo apt install gnome-screenshot
|
||||||
|
```
|
||||||
|
|
||||||
|
- Depuis le terminal, taper la commande `scrot`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pi@framboise:~ $ scrot
|
||||||
|
pi@framboise:~ $ ls
|
||||||
|
2019-01-19-070157_656x416_scrot.png Git Public Videos
|
||||||
|
Desktop Music python_games
|
||||||
|
Documents oldconffiles share
|
||||||
|
Downloads 2019-01-19-070157_656x416_scrot.jpg
|
||||||
|
|
||||||
|
# avec un délai de 4s (le temps de masquer le terminal ou de dérouler un menu)
|
||||||
|
pi@framboise:~ $ scrot -d 4
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Connaitre le modèle de RPi
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cat /proc/cpuinfo
|
||||||
|
|
||||||
|
Hardware : BCM2708
|
||||||
|
Revision : 0003
|
||||||
|
```
|
||||||
|
|
||||||
|
Voir le modèle correspondant à la révision [ici](https://elinux.org/RPi_HardwareHistory).
|
||||||
@@ -143,6 +143,8 @@ $ dpkg --purge dpkg-verify
|
|||||||
|
|
||||||
Les fichiers .conf se trouvent dans `/usr/local/etc/apache22 `ou `/usr/local/etc/apache24`
|
Les fichiers .conf se trouvent dans `/usr/local/etc/apache22 `ou `/usr/local/etc/apache24`
|
||||||
|
|
||||||
|
Editer le Le fichier de conf principal: `nano /usr/local/etc/apache22/conf/httpd22.conf`
|
||||||
|
|
||||||
Il est conseillé de faire les modifications dans `/usr/local/etc/apache22/sites-enabled`
|
Il est conseillé de faire les modifications dans `/usr/local/etc/apache22/sites-enabled`
|
||||||
|
|
||||||
#### Logs:
|
#### Logs:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ $ brew cask uninstall qlvideo
|
|||||||
### Liste de tous les Casks disponibles:
|
### Liste de tous les Casks disponibles:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ brew cask search
|
$ brew search
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -189,3 +189,48 @@ $ brew cask cleanup --outdated
|
|||||||
|
|
||||||
https://github.com/Homebrew/homebrew-cask/blob/master/doc/development/adding_a_cask.md
|
https://github.com/Homebrew/homebrew-cask/blob/master/doc/development/adding_a_cask.md
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Error: Cask 'handbrake' definition is invalid: invalid 'depends_on macos' value: ":lion":
|
||||||
|
|
||||||
|
```bash
|
||||||
|
Casks upgrade.
|
||||||
|
==> Satisfying dependencies
|
||||||
|
==> Downloading https://download.handbrake.fr/handbrake/releases/1.2.2/HandBrake
|
||||||
|
Already downloaded: /Users/bruno/Library/Caches/Homebrew/downloads/1916f7da74b033f06aecbb2b38e29c6b769d6d7fc019d26b794b1bb7d8a46aa3--HandBrake-1.2.2.dmg
|
||||||
|
==> Verifying SHA-256 checksum for Cask 'handbrake'.
|
||||||
|
Error: Cask 'handbrake' definition is invalid: invalid 'depends_on macos' value: ":lion"
|
||||||
|
```
|
||||||
|
|
||||||
|
Supprimer l'application HandBrake manuellement, puis:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ rm -rvf "$(brew --prefix)/Caskroom/handbrake"
|
||||||
|
/usr/local/Caskroom/handbrake/.metadata/1.2.0/20181224200347.982/Casks/handbrake.rb
|
||||||
|
/usr/local/Caskroom/handbrake/.metadata/1.2.0/20181224200347.982/Casks
|
||||||
|
/usr/local/Caskroom/handbrake/.metadata/1.2.0/20181224200347.982
|
||||||
|
/usr/local/Caskroom/handbrake/.metadata/1.2.0
|
||||||
|
/usr/local/Caskroom/handbrake/.metadata
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/LICENSE
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/AUTHORS.markdown
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/README.markdown
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/COPYING
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/THANKS.markdown
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc/NEWS.markdown
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0/doc
|
||||||
|
/usr/local/Caskroom/handbrake/1.2.0
|
||||||
|
/usr/local/Caskroom/handbrake
|
||||||
|
```
|
||||||
|
|
||||||
|
Réinstaller HandBrake
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew cask install handbrake
|
||||||
|
==> Satisfying dependencies
|
||||||
|
==> Downloading https://download.handbrake.fr/handbrake/releases/1.2.2/HandBrake-1.2.2.dmg
|
||||||
|
Already downloaded: /Users/bruno/Library/Caches/Homebrew/downloads/1916f7da74b033f06aecbb2b38e29c6b769d6d7fc019d26b794b1bb7d8a46aa3--HandBrake-1.2.2.dmg
|
||||||
|
==> Verifying SHA-256 checksum for Cask 'handbrake'.
|
||||||
|
==> Installing Cask handbrake
|
||||||
|
==> Moving App 'HandBrake.app' to '/Applications/HandBrake.app'.
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ $ nvm install 8.9.4
|
|||||||
|
|
||||||
# la dernière version 6
|
# la dernière version 6
|
||||||
$ nvm install 6
|
$ nvm install 6
|
||||||
|
|
||||||
|
# la dernière version LTS (v10)
|
||||||
|
$ nvm install --lts=dubnium
|
||||||
```
|
```
|
||||||
|
|
||||||
Liste des versions de Node installées:
|
Liste des versions de Node installées:
|
||||||
@@ -134,3 +137,21 @@ $ nvm use --lts
|
|||||||
Now using node v8.11.4 (npm v5.6.0)
|
Now using node v8.11.4 (npm v5.6.0)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Changer la version par défaut (résiste à un changement de fenêtre du terminal):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nvm alias default 10.15.0
|
||||||
|
default -> 10.15.0 (-> v10.15.0)
|
||||||
|
```
|
||||||
|
|
||||||
|
Réinstaller les paquets d'une ancienne version après une mise-à jour:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ nvm current
|
||||||
|
v8.11.4
|
||||||
|
$ nvm install --lts=dubnium
|
||||||
|
Now using node v10.15.0 (npm v6.4.1)
|
||||||
|
|
||||||
|
$ nvm reinstall-packages 8
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,8 @@ Requires: tornado, PyYAML, click, Markdown, Jinja2, livereload
|
|||||||
### Liste des modules installés:
|
### Liste des modules installés:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# --format=columns (par defaut)
|
||||||
|
|
||||||
$ pip list --format=columns
|
$ pip list --format=columns
|
||||||
|
|
||||||
Package Version
|
Package Version
|
||||||
@@ -149,6 +151,31 @@ backports-abc 0.5
|
|||||||
bdist-mpkg 0.5.0
|
bdist-mpkg 0.5.0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ pip3 freeze
|
||||||
|
appnope==0.1.0
|
||||||
|
attrs==18.2.0
|
||||||
|
autopep8==1.4.3
|
||||||
|
backcall==0.1.0
|
||||||
|
bleach==3.1.0
|
||||||
|
Click==7.0
|
||||||
|
decorator==4.3.2
|
||||||
|
defusedxml==0.5.0
|
||||||
|
Django==2.1.7
|
||||||
|
|
||||||
|
# Exporter la liste
|
||||||
|
$ pip3 freeze > export_liste_pip.txt
|
||||||
|
|
||||||
|
# puis l'importer sur une autre machine
|
||||||
|
$ pip install -r export_liste_pip.txt
|
||||||
|
|
||||||
|
# Ou créer un bundle
|
||||||
|
$ pip bundle <nom_du_bundle>.pybundle -r export_liste_pip.txt
|
||||||
|
|
||||||
|
# et importer les lib
|
||||||
|
$ pip install <nom_du_bundle>.pybundle
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Liste des modules mis-à-jour:
|
### Liste des modules mis-à-jour:
|
||||||
|
|||||||
140
docs/macos/python/virtuel.md
Normal file
140
docs/macos/python/virtuel.md
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
# Environnement virtuel en Python (> 3.3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
On crée un dossier pour regrouper tous les environnements virtuels:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cd
|
||||||
|
$ mkdir venv
|
||||||
|
$ cd venv
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
On crée l'environnement virtuel 'tuto-virtuel-env':
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python -m venv tuto-virtuel-env
|
||||||
|
|
||||||
|
$ cd tuto-virtuel-env/
|
||||||
|
total 8
|
||||||
|
drwxr-xr-x 6 bruno staff 192 15 mar 07:29 .
|
||||||
|
drwxr-xr-x 3 bruno staff 96 15 mar 07:29 ..
|
||||||
|
drwxr-xr-x 12 bruno staff 384 15 mar 07:29 bin
|
||||||
|
drwxr-xr-x 2 bruno staff 64 15 mar 07:29 include
|
||||||
|
drwxr-xr-x 3 bruno staff 96 15 mar 07:29 lib
|
||||||
|
-rw-r--r-- 1 bruno staff 105 15 mar 07:29 pyvenv.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
L'environnement est crée avec la version courante de Python.
|
||||||
|
|
||||||
|
Si plusieurs versions de Python sont installées sur le système, on peut spécifier une version particulière en exécutant `python3.x`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python3.6 -m venv tuto-venv-py36
|
||||||
|
```
|
||||||
|
|
||||||
|
On peut créer un environnement sans `pip`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ python -m venv env-sans-pip --without-pip
|
||||||
|
|
||||||
|
$ source env-sans-pip/bin/activate
|
||||||
|
(env-sans-pip) bruno@SilverBook:~/venv$ pip
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 583, in _build_master
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
On l'active:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Pour bash:
|
||||||
|
$ source tuto-virtuel-env/bin/activate
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv$
|
||||||
|
|
||||||
|
# Pour csh ou fish:
|
||||||
|
activate.csh
|
||||||
|
activate.fish
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
On lance Python:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv$ python
|
||||||
|
Python 3.7.2 (default, Feb 12 2019, 08:15:36)
|
||||||
|
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
|
||||||
|
Type "help", "copyright", "credits" or "license" for more information.
|
||||||
|
>>> import sys
|
||||||
|
>>> sys.path
|
||||||
|
['', '/usr/local/lib/python3.7/site-packages', '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/bruno/venv/tuto-virtuel-env/lib/python3.7/site-packages']
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Sortir de l'environnement virtuel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv$ deactivate
|
||||||
|
bruno@SilverBook:~/venv$
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Contenu de l'environnement virtuel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env$ cd bin/
|
||||||
|
total 64
|
||||||
|
drwxr-xr-x 12 bruno staff 384 15 mar 07:29 .
|
||||||
|
drwxr-xr-x 6 bruno staff 192 15 mar 07:29 ..
|
||||||
|
-rw-r--r-- 1 bruno staff 2234 15 mar 07:29 activate
|
||||||
|
-rw-r--r-- 1 bruno staff 1290 15 mar 07:29 activate.csh
|
||||||
|
-rw-r--r-- 1 bruno staff 2442 15 mar 07:29 activate.fish
|
||||||
|
-rwxr-xr-x 1 bruno staff 263 15 mar 07:29 easy_install
|
||||||
|
-rwxr-xr-x 1 bruno staff 263 15 mar 07:29 easy_install-3.7
|
||||||
|
-rwxr-xr-x 1 bruno staff 245 15 mar 07:29 pip
|
||||||
|
-rwxr-xr-x 1 bruno staff 245 15 mar 07:29 pip3
|
||||||
|
-rwxr-xr-x 1 bruno staff 245 15 mar 07:29 pip3.7
|
||||||
|
lrwxr-xr-x 1 bruno staff 51 15 mar 07:29 python -> /usr/local/Cellar/python/3.7.2_2/libexec/bin/python
|
||||||
|
lrwxr-xr-x 1 bruno staff 6 15 mar 07:29 python3 -> python
|
||||||
|
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ which pip3
|
||||||
|
/Users/bruno/venv/tuto-virtuel-env/bin/pip3
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ which python3
|
||||||
|
/Users/bruno/venv/tuto-virtuel-env/bin/python3
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Installer un module avec `pip`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ pip3 install easy-parse
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ pip3 freeze
|
||||||
|
...
|
||||||
|
docutils==0.14
|
||||||
|
easy-parse==0.1.1
|
||||||
|
entrypoints==0.3
|
||||||
|
...
|
||||||
|
(tuto-virtuel-env) bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ deactivate
|
||||||
|
|
||||||
|
bruno@SilverBook:~/venv/tuto-virtuel-env/bin$ pip3 freeze
|
||||||
|
...
|
||||||
|
docutils==0.14
|
||||||
|
entrypoints==0.3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Le module installé dans l'environnement virtuel est disponible UNIQUEMENT dans l'environnement virtuel.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[https://www.python.org/dev/peps/pep-0405/](https://www.python.org/dev/peps/pep-0405/)
|
||||||
|
|
||||||
|
[https://docs.python.org/fr/3/library/venv.html](https://docs.python.org/fr/3/library/venv.html)
|
||||||
|
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# d
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Installer Apache (homebrew)
|
# Installer Apache (homebrew)
|
||||||
|
|
||||||
### Installation:
|
### Installation:
|
||||||
@@ -82,7 +86,15 @@ Editer le fichier *httpd-vhosts.conf*:
|
|||||||
|
|
||||||
#### Redirection de port:
|
#### Redirection de port:
|
||||||
|
|
||||||
wiki.js tourne sur localhost:3000 Pour le rendre disponible sur wiki.silverbook.local:
|
wiki.js tourne sur localhost:3000
|
||||||
|
|
||||||
|
Pour le rendre disponible sur wiki.silverbook.local:
|
||||||
|
|
||||||
|
Editer le fichier *httpd.conf* et activer les modules `mod_proxy` et `mod_proxy_http`:
|
||||||
|
```bash
|
||||||
|
LoadModule proxy_module lib/httpd/modules/mod_proxy.so
|
||||||
|
LoadModule proxy_http_module lib/httpd/modules/mod_proxy_http.so
|
||||||
|
```
|
||||||
|
|
||||||
Editer le fichier *hosts*:
|
Editer le fichier *hosts*:
|
||||||
|
|
||||||
@@ -101,6 +113,7 @@ Editer le fichier *httpd-vhosts.conf*:
|
|||||||
ProxyPassReverse / http://localhost:3000/
|
ProxyPassReverse / http://localhost:3000/
|
||||||
ProxyPreserveHost On
|
ProxyPreserveHost On
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
120
docs/macos/webserver/install_mysql.md
Normal file
120
docs/macos/webserver/install_mysql.md
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
# Installer mysql
|
||||||
|
|
||||||
|
### Installation:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew update
|
||||||
|
$ brew install mariadb
|
||||||
|
$ brew services start mariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
`/usr/local/Cellar/mariadb/10.2.11`
|
||||||
|
|
||||||
|
### Arrêter MySQL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew services stop mariadb
|
||||||
|
```
|
||||||
|
|
||||||
|
### Démarrer MySQL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew services start mariadb
|
||||||
|
ou
|
||||||
|
$ mysql.server start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fix the 2002 MySQL Socket error:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sudo mkdir /var/mysql
|
||||||
|
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
|
||||||
|
```
|
||||||
|
|
||||||
|
### Version:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysql -v -u root -p
|
||||||
|
```
|
||||||
|
|
||||||
|
### Après une m-à-j:
|
||||||
|
|
||||||
|
arrêter puis démarrer
|
||||||
|
|
||||||
|
### Bases:
|
||||||
|
|
||||||
|
Les bases sont stockées ici: `/usr/local/var/mysql`
|
||||||
|
|
||||||
|
### Fichier de configuration:
|
||||||
|
|
||||||
|
my.cnf:
|
||||||
|
|
||||||
|
```
|
||||||
|
#osx (Homebrew): /usr/local/etc/my.cnf
|
||||||
|
|
||||||
|
[mysqld]
|
||||||
|
#innodb_force_recovery = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Erreurs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysql -v -u root -p
|
||||||
|
mysql: Can't read dir of '/usr/local/etc/my.cnf.d' (Errcode: 2 "No such file or directory")
|
||||||
|
Fatal error in defaults handling. Program aborted
|
||||||
|
```
|
||||||
|
|
||||||
|
Le répertoire `/usr/local/etc/my.cnf.d` n'existe plus, il faut le recréer et y créer un fichier:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mkdir /usr/local/etc/my.cnf.d
|
||||||
|
$ touch wont_prune.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Les fichiers [logs](https://dev.mysql.com/doc/refman/5.7/en/server-logs.html) (domain.err) sont avec les bases:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#osx (Homebrew):
|
||||||
|
|
||||||
|
$ cd /usr/local/var/mysql
|
||||||
|
total 388560
|
||||||
|
drwxr-xr-x 32 bruno admin 1024 28 nov 16:53 .
|
||||||
|
drwxrwxr-x 13 bruno admin 416 16 fév 2018 ..
|
||||||
|
-rw-rw---- 1 bruno admin 16384 28 nov 08:08 aria_log.00000001
|
||||||
|
-rw-rw---- 1 bruno admin 52 28 nov 08:08 aria_log_control
|
||||||
|
drwx------ 48 bruno admin 1536 1 déc 17:05 funnymac
|
||||||
|
drwx------ 53 bruno admin 1696 1 déc 17:05 ghost_prod
|
||||||
|
-rw-r----- 1 bruno admin 15114 28 nov 08:08 ib_buffer_pool
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 3 déc 07:19 ib_logfile0
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 24 oct 12:51 ib_logfile1
|
||||||
|
-rw-rw---- 1 bruno admin 79691776 3 déc 07:19 ibdata1
|
||||||
|
-rw-rw---- 1 bruno admin 12582912 28 nov 16:53 ibtmp1
|
||||||
|
-rw-rw---- 1 bruno admin 0 24 jul 2017 multi-master.info
|
||||||
|
drwx------ 89 bruno admin 2848 1 déc 17:05 mysql
|
||||||
|
drwx------ 3 bruno admin 96 24 jul 2017 performance_schema
|
||||||
|
drwx------ 41 bruno admin 1312 1 déc 17:05 phpmyadmin
|
||||||
|
-rw-rw---- 1 bruno admin 1271878 3 déc 07:19 silverbook.home.err
|
||||||
|
-rw-rw---- 1 bruno admin 5 28 nov 16:53 silverbook.home.pid
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Liens:
|
||||||
|
|
||||||
|
[:fa-link: https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/ ](https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/)
|
||||||
|
|
||||||
|
[:fa-link: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/ ](https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/)
|
||||||
|
|
||||||
|
[:fa-link: http://apple.stackexchange.com/questions/255671/error-mysql-server-pid-file-could-not-be-found](http://apple.stackexchange.com/questions/255671/error-mysql-server-pid-file-could-not-be-found)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Package MySQL
|
||||||
|
|
||||||
|
[:fa-link: Télécharger depuis mysql.com](http://dev.mysql.com/downloads/mysql/)
|
||||||
|
|
||||||
|
[:fa-link: Installation](https://dev.mysql.com/doc/refman/5.7/en/osx-installation.html)
|
||||||
|
|
||||||
|
###
|
||||||
@@ -1,79 +1,599 @@
|
|||||||
# Installer mysql
|
# mysql
|
||||||
|
|
||||||
### Installation:
|
|
||||||
|
|
||||||
|
### Connexion à la base:
|
||||||
|
|
||||||
|
#### Se connecter à MySQL:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ brew update
|
$ mysql -u root -p
|
||||||
$ brew install mariadb
|
Enter password:
|
||||||
$ brew services start mariadb
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
||||||
|
Your MariaDB connection id is 18
|
||||||
|
Server version: 10.3.11-MariaDB Homebrew
|
||||||
|
|
||||||
|
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
|
||||||
|
|
||||||
|
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
||||||
|
|
||||||
|
MariaDB [(none)]>
|
||||||
```
|
```
|
||||||
|
|
||||||
`/usr/local/Cellar/mariadb/10.2.11`
|
|
||||||
|
|
||||||
### Arrêter MySQL:
|
|
||||||
|
#### Connexion à la base wordpress4 par l’utilisateur root:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ brew services stop mariadb
|
$ mysql -u root -D wordpress4 -p
|
||||||
|
Enter password:
|
||||||
|
Reading table information for completion of table and column names
|
||||||
|
You can turn off this feature to get a quicker startup with -A
|
||||||
|
|
||||||
|
Welcome to the MariaDB monitor. Commands end with ; or \g.
|
||||||
|
Your MariaDB connection id is 17
|
||||||
|
Server version: 10.3.11-MariaDB Homebrew
|
||||||
|
|
||||||
|
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
|
||||||
|
|
||||||
|
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
|
||||||
|
|
||||||
|
MariaDB [wordpress4]>
|
||||||
```
|
```
|
||||||
|
|
||||||
### Démarrer MySQL:
|
|
||||||
|
|
||||||
|
#### Quitter MySQL:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ brew services start mariadb
|
MariaDB [wordpress4]> exit
|
||||||
ou
|
Bye
|
||||||
$ mysql.server start
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Fix the 2002 MySQL Socket error:
|
|
||||||
|
|
||||||
|
### Types de bases (moteur de stockage):
|
||||||
|
|
||||||
|
[InnoDB](https://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html)
|
||||||
|
|
||||||
|
Conseil: enable innodb_file_per_table = 1 option to put indexes and data for individual tables into distinct files.
|
||||||
|
|
||||||
|
Requête pour trouver les tables InnoDB parmi toutes les bases:
|
||||||
|
|
||||||
|
```mysql
|
||||||
|
mysql> SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'innodb';
|
||||||
|
```
|
||||||
|
|
||||||
|
Constitution de Mysql (par défaut):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ sudo mkdir /var/mysql
|
bruno@silverbook:/usr/local/var/mysql$
|
||||||
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
|
-rw-r----- 1 bruno admin 15114 28 nov 08:08 ib_buffer_pool
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 3 déc 10:35 ib_logfile0
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 24 oct 12:51 ib_logfile1
|
||||||
|
-rw-rw---- 1 bruno admin 79691776 3 déc 10:35 ibdata1
|
||||||
|
-rw-rw---- 1 bruno admin 12582912 28 nov 16:53 ibtmp1
|
||||||
|
-rw-rw---- 1 bruno admin 1272770 3 déc 10:35 silverbook.home.err
|
||||||
|
-rw-rw---- 1 bruno admin 5 28 nov 16:53 silverbook.home.pid
|
||||||
```
|
```
|
||||||
|
|
||||||
### Version:
|
- ibdata1: fichier de 10Mo extensible. InnoDB y stocke tout (bases,tables, index...) pour éviter la fragmentation.
|
||||||
|
- ib_logfile0, ib_logfile1: 2 fichiers log de 5Mo.
|
||||||
|
- ibtmp1
|
||||||
|
- ib_buffer_pool:
|
||||||
|
- silverbook.home.err: fichier log des erreurs
|
||||||
|
|
||||||
|
http://forum.wgpower.net/technique/innodb-fichier-ibdata1-trop-37009_1.html
|
||||||
|
|
||||||
|
https://vdachev.net/2007/02/22/mysql-reducing-ibdata1/
|
||||||
|
|
||||||
|
https://stackoverflow.com/questions/3456159/how-to-shrink-purge-ibdata1-file-in-mysql
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[MyISAM](https://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Connaitre le type de bases par défaut:
|
||||||
|
|
||||||
|
<u>mysql> show engine;</u>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ mysql -v -u root -p
|
MariaDB [(none)]> show engines;
|
||||||
|
|
||||||
|
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
|
||||||
|
|
||||||
|
| Engine | Support | Comment | Transactions | XA | Savepoints |
|
||||||
|
|
||||||
|
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
|
||||||
|
|
||||||
|
| MRG_MyISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
|
||||||
|
|
||||||
|
| CSV | YES | Stores tables as CSV files | NO | NO | NO |
|
||||||
|
|
||||||
|
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
|
||||||
|
|
||||||
|
| MyISAM | YES | Non-transactional engine with good performance and small data footprint | NO | NO | NO |
|
||||||
|
|
||||||
|
| Aria | YES | Crash-safe tables with MyISAM heritage | NO | NO | NO |
|
||||||
|
|
||||||
|
| InnoDB | DEFAULT | Supports transactions, row-level locking, foreign keys and encryption for tables | YES | YES | YES |
|
||||||
|
|
||||||
|
| PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
|
||||||
|
|
||||||
|
| SEQUENCE | YES | Generated tables filled with sequential values | YES | NO | YES |
|
||||||
|
|
||||||
|
+--------------------+---------+----------------------------------------------------------------------------------+--------------+------+------------+
|
||||||
|
|
||||||
|
8 rows in set (0.007 sec)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Après une m-à-j:
|
|
||||||
|
|
||||||
arrêter puis démarrer
|
|
||||||
|
|
||||||
### Erreurs:
|
#### ENGINE utilisé pour une table:
|
||||||
|
|
||||||
|
<u>mysql> SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'database';</u>
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ mysql -v -u root -p
|
MariaDB [(none)]> SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'zenphoto';
|
||||||
mysql: Can't read dir of '/usr/local/etc/my.cnf.d' (Errcode: 2 "No such file or directory")
|
|
||||||
Fatal error in defaults handling. Program aborted
|
+------------------+--------+
|
||||||
|
| TABLE_NAME | ENGINE |
|
||||||
|
+------------------+--------+
|
||||||
|
| _menu | InnoDB |
|
||||||
|
| .tags | InnoDB |
|
||||||
|
| .plugin_storage | InnoDB |
|
||||||
|
| _images | InnoDB |
|
||||||
|
| .pages | MyISAM |
|
||||||
|
| .menu | InnoDB |
|
||||||
|
| _plugin_storage | InnoDB |
|
||||||
|
| .admin_to_object | InnoDB |
|
||||||
|
| _tags | InnoDB |
|
||||||
|
.../...
|
||||||
|
| .captcha | InnoDB |
|
||||||
|
| .news | InnoDB |
|
||||||
|
| .comments | MyISAM |
|
||||||
|
| _admin_to_object | InnoDB |
|
||||||
|
| _comments | InnoDB |
|
||||||
|
| _pages | InnoDB |
|
||||||
|
+------------------+--------+
|
||||||
|
|
||||||
|
32 rows in set (0.012 sec)
|
||||||
```
|
```
|
||||||
|
|
||||||
Le répertoire `/usr/local/etc/my.cnf.d` n'existe plus, il faut le recréer et y créer un fichier:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
$ mkdir /usr/local/etc/my.cnf.d
|
|
||||||
$ touch wont_prune.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
### Bases:
|
### Bases:
|
||||||
|
|
||||||
Les bases sont stockées ici: `/usr/local/var/mysql`
|
#### Voir toutes les bases:
|
||||||
|
|
||||||
### Liens:
|
<u>mysql> SHOW DATABASES;</u>
|
||||||
|
|
||||||
[:fa-link: https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/ ](https://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-macos-sierra/)
|
```bash
|
||||||
|
MariaDB [(none)]> SHOW DATABASES;
|
||||||
|
|
||||||
[:fa-link: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/ ](https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/)
|
+--------------------+
|
||||||
|
| Database |
|
||||||
|
+--------------------+
|
||||||
|
| funnymac |
|
||||||
|
| ghost_prod |
|
||||||
|
| information_schema |
|
||||||
|
| mgpt |
|
||||||
|
| mysql |
|
||||||
|
| performance_schema |
|
||||||
|
| phpmyadmin |
|
||||||
|
| piwik |
|
||||||
|
| python |
|
||||||
|
| ssi |
|
||||||
|
| wordpress4 |
|
||||||
|
| wordpress5 |
|
||||||
|
| xhprof |
|
||||||
|
| xhprof_gui |
|
||||||
|
| yeswiki |
|
||||||
|
| zenphoto |
|
||||||
|
+--------------------+
|
||||||
|
|
||||||
[:fa-link: http://apple.stackexchange.com/questions/255671/error-mysql-server-pid-file-could-not-be-found](http://apple.stackexchange.com/questions/255671/error-mysql-server-pid-file-could-not-be-found)
|
16 rows in set (0.007 sec)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Package MySQL
|
#### Utiliser une base existante:
|
||||||
|
|
||||||
[:fa-link: Télécharger depuis mysql.com](http://dev.mysql.com/downloads/mysql/)
|
<u>mysql> USE database;</u>
|
||||||
|
|
||||||
[:fa-link: Installation](https://dev.mysql.com/doc/refman/5.7/en/osx-installation.html)
|
```bash
|
||||||
|
MariaDB [(none)]> USE ssi
|
||||||
|
|
||||||
|
Reading table information for completion of table and column names
|
||||||
|
|
||||||
|
You can turn off this feature to get a quicker startup with -A
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Database changed
|
||||||
|
|
||||||
|
MariaDB [ssi]>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Supprimer une base:
|
||||||
|
|
||||||
|
<u>mysql> DROP DATABASE database</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [(none)]> DROP DATABASE zenphoto
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Tables:
|
||||||
|
|
||||||
|
#### Voir les tables de la base courante:
|
||||||
|
|
||||||
|
<u>mysql [database]> SHOW TABLES;</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [zenphoto]> SHOW TABLES;
|
||||||
|
|
||||||
|
+--------------------+
|
||||||
|
| Tables_in_zenphoto |
|
||||||
|
+--------------------+
|
||||||
|
| .admin_to_object |
|
||||||
|
| .administrators |
|
||||||
|
| .albums |
|
||||||
|
| .captcha |
|
||||||
|
| .comments |
|
||||||
|
| .images |
|
||||||
|
.../...
|
||||||
|
| _news |
|
||||||
|
| _news2cat |
|
||||||
|
| _news_categories |
|
||||||
|
| _obj_to_tag |
|
||||||
|
| _options |
|
||||||
|
| _pages |
|
||||||
|
| _plugin_storage |
|
||||||
|
| _search_cache |
|
||||||
|
| _tags |
|
||||||
|
+--------------------+
|
||||||
|
|
||||||
|
32 rows in set (0.000 sec)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Structure d’une table:
|
||||||
|
|
||||||
|
<u>mysql [database]> DESCRIBE table;</u>
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [zenphoto]> DESCRIBE _tags;
|
||||||
|
|
||||||
|
+-------+------------------+------+-----+---------+----------------+
|
||||||
|
| Field | Type | Null | Key | Default | Extra |
|
||||||
|
+-------+------------------+------+-----+---------+----------------+
|
||||||
|
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
|
||||||
|
| name | varchar(255) | NO | UNI | NULL | |
|
||||||
|
+-------+------------------+------+-----+---------+----------------+
|
||||||
|
|
||||||
|
2 rows in set (0.030 sec)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Renommer une table:
|
||||||
|
|
||||||
|
mysql [database]> ALTER TABLE table AS new_table;
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [zenphoto]> ALTER TABLE _tags RENAME AS _new-tags;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Vérification des tables :
|
||||||
|
|
||||||
|
<u>2 solutions:</u>
|
||||||
|
|
||||||
|
**1) CHECK TABLE table;**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [zenphoto]> CHECK TABLE _tags;
|
||||||
|
|
||||||
|
+----------------+-------+----------+----------+
|
||||||
|
| Table | Op | Msg_type | Msg_text |
|
||||||
|
+----------------+-------+----------+----------+
|
||||||
|
| zenphoto._tags | check | status | OK |
|
||||||
|
+----------------+-------+----------+----------+
|
||||||
|
|
||||||
|
1 row in set (0.043 sec)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**2) [mysqlcheck](https://mariadb.com/kb/en/library/mysqlcheck/)**
|
||||||
|
|
||||||
|
mysqlcheck verrouille chaque table en lecture seule (la base est alors inaccessible pour les autres processus pendant ce temps) pour vérification ou réparation.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysqlcheck -u root -ppassword zenphoto
|
||||||
|
|
||||||
|
zenphoto..admin_to_object OK
|
||||||
|
zenphoto..administrators OK
|
||||||
|
zenphoto..albums OK
|
||||||
|
zenphoto..captcha OK
|
||||||
|
zenphoto..comments OK
|
||||||
|
zenphoto..images OK
|
||||||
|
zenphoto..menu OK
|
||||||
|
|
||||||
|
.../...
|
||||||
|
|
||||||
|
zenphoto._news2cat OK
|
||||||
|
zenphoto._news_categories OK
|
||||||
|
zenphoto._obj_to_tag OK
|
||||||
|
zenphoto._options OK
|
||||||
|
zenphoto._pages OK
|
||||||
|
zenphoto._plugin_storage OK
|
||||||
|
zenphoto._search_cache OK
|
||||||
|
zenphoto._tags OK
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Optimiser:
|
||||||
|
|
||||||
|
Les bases InnoDB ne supportent pas l’option OPTIMIZE.
|
||||||
|
|
||||||
|
A la place,MySQL crée une nouvelle table, y copie toutes les lignes, efface l’ancienne table, renomme la nouvelle et lance ANALYSE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mysqlcheck -u root -ppassword -o --all-databases
|
||||||
|
|
||||||
|
funnymac.download OK
|
||||||
|
funnymac.downloads OK
|
||||||
|
funnymac.eggs OK
|
||||||
|
funnymac.ipod OK
|
||||||
|
funnymac.ipod_news OK
|
||||||
|
funnymac.ipod_vers OK
|
||||||
|
funnymac.liens OK
|
||||||
|
funnymac.livre OK
|
||||||
|
funnymac.note OK
|
||||||
|
funnymac.numeric_info Table is already up to date
|
||||||
|
funnymac.numeric_log OK
|
||||||
|
funnymac.numeric_vers OK
|
||||||
|
funnymac.tips OK
|
||||||
|
funnymac.truc OK
|
||||||
|
funnymac.vote OK
|
||||||
|
ghost_prod.accesstokens
|
||||||
|
note : Table does not support optimize, doing recreate + analyze instead
|
||||||
|
|
||||||
|
status : OK
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Réparer des tables :
|
||||||
|
|
||||||
|
[MySQL Server logs](https://dev.mysql.com/doc/refman/5.7/en/server-logs.html)
|
||||||
|
|
||||||
|
La 1ere chose à faire en cas de problèmes est de consulter les fichiers logs. Ceux-çi sont généralement avec les tables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#osx (Homebrew):
|
||||||
|
|
||||||
|
$ cd /usr/local/var/mysql
|
||||||
|
total 388560
|
||||||
|
drwxr-xr-x 32 bruno admin 1024 28 nov 16:53 .
|
||||||
|
drwxrwxr-x 13 bruno admin 416 16 fév 2018 ..
|
||||||
|
-rw-rw---- 1 bruno admin 16384 28 nov 08:08 aria_log.00000001
|
||||||
|
-rw-rw---- 1 bruno admin 52 28 nov 08:08 aria_log_control
|
||||||
|
drwx------ 48 bruno admin 1536 1 déc 17:05 funnymac
|
||||||
|
drwx------ 53 bruno admin 1696 1 déc 17:05 ghost_prod
|
||||||
|
-rw-r----- 1 bruno admin 15114 28 nov 08:08 ib_buffer_pool
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 3 déc 07:19 ib_logfile0
|
||||||
|
-rw-rw---- 1 bruno admin 50331648 24 oct 12:51 ib_logfile1
|
||||||
|
-rw-rw---- 1 bruno admin 79691776 3 déc 07:19 ibdata1
|
||||||
|
-rw-rw---- 1 bruno admin 12582912 28 nov 16:53 ibtmp1
|
||||||
|
drwx------ 9 bruno admin 288 1 déc 17:05 mgpt
|
||||||
|
-rw-rw---- 1 bruno admin 0 24 jul 2017 multi-master.info
|
||||||
|
drwx------ 89 bruno admin 2848 1 déc 17:05 mysql
|
||||||
|
drwx------ 3 bruno admin 96 24 jul 2017 performance_schema
|
||||||
|
drwx------ 41 bruno admin 1312 1 déc 17:05 phpmyadmi
|
||||||
|
-rw-rw---- 1 bruno admin 1271878 3 déc 07:19 silverbook.home.err
|
||||||
|
-rw-rw---- 1 bruno admin 5 28 nov 16:53 silverbook.home.pid
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<u>Pour réparer, 2 solutions:</u>
|
||||||
|
|
||||||
|
**1) REPAIR TABLE:**
|
||||||
|
|
||||||
|
- ne nécessite pas l’arrêt de MySQL
|
||||||
|
- uniquement base MyISAM
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [zenphoto]> REPAIR TABLE _tags;
|
||||||
|
+----------------+--------+----------+---------------------------------------------------------+
|
||||||
|
| Table | Op | Msg_type | Msg_text |
|
||||||
|
+----------------+--------+----------+---------------------------------------------------------+
|
||||||
|
| zenphoto._tags | repair | note | The storage engine for the table doesn't support repair |
|
||||||
|
+----------------+--------+----------+---------------------------------------------------------+
|
||||||
|
|
||||||
|
1 row in set (0.006 sec)
|
||||||
|
```
|
||||||
|
|
||||||
|
Si l’erreur persiste, **vider le cache** (Flush all cache)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
**2) mysqlcheck -r:**
|
||||||
|
|
||||||
|
- nécessite un arrêt du service MySQL
|
||||||
|
|
||||||
|
- uniquement base MyISAM
|
||||||
|
|
||||||
|
[MyISAM](https://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysqlcheck -u root -ppassword -r zenphoto .comments
|
||||||
|
|
||||||
|
zenphoto..comments OK
|
||||||
|
```
|
||||||
|
|
||||||
|
[InnoDB](https://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysqlcheck -u root -ppassword -r zenphoto _tags
|
||||||
|
|
||||||
|
zenphoto._tags
|
||||||
|
|
||||||
|
note : The storage engine for the table doesn't support repair
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour les tables InnoDB, il faut [forcer la récupération](https://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html):
|
||||||
|
|
||||||
|
1) Arrêter **mysqld**:
|
||||||
|
|
||||||
|
2) Sauvegarder **mysql**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#Linux
|
||||||
|
/var/lib/mysql/
|
||||||
|
|
||||||
|
#osx (Homebrew)
|
||||||
|
/usr/local/var/mysql/
|
||||||
|
```
|
||||||
|
|
||||||
|
3) Ajouter au fichier de configuration MySQL my.cnf:
|
||||||
|
|
||||||
|
```
|
||||||
|
#osx (Homebrew): /usr/local/etc/my.cnf
|
||||||
|
|
||||||
|
[mysqld]
|
||||||
|
innodb_force_recovery = 4
|
||||||
|
```
|
||||||
|
|
||||||
|
4) Redémarrer **mysqld**:
|
||||||
|
|
||||||
|
5a) Faire un dump des tables de la base avec **SELECT ... INTO OUTFILE**:
|
||||||
|
|
||||||
|
```mysql
|
||||||
|
MariaDB [zenphoto]> SELECT * FROM _tags INTO OUTFILE '/tmp/corrupted.txt';
|
||||||
|
Query OK, 170 rows affected (0.011 sec)
|
||||||
|
|
||||||
|
# Pour exporter au format csv:
|
||||||
|
MariaDB [zenphoto]> SELECT * FROM _tags INTO OUTFILE '/tmp/corrupted.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n';
|
||||||
|
Query OK, 170 rows affected (0.006 sec)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
5b) Faire. un dump de toutes les tables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysqldump -A -u root -ppassword > '/tmp/dump.sql';
|
||||||
|
```
|
||||||
|
|
||||||
|
6) Parfois cela peut suffire. Sinon,
|
||||||
|
|
||||||
|
7) Supprimer les tables / bases corrompues (DROP ...)
|
||||||
|
|
||||||
|
8) Arrêter **mysqld**:
|
||||||
|
|
||||||
|
9) Supprimer les ib*:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#Linux
|
||||||
|
/var/lib/mysql/ib*
|
||||||
|
|
||||||
|
#osx (Homebrew)
|
||||||
|
/usr/local/var/mysql/ib*
|
||||||
|
```
|
||||||
|
|
||||||
|
10) Quitter le mode force recovery:
|
||||||
|
|
||||||
|
```
|
||||||
|
[mysqld]
|
||||||
|
#innodb_force_recovery = 0
|
||||||
|
```
|
||||||
|
|
||||||
|
11) Redémarrer **mysqld**:
|
||||||
|
|
||||||
|
12) Restaurer les bases:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysql -u root -ppassword < dump.sql
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
https://www.nixpal.com/mysql-innodb-corruption-repair-guide/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Vérifier et réparer:
|
||||||
|
|
||||||
|
Vérifier toutes les bases et réparer les tables corrompues:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mysqlcheck -u root -p -A --auto-repair
|
||||||
|
|
||||||
|
Enter password:
|
||||||
|
|
||||||
|
funnymac.download OK
|
||||||
|
funnymac.downloads OK
|
||||||
|
…/…
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Erreur de syntaxe:
|
||||||
|
|
||||||
|
Les commandes doivent se terminer par un **;**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
MariaDB [(none)]> mysqlcheck zenphoto
|
||||||
|
->
|
||||||
|
-> \c
|
||||||
|
MariaDB [(none)]>
|
||||||
|
```
|
||||||
|
|
||||||
|
Sinon taper **\c** pour revenir.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### Tache CRON pour maintenance MySQL
|
||||||
|
|
||||||
|
```bash
|
||||||
|
echo "0 4 * * Sun root mysqlcheck -u maintenance --optimize --all-databases" > /etc/cron.d/mysqlcheck
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
|
||||||
|
|
||||||
|
$ mysql_upgrade -u root -ppassword
|
||||||
|
Phase 1/7: Checking and upgrading mysql database
|
||||||
|
Processing databases
|
||||||
|
mysql
|
||||||
|
mysql.column_stats OK
|
||||||
|
mysql.columns_priv OK
|
||||||
|
mysql.db OK
|
||||||
|
mysql.event OK
|
||||||
|
```
|
||||||
|
|
||||||
###
|
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
|
# PHP 7.2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Installer PHP 7.2 (Homebrew)
|
Installer PHP 7.2 (Homebrew)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
133
docs/macos/webserver/php73.md
Normal file
133
docs/macos/webserver/php73.md
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
# PHP 7.3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Changer de version de PHP:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew unlink php@7.3 && brew link --force --overwrite php@5.6
|
||||||
|
```
|
||||||
|
|
||||||
|
On installe un petit utilitaire [PHP Switcher Script](https://gist.github.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw > /usr/local/bin/sphp
|
||||||
|
$ chmod +x /usr/local/bin/sphp
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Ensuite. pour changer de version:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sphp 7.3
|
||||||
|
```
|
||||||
|
|
||||||
|
Par exemple, pour passer de 7.2.13. à 7.3.0_1:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ sphp 7.3
|
||||||
|
Switching to php@7.3
|
||||||
|
Switching your shell
|
||||||
|
Unlinking /usr/local/Cellar/php@7.2/7.2.13... 25 symlinks removed
|
||||||
|
Unlinking /usr/local/Cellar/php/7.3.0_1... 0 symlinks removed
|
||||||
|
Linking /usr/local/Cellar/php/7.3.0_1... 24 symlinks created
|
||||||
|
You will need sudo power from now on
|
||||||
|
Switching your apache conf
|
||||||
|
Password:
|
||||||
|
Restarting apache
|
||||||
|
|
||||||
|
PHP 7.3.0 (cli) (built: Jan 3 2019 10:08:00) ( NTS )
|
||||||
|
Copyright (c) 1997-2018 The PHP Group
|
||||||
|
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
|
||||||
|
with Zend OPcache v7.3.0, Copyright (c) 1999-2018, by Zend Technologies
|
||||||
|
|
||||||
|
All done!
|
||||||
|
```
|
||||||
|
|
||||||
|
Il y a un autre utilitaire (<u>brew-php-switcher</u>):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew info brew-php-switcher
|
||||||
|
brew-php-switcher: stable 2.0, HEAD
|
||||||
|
Switch Apache / Valet / CLI configs between PHP versions
|
||||||
|
https://github.com/philcook/php-switcher
|
||||||
|
Not installed
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Extensions:
|
||||||
|
|
||||||
|
#### Liste des extensions (Homebrew):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ brew search php73
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Installer des extensions:
|
||||||
|
|
||||||
|
Elles s'installent via [PECL](https://pecl.php.net) (requiert autoconf, `brew install autoconf`).
|
||||||
|
|
||||||
|
- ```bash
|
||||||
|
$ pecl uninstall -r xdebug
|
||||||
|
|
||||||
|
$ pecl install xdebug
|
||||||
|
$ pecl install yaml
|
||||||
|
$ pecl install redis
|
||||||
|
$ pecl install apcu
|
||||||
|
$ pecl install memcached
|
||||||
|
$ pecl install imagick
|
||||||
|
|
||||||
|
# Pour une version spécifique:
|
||||||
|
$ pecl install xdebug-2.7.0beta1
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour les activer, créez un fichier de configuration dans `/usr/local/etc/php/7.3/conf.d/`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bruno@silverbook:/usr/local/etc/php/7.3/conf.d$ l
|
||||||
|
total 32
|
||||||
|
drwxr-xr-x 6 bruno admin 192 4 jan 19:32 .
|
||||||
|
drwxr-xr-x 9 bruno admin 288 3 jan 19:34 ..
|
||||||
|
-rw-r--r-- 1 bruno admin 72 4 jan 16:09 ext-opcache.ini
|
||||||
|
-rw-r--r-- 1 bruno admin 172 4 jan 18:58 ext-xdebug.ini
|
||||||
|
-rw-r--r-- 1 bruno admin 81 4 jan 18:43 ext-yaml.ini
|
||||||
|
-rw-r--r-- 1 bruno admin 87 13 déc 07:12 fix-jit.ini
|
||||||
|
|
||||||
|
bruno@silverbook:/usr/local/etc/php/7.3/conf.d$ nano ext-xdebug.ini
|
||||||
|
|
||||||
|
[xdebug]
|
||||||
|
zend_extension="/usr/local/lib/php/pecl/20180731/xdebug.so"
|
||||||
|
xdebug.remote_enable=1
|
||||||
|
xdebug.remote_host=localhost
|
||||||
|
xdebug.remote_handler=dbgp
|
||||||
|
xdebug.remote_port=9000
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### Erreurs:
|
||||||
|
|
||||||
|
#### Warning: preg_replace(): JIT compilation failed: no more memory in
|
||||||
|
|
||||||
|
Il s'agit d'un [bug](https://bugs.php.net/bug.php?id=77260) connu de PHP 7.3.
|
||||||
|
|
||||||
|
2 solutions:
|
||||||
|
|
||||||
|
- désinstaller php 7.3
|
||||||
|
`$ brew uninstall php@7.3`
|
||||||
|
- désactiver la compilation PCRE JIT dans le php.ini
|
||||||
|
`pcre.jit=0`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Pour désactiver la compilation PCRE JIT, on peut aussi créer un fichier `fix-jit.ini` dans `/usr/local/etc/php/7.3/conf.d`et y ajouter:
|
||||||
|
|
||||||
|
```php
|
||||||
|
; My php.ini settings
|
||||||
|
; Fix for PCRE "JIT compilation failed" error
|
||||||
|
[Pcre]
|
||||||
|
pcre.jit=0
|
||||||
|
```
|
||||||
26
mkdocs.yml
26
mkdocs.yml
@@ -13,6 +13,8 @@ nav:
|
|||||||
- Archiver / compresser: Linux/archiver.md
|
- Archiver / compresser: Linux/archiver.md
|
||||||
- apt-get: Raspberry/apt-get.md
|
- apt-get: Raspberry/apt-get.md
|
||||||
- aptitude: Raspberry/aptitude.md
|
- aptitude: Raspberry/aptitude.md
|
||||||
|
- awk: Linux/awk.md
|
||||||
|
- Chaines: Linux/string.md
|
||||||
- Commandes sympas: Linux/commandes.md
|
- Commandes sympas: Linux/commandes.md
|
||||||
- Conditions: Linux/conditions.md
|
- Conditions: Linux/conditions.md
|
||||||
- Editeurs:
|
- Editeurs:
|
||||||
@@ -21,18 +23,23 @@ nav:
|
|||||||
- vi: Linux/Editeurs/vi.md
|
- vi: Linux/Editeurs/vi.md
|
||||||
- Executer: Linux/executer.md
|
- Executer: Linux/executer.md
|
||||||
- Filtres: Linux/filtres.md
|
- Filtres: Linux/filtres.md
|
||||||
|
- Format ext4: Linux/format_ext4.md
|
||||||
- find: Linux/find.md
|
- find: Linux/find.md
|
||||||
|
- for: Linux/for.md
|
||||||
- grep: Linux/grep.md
|
- grep: Linux/grep.md
|
||||||
|
- Lire un fichier: Linux/read.md
|
||||||
- MàJ sans internet: Linux/maj.md
|
- MàJ sans internet: Linux/maj.md
|
||||||
- Permissions: Linux/permissions.md
|
- Permissions: Linux/permissions.md
|
||||||
- Pipelines: Linux/pipeline.md
|
- Pipelines: Linux/pipeline.md
|
||||||
- I/O Redirections: Linux/redirections.md
|
- I/O Redirections: Linux/redirections.md
|
||||||
- SCP: Linux/scp.md
|
- SCP: Linux/scp.md
|
||||||
- SFTP: Linux/sftp.md
|
- SFTP: Linux/sftp.md
|
||||||
|
- sed: Linux/sed.md
|
||||||
- Shells: Linux/shell.md
|
- Shells: Linux/shell.md
|
||||||
- SSH: Linux/ssh.md
|
- SSH: Linux/ssh.md
|
||||||
- Tail / Head: Linux/tail-head.md
|
- Tail / Head: Linux/tail-head.md
|
||||||
- Variables: Linux/variables.md
|
- Variables: Linux/variables.md
|
||||||
|
- Divers: Linux/divers.md
|
||||||
- macos:
|
- macos:
|
||||||
- Index: macos/index.md
|
- Index: macos/index.md
|
||||||
- Bash (exemples): macos/bash_exemples.md
|
- Bash (exemples): macos/bash_exemples.md
|
||||||
@@ -62,9 +69,11 @@ nav:
|
|||||||
- Composer: macos/webserver/composer.md
|
- Composer: macos/webserver/composer.md
|
||||||
- erreurs: macos/webserver/errors_apache.md
|
- erreurs: macos/webserver/errors_apache.md
|
||||||
- mongodb: macos/webserver/mongodb.md
|
- mongodb: macos/webserver/mongodb.md
|
||||||
- MySQL: macos/webserver/mysql.md
|
- MySQL (installation): macos/webserver/install_mysql.md
|
||||||
|
- MySQL (trucs): macos/webserver/mysql.md
|
||||||
- PHP: macos/webserver/php.md
|
- PHP: macos/webserver/php.md
|
||||||
- PHP 7.2: macos/webserver/php72.md
|
- PHP 7.2: macos/webserver/php72.md
|
||||||
|
- PHP 7.3: macos/webserver/php73.md
|
||||||
- Xhprof: macos/webserver/Xhprof.md
|
- Xhprof: macos/webserver/Xhprof.md
|
||||||
- you have mail: macos/youhavemail.md
|
- you have mail: macos/youhavemail.md
|
||||||
- Divers: macos/Divers.md
|
- Divers: macos/Divers.md
|
||||||
@@ -85,8 +94,18 @@ nav:
|
|||||||
- aptitude: Raspberry/aptitude.md
|
- aptitude: Raspberry/aptitude.md
|
||||||
- Boot et clone: Raspberry/boot.md
|
- Boot et clone: Raspberry/boot.md
|
||||||
- Backup: Raspberry/backup.md
|
- Backup: Raspberry/backup.md
|
||||||
|
- Hardware: Raspberry/hardware.md
|
||||||
|
- Installation sans écran: Raspberry/headless.md
|
||||||
|
- Matériels:
|
||||||
|
- Liste: Raspberry/materiels/materiels.md
|
||||||
|
- Cameras: Raspberry/materiels/camera.md
|
||||||
|
- HC-SR04: Raspberry/materiels/HC-SR04.md
|
||||||
|
- HC-SR501: Raspberry/materiels/HC-SR501.md
|
||||||
- Pi Desktop: Raspberry/pi-desktop.md
|
- Pi Desktop: Raspberry/pi-desktop.md
|
||||||
- Réseau: Raspberry/reseau.md
|
- Réseau: Raspberry/reseau.md
|
||||||
|
- Envoyer un mail depuis le RPi: Raspberry/send_mail.md
|
||||||
|
- SiriControl: Raspberry/siri_control.md
|
||||||
|
- Tools: Raspberry/tools.md
|
||||||
- Divers: Raspberry/divers.md
|
- Divers: Raspberry/divers.md
|
||||||
- Synology:
|
- Synology:
|
||||||
- Index: Synology/index.md
|
- Index: Synology/index.md
|
||||||
@@ -111,7 +130,11 @@ nav:
|
|||||||
- git: Divers/git/git.md
|
- git: Divers/git/git.md
|
||||||
- Session de travail avec git: Divers/git/git-session.md
|
- Session de travail avec git: Divers/git/git-session.md
|
||||||
- go: Divers/go.md
|
- go: Divers/go.md
|
||||||
|
- Markdown: Divers/markdown.md
|
||||||
- Plex: Divers/plex.md
|
- Plex: Divers/plex.md
|
||||||
|
- Vagrant:
|
||||||
|
- Installation: Divers/Vagrant/Vagrant.md
|
||||||
|
- Créer une Vagrant box: Divers/Vagrant/creer_une_vagrant_box.md
|
||||||
- Vider le cache DNS: Divers/Vider_cache_DNS.md
|
- Vider le cache DNS: Divers/Vider_cache_DNS.md
|
||||||
- wp-cli:
|
- wp-cli:
|
||||||
- Index: Divers/wp-cli/index.md
|
- Index: Divers/wp-cli/index.md
|
||||||
@@ -134,6 +157,7 @@ nav:
|
|||||||
- theme: Divers/wp-cli/wp_theme.md
|
- theme: Divers/wp-cli/wp_theme.md
|
||||||
- user: Divers/wp-cli/wp_user.md
|
- user: Divers/wp-cli/wp_user.md
|
||||||
- autres: Divers/wp-cli/autres.md
|
- autres: Divers/wp-cli/autres.md
|
||||||
|
- OVH: Divers/wp-cli/ovh.md
|
||||||
- MkDocs: mkdocs.md
|
- MkDocs: mkdocs.md
|
||||||
|
|
||||||
theme:
|
theme:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ nav:
|
|||||||
- Archiver / compresser: Linux/archiver.md
|
- Archiver / compresser: Linux/archiver.md
|
||||||
- apt-get: Raspberry/apt-get.md
|
- apt-get: Raspberry/apt-get.md
|
||||||
- aptitude: Raspberry/aptitude.md
|
- aptitude: Raspberry/aptitude.md
|
||||||
|
- Chaines: Linux/string.md
|
||||||
- Commandes sympas: Linux/commandes.md
|
- Commandes sympas: Linux/commandes.md
|
||||||
- Conditions: Linux/conditions.md
|
- Conditions: Linux/conditions.md
|
||||||
- Editeurs:
|
- Editeurs:
|
||||||
@@ -22,6 +23,7 @@ nav:
|
|||||||
- Executer: Linux/executer.md
|
- Executer: Linux/executer.md
|
||||||
- Filtres: Linux/filtres.md
|
- Filtres: Linux/filtres.md
|
||||||
- find: Linux/find.md
|
- find: Linux/find.md
|
||||||
|
- for: Linux/for.md
|
||||||
- grep: Linux/grep.md
|
- grep: Linux/grep.md
|
||||||
- MàJ sans internet: Linux/maj.md
|
- MàJ sans internet: Linux/maj.md
|
||||||
- Permissions: Linux/permissions.md
|
- Permissions: Linux/permissions.md
|
||||||
@@ -62,9 +64,11 @@ nav:
|
|||||||
- Composer: macos/webserver/composer.md
|
- Composer: macos/webserver/composer.md
|
||||||
- erreurs: macos/webserver/errors_apache.md
|
- erreurs: macos/webserver/errors_apache.md
|
||||||
- mongodb: macos/webserver/mongodb.md
|
- mongodb: macos/webserver/mongodb.md
|
||||||
- MySQL: macos/webserver/mysql.md
|
- MySQL (installation): macos/webserver/install_mysql.md
|
||||||
|
- MySQL (trucs): macos/webserver/mysql.md
|
||||||
- PHP: macos/webserver/php.md
|
- PHP: macos/webserver/php.md
|
||||||
- PHP 7.2: macos/webserver/php72.md
|
- PHP 7.2: macos/webserver/php72.md
|
||||||
|
- PHP 7.3: macos/webserver/php73.md
|
||||||
- Xhprof: macos/webserver/Xhprof.md
|
- Xhprof: macos/webserver/Xhprof.md
|
||||||
- you have mail: macos/youhavemail.md
|
- you have mail: macos/youhavemail.md
|
||||||
- Divers: macos/Divers.md
|
- Divers: macos/Divers.md
|
||||||
@@ -87,6 +91,7 @@ nav:
|
|||||||
- Backup: Raspberry/backup.md
|
- Backup: Raspberry/backup.md
|
||||||
- Pi Desktop: Raspberry/pi-desktop.md
|
- Pi Desktop: Raspberry/pi-desktop.md
|
||||||
- Réseau: Raspberry/reseau.md
|
- Réseau: Raspberry/reseau.md
|
||||||
|
- Tools: Raspberry/tools.md
|
||||||
- Divers: Raspberry/divers.md
|
- Divers: Raspberry/divers.md
|
||||||
- Synology:
|
- Synology:
|
||||||
- Index: Synology/index.md
|
- Index: Synology/index.md
|
||||||
@@ -111,7 +116,11 @@ nav:
|
|||||||
- git: Divers/git/git.md
|
- git: Divers/git/git.md
|
||||||
- Session de travail avec git: Divers/git/git-session.md
|
- Session de travail avec git: Divers/git/git-session.md
|
||||||
- go: Divers/go.md
|
- go: Divers/go.md
|
||||||
|
- Markdown: Divers/markdown.md
|
||||||
- Plex: Divers/plex.md
|
- Plex: Divers/plex.md
|
||||||
|
- Vagrant:
|
||||||
|
- Installation: Divers/Vagrant/Vagrant.md
|
||||||
|
- Créer une Vagrant box: Divers/Vagrant/creer_une_vagrant_box.md
|
||||||
- Vider le cache DNS: Divers/Vider_cache_DNS.md
|
- Vider le cache DNS: Divers/Vider_cache_DNS.md
|
||||||
- wp-cli:
|
- wp-cli:
|
||||||
- Index: Divers/wp-cli/index.md
|
- Index: Divers/wp-cli/index.md
|
||||||
@@ -134,6 +143,7 @@ nav:
|
|||||||
- theme: Divers/wp-cli/wp_theme.md
|
- theme: Divers/wp-cli/wp_theme.md
|
||||||
- user: Divers/wp-cli/wp_user.md
|
- user: Divers/wp-cli/wp_user.md
|
||||||
- autres: Divers/wp-cli/autres.md
|
- autres: Divers/wp-cli/autres.md
|
||||||
|
- OVH: Divers/wp-cli/ovh.md
|
||||||
- MkDocs: mkdocs.md
|
- MkDocs: mkdocs.md
|
||||||
|
|
||||||
theme:
|
theme:
|
||||||
|
|||||||
Reference in New Issue
Block a user