import re
import sys
import argparse
+import requests
+import warnings
from operator import itemgetter
import jinja2
-REQ_JSON_URL = "https://onap.readthedocs.io/en/latest/_downloads/needs.json"
+NEEDS_JSON_URL = "https://nexus.onap.org/service/local/repositories/raw/content/org.onap.vnfrqts.requirements/master/needs.json"
NEEDS_PATH = "docs/data/needs.json"
JINJA_TEMPLATE = "release-requirement-changes.rst.jinja2"
"id": r_id,
"description": current_text,
"sections": sections,
+ "introduced": self.current_requirements[r_id].get("introduced"),
+ "updated": self.current_requirements[r_id].get("updated")
}
return result
return json.load(req_file)
+def load_current_requirements():
+ """Loads dict of current requirements or empty dict if file doesn't exist"""
+ try:
+ r = requests.get(NEEDS_JSON_URL)
+ if r.headers.get("content-type") == "application/json":
+ with open(NEEDS_PATH, "wb") as needs:
+ needs.write(r.content)
+ else:
+ warnings.warn(
+ (
+ "Unexpected content-type ({}) encountered downloading "
+ + "requirements.json, using last saved copy"
+ ).format(r.headers.get("content-type"))
+ )
+ except requests.exceptions.RequestException as e:
+ warnings.warn("Error downloading latest JSON, using last saved copy.")
+ warnings.warn(UserWarning(e))
+ with open(NEEDS_PATH, "r") as f:
+ return json.load(f)
+
def parse_args():
"""Parse the command-line arguments and return the arguments:
def print_invalid_metadata_report(difference_finder, current_version):
"""Write a report to the console for any instances where differences
- are detected, but teh appropriate :introduced: or :updated: metadata
+ are detected, but the appropriate :introduced: or :updated: metadata
is not applied to the requirement."""
print("Validating Metadata...")
print()
if __name__ == "__main__":
args = parse_args()
- requirements = load_requirements(NEEDS_PATH)
+ requirements = load_current_requirements()
differ = DifferenceFinder(requirements,
args.current_version,
args.prior_version)
num_changed=len(differ.changed_requirements),
)
-