From 0682ac89616c76b84f0e48ef27fc1fe5801cced0 Mon Sep 17 00:00:00 2001 From: Digital Studium Date: Sun, 9 Apr 2023 20:34:41 +0300 Subject: [PATCH] Add pyinstaller step --- .../how-to-easily-write-linux-cli-tool.md | 17 +++++++++++++++-- .../how-to-easily-write-linux-cli-tool.md | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/content/en/python-programming/how-to-easily-write-linux-cli-tool.md b/content/en/python-programming/how-to-easily-write-linux-cli-tool.md index 9c27dc7..5693ee8 100644 --- a/content/en/python-programming/how-to-easily-write-linux-cli-tool.md +++ b/content/en/python-programming/how-to-easily-write-linux-cli-tool.md @@ -72,7 +72,7 @@ COMMANDS A method for getting kernel version ``` -## Making the tool more complex +## Step 3. Making the tool more complex For example, we also want our tool to be able to print the kernel version in short form, like this: `6.2.2`. We rewrite the code as follows: ```python @@ -124,4 +124,17 @@ FLAGS -f, --format=FORMAT Type: ('short', 'full') Default: 'full' -``` \ No newline at end of file +``` + +## Step 4. Create a binary file + +First install `pyinstaller`: +```bash +pip install pytinstaller +``` +Then we run the command: +``` +pyinstaller my-cli-tool --onefile +``` +A folder `dist` shoud appear, and a binary file `my-cli-tool` inside it with all dependencies, which can be used even on servers, +which do not have python or fire installed. Just put this file in the path `/usr/local/bin` and `my-cli-tool` can be used! \ No newline at end of file diff --git a/content/ru/python-programming/how-to-easily-write-linux-cli-tool.md b/content/ru/python-programming/how-to-easily-write-linux-cli-tool.md index 47a5a20..1780564 100644 --- a/content/ru/python-programming/how-to-easily-write-linux-cli-tool.md +++ b/content/ru/python-programming/how-to-easily-write-linux-cli-tool.md @@ -72,7 +72,7 @@ COMMANDS A method for getting kernel version ``` -## Усложняем инструмент +## Шаг 3. Усложняем инструмент Например, мы хотим также, чтобы наш инструмент мог выводить версию ядра в коротком варианте, то есть так: `6.2.2`. Переписываем код следующим образом: ```python @@ -124,4 +124,17 @@ FLAGS -f, --format=FORMAT Type: ('short', 'full') Default: 'full' -``` \ No newline at end of file +``` + +## Шаг 4. Создаём бинарный файл + +Сначала устанавливаем `pyinstaller`: +```bash +pip install pytinstaller +``` +Затем запускаем команду: +``` +pyinstaller my-cli-tool --onefile +``` +У вас должна появиться папка `dist`, а в ней файл бинарный `my-cli-tool` со всеми зависимостями, который можно использовать даже на серверах, +на которых не установлен python или fire. Просто кладём этот файл по пути `/usr/local/bin` и `my-cli-tool` можно использовать! \ No newline at end of file