summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/github_file_system_provider.py
blob: b5e5c224269d162382947c40bbc80ca91a48745a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from caching_file_system import CachingFileSystem
from empty_dir_file_system import EmptyDirFileSystem
from github_file_system import GithubFileSystem as OldGithubFileSystem
from new_github_file_system import GithubFileSystem as NewGithubFileSystem


class GithubFileSystemProvider(object):
  '''Provides GithubFileSystems bound to an owner/repo pair.
  '''

  def __init__(self, object_store_creator):
    self._object_store_creator = object_store_creator

  def Create(self, owner, repo):
    '''Creates a GithubFileSystem. For legacy reasons this is hacked
    such that the apps samples returns the old GithubFileSystem.

    |owner| is the owner of the GitHub account, e.g. 'GoogleChrome'.
    |repo| is the repository name, e.g. 'devtools-docs'.
    '''
    if owner == 'GoogleChrome' and repo == 'chrome-app-samples':
      # NOTE: The old GitHub file system implementation doesn't support being
      # wrapped by a CachingFileSystem. It's also too slow to run on the dev
      # server, since every app API page would need to read from it.
      return OldGithubFileSystem.CreateChromeAppsSamples(
          self._object_store_creator)
    return CachingFileSystem(
        NewGithubFileSystem.Create(owner, repo, self._object_store_creator),
        self._object_store_creator)

  @staticmethod
  def ForEmpty():
    class EmptyImpl(object):
      def Create(self, owner, repo):
        return EmptyDirFileSystem()
    return EmptyImpl()