mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
python: Use universal_newlines to get str from subprocess.
We can replace ‘universal_newlines’ with ‘text’ when we bump our minimum Python version to 3.7. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
9281dccae4
commit
aaa7b766d8
@@ -2,9 +2,10 @@ import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from typing import List, Optional
|
||||
|
||||
from scripts.lib.zulip_tools import run, subprocess_text_output
|
||||
from scripts.lib.zulip_tools import run
|
||||
|
||||
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
ZULIP_SRV_PATH = "/srv"
|
||||
@@ -30,14 +31,16 @@ def generate_sha1sum_node_modules(
|
||||
PACKAGE_JSON_FILE_PATH = os.path.join(setup_dir, 'package.json')
|
||||
YARN_LOCK_FILE_PATH = os.path.join(setup_dir, 'yarn.lock')
|
||||
sha1sum = hashlib.sha1()
|
||||
sha1sum.update(subprocess_text_output(['cat', PACKAGE_JSON_FILE_PATH]).encode('utf8'))
|
||||
with open(PACKAGE_JSON_FILE_PATH, "rb") as fb:
|
||||
sha1sum.update(fb.read().strip())
|
||||
if os.path.exists(YARN_LOCK_FILE_PATH):
|
||||
# For backwards compatibility, we can't assume yarn.lock exists
|
||||
sha1sum.update(subprocess_text_output(['cat', YARN_LOCK_FILE_PATH]).encode('utf8'))
|
||||
with open(YARN_LOCK_FILE_PATH, "rb") as fb:
|
||||
sha1sum.update(fb.read().strip())
|
||||
with open(YARN_PACKAGE_JSON) as f:
|
||||
yarn_version = json.load(f)['version']
|
||||
sha1sum.update(yarn_version.encode("utf8"))
|
||||
sha1sum.update(subprocess_text_output(['node', '--version']).encode('utf8'))
|
||||
sha1sum.update(subprocess.check_output(['node', '--version']).strip())
|
||||
yarn_args = get_yarn_args(production=production)
|
||||
sha1sum.update(''.join(sorted(yarn_args)).encode('utf8'))
|
||||
return sha1sum.hexdigest()
|
||||
|
||||
@@ -232,7 +232,7 @@ migrations_needed = False
|
||||
if not args.skip_migrations:
|
||||
logging.info("Checking for needed migrations")
|
||||
migrations_output = subprocess.check_output(["./manage.py", "showmigrations"],
|
||||
preexec_fn=su_to_zulip).decode("utf-8")
|
||||
preexec_fn=su_to_zulip, universal_newlines=True)
|
||||
need_create_large_indexes = False
|
||||
for ln in migrations_output.split("\n"):
|
||||
line_str = ln.strip()
|
||||
|
||||
@@ -106,9 +106,6 @@ def is_invalid_upgrade(current_version: str, new_version: str) -> bool:
|
||||
return True
|
||||
return False
|
||||
|
||||
def subprocess_text_output(args: Sequence[str]) -> str:
|
||||
return subprocess.check_output(args, universal_newlines=True).strip()
|
||||
|
||||
def get_zulip_pwent() -> pwd.struct_passwd:
|
||||
deploy_root_uid = os.stat(get_deploy_root()).st_uid
|
||||
if deploy_root_uid != 0:
|
||||
|
||||
Reference in New Issue
Block a user