Remove the requirement R-27711 in VNFRQTS-585
[vnfrqts/requirements.git] / make_ids.py
1 # -*- coding: utf8 -*-
2 # org.onap.vnfrqts/requirements
3 # ============LICENSE_START====================================================
4 # Copyright © 2018 AT&T Intellectual Property. All rights reserved.
5 #
6 # Unless otherwise specified, all software contained herein is licensed
7 # under the Apache License, Version 2.0 (the "License");
8 # you may not use this software except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #             http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 # Unless otherwise specified, all documentation contained herein is licensed
20 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
21 # you may not use this documentation except in compliance with the License.
22 # You may obtain a copy of the License at
23 #
24 #             https://creativecommons.org/licenses/by/4.0/
25 #
26 # Unless required by applicable law or agreed to in writing, documentation
27 # distributed under the License is distributed on an "AS IS" BASIS,
28 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 # See the License for the specific language governing permissions and
30 # limitations under the License.
31 #
32 # ============LICENSE_END============================================
33 import argparse
34 import itertools
35 import json
36 import random
37
38 REQUIREMENTS_FILE = "docs/data/needs.json"
39
40
41 def load_all_ids():
42     """Loads the """
43     with open(REQUIREMENTS_FILE, "r") as f:
44         data = json.load(f)
45         result = set()
46         for version in data["versions"]:
47             result.update(data["versions"][version]["needs"].keys())
48         return result
49
50
51 def generate_ids():
52     """Generates a stream of unique requirement IDs"""
53     all_ids = load_all_ids()
54     while True:
55         new_id = "R-{:0>5d}".format(random.randint(0, 999999))
56         if new_id in all_ids:
57             continue  # skip this one and generate another one
58         all_ids.add(new_id)
59         yield new_id
60
61
62 if __name__ == "__main__":
63     parser = argparse.ArgumentParser(
64         description="""
65         Generate random, unique requirement IDs for use when adding new requirements
66         to the RST documentation.
67         """
68     )
69     parser.add_argument("num_ids", action="store", nargs="?", type=int, default=1,
70                         help="Number of IDs to generate")
71     args = parser.parse_args()
72     for req_id in itertools.islice(generate_ids(), args.num_ids):
73         print(req_id)
74
75