This whole function could be predicated on `if sys.platform == 'linux':` which would save the subprocess calls on OS X and stuff like that.