1# Copyright 2013 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from caching_file_system import CachingFileSystem 6from empty_dir_file_system import EmptyDirFileSystem 7from github_file_system import GithubFileSystem as OldGithubFileSystem 8from new_github_file_system import GithubFileSystem as NewGithubFileSystem 9 10 11class GithubFileSystemProvider(object): 12 '''Provides GithubFileSystems bound to an owner/repo pair. 13 ''' 14 15 def __init__(self, object_store_creator): 16 self._object_store_creator = object_store_creator 17 18 def Create(self, owner, repo): 19 '''Creates a GithubFileSystem. For legacy reasons this is hacked 20 such that the apps samples returns the old GithubFileSystem. 21 22 |owner| is the owner of the GitHub account, e.g. 'GoogleChrome'. 23 |repo| is the repository name, e.g. 'devtools-docs'. 24 ''' 25 if owner == 'GoogleChrome' and repo == 'chrome-app-samples': 26 # NOTE: The old GitHub file system implementation doesn't support being 27 # wrapped by a CachingFileSystem. It's also too slow to run on the dev 28 # server, since every app API page would need to read from it. 29 return OldGithubFileSystem.CreateChromeAppsSamples( 30 self._object_store_creator) 31 return CachingFileSystem( 32 NewGithubFileSystem.Create(owner, repo, self._object_store_creator), 33 self._object_store_creator) 34 35 @staticmethod 36 def ForEmpty(): 37 class EmptyImpl(object): 38 def Create(self, owner, repo): 39 return EmptyDirFileSystem() 40 return EmptyImpl() 41