Add remote-url command line argument
[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
10     def __init__(self, remote_url):
11
12         self.remote_url = remote_url
13
14     @staticmethod
15     def get_project_names():
16         # TODO: when autorelease starts publishing the dependencies.log artifact, this function (or the consumer
17         # of this tool) can take the latest dependencies.log from jenkins lastSuccessfulArtifacts and put it
18         # in /tmp/ For now the functionality to read the projects from that file are commented.
19
20         """
21         projects = []
22         with open("/tmp/dependencies.log") as dep_file:
23             for line in dep_file:
24                 if line != "\n":
25                     projects.append(line.split(":")[0])
26
27         return projects
28         """
29         # this hard coded list of projects was taken from a Carbon dependencies.log - late January 2017
30         return ['eman', 'integration/distribution', 'snbi', 'mdsal', 'alto', 'sfc', 'sdninterfaceapp', 'topoprocessing',
31                 'usc', 'ovsdb', 'lispflowmapping', 'groupbasedpolicy', 'usecplugin', 'snmp4sdn', 'capwap', 'aaa',
32                 'honeycomb/vbd', 'atrium', 'next', 'nic', 'vtn', 'lacp', 'openflowplugin', 'faas', 'ttp', 'of-config',
33                 'packetcable', 'genius', 'yangtools', 'natapp', 'didm', 'infrautils', 'netide', 'netvirt', 'neutron',
34                 'cardinal', 'snmp', 'bgpcep', 'nemo', 'netconf', 'yang-push', 'iotdm', 'tsdr', 'sxp', 'centinel',
35                 'odlparent', 'l2switch', 'unimgr', 'openflowjava', 'ocpplugin', 'dlux', 'controller']
36
37     def run_cmd(self):
38         query_limit = 100
39         num_to_display = 50
40         branch = 'master'
41         project_names = self.get_project_names()
42         extracted_distro_locations = {'new': '/tmp/distro_new', 'old': '/tmp/distro_old'}
43
44         new_changes = Changes(branch, extracted_distro_locations['new'], num_to_display,
45                               query_limit, project_names, self.remote_url)
46
47         new_projects = new_changes.run_cmd()
48         new_changes.pretty_print_projects(new_projects)
49
50         old_changes = Changes(branch, extracted_distro_locations['old'], num_to_display,
51                               query_limit, project_names, self.remote_url)
52
53         old_projects = old_changes.run_cmd()
54         old_changes.pretty_print_projects(old_projects)
55
56         patchset_diff = []
57         print("\nPatch differences:\n------------------")
58         for project_name, values in new_projects.items():
59             new_gerrits = values['includes']
60             for gerrit in new_gerrits:
61                 if gerrit not in old_projects[project_name]['includes']:
62                     patchset_diff.append(gerrit)
63                     print('{:<20}{}\t{}'.format(project_name, gerrit['url'], gerrit['subject']))
64
65         print("\n%s different patches between the two distros." % len(patchset_diff))
66
67
68 def main():
69
70     parser = argparse.ArgumentParser(description='Returns the list of patches found in the unzipped distribution at '
71                                                  '/tmp/distro_new that are not found in the distribution at '
72                                                  '/tmp/distro_old. This should result in a listing of what new changes '
73                                                  'were made between the two distributions.')
74     parser.add_argument("-r", "--remote", dest="remote_url", default=Changes.REMOTE_URL,
75                         help="git remote url to use for gerrit")
76     options = parser.parse_args()
77
78     distc = DistCompare(options.remote_url)
79     distc.run_cmd()
80
81
82 if __name__ == "__main__":
83     main()