Add update --refresh and --keep_date flags
* Use --refresh to update a project with its current version,
to check for any missing local changes after the update.
* Use --keep_date to not change the last_upgrade_date in METADATA,
useful to minimize diff output after a refresh update.
Bug: 169725446
Test: .../updater.sh update --refresh --keep_date rust/crates/bitflags
Change-Id: I7e0396c2653eb7b4c859a5887a8b1d62fc446910
diff --git a/fileutils.py b/fileutils.py
index d7dd0fa..f6a51cc 100644
--- a/fileutils.py
+++ b/fileutils.py
@@ -66,7 +66,7 @@
return text_format.Parse(metadata, metadata_pb2.MetaData())
-def write_metadata(proj_path: Path, metadata: metadata_pb2.MetaData) -> None:
+def write_metadata(proj_path: Path, metadata: metadata_pb2.MetaData, keep_date: bool) -> None:
"""Writes updated METADATA file for a project.
This function updates last_upgrade_date in metadata and write to the project
@@ -75,13 +75,15 @@
Args:
proj_path: Path to the project.
metadata: The MetaData proto to write.
+ keep_date: Do not change date.
"""
- date = metadata.third_party.last_upgrade_date
- now = datetime.datetime.now()
- date.year = now.year
- date.month = now.month
- date.day = now.day
+ if not keep_date:
+ date = metadata.third_party.last_upgrade_date
+ now = datetime.datetime.now()
+ date.year = now.year
+ date.month = now.month
+ date.day = now.day
text_metadata = text_format.MessageToString(metadata)
with get_metadata_path(proj_path).open('w') as metadata_file:
metadata_file.write(text_metadata)