Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 57 lines (42 sloc) 1.62 KB
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:
self.user_cache[user] = [ for r in self.github.repos.list(user)]
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:
self.branch_cache[project] = self.github.repos.branches(project)
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__':
Jump to Line
Something went wrong with that request. Please try again.