From 9ed2f8d017a880e0f6916713b86a7c36a0b31759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Sat, 10 Feb 2024 15:02:05 +0100 Subject: [PATCH] Use pathlib.Path --- .../autoupdate_app_sources.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/autoupdate_app_sources/autoupdate_app_sources.py b/autoupdate_app_sources/autoupdate_app_sources.py index 79ff60d..0d41404 100644 --- a/autoupdate_app_sources/autoupdate_app_sources.py +++ b/autoupdate_app_sources/autoupdate_app_sources.py @@ -4,15 +4,21 @@ import argparse import glob import hashlib import os +import subprocess import re import sys import time +from pathlib import Path from datetime import datetime import requests import toml from rest_api import GithubAPI, GitlabAPI, GiteaForgejoAPI, RefType +REPO_APPS_ROOT = Path(subprocess.check_output([ + "git", "-C", Path(__file__).parent, "rev-parse", "--show-toplevel"]).decode("utf-8").strip()) + + STRATEGIES = [ "latest_github_release", "latest_github_tag", @@ -468,7 +474,7 @@ def paste_on_haste(data): def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument("app_dir", nargs="?", type=str) + parser.add_argument("app_dir", nargs="?", type=Path) parser.add_argument("--commit-and-create-PR", action="store_true") args = parser.parse_args() @@ -476,17 +482,11 @@ def main() -> None: dry_run = args.commit_and_create_PR if args.app_dir: - AppAutoUpdater(args.app_dir, app_id_is_local_app_dir=True).run() + AppAutoUpdater(str(args.app_dir), app_id_is_local_app_dir=True).run() else: - GITHUB_LOGIN = ( - open(os.path.dirname(__file__) + "/../../.github_login").read().strip() - ) - GITHUB_TOKEN = ( - open(os.path.dirname(__file__) + "/../../.github_token").read().strip() - ) - GITHUB_EMAIL = ( - open(os.path.dirname(__file__) + "/../../.github_email").read().strip() - ) + GITHUB_LOGIN = (REPO_APPS_ROOT / ".github_login").open("r", encoding="utf-8").read().strip() + GITHUB_TOKEN = (REPO_APPS_ROOT / ".github_token").open("r", encoding="utf-8").read().strip() + GITHUB_EMAIL = (REPO_APPS_ROOT / ".github_email").open("r", encoding="utf-8").read().strip() from github import Github, InputGitAuthor