scripts: Replace calls to lsb release with our own parsing.

This improves the performance of these operations, by saving a ~50ms
Python process startup.  While not a major performance improvement, it
seems worth it, given how often these commands get run.

Fixes #9571.
This commit is contained in:
Raymond Akornor
2018-05-28 19:55:07 +00:00
committed by Tim Abbott
parent 8b8a9be377
commit 5d39a0f0fc
3 changed files with 16 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ import json
import uuid
if False:
from typing import Sequence, Set, Any
from typing import Sequence, Set, Any, Dict
DEPLOYMENTS_DIR = "/home/zulip/deployments"
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
@@ -303,3 +303,12 @@ def may_be_perform_purging(dirs_to_purge, dirs_to_keep, dir_type, dry_run, verbo
for directory in dirs_to_keep:
if verbose:
print("Keeping used %s: %s" % (dir_type, directory))
def parse_lsb_release():
# type: () -> Dict[str, str]
distro_info = {}
with open('/etc/lsb-release', 'r') as fp:
data = [line.strip().split('=') for line in fp]
for k, v in data:
distro_info[k] = v
return distro_info