Skip to content

Commit

Permalink
Try to get dateOfLastChange from git
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Jul 26, 2023
1 parent 2b72e93 commit cee2562
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import json
import os.path
import re
import subprocess
import sys
from argparse import ArgumentParser
import datetime
from pathlib import Path
import traceback

Expand Down Expand Up @@ -52,6 +54,32 @@ def postprocess(registered_items_path: str | Path = 'registereditems',
id_prefix=id_prefix)

def do_postprocess(bblock: BuildingBlock) -> bool:

try:
last_git_modified = datetime.datetime.fromisoformat(subprocess.run([
'git',
'log',
'-1',
'--pretty=format:%cI',
str(bblock.files_path),
], capture_output=True).stdout.decode()).astimezone(datetime.timezone.utc).date()
except (ValueError, OSError):
last_git_modified = None

last_update = bblock.metadata.get('dateOfLastChange')
if last_update:
try:
last_update = datetime.date.fromisoformat(last_update)
if last_git_modified and last_git_modified > last_update:
last_update = last_git_modified
except ValueError:
last_update = last_git_modified

if last_update:
bblock.metadata['dateOfLastChange'] = last_update.isoformat()
else:
bblock.metadata.pop('dateOfLastChange', None)

output_file_root = Path(output_file).resolve().parent
if bblock.annotated_schema.is_file():
if base_url:
Expand Down

0 comments on commit cee2562

Please sign in to comment.