Skip to content

Instantly share code, notes, and snippets.

@ttx
Created January 22, 2016 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttx/de1b105aef95b708fd40 to your computer and use it in GitHub Desktop.
Save ttx/de1b105aef95b708fd40 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# Script to generate TC agenda under various forms
#
# Copyright 2014 Thierry Carrez <thierry@openstack.org>
# All Rights Reserved.
#
# 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.
from argparse import ArgumentParser
import datetime
import json
import re
import requests
import subprocess
wiki = 'https://wiki.openstack.org'
page = 'Meetings/TechnicalCommittee'
sect = '2'
wikiurl = wiki + '/w/index.php?title=' + page + '&action=raw&section=' + sect
def get_governance_changes(*args):
chg = {}
host = "review.openstack.org"
port = "29418"
cmd = ['/usr/bin/ssh', '-p', port,
host, 'gerrit', 'query', '--format=JSON',
'project:openstack/governance', 'branch:master', 'status:open',
] + list(args)
proc = subprocess.Popen(cmd, bufsize=1,
stdin=None, stdout=subprocess.PIPE, stderr=None)
for line in proc.stdout:
data = json.loads(line)
if 'subject' in data:
chg[data['url']] = data
return chg
if __name__ == '__main__':
# Parameters
parser = ArgumentParser(description="Generate TC agenda")
parser.add_argument('output', choices=['wiki', 'email', 'irc'],
help='Output format for TC agenda')
args = parser.parse_args()
if args.output == 'wiki':
# Fetch governance reviews from gerrit and turn them into list
print "[ Formal vote changes ]"
changes = get_governance_changes('topic:formal-vote')
for url in sorted(changes.keys()):
print "* %s [%s]" % (changes[url]['subject'], url)
print
print "[ One-week-old other changes ]"
changes = get_governance_changes('AND', 'NOT', 'topic:formal-vote')
old = True
seven_days_ago = datetime.datetime.utcnow() - datetime.timedelta(days=7)
for url in sorted(changes.keys()):
created = datetime.datetime.fromtimestamp(changes[url]['createdOn'])
if (old and created > seven_days_ago):
old = False
print
print "[ Younger other changes ]"
print "* %s [%s]" % (changes[url]['subject'], url)
else:
# Agenda lives on the wiki
r = requests.get(wikiurl)
agenda = r.text
if args.output == 'email':
agenda = agenda.replace('**', ' *')
# Find links in agenda and email-friendlize them
links = []
def repl(m):
links.append(m.group(1))
return '[%d]' % len(links)
email = re.sub(r'\[([^\]]+)\]', repl, agenda) + '\n\n'
for num,link in enumerate(links):
email += '[%d] %s\n' % (num+1, link)
# Output resulting email
print email
else:
# Print tcmeeting script skeleton
for line in agenda.split('\n'):
if line.startswith('** '):
line = line.replace('**','\n*')
line = line.replace('[','(')
line = line.replace(']',')')
print line
else:
if line.startswith('* '):
line = line.replace('* ','\n\n============\n\n#topic ')
line = line.replace('[','\n\n#link ')
line = line.replace(']','\n')
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment