mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
scripts: Change use of typing.Text to str.
This commit is contained in:
committed by
Tim Abbott
parent
64ddfc6ac0
commit
e14974ff2c
@@ -3,7 +3,7 @@ import os
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Optional, List, IO, Text, Tuple, Any
|
from typing import Optional, List, IO, Tuple, Any
|
||||||
|
|
||||||
from scripts.lib.zulip_tools import subprocess_text_output, run
|
from scripts.lib.zulip_tools import subprocess_text_output, run
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ def get_yarn_args(production):
|
|||||||
return yarn_args
|
return yarn_args
|
||||||
|
|
||||||
def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION):
|
def generate_sha1sum_node_modules(setup_dir=None, production=DEFAULT_PRODUCTION):
|
||||||
# type: (Optional[Text], bool) -> str
|
# type: (Optional[str], bool) -> str
|
||||||
if setup_dir is None:
|
if setup_dir is None:
|
||||||
setup_dir = os.path.realpath(os.getcwd())
|
setup_dir = os.path.realpath(os.getcwd())
|
||||||
PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, 'package.json')
|
PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, 'package.json')
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Sequence, Set, Text, Any
|
from typing import Sequence, Set, Any
|
||||||
|
|
||||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||||
@@ -38,7 +38,7 @@ MAGENTA = '\x1b[35m'
|
|||||||
CYAN = '\x1b[36m'
|
CYAN = '\x1b[36m'
|
||||||
|
|
||||||
def parse_cache_script_args(description):
|
def parse_cache_script_args(description):
|
||||||
# type: (Text) -> argparse.Namespace
|
# type: (str) -> argparse.Namespace
|
||||||
parser = argparse.ArgumentParser(description=description)
|
parser = argparse.ArgumentParser(description=description)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -171,7 +171,7 @@ def run(args, **kwargs):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def log_management_command(cmd, log_path):
|
def log_management_command(cmd, log_path):
|
||||||
# type: (Text, Text) -> None
|
# type: (str, str) -> None
|
||||||
log_dir = os.path.dirname(log_path)
|
log_dir = os.path.dirname(log_path)
|
||||||
if not os.path.exists(log_dir):
|
if not os.path.exists(log_dir):
|
||||||
os.makedirs(log_dir)
|
os.makedirs(log_dir)
|
||||||
@@ -186,7 +186,7 @@ def log_management_command(cmd, log_path):
|
|||||||
logger.info("Ran '%s'" % (cmd,))
|
logger.info("Ran '%s'" % (cmd,))
|
||||||
|
|
||||||
def get_environment():
|
def get_environment():
|
||||||
# type: () -> Text
|
# type: () -> str
|
||||||
if os.path.exists(DEPLOYMENTS_DIR):
|
if os.path.exists(DEPLOYMENTS_DIR):
|
||||||
return "prod"
|
return "prod"
|
||||||
if os.environ.get("TRAVIS"):
|
if os.environ.get("TRAVIS"):
|
||||||
@@ -194,7 +194,7 @@ def get_environment():
|
|||||||
return "dev"
|
return "dev"
|
||||||
|
|
||||||
def get_recent_deployments(threshold_days):
|
def get_recent_deployments(threshold_days):
|
||||||
# type: (int) -> Set[Text]
|
# type: (int) -> Set[str]
|
||||||
# Returns a list of deployments not older than threshold days
|
# Returns a list of deployments not older than threshold days
|
||||||
# including `/root/zulip` directory if it exists.
|
# including `/root/zulip` directory if it exists.
|
||||||
recent = set()
|
recent = set()
|
||||||
@@ -230,7 +230,7 @@ def get_threshold_timestamp(threshold_days):
|
|||||||
return threshold_timestamp
|
return threshold_timestamp
|
||||||
|
|
||||||
def get_caches_to_be_purged(caches_dir, caches_in_use, threshold_days):
|
def get_caches_to_be_purged(caches_dir, caches_in_use, threshold_days):
|
||||||
# type: (Text, Set[Text], int) -> Set[Text]
|
# type: (str, Set[str], int) -> Set[str]
|
||||||
# Given a directory containing caches, a list of caches in use
|
# Given a directory containing caches, a list of caches in use
|
||||||
# and threshold days, this function return a list of caches
|
# and threshold days, this function return a list of caches
|
||||||
# which can be purged. Remove the cache only if it is:
|
# which can be purged. Remove the cache only if it is:
|
||||||
@@ -250,7 +250,7 @@ def get_caches_to_be_purged(caches_dir, caches_in_use, threshold_days):
|
|||||||
return caches_to_purge
|
return caches_to_purge
|
||||||
|
|
||||||
def purge_unused_caches(caches_dir, caches_in_use, cache_type, args):
|
def purge_unused_caches(caches_dir, caches_in_use, cache_type, args):
|
||||||
# type: (Text, Set[Text], Text, argparse.Namespace) -> None
|
# type: (str, Set[str], str, argparse.Namespace) -> None
|
||||||
all_caches = set([os.path.join(caches_dir, cache) for cache in os.listdir(caches_dir)])
|
all_caches = set([os.path.join(caches_dir, cache) for cache in os.listdir(caches_dir)])
|
||||||
caches_to_purge = get_caches_to_be_purged(caches_dir, caches_in_use, args.threshold_days)
|
caches_to_purge = get_caches_to_be_purged(caches_dir, caches_in_use, args.threshold_days)
|
||||||
caches_to_keep = all_caches - caches_to_purge
|
caches_to_keep = all_caches - caches_to_purge
|
||||||
@@ -261,7 +261,7 @@ def purge_unused_caches(caches_dir, caches_in_use, cache_type, args):
|
|||||||
print("Done!")
|
print("Done!")
|
||||||
|
|
||||||
def generate_sha1sum_emoji(zulip_path):
|
def generate_sha1sum_emoji(zulip_path):
|
||||||
# type: (Text) -> Text
|
# type: (str) -> str
|
||||||
ZULIP_EMOJI_DIR = os.path.join(zulip_path, 'tools', 'setup', 'emoji')
|
ZULIP_EMOJI_DIR = os.path.join(zulip_path, 'tools', 'setup', 'emoji')
|
||||||
sha = hashlib.sha1()
|
sha = hashlib.sha1()
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ def generate_sha1sum_emoji(zulip_path):
|
|||||||
return sha.hexdigest()
|
return sha.hexdigest()
|
||||||
|
|
||||||
def may_be_perform_purging(dirs_to_purge, dirs_to_keep, dir_type, dry_run, verbose):
|
def may_be_perform_purging(dirs_to_purge, dirs_to_keep, dir_type, dry_run, verbose):
|
||||||
# type: (Set[Text], Set[Text], Text, bool, bool) -> None
|
# type: (Set[str], Set[str], str, bool, bool) -> None
|
||||||
if dry_run:
|
if dry_run:
|
||||||
print("Performing a dry run...")
|
print("Performing a dry run...")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
if False:
|
if False:
|
||||||
from typing import Dict, List, Optional, Text
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
sys.path.append(BASE_DIR)
|
sys.path.append(BASE_DIR)
|
||||||
@@ -36,7 +36,7 @@ AUTOGENERATED_SETTINGS = [
|
|||||||
# TODO: We can eliminate this function if we refactor the install
|
# TODO: We can eliminate this function if we refactor the install
|
||||||
# script to run generate_secrets before zulip-puppet-apply.
|
# script to run generate_secrets before zulip-puppet-apply.
|
||||||
def generate_camo_config_file(camo_key):
|
def generate_camo_config_file(camo_key):
|
||||||
# type: (Text) -> None
|
# type: (str) -> None
|
||||||
camo_config = """ENABLED=yes
|
camo_config = """ENABLED=yes
|
||||||
PORT=9292
|
PORT=9292
|
||||||
CAMO_KEY=%s
|
CAMO_KEY=%s
|
||||||
@@ -46,13 +46,13 @@ CAMO_KEY=%s
|
|||||||
print("Generated Camo config file %s" % (CAMO_CONFIG_FILENAME,))
|
print("Generated Camo config file %s" % (CAMO_CONFIG_FILENAME,))
|
||||||
|
|
||||||
def generate_django_secretkey():
|
def generate_django_secretkey():
|
||||||
# type: () -> Text
|
# type: () -> str
|
||||||
"""Secret key generation taken from Django's startproject.py"""
|
"""Secret key generation taken from Django's startproject.py"""
|
||||||
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
||||||
return get_random_string(50, chars)
|
return get_random_string(50, chars)
|
||||||
|
|
||||||
def get_old_conf(output_filename):
|
def get_old_conf(output_filename):
|
||||||
# type: (str) -> Dict[str, Text]
|
# type: (str) -> Dict[str, str]
|
||||||
if not os.path.exists(output_filename) or os.path.getsize(output_filename) == 0:
|
if not os.path.exists(output_filename) or os.path.getsize(output_filename) == 0:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ def generate_secrets(development=False):
|
|||||||
OUTPUT_SETTINGS_FILENAME = "/etc/zulip/zulip-secrets.conf"
|
OUTPUT_SETTINGS_FILENAME = "/etc/zulip/zulip-secrets.conf"
|
||||||
current_conf = get_old_conf(OUTPUT_SETTINGS_FILENAME)
|
current_conf = get_old_conf(OUTPUT_SETTINGS_FILENAME)
|
||||||
|
|
||||||
lines = [] # type: List[Text]
|
lines = [] # type: List[str]
|
||||||
if len(current_conf) == 0:
|
if len(current_conf) == 0:
|
||||||
lines = ['[secrets]\n']
|
lines = ['[secrets]\n']
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def generate_secrets(development=False):
|
|||||||
return name not in current_conf
|
return name not in current_conf
|
||||||
|
|
||||||
def add_secret(name, value):
|
def add_secret(name, value):
|
||||||
# type: (str, Text) -> None
|
# type: (str, str) -> None
|
||||||
lines.append("%s = %s\n" % (name, value))
|
lines.append("%s = %s\n" % (name, value))
|
||||||
current_conf[name] = value
|
current_conf[name] = value
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user