Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
executable file 57 lines (42 sloc) 1.662 kB
#!/usr/bin/python
from github2 import client
import routes
import routefs
class GithubFS(routefs.RouteFS):
def __init__(self, *args, **kwargs):
super(GithubFS, self).__init__(*args, **kwargs)
self.user_cache = {}
self.branch_cache = {}
self.github = client.Github()
def make_map(self):
m = routes.Mapper()
m.connect('/', controller='list_users')
m.connect('/{user}', controller='list_repos')
m.connect('/{user}/{repo}', controller='list_branches')
m.connect('/{user}/{repo}/{branch}', controller='get_branch')
return m
def list_users(self, **kwargs):
return [user for user, projects in self.user_cache.iteritems() if projects]
def list_repos(self, user, **kwargs):
if user not in self.user_cache:
try:
self.user_cache[user] = [r.name for r in self.github.repos.list(user)]
except:
self.user_cache[user] = None
return self.user_cache[user]
def list_branches(self, user, repo, **kwargs):
project = '%s/%s' % (user, repo)
if project not in self.branch_cache:
try:
self.branch_cache[project] = self.github.repos.branches(project)
except:
self.branch_cache[project] = {}
return self.branch_cache[project].keys()
def get_branch(self, user, repo, branch, **kwargs):
project = '%s/%s' % (user, repo)
sha1 = self.branch_cache.get(project, {}).get(branch, None)
if sha1:
sha1 += '\n'
return sha1
if __name__ == '__main__':
routefs.main(GithubFS)
Jump to Line
Something went wrong with that request. Please try again.