prune_builds: add `--timestamp-only` option
This adds an arg that will only update the `timestamp` field of
`builds.json` with an RFC3339 timestamp.
@@ -15,6 +15,8 @@ import subprocess
import dateutil.parser
+from datetime import datetime
+
sys.path.insert(0, '/usr/lib/coreos-assembler')
from cmdlib import write_json
@@ -27,6 +29,8 @@ parser.add_argument("--keep-last-n", type=int, default=DEFAULT_KEEP_LAST_N,
help="Number of builds to keep (0 for all)")
parser.add_argument("--insert-only", help="Append a new latest build, do not prune",
action='store')
+parser.add_argument("--timestamp-only", help="Update timestamp on builds.json",
+ action='store_true')
args = parser.parse_args()
builds = []
@@ -39,9 +43,19 @@ if os.path.isfile(builds_json):
else:
builddata = {'builds': []}
+# generate RFC3339 timestamp
+now = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
+
+# handle --timestamp-only
+if args.timestamp_only:
+ builddata['timestamp'] = now
+ write_json(builds_json, builddata)
+ sys.exit(0)
+
# Handle --insert-only
if args.insert_only:
builddata['builds'].insert(0, args.insert_only)
+ builddata['timestamp'] = now
write_json(builds_json, builddata)
sys.exit(0)
@@ -79,6 +93,7 @@ if not skip_pruning and len(builds) > args.keep_last_n:
del builds[args.keep_last_n:]
builddata['builds'] = [x[0] for x in builds]
+builddata['timestamp'] = now
write_json(builds_json, builddata)
# if we're not pruning, then we're done!
