Changeset 7f11e4a in rtems-central


Ignore:
Timestamp:
02/23/22 08:07:37 (8 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
c061f7b
Parents:
4949a33
git-author:
Sebastian Huber <sebastian.huber@…> (02/23/22 08:07:37)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/23/22 08:18:17)
Message:

spec2modules.py: Add --diff option

File:
1 edited

Legend:

Unmodified
Added
Removed
  • spec2modules.py

    r4949a33 r7f11e4a  
    2727
    2828import argparse
     29import difflib
    2930import sys
    3031
     
    3233
    3334
     35def _diff(obj: rtemsspec.content.Content, path: str) -> None:
     36    from_file = f"a/{path}"
     37    to_file = f"b/{path}"
     38    try:
     39        file_lines = open(path).read().splitlines()
     40    except FileNotFoundError:
     41        file_lines = []
     42    diff_lines = list(
     43        difflib.unified_diff(file_lines,
     44                             str(obj).splitlines(),
     45                             fromfile=from_file,
     46                             tofile=to_file,
     47                             n=3,
     48                             lineterm=""))
     49    if diff_lines:
     50        print(f"diff -u {from_file} {to_file}")
     51        print("\n".join(diff_lines))
     52
     53
    3454def main() -> None:
    3555    """ Generates files of the modules from the specification. """
    3656    parser = argparse.ArgumentParser()
     57    parser.add_argument("-u",
     58                        "--diff",
     59                        action="store_true",
     60                        help="print the unified difference from the original"
     61                        " file content to the new generated content")
    3762    parser.add_argument("targets",
    3863                        metavar="TARGET",
     
    4065                        help="a target file of a specification item")
    4166    args = parser.parse_args(sys.argv[1:])
     67    if args.diff:
     68        rtemsspec.content.Content.write = _diff  # type: ignore
    4269    config = rtemsspec.util.load_config("config.yml")
    4370    item_cache = rtemsspec.items.ItemCache(config["spec"])
Note: See TracChangeset for help on using the changeset viewer.