From c4772bc5b558b2443c4b4769715d2cfa4f2b8bfd Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Fri, 10 Dec 2021 11:51:47 +0300 Subject: [PATCH] chore(lint): Run pyupgrade --- build/frappe-worker/commands/check_connection.py | 2 +- build/frappe-worker/commands/doctor.py | 2 +- build/frappe-worker/commands/restore_backup.py | 16 ++++++++-------- build/frappe-worker/commands/utils.py | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/build/frappe-worker/commands/check_connection.py b/build/frappe-worker/commands/check_connection.py index 359cc58f..946f41e7 100644 --- a/build/frappe-worker/commands/check_connection.py +++ b/build/frappe-worker/commands/check_connection.py @@ -29,7 +29,7 @@ def check_host(ip, port, retry=10, delay=3, print_attempt=True): ipup = False for i in range(retry): if print_attempt: - print("Attempt {i} to connect to {ip}:{port}".format(ip=ip, port=port, i=i+1)) + print(f"Attempt {i+1} to connect to {ip}:{port}") if is_open(ip, port): ipup = True break diff --git a/build/frappe-worker/commands/doctor.py b/build/frappe-worker/commands/doctor.py index 1cb9b200..37c69e2c 100644 --- a/build/frappe-worker/commands/doctor.py +++ b/build/frappe-worker/commands/doctor.py @@ -51,7 +51,7 @@ def main(): service_name=service_name, service_port=service_port, ) - print("{0}:{1} Connected".format(service_name, service_port)) + print(f"{service_name}:{service_port} Connected") print("Health check successful") exit(0) diff --git a/build/frappe-worker/commands/restore_backup.py b/build/frappe-worker/commands/restore_backup.py index 9989d18d..39ddeb47 100644 --- a/build/frappe-worker/commands/restore_backup.py +++ b/build/frappe-worker/commands/restore_backup.py @@ -34,7 +34,7 @@ def get_backup_dir(): def decompress_db(database_file, site): command = ["gunzip", "-c", database_file] with open(database_file.replace(".gz", ""), "w") as db_file: - print('Extract Database GZip for site {}'.format(site)) + print(f'Extract Database GZip for site {site}') run_command(command, stdout=db_file) @@ -80,14 +80,14 @@ def restore_files(files_base): public_files = files_base + '-files.tar' # extract tar public_tar = tarfile.open(public_files) - print('Extracting {}'.format(public_files)) + print(f'Extracting {public_files}') public_tar.extractall() def restore_private_files(files_base): private_files = files_base + '-private-files.tar' private_tar = tarfile.open(private_files) - print('Extracting {}'.format(private_files)) + print(f'Extracting {private_files}') private_tar.extractall() @@ -143,7 +143,7 @@ def pull_backup_from_s3(): if backup in backup_file: if not os.path.exists(os.path.dirname(backup_file)): os.makedirs(os.path.dirname(backup_file)) - print('Downloading {}'.format(backup_file)) + print(f'Downloading {backup_file}') bucket.download_file(bucket_dir + '/' + backup_file, backup_file) os.chdir(os.path.join(os.path.expanduser('~'), 'frappe-bench', 'sites')) @@ -196,7 +196,7 @@ def restore_postgres(config, site_config, database_file): run_command(psql_command + [psql_uri, "-c", f"CREATE DATABASE \"{db_name}\""]) run_command(psql_command + [psql_uri, "-c", f"CREATE user {db_name} password '{db_password}'"]) run_command(psql_command + [psql_uri, "-c", f"GRANT ALL PRIVILEGES ON DATABASE \"{db_name}\" TO {db_name}"]) - with open(database_file.replace('.gz', ''), 'r') as db_file: + with open(database_file.replace('.gz', '')) as db_file: run_command(psql_command + [f"{psql_uri}/{db_name}", "<"], stdin=db_file) @@ -240,7 +240,7 @@ def restore_mariadb(config, site_config, database_file): run_command(grant_privileges_command) print('Restoring MariaDB') - with open(database_file.replace('.gz', ''), 'r') as db_file: + with open(database_file.replace('.gz', '')) as db_file: run_command(mysql_command + [f"{db_name}"], stdin=db_file) @@ -260,7 +260,7 @@ def main(): if not os.path.exists(site_config_path): site_config_path = os.path.join(backup_dir, site, 'site_config.json') if site in get_sites(): - print('Overwrite site {}'.format(site)) + print(f'Overwrite site {site}') restore_database(files_base, site_config_path, site) restore_private_files(files_base) restore_files(files_base) @@ -279,7 +279,7 @@ def main(): ) make_site_dirs() - print('Create site {}'.format(site)) + print(f'Create site {site}') restore_database(files_base, site_config_path, site) restore_private_files(files_base) restore_files(files_base) diff --git a/build/frappe-worker/commands/utils.py b/build/frappe-worker/commands/utils.py index eaa9a2cf..0fdd6005 100644 --- a/build/frappe-worker/commands/utils.py +++ b/build/frappe-worker/commands/utils.py @@ -94,7 +94,7 @@ def get_config(): def get_site_config(site_name): site_config = None - with open('{site_name}/site_config.json'.format(site_name=site_name)) as site_config_file: + with open(f'{site_name}/site_config.json') as site_config_file: site_config = json.load(site_config_file) return site_config @@ -164,7 +164,7 @@ def list_directories(path): def get_site_config_from_path(site_config_path): site_config = dict() if os.path.exists(site_config_path): - with open(site_config_path, 'r') as sc: + with open(site_config_path) as sc: site_config = json.load(sc) return site_config @@ -173,7 +173,7 @@ def set_key_in_site_config(key, site, site_config_path): site_config = get_site_config_from_path(site_config_path) value = site_config.get(key) if value: - print('Set {key} in site config for site: {site}'.format(key=key, site=site)) + print(f'Set {key} in site config for site: {site}') update_site_config(key, value, site_config_path=os.path.join(os.getcwd(), site, "site_config.json"))