Add support for multiple files
This patch makes it possible to specify multiple dashboard files at once. Change-Id: I03aac98808f005768d0c3d7b4b197a79c7aa8048
This commit is contained in:
parent
60a0a5fe8a
commit
73b781922c
|
@ -64,9 +64,9 @@ def generate_dashboard_url(dashboard):
|
|||
def get_options():
|
||||
"""Parse command line arguments and options."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Create a Gerrit dashboard URL from a dashboard '
|
||||
'definition file')
|
||||
parser.add_argument('dashboard_file',
|
||||
description='Create a Gerrit dashboard URL from specified dashboard '
|
||||
'definition files')
|
||||
parser.add_argument('dashboard_files', nargs='+',
|
||||
metavar='dashboard_file',
|
||||
help='Dashboard definition file to create URL from')
|
||||
return parser.parse_args()
|
||||
|
@ -81,33 +81,38 @@ def read_dashboard_file(fname):
|
|||
|
||||
def main():
|
||||
"""Entrypoint."""
|
||||
result = 0
|
||||
opts = get_options()
|
||||
|
||||
if (not os.path.isfile(opts.dashboard_file) or
|
||||
not os.access(opts.dashboard_file, os.R_OK)):
|
||||
print("error: dashboard file '%s' is missing or is not readable" %
|
||||
opts.dashboard_file)
|
||||
return 1
|
||||
for dashboard_file in opts.dashboard_files:
|
||||
if (not os.path.isfile(dashboard_file) or
|
||||
not os.access(dashboard_file, os.R_OK)):
|
||||
print("\nerror: dashboard file '%s' is missing or is not "
|
||||
"readable" % dashboard_file)
|
||||
result = 1
|
||||
continue
|
||||
|
||||
try:
|
||||
dashboard = read_dashboard_file(opts.dashboard_file)
|
||||
except configparser.Error as e:
|
||||
print("error: dashboard file '%s' cannot be parsed\n\n%s" %
|
||||
(opts.dashboard_file, e))
|
||||
return 1
|
||||
try:
|
||||
dashboard = read_dashboard_file(dashboard_file)
|
||||
except configparser.Error as e:
|
||||
print("\nerror: dashboard file '%s' cannot be parsed\n\n%s" %
|
||||
(dashboard_file, e))
|
||||
return 1
|
||||
continue
|
||||
|
||||
try:
|
||||
url = generate_dashboard_url(dashboard)
|
||||
except ValueError as e:
|
||||
print("error:\tgenerating dashboard '%s' failed\n\t%s" %
|
||||
(opts.dashboard_file, e))
|
||||
return 1
|
||||
try:
|
||||
url = generate_dashboard_url(dashboard)
|
||||
except ValueError as e:
|
||||
print("\nerror:\tgenerating dashboard '%s' failed\n\t%s" %
|
||||
(dashboard_file, e))
|
||||
result = 1
|
||||
continue
|
||||
|
||||
print("Generated URL for the Gerrit dashboard '%s':" % opts.dashboard_file)
|
||||
print("")
|
||||
print(url)
|
||||
print("\nGenerated URL for the Gerrit dashboard '%s':\n" %
|
||||
dashboard_file)
|
||||
print(url)
|
||||
|
||||
return 0
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue