Commit 8459713f authored by Sergey Pinus's avatar Sergey Pinus
Browse files

add update arg `--update`

parent 5f51c81b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ $ git clone https://github.com/dmMaze/BallonsTranslator.git ; cd BallonsTranslat

# 启动程序
$ python3 launch.py

# 更新程序
python3 launch.py --update
```

第一次运行会自动安装 torch 等依赖项并下载所需模型和文件,如果模型下载失败,需要手动从 [MEGA](https://mega.nz/folder/gmhmACoD#dkVlZ2nphOkU5-2ACb5dKw)[Google Drive](https://drive.google.com/drive/folders/1uElIYRLNakJj-YS0Kd3r3HE-wzeEvrWd?usp=sharing) 下载 data 文件夹(或者报错里提到缺失的文件),并保存到源码目录下的对应位置。
+4 −1
Original line number Diff line number Diff line
@@ -44,8 +44,11 @@ Install [Python](https://www.python.org/downloads/release/python-31011) **< 3.12
# Clone this repo
$ git clone https://github.com/dmMaze/BallonsTranslator.git ; cd BallonsTranslator

# Launch the app
# Launch app
$ python3 launch.py

# Update app
$ python3 launch.py --update
```

Note the first time you launch it will install the required libraries and download models automatically. If the downloads fail, you will need to download the **data** folder (or missing files mentioned in the terminal) from [MEGA](https://mega.nz/folder/gmhmACoD#dkVlZ2nphOkU5-2ACb5dKw) or [Google Drive](https://drive.google.com/drive/folders/1uElIYRLNakJj-YS0Kd3r3HE-wzeEvrWd?usp=sharing) and save it to the corresponding path in source code folder.
+33 −6
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ parser.add_argument("--ldpi", default=None, type=float, help='logical dots perin
parser.add_argument("--export-translation-txt", action='store_true', help='save translation to txt file once RUN completed')
parser.add_argument("--export-source-txt", action='store_true', help='save source to txt file once RUN completed')
parser.add_argument("--frozen", action='store_true', help='run without checking requirements')
parser.add_argument("--update", action='store_true', help="Update the repository before launching") # Добавлен аргумент --update
args, _ = parser.parse_known_args()


@@ -90,7 +91,7 @@ def run_pip(args, desc=None):
        return

    index_url_line = f' --index-url {index_url}' if index_url != '' else ''
    return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line} --disable-pip-version-check', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=True)
    return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line} --disable-pip-version-check --no-warn-script-location', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=True)


def commit_hash():
@@ -133,6 +134,7 @@ APP = None
def restart():
    global BT
    print('restarting...\n')
    if BT: # Проверка на None перед закрытием
        BT.close()
    os.execv(sys.executable, ['python'] + sys.argv)

@@ -157,6 +159,30 @@ def main():

    prepare_environment()

    # Проверка обновлений ПЕРЕД инициализацией GUI
    if args.update:
        if getattr(sys, 'frozen', False):
            print('Running as app, skipping update.')
        else:
            print('Checking for updates...')
            try:
                current_commit = commit_hash()
                run(f"{git} fetch origin {BRANCH}", desc="Fetching updates from git...", errdesc="Failed to fetch updates.")
                latest_commit = run(f"{git} rev-parse origin/{BRANCH}").strip()

                if current_commit != latest_commit:
                    print("New updates found. Updating repository...")
                    run(f"{git} pull origin {BRANCH}", desc="Updating repository...", errdesc="Failed to update repository.")
                    print("Repository updated. Restarting to apply updates...")
                    restart()
                    return # Важно выйти после перезапуска, чтобы продолжить уже в новом процессе
                else:
                    print("No updates found.")
            except Exception as e:
                print(f"Update check failed: {e}")
                print("Continuing with the current version.")


    from utils.logger import setup_logging, logger as LOGGER
    import utils.shared as shared
    from utils.io_utils import find_all_files_recursive
@@ -272,6 +298,7 @@ def main():
    BT = ballontrans
    BT.restart_signal.connect(restart)


    if not args.headless:
        if shared.SCREEN_W > 1707 and sys.platform == 'win32':   # higher than 2560 (1440p) / 1.5
            # https://github.com/dmMaze/BallonsTranslator/issues/220