Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic ruff fixes #655

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions bin/check-attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@
from sqlalchemy import true
from sqlalchemy.sql.expression import func

from inbox.crispin import connection_pool
from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
from inbox.models import Account, Block
from inbox.models.backends.generic import GenericAccount
from inbox.models.session import (
global_session_scope,
session_scope,
session_scope_by_shard_id,
)
from inbox.models.session import global_session_scope, session_scope
from inbox.s3.base import get_raw_from_provider
from inbox.s3.exc import EmailFetchException, TemporaryEmailFetchException

configure_logging()
log = get_logger(purpose="separator-backfix")
Expand Down
3 changes: 1 addition & 2 deletions bin/clear-all-heartbeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
SOCKET_TIMEOUT,
STATUS_DATABASE,
WAIT_TIMEOUT,
get_redis_client,
)


Expand Down Expand Up @@ -43,7 +42,7 @@ def main(host, port, database):
count += 1

batch_client.execute()
print("{} heartbeats deleted!".format(count))
print(f"{count} heartbeats deleted!")
exit(0)


Expand Down
2 changes: 1 addition & 1 deletion bin/clear-heartbeat-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main(host, port, account_id, folder_id, device_id):

print("Clearing heartbeat status...")
n = clear_heartbeat_status(account_id, folder_id, device_id, host, port)
print("{} folders cleared.".format(n))
print(f"{n} folders cleared.")
exit(0)


Expand Down
2 changes: 1 addition & 1 deletion bin/contact-search-backfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main(namespace_ids):
maybe_enable_rollbar()

for namespace_id in namespace_ids:
log.info("indexing namespace {namespace_id}".format(namespace_id=namespace_id))
log.info(f"indexing namespace {namespace_id}")
index_namespace(namespace_id)


Expand Down
2 changes: 1 addition & 1 deletion bin/contact-search-service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
""" Start the contact search indexing service. """
"""Start the contact search indexing service."""
from gevent import monkey

monkey.patch_all()
Expand Down
4 changes: 2 additions & 2 deletions bin/correct-autoincrements.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def reset_db(dry_run):
engine = engine_manager.engines[key]
schema = shard["SCHEMA_NAME"]

print("Resetting invalid autoincrements for database: {}".format(schema))
print(f"Resetting invalid autoincrements for database: {schema}")
reset_tables = reset_invalid_autoincrements(engine, schema, key, dry_run)
if dry_run:
print("dry_run=True")
if reset_tables:
print("Reset tables: {}".format(", ".join(reset_tables)))
else:
print("Schema {} okay".format(schema))
print(f"Schema {schema} okay")


if __name__ == "__main__":
Expand Down
12 changes: 5 additions & 7 deletions bin/create-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def main(target_hostname, host_ip):
)

schema_name = shard["SCHEMA_NAME"]
print("Setting up database: {}".format(schema_name))
print(f"Setting up database: {schema_name}")

# Create the database IF needed.
base_engine.execute(
"CREATE DATABASE IF NOT EXISTS {} DEFAULT CHARACTER "
"SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;".format(schema_name)
f"CREATE DATABASE IF NOT EXISTS {schema_name} DEFAULT CHARACTER "
"SET utf8mb4 DEFAULT COLLATE utf8mb4_general_ci;"
)

engine = engine_manager.engines[int(key)]
Expand All @@ -71,17 +71,15 @@ def main(target_hostname, host_ip):
assert (
current_revision
), "Need current revision in alembic_version table."
print(
"Already revisioned by alembic version: {}".format(current_revision)
)
print(f"Already revisioned by alembic version: {current_revision}")
else:
# Initialize shards, stamp alembic revision
print("Initializing database.")
init_db(engine, int(key))
alembic_ini_filename = os.environ.get("ALEMBIC_INI_PATH", "alembic.ini")
assert os.path.isfile(
alembic_ini_filename
), "Must have alembic.ini file at {}".format(alembic_ini_filename)
), f"Must have alembic.ini file at {alembic_ini_filename}"
alembic_cfg = alembic.config.Config(alembic_ini_filename)
# Alembic option values need to be strings.
alembic_cfg.set_main_option("shard_id", str(key))
Expand Down
11 changes: 4 additions & 7 deletions bin/create-encryption-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def main():
# If the config contains encryption keys, don't override.
if config.get("SECRET_ENCRYPTION_KEY"):
raise Exception(
"Encryption keys already present in secrets config "
"file {0}".format(secrets_path)
"Encryption keys already present in secrets config " f"file {secrets_path}"
)

# Generate keys
Expand All @@ -37,12 +36,10 @@ def main():
# Update it
try:
with open(secrets_path, "a") as f:
print("Writing keys to secrets config file {0}".format(secrets_path))
print(f"Writing keys to secrets config file {secrets_path}")
yaml.dump(data, f, default_flow_style=False)
except IOError:
raise Exception(
"Check file write permissions on config file {0}".format(secrets_path)
)
except OSError:
raise Exception(f"Check file write permissions on config file {secrets_path}")

# Update the config dict
config.update(data)
Expand Down
16 changes: 8 additions & 8 deletions bin/delete-account-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ def delete_account_data(account_id, dry_run, yes, throttle):
account = db_session.query(Account).get(account_id)

if not account:
print("Account with id {} does NOT exist.".format(account_id))
return
print(f"Account with id {account_id} does NOT exist.")
return None

email_address = account.email_address
namespace_id = account.namespace.id

if account.sync_should_run or not account.is_marked_for_deletion:
print(
"Account with id {} NOT marked for deletion.\n"
"Will NOT delete, goodbye.".format(account_id)
f"Account with id {account_id} NOT marked for deletion.\n"
"Will NOT delete, goodbye."
)
return -1

Expand All @@ -69,26 +69,26 @@ def delete_account_data(account_id, dry_run, yes, throttle):
print("Will NOT delete, goodbye.")
return 0

print("Deleting account with id: {}...".format(account_id))
print(f"Deleting account with id: {account_id}...")
start = time.time()

# Delete data in database
try:
print("Deleting database data")
delete_namespace(namespace_id, dry_run=dry_run, throttle=throttle)
except Exception as e:
print("Database data deletion failed! Error: {}".format(str(e)))
print(f"Database data deletion failed! Error: {str(e)}")
return -1

database_end = time.time()
print("Database data deleted. Time taken: {}".format(database_end - start))
print(f"Database data deleted. Time taken: {database_end - start}")

# Delete liveness data
print("Deleting liveness data")
clear_heartbeat_status(account_id)

end = time.time()
print("All data deleted successfully! TOTAL time taken: {}".format(end - start))
print(f"All data deleted successfully! TOTAL time taken: {end - start}")
return 0


Expand Down
2 changes: 1 addition & 1 deletion bin/get-accounts-for-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main(hostname):
with global_session_scope() as db_session:
account_ids = db_session.query(Account.id).filter(Account.sync_host == hostname)

print("Accounts being synced by {}:".format(hostname))
print(f"Accounts being synced by {hostname}:")
for account_id in account_ids:
print(account_id[0])
db_session.commit()
Expand Down
2 changes: 1 addition & 1 deletion bin/get-id.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main(type, id, public_id):
type = type.lower()

if type not in cls_for_type:
print("Error: unknown type '{}'".format(type))
print(f"Error: unknown type '{type}'")
sys.exit(-1)

cls = cls_for_type[type]
Expand Down
8 changes: 2 additions & 6 deletions bin/get-object.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@
from inbox.error_handling import maybe_enable_rollbar
from inbox.models import (
Account,
ActionLog,
Block,
Calendar,
Category,
Event,
Folder,
Label,
Message,
Namespace,
Part,
Thread,
Transaction,
)
from inbox.models.session import global_session_scope, session_scope
from inbox.models.session import global_session_scope

cls_for_type = dict(
account=Account,
Expand Down Expand Up @@ -58,7 +54,7 @@ def main(type, id, public_id, account_id, namespace_id, readwrite):
type = type.lower()

if type not in cls_for_type:
print("Error: unknown type '{}'".format(type))
print(f"Error: unknown type '{type}'")
sys.exit(-1)

cls = cls_for_type[type]
Expand Down
2 changes: 1 addition & 1 deletion bin/inbox-auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main(email_address, reauth, target, provider):
except NotSupportedError as e:
sys.exit(str(e))

print("OK. Authenticated account for {}".format(email_address))
print(f"OK. Authenticated account for {email_address}")


if __name__ == "__main__":
Expand Down
10 changes: 4 additions & 6 deletions bin/inbox-start.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

esc = "\033"

banner = r"""{esc}[1;95m
banner = rf"""{esc}[1;95m
_ _ _
| \ | | | |
| \| |_ _| | __ _ ___
Expand All @@ -53,9 +53,7 @@

{esc}[0m
Use CTRL-C to stop.
""".format(
esc=esc
)
"""


@click.command()
Expand Down Expand Up @@ -110,7 +108,7 @@ def main(prod, enable_tracer, enable_profiler, config, process_num, exit_after):

total_processes = int(os.environ.get("MAILSYNC_PROCESSES", 1))

setproctitle.setproctitle("sync-engine-{}".format(process_num))
setproctitle.setproctitle(f"sync-engine-{process_num}")

log = get_logger()
log.info(
Expand All @@ -132,7 +130,7 @@ def main(prod, enable_tracer, enable_profiler, config, process_num, exit_after):
port = 16384 + process_num
enable_profiler_api = inbox_config.get("DEBUG_PROFILING_ON")

process_identifier = "{}:{}".format(platform.node(), process_num)
process_identifier = f"{platform.node()}:{process_num}"

if exit_after:
exit_after = exit_after.split(":")
Expand Down
10 changes: 4 additions & 6 deletions bin/migrate-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def main():
alembic_ini_filename = os.environ.get("ALEMBIC_INI_PATH", "alembic.ini")
assert os.path.isfile(
alembic_ini_filename
), "Missing alembic.ini file at {}".format(alembic_ini_filename)
), f"Missing alembic.ini file at {alembic_ini_filename}"

database_hosts = config.get_required("DATABASE_HOSTS")

Expand All @@ -33,15 +33,13 @@ def main():
key = shard["ID"]

try:
print("Upgrading shard_id {}".format(key))
print(f"Upgrading shard_id {key}")
alembic_cfg = alembic.config.Config(alembic_ini_filename)
alembic_cfg.set_main_option("shard_id", str(key))
alembic.command.upgrade(alembic_cfg, "head")
print("Upgraded shard_id {}\n".format(key))
print(f"Upgraded shard_id {key}\n")
except alembic.util.CommandError as e:
print(
"FAILED to upgrade shard_id {} with error: {}".format(key, str(e))
)
print(f"FAILED to upgrade shard_id {key} with error: {str(e)}")
continue


Expand Down
2 changes: 1 addition & 1 deletion bin/mysql-prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main(shard_num):

for key in creds.keys():
if creds[key] is None:
print("Error: {key} is None".format(key=key))
print(f"Error: {key} is None")
sys.exit(-1)

proc = subprocess.Popen(
Expand Down
12 changes: 6 additions & 6 deletions bin/set-desired-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ def main(account_id, desired_host, dry_run, toggle_sync):
with global_session_scope() as db_session:
account = db_session.query(Account).get(int(account_id))

print("Before sync host: {}".format(account.sync_host))
print("Before desired sync host: {}".format(account.desired_sync_host))
print("Before sync should run: {}".format(account.sync_should_run))
print(f"Before sync host: {account.sync_host}")
print(f"Before desired sync host: {account.desired_sync_host}")
print(f"Before sync should run: {account.sync_should_run}")

if dry_run:
return
account.desired_sync_host = desired_host
if toggle_sync:
account.sync_should_run = not account.sync_should_run

print("After sync host: {}".format(account.sync_host))
print("After desired sync host: {}".format(account.desired_sync_host))
print("After sync should run: {}".format(account.sync_should_run))
print(f"After sync host: {account.sync_host}")
print(f"After desired sync host: {account.desired_sync_host}")
print(f"After sync should run: {account.sync_should_run}")
db_session.commit()


Expand Down
8 changes: 4 additions & 4 deletions bin/stamp-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main(revision_id):
alembic_ini_filename = os.environ.get("ALEMBIC_INI_PATH", "alembic.ini")
assert os.path.isfile(
alembic_ini_filename
), "Missing alembic.ini file at {}".format(alembic_ini_filename)
), f"Missing alembic.ini file at {alembic_ini_filename}"

database_hosts = config.get_required("DATABASE_HOSTS")

Expand All @@ -34,13 +34,13 @@ def main(revision_id):
key = shard["ID"]

try:
print("Stamping shard_id {}".format(key))
print(f"Stamping shard_id {key}")
alembic_cfg = alembic.config.Config(alembic_ini_filename)
alembic_cfg.set_main_option("shard_id", str(key))
alembic.command.stamp(alembic_cfg, revision_id)
print("Stamped shard_id {}\n".format(key))
print(f"Stamped shard_id {key}\n")
except alembic.util.CommandError as e:
print("FAILED to stamp shard_id {} with error: {}".format(key, str(e)))
print(f"FAILED to stamp shard_id {key} with error: {str(e)}")
continue


Expand Down
2 changes: 1 addition & 1 deletion bin/syncback-service.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
)
def main(prod, config, process_num, syncback_id, enable_tracer, enable_profiler):
"""Launch the actions syncback service."""
setproctitle("syncback-{}".format(process_num))
setproctitle(f"syncback-{process_num}")

maybe_enable_rollbar()

Expand Down
Loading
Loading