diff --git a/gerrit-dash-creator b/gerrit-dash-creator deleted file mode 100755 index 4da860d..0000000 --- a/gerrit-dash-creator +++ /dev/null @@ -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()) diff --git a/gerrit-dash-creator b/gerrit-dash-creator new file mode 120000 index 0000000..7b110e1 --- /dev/null +++ b/gerrit-dash-creator @@ -0,0 +1 @@ +gerrit_dash_creator/cmd/creator.py \ No newline at end of file diff --git a/gerrit_dash_creator/__init__.py b/gerrit_dash_creator/__init__.py new file mode 100644 index 0000000..cef717a --- /dev/null +++ b/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() diff --git a/gerrit_dash_creator/cmd/__init__.py b/gerrit_dash_creator/cmd/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gerrit_dash_creator/cmd/creator.py b/gerrit_dash_creator/cmd/creator.py new file mode 100755 index 0000000..4da860d --- /dev/null +++ b/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())