def testGetBranchNumberForChannelName(self): b_util = BranchUtility(test_urlfetch) b_util.SetURL('branch_utility/first.json') self.assertEquals('1132', b_util.GetBranchNumberForChannelName('dev')) self.assertEquals('1084', b_util.GetBranchNumberForChannelName('beta')) self.assertEquals('1234', b_util.GetBranchNumberForChannelName('stable')) self.assertEquals('trunk', b_util.GetBranchNumberForChannelName('trunk'))
def get(self): path = self.request.path.replace('/chrome/extensions/', '') parts = path.split('/') if len(parts) > 1: filename = parts[1] else: filename = parts[0] if len(path) > 0 and path[0] == '/': path = path.strip('/') fetcher = SubversionFetcher(urlfetch) b_util = BranchUtility(urlfetch) channel_name = b_util.GetChannelNameFromPath(path) branch = b_util.GetBranchNumberForChannelName(channel_name) logging.info(channel_name + ' ' + branch) try: result = fetcher.FetchResource(branch, EXTENSIONS_PATH + filename) content = result.content for key in result.headers: self.response.headers[key] = result.headers[key] except: content = 'File not found.' self.response.out.write(content)
class BranchUtilityTest(unittest.TestCase): def setUp(self): self._branch_util = BranchUtility( os.path.join('branch_utility', 'first.json'), FakeUrlFetcher(os.path.join(sys.path[0], 'test_data')), object_store=TestObjectStore('test')) def testSplitChannelNameFromPath(self): self.assertEquals(('stable', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'stable/extensions/stuff.html')) self.assertEquals(('dev', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'dev/extensions/stuff.html')) self.assertEquals(('beta', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'beta/extensions/stuff.html')) self.assertEquals(('trunk', 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'trunk/extensions/stuff.html')) self.assertEquals((None, 'extensions/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/stuff.html')) self.assertEquals( (None, 'apps/stuff.html'), self._branch_util.SplitChannelNameFromPath('apps/stuff.html')) self.assertEquals((None, 'extensions/dev/stuff.html'), self._branch_util.SplitChannelNameFromPath( 'extensions/dev/stuff.html')) self.assertEquals( (None, 'stuff.html'), self._branch_util.SplitChannelNameFromPath('stuff.html')) def testGetBranchNumberForChannelName(self): self.assertEquals( '1145', self._branch_util.GetBranchNumberForChannelName('dev')) self.assertEquals( '1084', self._branch_util.GetBranchNumberForChannelName('beta')) self.assertEquals( '1084', self._branch_util.GetBranchNumberForChannelName('stable')) self.assertEquals( 'trunk', self._branch_util.GetBranchNumberForChannelName('trunk'))
def _SplitFilenameUnix(files): return [UnixName(os.path.splitext(f.split('/')[-1])[0]) for f in files] def _CreateMemcacheFileSystem(branch, branch_memcache): svn_url = _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH stat_fetcher = AppEngineUrlFetcher( svn_url.replace(url_constants.SVN_URL, url_constants.VIEWVC_URL)) fetcher = AppEngineUrlFetcher(svn_url) return MemcacheFileSystem(SubversionFileSystem(fetcher, stat_fetcher), branch_memcache) APPS_BRANCH = BRANCH_UTILITY.GetBranchNumberForChannelName( DEFAULT_BRANCHES['apps']) APPS_MEMCACHE = InMemoryObjectStore(APPS_BRANCH) APPS_FILE_SYSTEM = _CreateMemcacheFileSystem(APPS_BRANCH, APPS_MEMCACHE) APPS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory(APPS_FILE_SYSTEM, APPS_MEMCACHE).Create( _SplitFilenameUnix, compiled_fs.APPS_FS) EXTENSIONS_BRANCH = BRANCH_UTILITY.GetBranchNumberForChannelName( DEFAULT_BRANCHES['extensions']) EXTENSIONS_MEMCACHE = InMemoryObjectStore(EXTENSIONS_BRANCH) EXTENSIONS_FILE_SYSTEM = _CreateMemcacheFileSystem(EXTENSIONS_BRANCH, EXTENSIONS_MEMCACHE) EXTENSIONS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( EXTENSIONS_FILE_SYSTEM, EXTENSIONS_MEMCACHE).Create(_SplitFilenameUnix, compiled_fs.EXTENSIONS_FS)
if branch == 'trunk': return url_constants.SVN_TRUNK_URL + '/src' return url_constants.SVN_BRANCH_URL + '/' + branch + '/src' def _SplitFilenameUnix(base_dir, files): return [UnixName(os.path.splitext(f.split('/')[-1])[0]) for f in files] def _CreateMemcacheFileSystem(branch, branch_memcache): svn_url = _GetURLFromBranch(branch) + '/' + EXTENSIONS_PATH stat_fetcher = AppEngineUrlFetcher( svn_url.replace(url_constants.SVN_URL, url_constants.VIEWVC_URL)) fetcher = AppEngineUrlFetcher(svn_url) return MemcacheFileSystem(SubversionFileSystem(fetcher, stat_fetcher), branch_memcache) _default_branch = BRANCH_UTILITY.GetBranchNumberForChannelName(_DEFAULT_CHANNEL) APPS_MEMCACHE = InMemoryObjectStore(_default_branch) APPS_FILE_SYSTEM = _CreateMemcacheFileSystem(_default_branch, APPS_MEMCACHE) APPS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( APPS_FILE_SYSTEM, APPS_MEMCACHE).Create(_SplitFilenameUnix, compiled_fs.APPS_FS) EXTENSIONS_MEMCACHE = InMemoryObjectStore(_default_branch) EXTENSIONS_FILE_SYSTEM = _CreateMemcacheFileSystem(_default_branch, EXTENSIONS_MEMCACHE) EXTENSIONS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( EXTENSIONS_FILE_SYSTEM, EXTENSIONS_MEMCACHE).Create(_SplitFilenameUnix, compiled_fs.EXTENSIONS_FS) KNOWN_ISSUES_DATA_SOURCE = KnownIssuesDataSource( InMemoryObjectStore('KnownIssues'),