11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)# found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from caching_file_system import CachingFileSystem 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from empty_dir_file_system import EmptyDirFileSystem 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from github_file_system import GithubFileSystem as OldGithubFileSystem 81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)from new_github_file_system import GithubFileSystem as NewGithubFileSystem 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class GithubFileSystemProvider(object): 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) '''Provides GithubFileSystems bound to an owner/repo pair. 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ''' 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) def __init__(self, object_store_creator): 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) self._object_store_creator = object_store_creator 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) def Create(self, owner, repo): 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) '''Creates a GithubFileSystem. For legacy reasons this is hacked 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) such that the apps samples returns the old GithubFileSystem. 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) |owner| is the owner of the GitHub account, e.g. 'GoogleChrome'. 231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) |repo| is the repository name, e.g. 'devtools-docs'. 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ''' 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if owner == 'GoogleChrome' and repo == 'chrome-app-samples': 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) # NOTE: The old GitHub file system implementation doesn't support being 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) # wrapped by a CachingFileSystem. It's also too slow to run on the dev 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) # server, since every app API page would need to read from it. 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return OldGithubFileSystem.CreateChromeAppsSamples( 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) self._object_store_creator) 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return CachingFileSystem( 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) NewGithubFileSystem.Create(owner, repo, self._object_store_creator), 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) self._object_store_creator) 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) @staticmethod 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) def ForEmpty(): 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) class EmptyImpl(object): 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) def Create(self, owner, repo): 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return EmptyDirFileSystem() 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return EmptyImpl() 41