Auto-generated patch by python-black
[integration/test.git] / tools / distchanges / distcompare.py
1 import argparse
2 from changes import Changes
3
4 # assumes that the new/current and older distributions are unzipped in /tmp/distro_new and
5 # /tmp_distro_old respectively
6
7
8 class DistCompare(object):
9     def __init__(self, remote_url):
10
11         self.remote_url = remote_url
12
13     @staticmethod
14     def get_project_names():
15         # TODO: when autorelease starts publishing the dependencies.log artifact, this function (or the consumer
16         # of this tool) can take the latest dependencies.log from jenkins lastSuccessfulArtifacts and put it
17         # in /tmp/ For now the functionality to read the projects from that file are commented.
18         """
19         projects = []
20         with open("/tmp/dependencies.log") as dep_file:
21             for line in dep_file:
22                 if line != "\n":
23                     projects.append(line.split(":")[0])
24
25         return projects
26         """
27         # this hard coded list of projects was taken from Oxygen dependencies.log - late January 2018
28         return [
29             "integration/distribution",
30             "mdsal",
31             "alto",
32             "sfc",
33             "bier",
34             "serviceutils",
35             "usc",
36             "ovsdb",
37             "lispflowmapping",
38             "groupbasedpolicy",
39             "snmp4sdn",
40             "aaa",
41             "honeycomb/vbd",
42             "openflowplugin",
43             "of-config",
44             "daexim",
45             "dluxapps",
46             "coe",
47             "packetcable",
48             "genius",
49             "yangtools",
50             "infrautils",
51             "netvirt",
52             "neutron",
53             "snmp",
54             "bgpcep",
55             "nemo",
56             "netconf",
57             "tsdr",
58             "sxp",
59             "jsonrpc",
60             "p4plugin",
61             "odlparent",
62             "l2switch",
63             "dlux",
64             "controller",
65         ]
66
67     def run_cmd(self):
68         query_limit = 100
69         num_to_display = 50
70         branch = "master"
71         project_names = self.get_project_names()
72         extracted_distro_locations = {
73             "new": "/tmp/distro_new",
74             "old": "/tmp/distro_old",
75         }
76
77         new_changes = Changes(
78             branch,
79             extracted_distro_locations["new"],
80             num_to_display,
81             query_limit,
82             project_names,
83             self.remote_url,
84         )
85
86         new_projects = new_changes.run_cmd()
87         new_changes.pretty_print_projects(new_projects)
88
89         old_changes = Changes(
90             branch,
91             extracted_distro_locations["old"],
92             num_to_display,
93             query_limit,
94             project_names,
95             self.remote_url,
96         )
97
98         old_projects = old_changes.run_cmd()
99         old_changes.pretty_print_projects(old_projects)
100
101         patchset_diff = []
102         print("\nPatch differences:\n------------------")
103         for project_name, values in new_projects.items():
104             new_gerrits = values["includes"]
105             for gerrit in new_gerrits:
106                 if gerrit not in old_projects[project_name]["includes"]:
107                     patchset_diff.append(gerrit)
108                     print(
109                         "{:<20}{}\t{}".format(
110                             project_name, gerrit["url"], gerrit["subject"]
111                         )
112                     )
113
114         print("\n%s different patches between the two distros." % len(patchset_diff))
115
116
117 def main():
118
119     parser = argparse.ArgumentParser(
120         description="Returns the list of patches found in the unzipped distribution at "
121         "/tmp/distro_new that are not found in the distribution at "
122         "/tmp/distro_old. This should result in a listing of what new changes "
123         "were made between the two distributions."
124     )
125     parser.add_argument(
126         "-r",
127         "--remote",
128         dest="remote_url",
129         default=Changes.REMOTE_URL,
130         help="git remote url to use for gerrit",
131     )
132     options = parser.parse_args()
133
134     distc = DistCompare(options.remote_url)
135     distc.run_cmd()
136
137
138 if __name__ == "__main__":
139     main()