A few days ago Jussi asked me to take a look at the new LP teams that he had created to manage our IRC operators and core channels. I’m not sure if it was due to the lack of caffeine, but I was having a hard time figuring out what the hierarchy of teams was from looking at their launchpad pages. Since I’m now more familiar using launchpadlib, I thought I’d put a small script together to graph out the team relationships. In order to do the actual drawing, I used pydot, which is a python interface for Graphviz.
I showed some test output images to the folks in #ubuntu-offtopic and a few of them thought it was neat and asked me for the code so that they could make their own graphs. I took that as a sign that I should clean up the code to make it more efficient. I also went ahead and used optparse to make the application more user-friendly.
To start, lets take a look at what the output for the teams that Jussi created:

Well that’s rather self-explanatory. Much more so than looking at a bunch of lists on LP.
How if we looked at someone that has administrative access for some Launchpad teams. Perhaps Jono:

Green filled team nodes indicate that the root user has administrative access to them. I chose to focus on what teams a person had control over, rather than which relationships granted that level of access. This was mostly due to not being happy with the options that Graphviz had for shading and coloring edges.
I suppose that graph was somewhat complex… although its nothing compared to sabdfl’s:

Anyway, the python script itself is available here. And the help page is as follows:
Usage: lpdot.py [-c COLOR] [-a COLOR] [-o PATH] [-d PATH] username
Options:
-h, --help show this help message and exit
-c COLOR set default node color to COLOR (defaults to white)
-a COLOR set administrative node color to COLOR (defaults to greenyellow)
-o PATH write png file to PATH (defaults to pwd)
-d PATH write dot file to PATH
A list of valid colors can be found here:
http://www.graphviz.org/doc/info/colors.html
One of the many tasks that the Ubuntu IRC Council is responsible for is granting Ubuntu member hostname cloaks to people who have gained Ubuntu membership. We currently use a Launchpad team to keep track of the people that have been cloaked. When someone requests a cloak in #ubuntu-irc, there are a number of steps that we need to go:
- Get the user’s Launchpad page
- Check if they’re indeed an Ubuntu member
- Go to the cloaked Ubuntu members team
- Remember the user’s Launchpad id and add them to the team
- Ask freenode staff to apply the cloak
Now this doesn’t sound that difficult, but we’re all busy and we know that Launchpad isn’t exactly the fastest site around. So, in order to make this easier for myself, I put together a small python script using launchpadlib to do all the dirty work for me. It also gave me an excuse to play with optparse, which I have been looking to have a reason to use.
The script gives me the ability to check a member’s status and add them to the cloak team in one step. I can also choose to use the launchpad staging server to do a dry-run if I’m just testing.
This was my first time using launchpadlib to update information on Launchpad itself. I have to say that it was a lot easier than I had originally thought it would be.
As of revision 9, the code is as follows:
#!/usr/bin/env python
cachedir = '~/.launchpadlib/cache/'
import sys
from optparse import OptionParser
def main():
usage = 'usage: %prog [options] username'
parser = OptionParser(usage)
parser.add_option('-f','--force',action='store_true',dest='force',
help='add user regardless of membership in ubuntumembers')
parser.add_option('-s','--staging',action='store_true',dest='staging',
help='preform events against the launchpad staging server')
options,args = parser.parse_args()
if len(args) != 1:
print 'Error: incorrect number of arguments'
parser.print_help()
sys.exit(2)
from launchpadlib.launchpad import Launchpad,STAGING_SERVICE_ROOT,EDGE_SERVICE_ROOT
from launchpadlib.errors import HTTPError
if options.staging:
print 'Warning: using staging.launchpad.net'
service = STAGING_SERVICE_ROOT
else:
service = EDGE_SERVICE_ROOT
launchpad = Launchpad.login_with('irc_lpteam',service,cachedir)
membername = args[0]
teamname='ubuntu-irc-cloaks'
team = launchpad.people[teamname]
member = launchpad.people[membername]
if 'ubuntumembers' in [e.name for e in member.super_teams]:
print "'%s' (%s) is an Ubuntu Member" % (member.display_name,membername)
print "Attempting to add '%s' (%s) to '%s' (%s)..." % (member.display_name,membername,team.display_name,teamname)
try:
status = team.addMember(person=member,status="Approved")
except HTTPError as error:
print "Error: %s has occurred" % error
sys.exit(1)
else:
print "'%s' (%s) does not appear to be an Ubuntu Member." % (member.display_name,membername)
if options.force:
print 'Warning: force enabled, adding to team anyway'
try:
status = team.addMember(person=member,status="Approved")
except HTTPError as error:
print "Error: %s has occurred" % error
sys.exit(1)
print 'Success!'
if __name__ == "__main__":
main()
The latest code is available here for anyone who wants to play around with it themselves.
Note: I have filed a bug against launchpad that could make it easier to add people to teams.