Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

python: Convert percent formatting to "".format in certain files.

Anders Kaseorg3461db7ef5cc
diff --git a/scripts/lib/node_cache.py b/scripts/lib/node_cache.py
index b292e8c3af1..c2d086e9bd2 100644
--- a/scripts/lib/node_cache.py
+++ b/scripts/lib/node_cache.py
@@ -59,7 +59,7 @@ def setup_node_modules(
yarn_args,
success_stamp)
- print("Using cached node modules from %s" % (cached_node_modules,))
+ print("Using cached node modules from {}".format(cached_node_modules))
if os.path.islink('node_modules'):
os.remove('node_modules')
elif os.path.isdir('node_modules'):
diff --git a/scripts/lib/setup_venv.py b/scripts/lib/setup_venv.py
index 155df9818ec..1a26c1ee84e 100644
--- a/scripts/lib/setup_venv.py
+++ b/scripts/lib/setup_venv.py
@@ -124,7 +124,7 @@ def get_package_names(requirements_file: str) -> List[str]:
if package.startswith("git+https://") and '#egg=' in package:
split_package = package.split("#egg=")
if len(split_package) != 2:
- raise Exception("Unexpected duplicate #egg in package %s" % (package,))
+ raise Exception("Unexpected duplicate #egg in package {}".format(package))
# Extract the package name from Git requirements entries
package = split_package[1]
@@ -270,7 +270,7 @@ def do_patch_activate_script(venv_path: str) -> None:
lines = f.readlines()
for i, line in enumerate(lines):
if line.startswith('VIRTUAL_ENV='):
- lines[i] = 'VIRTUAL_ENV="%s"\n' % (venv_path,)
+ lines[i] = 'VIRTUAL_ENV="{}"\n'.format(venv_path)
with open(script_path, 'w') as f:
f.write("".join(lines))
@@ -296,7 +296,7 @@ def setup_virtualenv(
with open(success_stamp, 'w') as f:
f.close()
- print("Using cached Python venv from %s" % (cached_venv_path,))
+ print("Using cached Python venv from {}".format(cached_venv_path))
if target_venv_path is not None:
run_as_root(["ln", "-nsf", cached_venv_path, target_venv_path])
if patch_activate_script:
diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py
index 4ab2dd2b220..f4608308094 100755
--- a/scripts/lib/zulip_tools.py
+++ b/scripts/lib/zulip_tools.py
@@ -165,13 +165,13 @@ def get_deployment_lock(error_rerun_script: str) -> None:
break
except OSError:
print(WARNING + "Another deployment in progress; waiting for lock... " +
- "(If no deployment is running, rmdir %s)" % (LOCK_DIR,) + ENDC)
+ "(If no deployment is running, rmdir {})".format(LOCK_DIR) + ENDC)
sys.stdout.flush()
time.sleep(3)
if not got_lock:
print(FAIL + "Deployment already in progress. Please run\n" +
- " %s\n" % (error_rerun_script,) +
+ " {}\n".format(error_rerun_script) +
"manually when the previous deployment finishes, or run\n" +
" rmdir %s\n" % (LOCK_DIR,) +
"if the previous deployment crashed." +
@@ -183,7 +183,7 @@ def release_deployment_lock() -> None:
def run(args: Sequence[str], **kwargs: Any) -> None:
# Output what we're doing in the `set -x` style
- print("+ %s" % (" ".join(map(shlex.quote, args)),))
+ print("+ {}".format(" ".join(map(shlex.quote, args))))
try:
subprocess.check_call(args, **kwargs)
@@ -325,17 +325,17 @@ def may_be_perform_purging(
if dry_run:
print("Performing a dry run...")
if not no_headings:
- print("Cleaning unused %ss..." % (dir_type,))
+ print("Cleaning unused {}s...".format(dir_type))
for directory in dirs_to_purge:
if verbose:
- print("Cleaning unused %s: %s" % (dir_type, directory))
+ print("Cleaning unused {}: {}".format(dir_type, directory))
if not dry_run:
run_as_root(["rm", "-rf", directory])
for directory in dirs_to_keep:
if verbose:
- print("Keeping used %s: %s" % (dir_type, directory))
+ print("Keeping used {}: {}".format(dir_type, directory))
@functools.lru_cache(None)
def parse_os_release() -> Dict[str, str]:
diff --git a/tools/lib/provision.py b/tools/lib/provision.py
index b52b94d5241..a67034129b6 100755
--- a/tools/lib/provision.py
+++ b/tools/lib/provision.py
@@ -52,8 +52,8 @@ with open("/proc/meminfo") as meminfo:
ram_size = meminfo.readlines()[0].strip().split(" ")[-2]
ram_gb = float(ram_size) / 1024.0 / 1024.0
if ram_gb < 1.5:
- print("You have insufficient RAM (%s GB) to run the Zulip development environment." % (
- round(ram_gb, 2),))
+ print("You have insufficient RAM ({} GB) to run the Zulip development environment.".format(
+ round(ram_gb, 2)))
print("We recommend at least 2 GB of RAM, and require at least 1.5 GB.")
sys.exit(1)
@@ -210,9 +210,9 @@ elif "fedora" in os_families():
BUILD_PGROONGA_FROM_SOURCE = True
if "fedora" in os_families():
- TSEARCH_STOPWORDS_PATH = "/usr/pgsql-%s/share/tsearch_data/" % (POSTGRES_VERSION,)
+ TSEARCH_STOPWORDS_PATH = "/usr/pgsql-{}/share/tsearch_data/".format(POSTGRES_VERSION)
else:
- TSEARCH_STOPWORDS_PATH = "/usr/share/postgresql/%s/tsearch_data/" % (POSTGRES_VERSION,)
+ TSEARCH_STOPWORDS_PATH = "/usr/share/postgresql/{}/tsearch_data/".format(POSTGRES_VERSION)
REPO_STOPWORDS_PATH = os.path.join(
ZULIP_PATH,
"puppet",
@@ -285,16 +285,16 @@ def install_yum_deps(deps_to_install: List[str]) -> None:
run_as_root(["python36", "-m", "ensurepip"])
# `python36` is not aliased to `python3` by default
run_as_root(["ln", "-nsf", "/usr/bin/python36", "/usr/bin/python3"])
- postgres_dir = 'pgsql-%s' % (POSTGRES_VERSION,)
+ postgres_dir = 'pgsql-{}'.format(POSTGRES_VERSION)
for cmd in ['pg_config', 'pg_isready', 'psql']:
# Our tooling expects these postgres scripts to be at
# well-known paths. There's an argument for eventually
# making our tooling auto-detect, but this is simpler.
- run_as_root(["ln", "-nsf", "/usr/%s/bin/%s" % (postgres_dir, cmd),
- "/usr/bin/%s" % (cmd,)])
+ run_as_root(["ln", "-nsf", "/usr/{}/bin/{}".format(postgres_dir, cmd),
+ "/usr/bin/{}".format(cmd)])
# From here, we do the first-time setup/initialization for the postgres database.
- pg_datadir = "/var/lib/pgsql/%s/data" % (POSTGRES_VERSION,)
+ pg_datadir = "/var/lib/pgsql/{}/data".format(POSTGRES_VERSION)
pg_hba_conf = os.path.join(pg_datadir, "pg_hba.conf")
# We can't just check if the file exists with os.path, since the
@@ -304,7 +304,7 @@ def install_yum_deps(deps_to_install: List[str]) -> None:
# Skip setup if it has been applied previously
return
- run_as_root(["/usr/%s/bin/postgresql-%s-setup" % (postgres_dir, POSTGRES_VERSION), "initdb"],
+ run_as_root(["/usr/{}/bin/postgresql-{}-setup".format(postgres_dir, POSTGRES_VERSION), "initdb"],
sudo_args = ['-H'])
# Use vendored pg_hba.conf, which enables password authentication.
run_as_root(["cp", "-a", "puppet/zulip/files/postgresql/centos_pg_hba.conf", pg_hba_conf])
@@ -367,7 +367,7 @@ def main(options: argparse.Namespace) -> "NoReturn":
if not os.access(NODE_MODULES_CACHE_PATH, os.W_OK):
run_as_root(["mkdir", "-p", NODE_MODULES_CACHE_PATH])
- run_as_root(["chown", "%s:%s" % (os.getuid(), os.getgid()), NODE_MODULES_CACHE_PATH])
+ run_as_root(["chown", "{}:{}".format(os.getuid(), os.getgid()), NODE_MODULES_CACHE_PATH])
# This is a wrapper around `yarn`, which we run last since
# it can often fail due to network issues beyond our control.
@@ -401,7 +401,7 @@ def main(options: argparse.Namespace) -> "NoReturn":
elif "fedora" in os_families():
# These platforms don't enable and start services on
# installing their package, so we do that here.
- for service in ["postgresql-%s" % (POSTGRES_VERSION,), "rabbitmq-server", "memcached", "redis"]:
+ for service in ["postgresql-{}".format(POSTGRES_VERSION), "rabbitmq-server", "memcached", "redis"]:
run_as_root(["systemctl", "enable", service], sudo_args = ['-H'])
run_as_root(["systemctl", "start", service], sudo_args = ['-H'])