summaryrefslogtreecommitdiff
path: root/buildscripts/prune_check.py
diff options
context:
space:
mode:
Diffstat (limited to 'buildscripts/prune_check.py')
-rw-r--r--buildscripts/prune_check.py60
1 files changed, 32 insertions, 28 deletions
diff --git a/buildscripts/prune_check.py b/buildscripts/prune_check.py
index 570715c4c1f..1579c396fda 100644
--- a/buildscripts/prune_check.py
+++ b/buildscripts/prune_check.py
@@ -1,26 +1,28 @@
#!/usr/bin/env python2
-""" This program stamps the shared scons directory with a timestamp so we can
- determine the last prune time and run the prune script on a schedule.
- It is meant to be invoked from the shell:
+"""Prune check program.
- if python prune_check.py; then
- echo 'Pruning'
- else
- echo 'Less than 24 hours, waiting ...'
- fi
+This program stamps the shared scons directory with a timestamp so we can
+determine the last prune time and run the prune script on a schedule.
+It is meant to be invoked from the shell:
- The script can be invoked with optional arguments for mount point and 'seconds
- since last prune' (default is 86400 - 24 hours). Use -h to see options and defaults.
+if python prune_check.py; then
+ echo 'Pruning'
+else
+ echo 'Less than 24 hours, waiting ...'
+fi
- python prune_check.py -m '/mount_point' -p 86400
+The script can be invoked with optional arguments for mount point and 'seconds
+since last prune' (default is 86400 - 24 hours). Use -h to see options and defaults.
- To write the latest timestamp to a directory
+python prune_check.py -m '/mount_point' -p 86400
- python prune_check.py -w
+To write the latest timestamp to a directory
- If it is time to prune (ie. more than 24 hours since the last timestamp),
- the script exits with a 0 return code.
- Otherwise the script returns exit code 1.
+python prune_check.py -w
+
+If it is time to prune (ie. more than 24 hours since the last timestamp),
+the script exits with a 0 return code.
+Otherwise the script returns exit code 1.
"""
import argparse
@@ -33,23 +35,23 @@ DATE_TIME_STR = "%Y-%m-%d %H:%M:%S"
def get_prune_file_path(mount_point):
- """ Get the shared scons directory for this AMI """
- with open('/etc/mongodb-build-system-id', 'r') as f:
- uuid = f.read().strip()
+ """Get the shared scons directory for this AMI."""
+ with open('/etc/mongodb-build-system-id', 'r') as fh:
+ uuid = fh.read().strip()
return os.path.join(mount_point, uuid, 'info', 'last_prune_time')
def write_last_prune_time(last_prune_time, prune_file_path):
- """ Write the last prune timestamp in a 'last_prune_time' file """
- with open(prune_file_path, 'w') as f:
- f.write(last_prune_time.strftime(DATE_TIME_STR) + '\n')
+ """Write the last prune timestamp in a 'last_prune_time' file."""
+ with open(prune_file_path, 'w') as fh:
+ fh.write(last_prune_time.strftime(DATE_TIME_STR) + '\n')
def retrieve_last_prune_time(prune_file_path):
- """ Get the last prune time from the 'last_prune_time' file """
+ """Get the last prune time from the 'last_prune_time' file."""
if os.path.isfile(prune_file_path):
- with open(prune_file_path, 'r') as f:
- last_prune_time_str = f.read().strip()
+ with open(prune_file_path, 'r') as fh:
+ last_prune_time_str = fh.read().strip()
last_prune_time = datetime.strptime(last_prune_time_str, DATE_TIME_STR)
else:
last_prune_time = datetime.utcnow()
@@ -59,8 +61,9 @@ def retrieve_last_prune_time(prune_file_path):
def check_last_prune_time(args):
- """ Returns exit code 0 if time to run again, else returns exit code 1
- This is meant to be called from the shell
+ """Return exit code 0 if time to run again, else return exit code 1.
+
+ This is meant to be called from the shell
"""
seconds_since_last_prune = args.prune_seconds
@@ -87,7 +90,7 @@ def check_last_prune_time(args):
def get_command_line_args():
- """ Get the command line arguments """
+ """Get the command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--mount_point', type=str, required=False,
help="The base mount where efs is mounted. Default is '/efs'",
@@ -102,6 +105,7 @@ def get_command_line_args():
def main():
+ """Execute Main program."""
args = get_command_line_args()
mount_point = args.mount_point