Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a953479ebf | |||
| db21914afe | |||
| 084b8a3a08 |
@@ -1,4 +1,5 @@
|
|||||||
import traceback
|
import traceback
|
||||||
|
import os
|
||||||
|
|
||||||
from aiogram import Bot, Dispatcher
|
from aiogram import Bot, Dispatcher
|
||||||
from aiogram.client.default import DefaultBotProperties
|
from aiogram.client.default import DefaultBotProperties
|
||||||
@@ -21,26 +22,65 @@ dp = Dispatcher(bot=bot, storage=storage)
|
|||||||
|
|
||||||
def get_git_commit_number() -> str:
|
def get_git_commit_number() -> str:
|
||||||
repo_url = "https://github.com/Vladless/Solo_bot"
|
repo_url = "https://github.com/Vladless/Solo_bot"
|
||||||
|
cwd = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
if not os.path.isdir(os.path.join(cwd, ".git")):
|
||||||
|
cwd = "/root/Prod/Solo_bot"
|
||||||
|
|
||||||
|
env = os.environ.copy()
|
||||||
|
env["GIT_DIR"] = os.path.join(cwd, ".git")
|
||||||
|
env["GIT_WORK_TREE"] = cwd
|
||||||
|
|
||||||
try:
|
try:
|
||||||
local_number = subprocess.check_output(
|
local_number = subprocess.check_output(
|
||||||
["git", "rev-list", "--count", "HEAD"]
|
["git", "rev-list", "--count", "HEAD"],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env
|
||||||
).decode().strip()
|
).decode().strip()
|
||||||
|
|
||||||
local_hash = subprocess.check_output(
|
local_hash = subprocess.check_output(
|
||||||
["git", "rev-parse", "HEAD"]
|
["git", "rev-parse", "HEAD"],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env
|
||||||
).decode().strip()
|
).decode().strip()
|
||||||
except Exception:
|
|
||||||
return "\n(Требуется обновление через CLI)"
|
try:
|
||||||
|
branch = subprocess.check_output(
|
||||||
|
["git", "rev-parse", "--abbrev-ref", "HEAD"],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env
|
||||||
|
).decode().strip()
|
||||||
|
|
||||||
|
if branch == "HEAD":
|
||||||
|
describe = subprocess.check_output(
|
||||||
|
["git", "describe", "--tags", "--exact-match"],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
).decode().strip()
|
||||||
|
|
||||||
|
if describe.startswith("v") or "release" in describe.lower():
|
||||||
|
branch = "main"
|
||||||
|
else:
|
||||||
|
branch = "dev"
|
||||||
|
except Exception:
|
||||||
|
branch = "dev"
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return f"\n(Требуется обновление через CLI: {e})"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
remote_commit = subprocess.check_output(
|
remote_commit = subprocess.check_output(
|
||||||
["git", "ls-remote", "origin", "refs/heads/dev"]
|
["git", "ls-remote", "origin", f"refs/heads/{branch}"],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env
|
||||||
).decode()
|
).decode()
|
||||||
remote_hash = remote_commit.split()[0]
|
remote_hash = remote_commit.split()[0]
|
||||||
|
|
||||||
remote_number = subprocess.check_output(
|
remote_number = subprocess.check_output(
|
||||||
["git", "rev-list", "--count", remote_hash]
|
["git", "rev-list", "--count", remote_hash],
|
||||||
|
cwd=cwd,
|
||||||
|
env=env
|
||||||
).decode().strip()
|
).decode().strip()
|
||||||
|
|
||||||
if local_hash == remote_hash:
|
if local_hash == remote_hash:
|
||||||
@@ -53,10 +93,7 @@ def get_git_commit_number() -> str:
|
|||||||
)
|
)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return (
|
return ""
|
||||||
f"\n(commit <a href=\"{repo_url}/commit/{local_hash}\">"
|
|
||||||
f"#{local_number}</a> / actual commit unknown)"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
version = f"v4.3-Release{get_git_commit_number()}"
|
version = f"v4.3-Release{get_git_commit_number()}"
|
||||||
|
|||||||
+14
-6
@@ -101,6 +101,7 @@ def clean_project_dir_safe(update_buttons=False, update_img=False):
|
|||||||
preserved_paths = {
|
preserved_paths = {
|
||||||
os.path.join(PROJECT_DIR, "config.py"),
|
os.path.join(PROJECT_DIR, "config.py"),
|
||||||
os.path.join(PROJECT_DIR, "handlers", "texts.py"),
|
os.path.join(PROJECT_DIR, "handlers", "texts.py"),
|
||||||
|
os.path.join(PROJECT_DIR, ".git"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if not update_buttons:
|
if not update_buttons:
|
||||||
@@ -205,9 +206,7 @@ def update_from_beta():
|
|||||||
f"[cyan]🔢 Локальная версия: {local_version} | Последняя в dev: {remote_version}[/cyan]"
|
f"[cyan]🔢 Локальная версия: {local_version} | Последняя в dev: {remote_version}[/cyan]"
|
||||||
)
|
)
|
||||||
if local_version == remote_version:
|
if local_version == remote_version:
|
||||||
if not Confirm.ask(
|
if not Confirm.ask("[yellow]❗ Версия актуальна. Обновить всё равно?[/yellow]"):
|
||||||
"[yellow]❗ Версия актуальна. Обновить всё равно?[/yellow]"
|
|
||||||
):
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
console.print("[red]⚠️ Не удалось определить версии.[/red]")
|
console.print("[red]⚠️ Не удалось определить версии.[/red]")
|
||||||
@@ -229,7 +228,8 @@ def update_from_beta():
|
|||||||
os.chdir(PROJECT_DIR)
|
os.chdir(PROJECT_DIR)
|
||||||
console.print("[cyan]📅 Клонируем временный репозиторий...[/cyan]")
|
console.print("[cyan]📅 Клонируем временный репозиторий...[/cyan]")
|
||||||
subprocess.run(["rm", "-rf", TEMP_DIR])
|
subprocess.run(["rm", "-rf", TEMP_DIR])
|
||||||
if os.system(f"git clone -b dev {GITHUB_REPO} {TEMP_DIR}") != 0:
|
|
||||||
|
if os.system(f"git clone --depth=1000000 -b dev {GITHUB_REPO} {TEMP_DIR}") != 0:
|
||||||
console.print("[red]❌ Ошибка при клонировании. Обновление отменено.[/red]")
|
console.print("[red]❌ Ошибка при клонировании. Обновление отменено.[/red]")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -243,6 +243,10 @@ def update_from_beta():
|
|||||||
exclude_options += "--exclude=handlers/buttons.py "
|
exclude_options += "--exclude=handlers/buttons.py "
|
||||||
|
|
||||||
subprocess.run(f"rsync -a {exclude_options} {TEMP_DIR}/ {PROJECT_DIR}/", shell=True)
|
subprocess.run(f"rsync -a {exclude_options} {TEMP_DIR}/ {PROJECT_DIR}/", shell=True)
|
||||||
|
|
||||||
|
if os.path.exists(os.path.join(TEMP_DIR, ".git")):
|
||||||
|
subprocess.run(["cp", "-r", os.path.join(TEMP_DIR, ".git"), PROJECT_DIR])
|
||||||
|
|
||||||
subprocess.run(["rm", "-rf", TEMP_DIR])
|
subprocess.run(["rm", "-rf", TEMP_DIR])
|
||||||
|
|
||||||
fix_permissions()
|
fix_permissions()
|
||||||
@@ -298,7 +302,7 @@ def update_from_release():
|
|||||||
console.print(f"[cyan]📥 Клонируем релиз {tag_name} во временную папку...[/cyan]")
|
console.print(f"[cyan]📥 Клонируем релиз {tag_name} во временную папку...[/cyan]")
|
||||||
subprocess.run(["rm", "-rf", TEMP_DIR])
|
subprocess.run(["rm", "-rf", TEMP_DIR])
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
f"git clone --depth 1 --branch {tag_name} {GITHUB_REPO} {TEMP_DIR}",
|
f"git clone --branch {tag_name} {GITHUB_REPO} {TEMP_DIR}",
|
||||||
shell=True,
|
shell=True,
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
@@ -314,6 +318,10 @@ def update_from_release():
|
|||||||
exclude_options += "--exclude=handlers/buttons.py "
|
exclude_options += "--exclude=handlers/buttons.py "
|
||||||
|
|
||||||
subprocess.run(f"rsync -a {exclude_options} {TEMP_DIR}/ {PROJECT_DIR}/", shell=True)
|
subprocess.run(f"rsync -a {exclude_options} {TEMP_DIR}/ {PROJECT_DIR}/", shell=True)
|
||||||
|
|
||||||
|
if os.path.exists(os.path.join(TEMP_DIR, ".git")):
|
||||||
|
subprocess.run(["cp", "-r", os.path.join(TEMP_DIR, ".git"), PROJECT_DIR])
|
||||||
|
|
||||||
subprocess.run(["rm", "-rf", TEMP_DIR])
|
subprocess.run(["rm", "-rf", TEMP_DIR])
|
||||||
|
|
||||||
fix_permissions()
|
fix_permissions()
|
||||||
@@ -351,7 +359,7 @@ def show_update_menu():
|
|||||||
|
|
||||||
def show_menu():
|
def show_menu():
|
||||||
table = Table(
|
table = Table(
|
||||||
title="Solobot CLI v0.1.8", title_style="bold magenta", header_style="bold blue"
|
title="Solobot CLI v0.2.0", title_style="bold magenta", header_style="bold blue"
|
||||||
)
|
)
|
||||||
table.add_column("№", justify="center", style="cyan", no_wrap=True)
|
table.add_column("№", justify="center", style="cyan", no_wrap=True)
|
||||||
table.add_column("Операция", style="white")
|
table.add_column("Операция", style="white")
|
||||||
|
|||||||
Reference in New Issue
Block a user