mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
zulip_tools.py: Add get_recent_deployments() function.
This function returns a list of all the deployments directories which are newer than some threshold number of days including the `/root/zulip` directory if it exists.
This commit is contained in:
committed by
Tim Abbott
parent
931e4752aa
commit
8954605726
@@ -12,7 +12,7 @@ import sys
|
||||
import time
|
||||
|
||||
if False:
|
||||
from typing import Sequence, Text, Any
|
||||
from typing import Sequence, Set, Text, Any
|
||||
|
||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||
@@ -155,3 +155,21 @@ def get_environment():
|
||||
if os.environ.get("TRAVIS"):
|
||||
return "travis"
|
||||
return "dev"
|
||||
|
||||
def get_recent_deployments(threshold_days):
|
||||
# type: (int) -> Set[Text]
|
||||
# Returns a list of deployments not older than threshold days
|
||||
# including `/root/zulip` directory if it exists.
|
||||
recent = set()
|
||||
threshold_date = datetime.datetime.now() - datetime.timedelta(days=threshold_days)
|
||||
for dir_name in os.listdir(DEPLOYMENTS_DIR):
|
||||
try:
|
||||
date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT)
|
||||
if date >= threshold_date:
|
||||
recent.add(os.path.join(DEPLOYMENTS_DIR, dir_name))
|
||||
except ValueError:
|
||||
# Always include deployments whose name is not in the format of a timestamp.
|
||||
recent.add(os.path.join(DEPLOYMENTS_DIR, dir_name))
|
||||
if os.path.exists("/root/zulip"):
|
||||
recent.add("/root/zulip")
|
||||
return recent
|
||||
|
||||
Reference in New Issue
Block a user