|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | + |
| 4 | +from telegram.ext import CommandHandler |
| 5 | + |
| 6 | +from pycamp_bot.utils import escape_markdown |
| 7 | + |
| 8 | + |
| 9 | +async def show_version(update, context): |
| 10 | + """Let people see the details about what is being run and how""" |
| 11 | + |
| 12 | + git_rev_parse = subprocess.run(['git', 'rev-parse', '--short', 'HEAD'], capture_output=True, check=True) |
| 13 | + commit = git_rev_parse.stdout.decode().rstrip() |
| 14 | + |
| 15 | + git_log = subprocess.run(['git', 'log', '--max-count=1', '--pretty=format:%ai'], capture_output=True, check=True) |
| 16 | + author_date = git_log.stdout.decode().rstrip() |
| 17 | + |
| 18 | + git_diff = subprocess.run(['git', 'diff', '--quiet'], capture_output=True) |
| 19 | + if git_diff.returncode == 0: |
| 20 | + clean_worktree = '🟢' |
| 21 | + else: |
| 22 | + clean_worktree = '🔴' |
| 23 | + |
| 24 | + python_version = '.'.join(str(component) for component in sys.version_info[:3]) |
| 25 | + |
| 26 | + pip_freeze = subprocess.run(['pip', 'freeze', '--exclude', 'PyCamp_Bot'], capture_output=True, check=True) |
| 27 | + dependencies = [] |
| 28 | + for pip_line in pip_freeze.stdout.decode().splitlines(): |
| 29 | + dependencies.append(escape_markdown(pip_line)) |
| 30 | + |
| 31 | + lines = [ |
| 32 | + f'Commit deployado: `{commit}`', |
| 33 | + f'Fecha del commit \\(author date\\): `{escape_markdown(author_date)}`', |
| 34 | + f'Clean worktree: {clean_worktree}', |
| 35 | + f'Versión de Python: `{python_version}`', |
| 36 | + 'Dependencias:', |
| 37 | + '```', |
| 38 | + *dependencies, |
| 39 | + '```', |
| 40 | + ] |
| 41 | + |
| 42 | + await update.message.reply_text('\n'.join(lines), parse_mode='MarkdownV2') |
| 43 | + |
| 44 | + |
| 45 | +def set_handlers(application): |
| 46 | + application.add_handler(CommandHandler('mostrar_version', show_version)) |
0 commit comments