mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-26 09:13:35 +05:00
Compare commits
8 Commits
fcff21317e
...
v6.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc026a7a2b | ||
|
|
ac54d04b40 | ||
|
|
c19364360c | ||
|
|
2e6c66e524 | ||
|
|
a8a73249a5 | ||
|
|
ec3f93eeda | ||
|
|
4cf523a758 | ||
|
|
1d06bf76f3 |
@@ -6,8 +6,16 @@
|
|||||||
# #
|
# #
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
import re
|
||||||
from subprocess import PIPE, STDOUT, CalledProcessError, Popen, check_output, run
|
from subprocess import (
|
||||||
|
DEVNULL,
|
||||||
|
PIPE,
|
||||||
|
STDOUT,
|
||||||
|
CalledProcessError,
|
||||||
|
Popen,
|
||||||
|
check_output,
|
||||||
|
run,
|
||||||
|
)
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from components.klipper import KLIPPER_DIR
|
from components.klipper import KLIPPER_DIR
|
||||||
@@ -32,16 +40,18 @@ def find_firmware_file() -> bool:
|
|||||||
f3 = "klipper.bin"
|
f3 = "klipper.bin"
|
||||||
f4 = "klipper.uf2"
|
f4 = "klipper.uf2"
|
||||||
fw_file_exists: bool = (
|
fw_file_exists: bool = (
|
||||||
target.joinpath(f1).exists() and target.joinpath(f2).exists()
|
(target.joinpath(f1).exists() and target.joinpath(f2).exists())
|
||||||
) or target.joinpath(f3).exists() or target.joinpath(f4).exists()
|
or target.joinpath(f3).exists()
|
||||||
|
or target.joinpath(f4).exists()
|
||||||
|
)
|
||||||
|
|
||||||
return target_exists and fw_file_exists
|
return target_exists and fw_file_exists
|
||||||
|
|
||||||
|
|
||||||
def find_usb_device_by_id() -> List[str]:
|
def find_usb_device_by_id() -> List[str]:
|
||||||
try:
|
try:
|
||||||
command = "find /dev/serial/by-id/* 2>/dev/null"
|
command = "find /dev/serial/by-id/*"
|
||||||
output = check_output(command, shell=True, text=True)
|
output = check_output(command, shell=True, text=True, stderr=DEVNULL)
|
||||||
return output.splitlines()
|
return output.splitlines()
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
Logger.print_error("Unable to find a USB device!")
|
Logger.print_error("Unable to find a USB device!")
|
||||||
@@ -51,9 +61,14 @@ def find_usb_device_by_id() -> List[str]:
|
|||||||
|
|
||||||
def find_uart_device() -> List[str]:
|
def find_uart_device() -> List[str]:
|
||||||
try:
|
try:
|
||||||
command = '"find /dev -maxdepth 1 -regextype posix-extended -regex "^\/dev\/tty(AMA0|S0)$" 2>/dev/null"'
|
cmd = "find /dev -maxdepth 1"
|
||||||
output = check_output(command, shell=True, text=True)
|
output = check_output(cmd, shell=True, text=True, stderr=DEVNULL)
|
||||||
return output.splitlines()
|
device_list = []
|
||||||
|
if output:
|
||||||
|
pattern = r"^/dev/tty(AMA0|S0)$"
|
||||||
|
devices = output.splitlines()
|
||||||
|
device_list = [d for d in devices if re.search(pattern, d)]
|
||||||
|
return device_list
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
Logger.print_error("Unable to find a UART device!")
|
Logger.print_error("Unable to find a UART device!")
|
||||||
Logger.print_error(e, prefix=False)
|
Logger.print_error(e, prefix=False)
|
||||||
@@ -62,9 +77,13 @@ def find_uart_device() -> List[str]:
|
|||||||
|
|
||||||
def find_usb_dfu_device() -> List[str]:
|
def find_usb_dfu_device() -> List[str]:
|
||||||
try:
|
try:
|
||||||
command = '"lsusb | grep "DFU" | cut -d " " -f 6 2>/dev/null"'
|
output = check_output("lsusb", shell=True, text=True, stderr=DEVNULL)
|
||||||
output = check_output(command, shell=True, text=True)
|
device_list = []
|
||||||
return output.splitlines()
|
if output:
|
||||||
|
devices = output.splitlines()
|
||||||
|
device_list = [d.split(" ")[5] for d in devices if "DFU" in d]
|
||||||
|
return device_list
|
||||||
|
|
||||||
except CalledProcessError as e:
|
except CalledProcessError as e:
|
||||||
Logger.print_error("Unable to find a USB DFU device!")
|
Logger.print_error("Unable to find a USB DFU device!")
|
||||||
Logger.print_error(e, prefix=False)
|
Logger.print_error(e, prefix=False)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Moonraker Telegram Bot SV1 %INST%
|
Description=Moonraker Telegram Bot SV1
|
||||||
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
|
Documentation=https://github.com/nlef/moonraker-telegram-bot/wiki
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
|
|
||||||
|
|||||||
@@ -161,10 +161,11 @@ class TelegramBotExtension(BaseExtension):
|
|||||||
# install dependencies
|
# install dependencies
|
||||||
script = TG_BOT_DIR.joinpath("scripts/install.sh")
|
script = TG_BOT_DIR.joinpath("scripts/install.sh")
|
||||||
package_list = parse_packages_from_file(script)
|
package_list = parse_packages_from_file(script)
|
||||||
|
|
||||||
check_install_dependencies({*package_list})
|
check_install_dependencies({*package_list})
|
||||||
|
|
||||||
# create virtualenv
|
# create virtualenv
|
||||||
if create_python_venv(TG_BOT_ENV):
|
if create_python_venv(TG_BOT_ENV, allow_access_to_system_site_packages=True):
|
||||||
install_python_requirements(TG_BOT_ENV, TG_BOT_REQ_FILE)
|
install_python_requirements(TG_BOT_ENV, TG_BOT_REQ_FILE)
|
||||||
|
|
||||||
def _patch_bot_update_manager(self, instances: List[Moonraker]) -> None:
|
def _patch_bot_update_manager(self, instances: List[Moonraker]) -> None:
|
||||||
|
|||||||
@@ -91,19 +91,27 @@ def parse_packages_from_file(source_file: Path) -> List[str]:
|
|||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|
||||||
def create_python_venv(target: Path, force: bool = False) -> bool:
|
def create_python_venv(
|
||||||
|
target: Path,
|
||||||
|
force: bool = False,
|
||||||
|
allow_access_to_system_site_packages: bool = False,
|
||||||
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Create a python 3 virtualenv at the provided target destination.
|
Create a python 3 virtualenv at the provided target destination.
|
||||||
Returns True if the virtualenv was created successfully.
|
Returns True if the virtualenv was created successfully.
|
||||||
Returns False if the virtualenv already exists, recreation was declined or creation failed.
|
Returns False if the virtualenv already exists, recreation was declined or creation failed.
|
||||||
:param force: Force recreation of the virtualenv
|
|
||||||
:param target: Path where to create the virtualenv at
|
:param target: Path where to create the virtualenv at
|
||||||
|
:param force: Force recreation of the virtualenv
|
||||||
|
:param allow_access_to_system_site_packages: give the virtual environment access to the system site-packages dir
|
||||||
:return: bool
|
:return: bool
|
||||||
"""
|
"""
|
||||||
Logger.print_status("Set up Python virtual environment ...")
|
Logger.print_status("Set up Python virtual environment ...")
|
||||||
|
cmd = ["virtualenv", "-p", "/usr/bin/python3", target.as_posix()]
|
||||||
|
cmd.append(
|
||||||
|
"--system-site-packages"
|
||||||
|
) if allow_access_to_system_site_packages else None
|
||||||
if not target.exists():
|
if not target.exists():
|
||||||
try:
|
try:
|
||||||
cmd = ["virtualenv", "-p", "/usr/bin/python3", target.as_posix()]
|
|
||||||
run(cmd, check=True)
|
run(cmd, check=True)
|
||||||
Logger.print_ok("Setup of virtualenv successful!")
|
Logger.print_ok("Setup of virtualenv successful!")
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user