Browse Source

Transform into a Python module

Change-Id: Idcd460c9ed8c5fe2ef52d3fbefbf9705eadc2710
changes/69/112269/4
Christian Berendt 7 years ago
parent
commit
9cfb18f1e6
  1. 87
      gerrit-dash-creator
  2. 1
      gerrit-dash-creator
  3. 16
      gerrit_dash_creator/__init__.py
  4. 0
      gerrit_dash_creator/cmd/__init__.py
  5. 87
      gerrit_dash_creator/cmd/creator.py

87
gerrit-dash-creator

@ -1,87 +0,0 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import fileinput
import re
import sys
import urllib
def escape_comma(buff):
"""Because otherwise Firefox is a sad panda."""
return buff.replace(',', '%2c')
def get_title(fname):
title = ""
foreach = ""
for line in fileinput.input(fname):
m = re.match("title = (.+)", line)
if m:
title = m.group(1)
m = re.match("foreach = (.+)", line)
if m:
foreach = escape_comma(m.group(1))
fileinput.close()
return title, foreach
def get_sections(fname):
sections = []
sname = None
for line in fileinput.input(fname):
m = re.match('\[section "([^"]+)', line)
if m:
sname = m.group(1)
elif sname:
m = re.match("query = (.+)", line)
if m:
query = escape_comma(m.group(1))
sections.append({'title': sname, 'query': query})
fileinput.close()
return sections
def gen_url(title, foreach, sections):
base = 'https://review.openstack.org/#/dashboard/?'
base += urllib.urlencode({'title': title, 'foreach': foreach})
base += '&'
encoded = [urllib.urlencode({x['title']: x['query']}) for x in sections]
base += '&'.join(encoded)
return base
def get_options():
parser = argparse.ArgumentParser(
description='Create a gerrit dashboard URL from a dashboard definition')
parser.add_argument('dash',
metavar='dashboard_file',
help="Dashboard file to create url from")
return parser.parse_args()
def main():
opts = get_options()
title, foreach = get_title(opts.dash)
sections = get_sections(opts.dash)
url = gen_url(title, foreach, sections)
print("URL for %s" % title)
print(url)
if __name__ == '__main__':
sys.exit(main())

1
gerrit-dash-creator

@ -0,0 +1 @@
gerrit_dash_creator/cmd/creator.py

16
gerrit_dash_creator/__init__.py

@ -0,0 +1,16 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import pbr.version
__version__ = pbr.version.VersionInfo('reviewstats').version_string()

0
gerrit_dash_creator/cmd/__init__.py

87
gerrit_dash_creator/cmd/creator.py

@ -0,0 +1,87 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import fileinput
import re
import sys
import urllib
def escape_comma(buff):
"""Because otherwise Firefox is a sad panda."""
return buff.replace(',', '%2c')
def get_title(fname):
title = ""
foreach = ""
for line in fileinput.input(fname):
m = re.match("title = (.+)", line)
if m:
title = m.group(1)
m = re.match("foreach = (.+)", line)
if m:
foreach = escape_comma(m.group(1))
fileinput.close()
return title, foreach
def get_sections(fname):
sections = []
sname = None
for line in fileinput.input(fname):
m = re.match('\[section "([^"]+)', line)
if m:
sname = m.group(1)
elif sname:
m = re.match("query = (.+)", line)
if m:
query = escape_comma(m.group(1))
sections.append({'title': sname, 'query': query})
fileinput.close()
return sections
def gen_url(title, foreach, sections):
base = 'https://review.openstack.org/#/dashboard/?'
base += urllib.urlencode({'title': title, 'foreach': foreach})
base += '&'
encoded = [urllib.urlencode({x['title']: x['query']}) for x in sections]
base += '&'.join(encoded)
return base
def get_options():
parser = argparse.ArgumentParser(
description='Create a gerrit dashboard URL from a dashboard definition')
parser.add_argument('dash',
metavar='dashboard_file',
help="Dashboard file to create url from")
return parser.parse_args()
def main():
opts = get_options()
title, foreach = get_title(opts.dash)
sections = get_sections(opts.dash)
url = gen_url(title, foreach, sections)
print("URL for %s" % title)
print(url)
if __name__ == '__main__':
sys.exit(main())
Loading…
Cancel
Save