From fa3abe73569c3af6e569d9ba168e5bd739e9afaf Mon Sep 17 00:00:00 2001
From: Pavel Korshunov <pavel.korshunov@idiap.ch>
Date: Tue, 27 Mar 2018 16:21:05 +0200
Subject: [PATCH] added more options to changelog script and cleaned up code

---
 release/generate_changelog.py | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/release/generate_changelog.py b/release/generate_changelog.py
index 6fc5cbf..52c5c42 100755
--- a/release/generate_changelog.py
+++ b/release/generate_changelog.py
@@ -12,10 +12,15 @@ Arguments:
   <private_token>  Private token used to access GitLab.
   
 Options:
-  -h --help                    Show this screen.
-  --version                    Show version.
-  -p, --package-name STR       If the name of a package is provided, then the changelog will only be generated for this package.
-
+  -h --help                     Show this screen.
+  --version                     Show version.
+  -p, --package-name STR        If the name of a package is provided, then the changelog
+                                will be generated for this package only.
+  -g, --group-name STR          Group name where we are looking for packages.
+                                [default: bob].
+  -l, --list-of-packages STR    A file with the list of packages (in order) to generate changelog for.
+                                By default, it will look in file 'order.txt' inside 'bob.nightlies' package.
+                                [default: bob.nightlies].
 """
 
 import sys
@@ -25,7 +30,6 @@ import datetime
 
 
 def _insure_correct_package(candidates, group_name, pkg_name):
-    pkg = None
     for pkg in candidates:
         # make sure the name and the group name match exactly
         if pkg.name == pkg_name and pkg.namespace['name'] == group_name:
@@ -53,7 +57,6 @@ def bob_last_release(gl):
 
 
 def get_datetime_from_gitdate(gitdate):
-    #    import ipdb; ipdb.set_trace()
     return datetime.datetime.strptime(gitdate[:-6], '%Y-%m-%dT%H:%M:%S.%f')
 
 
@@ -152,15 +155,12 @@ def print_tags_with_commits(pkg_name, gitpkg, since='2017-01-01T00:00:00Z'):
     print_commits_range(pkg_name, leftover_commits)
 
 
-def main(private_token, pkg_name=""):
+def main(private_token, group_name='bob', pkg_name="", packages_list='bob.nightlies'):
     gl = gitlab.Gitlab('https://gitlab.idiap.ch', private_token=private_token, api_version=4)
-    group_name = 'bob'
     bob_group = gl.groups.list(search=group_name)[0]
-    #    print(pkg_list_ordered)
     last_release_date = bob_last_release(gl)
-    #    print(last_release_date)
+
     # print name of the package, its version and tags
-#    import ipdb; ipdb.set_trace()
     if pkg_name:
         # group returns a simplified description of the project
         grpkg = _insure_correct_package(bob_group.projects.list(search=pkg_name), group_name, pkg_name)
@@ -168,7 +168,12 @@ def main(private_token, pkg_name=""):
         gitpkg = gl.projects.get(id=grpkg.id)
         print_tags_with_commits(pkg_name, gitpkg, since=last_release_date)
     else:
-        pkg_list_ordered = get_packages_list(gl, gl_group=bob_group)
+        if packages_list == 'bob.nightlies':
+            pkg_list_ordered = get_packages_list(gl, gl_group=bob_group)
+        else:  # if not bob.nightlies, assume it is a file with the list
+            with open(packages_list) as f:
+                pkg_list_ordered = f.readlines()
+                pkg_list_ordered = [line.strip() for line in pkg_list_ordered]
         for pkg_name in pkg_list_ordered:
             if pkg_name == group_name:  # skip bob meta-package
                 continue
@@ -183,4 +188,5 @@ def main(private_token, pkg_name=""):
 
 if __name__ == '__main__':
     arguments = docopt(__doc__.format(sys.argv[0]), version='Changelog 0.0.1')
-    main(arguments['<private_token>'], pkg_name=arguments['--package-name'])
+    main(arguments['<private_token>'], group_name=arguments['--group-name'],
+         pkg_name=arguments['--package-name'], packages_list=arguments['--list-of-packages'])
-- 
GitLab