def setUp(self): ConfigureFakeFetchers(os.path.join(sys.path[0], os.pardir)) self._base_path = os.path.join(sys.path[0], 'test_data', 'github_file_system') self._file_system = GithubFileSystem( AppEngineUrlFetcher(url_constants.GITHUB_URL), AppEngineBlobstore())
class GithubFileSystemTest(unittest.TestCase): def setUp(self): ConfigureFakeFetchers(os.path.join(sys.path[0], os.pardir)) self._base_path = os.path.join(sys.path[0], 'test_data', 'github_file_system') self._file_system = GithubFileSystem( AppEngineUrlFetcher(url_constants.GITHUB_URL), AppEngineBlobstore()) def _ReadLocalFile(self, filename): with open(os.path.join(self._base_path, filename), 'r') as f: return f.read() def testList(self): self.assertEqual(json.loads(self._ReadLocalFile('expected_list.json')), self._file_system.Read(['/']).Get()) def testRead(self): self.assertEqual(self._ReadLocalFile('expected_read.txt'), self._file_system.ReadSingle('/analytics/launch.js')) def testStat(self): self.assertEqual(0, self._file_system.Stat('zipball').version) def testKeyGeneration(self): self.assertEqual(0, len(files.GetBlobKeys())) self._file_system.ReadSingle('/analytics/launch.js') self.assertEqual(1, len(files.GetBlobKeys())) self._file_system.ReadSingle('/analytics/main.css') self.assertEqual(1, len(files.GetBlobKeys()))
def _GetOrCreateGithubFileSystem(): # Initialising github is pointless if samples are disabled, since it's only # used for apps samples. if ServerInstance.github_file_system is None: if _IsSamplesDisabled(): ServerInstance.github_file_system = EmptyDirFileSystem() else: ServerInstance.github_file_system = GithubFileSystem( AppEngineUrlFetcher(url_constants.GITHUB_URL), AppEngineBlobstore()) return ServerInstance.github_file_system
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)
def setUp(self): ConfigureFakeFetchers() self._base_path = os.path.join(sys.path[0], 'test_data', 'github_file_system') self._file_system = GithubFileSystem.CreateChromeAppsSamples( ObjectStoreCreator.ForTest())
def CreateAppSamplesFileSystem(self, object_store_creator): # TODO(kalman): CachingFileSystem wrapper for GithubFileSystem, but it's # not supported yet (see comment there). return (EmptyDirFileSystem() if IsDevServer() else GithubFileSystem.Create(object_store_creator))
DEFAULT_BRANCHES = {'extensions': 'stable', 'apps': 'trunk'} # Dev settings: # DEFAULT_BRANCHES = { 'extensions': 'local', 'apps': 'local' } # Increment this version to force the server to reload all pages in the first # cron job that is run. _VERSION = 0 BRANCH_UTILITY_MEMCACHE = InMemoryObjectStore('branch_utility') BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, DEFAULT_BRANCHES, AppEngineUrlFetcher(None), BRANCH_UTILITY_MEMCACHE) GITHUB_MEMCACHE = InMemoryObjectStore('github') GITHUB_FILE_SYSTEM = GithubFileSystem( AppEngineUrlFetcher(url_constants.GITHUB_URL), GITHUB_MEMCACHE, AppEngineBlobstore()) GITHUB_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( GITHUB_FILE_SYSTEM, GITHUB_MEMCACHE) EXTENSIONS_PATH = 'chrome/common/extensions' DOCS_PATH = 'docs' API_PATH = 'api' TEMPLATE_PATH = DOCS_PATH + '/templates' INTRO_PATH = TEMPLATE_PATH + '/intros' ARTICLE_PATH = TEMPLATE_PATH + '/articles' PUBLIC_TEMPLATE_PATH = TEMPLATE_PATH + '/public' PRIVATE_TEMPLATE_PATH = TEMPLATE_PATH + '/private' EXAMPLES_PATH = DOCS_PATH + '/examples' JSON_PATH = TEMPLATE_PATH + '/json'
def _GetOrCreateGithubFileSystem(): if ServerInstance.github_file_system is None: ServerInstance.github_file_system = GithubFileSystem( AppEngineUrlFetcher(url_constants.GITHUB_URL), AppEngineBlobstore()) return ServerInstance.github_file_system
def CreateAppSamplesFileSystem(self, object_store_creator): # TODO(kalman): OfflineServerInstance wrapper for GithubFileSystem, but # the cron job doesn't crawl the samples yet. return (EmptyDirFileSystem() if IsDevServer() else GithubFileSystem.Create(object_store_creator))