Skip to content

Commit

Permalink
Add a mutually_exclusive_option group to handle projects
Browse files Browse the repository at this point in the history
Projects can still be provided on the command line with --project_list.
But for large list of projects, a configuration file is more suitable.

The syntax of such pmr.conf file is:

    [PMR]

    [lp:plainbox-provider-certification-client]
    [lp:plainbox-provider-certification-server]

Note that all projects have to be prefixed by "lp:". More than a convention
it's a way to select all section names in one go and keep the top level section
for future needs.
  • Loading branch information
yphus committed Sep 28, 2016
1 parent 1240ef2 commit 1ea932d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions process-merge-requests
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Git-based merge requests are supported.
from __future__ import absolute_import, unicode_literals, print_function

import argparse
import ConfigParser
import gettext
import logging
import os
Expand Down Expand Up @@ -307,16 +308,27 @@ def main():
const='https://api.launchpad.net/',
help=_("Use production launchpad instance (default)"))
group.set_defaults(lp_api_url='https://api.launchpad.net/')
parser.add_argument(
'project_list', metavar=_('PROJECT'), nargs="+",
group2 = parser.add_mutually_exclusive_group(required=True)
group2.add_argument("--conf_file",
help="Specify config file", metavar="CONF")
group2.add_argument(
'--project_list', metavar=_('PROJECT'), nargs="+",
help=_("name of the launchpad project to process"))
ns = parser.parse_args()
_logger.info(_("Logging into launchpad.net"))
lp = Launchpad.login_with('process-merge-requests', ns.lp_api_url)
_logger.info(_("Checking for new things to land every minute..."))
try:
while True:
for project_name in ns.project_list:
projects = []
if ns.conf_file:
config = ConfigParser.ConfigParser()
config.read(ns.conf_file)
projects = [section[3:] for section in config.sections() if
section.startswith('lp:')]
else:
projects = ns.project_list
for project_name in projects:
try:
project = lp.projects[project_name]
except KeyError:
Expand Down

0 comments on commit 1ea932d

Please sign in to comment.