コード例 #1
0
ファイル: server_instance.py プロジェクト: qingchen1984/SPA
    def CreateOnline(channel):
        '''Creates/creates an online server instance, meaning that both local and
    subversion/github resources are queried.
    '''
        branch_utility = ServerInstance._GetOrCreateBranchUtility()
        branch = branch_utility.GetBranchNumberForChannelName(channel)

        if branch == 'trunk':
            svn_url = '/'.join((url_constants.SVN_TRUNK_URL, 'src',
                                svn_constants.EXTENSIONS_PATH))
        else:
            svn_url = '/'.join((url_constants.SVN_BRANCH_URL, branch, 'src',
                                svn_constants.EXTENSIONS_PATH))

        viewvc_url = svn_url.replace(url_constants.SVN_URL,
                                     url_constants.VIEWVC_URL)

        object_store_creator_factory = ObjectStoreCreator.Factory(
            GetAppVersion(), branch, start_empty=True)

        svn_file_system = CachingFileSystem(
            SubversionFileSystem(AppEngineUrlFetcher(svn_url),
                                 AppEngineUrlFetcher(viewvc_url)),
            object_store_creator_factory)

        return ServerInstance(channel, object_store_creator_factory,
                              svn_file_system,
                              ServerInstance._GetOrCreateGithubFileSystem())
コード例 #2
0
 def testWithCategory(self):
   store = self._creator.Create(_FooClass, category='hi')
   self.assertEqual(
       'class=_FooClass&category=hi&channel=trunk&app_version=%s' %
           GetAppVersion(),
       store.namespace)
   self.assertFalse(store.start_empty)
コード例 #3
0
ファイル: branch_utility.py プロジェクト: qingchen1984/SPA
 def __init__(self, fetch_url, fetcher, object_store=None):
     self._fetch_url = fetch_url
     self._fetcher = fetcher
     if object_store is None:
         object_store = (ObjectStoreCreator.SharedFactory(
             GetAppVersion()).Create(BranchUtility).Create())
     self._object_store = object_store
コード例 #4
0
 def __init__(self, fetcher, blobstore):
     self._fetcher = fetcher
     self._stat_object_store = (ObjectStoreCreator.SharedFactory(
         GetAppVersion()).Create(GithubFileSystem).Create())
     self._blobstore = blobstore
     self._version = None
     self._GetZip(self.Stat(ZIP_KEY).version)
コード例 #5
0
 def testIdentityNamespace(self):
     factory = _CreateFactory()
     compiled_fs = factory.CreateIdentity(CompiledFileSystemTest)
     self.assertEqual(
         'class=CompiledFileSystem&category=CompiledFileSystemTest/file&'
         'channel=test&app_version=%s' % GetAppVersion(),
         compiled_fs._file_object_store.namespace)
コード例 #6
0
    def Create(
            self,
            cls,
            category=None,
            # Override any of these for a custom configuration.
            start_empty=_unspecified,
            app_version=_unspecified):
        # Resolve namespace components.
        if start_empty is not _unspecified:
            start_empty = bool(start_empty)
        else:
            start_empty = self._start_empty
        if app_version is _unspecified:
            app_version = GetAppVersion()

        # Reserve & and = for namespace separators.
        for component in (category, app_version):
            if component and ('&' in component or '=' in component):
                raise ValueError('%s cannot be used in a namespace')

        namespace = '&'.join('%s=%s' % (key, value)
                             for key, value in (('class', cls.__name__),
                                                ('category', category),
                                                ('app_version', app_version))
                             if value is not None)

        if self._disable_wrappers:
            return self._store_type(namespace, start_empty=start_empty)

        if self._store_type is not None:
            chain = (self._store_type(namespace), )
        else:
            chain = (MemcacheObjectStore(namespace),
                     PersistentObjectStore(namespace))
        return CacheChainObjectStore(chain, start_empty=start_empty)
コード例 #7
0
def _MakeHeaders(username, password):
    headers = {
        'User-Agent': 'Chromium docserver %s' % GetAppVersion(),
        'Cache-Control': 'max-age=0',
    }
    if username is not None and password is not None:
        headers['Authorization'] = 'Basic %s' % base64.b64encode(
            '%s:%s' % (username, password))
    return headers
コード例 #8
0
    def testPopulateNamespace(self):
        def CheckNamespace(expected_file, expected_list, fs):
            self.assertEqual(expected_file, fs._file_object_store.namespace)
            self.assertEqual(expected_list, fs._list_object_store.namespace)

        factory = _CreateFactory()
        f = lambda x: x
        CheckNamespace(
            'class=CompiledFileSystem&category=CompiledFileSystemTest/file&'
            'channel=test&app_version=%s' % GetAppVersion(),
            'class=CompiledFileSystem&category=CompiledFileSystemTest/list&'
            'channel=test&app_version=%s' % GetAppVersion(),
            factory.Create(f, CompiledFileSystemTest))
        CheckNamespace(
            'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/file&'
            'channel=test&app_version=%s' % GetAppVersion(),
            'class=CompiledFileSystem&category=CompiledFileSystemTest/foo/list&'
            'channel=test&app_version=%s' % GetAppVersion(),
            factory.Create(f, CompiledFileSystemTest, category='foo'))
コード例 #9
0
    def testPopulateNamespace(self):
        def CheckNamespace(expected_file, expected_list, fs):
            self.assertEqual(expected_file, fs._file_object_store.namespace)
            self.assertEqual(expected_list, fs._list_object_store.namespace)

        compiled_fs_creator = _GetTestCompiledFsCreator()
        f = lambda x: x
        CheckNamespace(
            'class=CompiledFileSystem&'
            'category=CompiledFileSystemTest/TestFileSystem/file&'
            'app_version=%s' % GetAppVersion(), 'class=CompiledFileSystem&'
            'category=CompiledFileSystemTest/TestFileSystem/list&'
            'app_version=%s' % GetAppVersion(),
            compiled_fs_creator(f, CompiledFileSystemTest))
        CheckNamespace(
            'class=CompiledFileSystem&'
            'category=CompiledFileSystemTest/TestFileSystem/foo/file&'
            'app_version=%s' % GetAppVersion(), 'class=CompiledFileSystem&'
            'category=CompiledFileSystemTest/TestFileSystem/foo/list&'
            'app_version=%s' % GetAppVersion(),
            compiled_fs_creator(f, CompiledFileSystemTest, category='foo'))
コード例 #10
0
ファイル: server_instance.py プロジェクト: qingchen1984/SPA
 def GetOrCreateOffline(channel):
     '''Gets/creates a local ServerInstance, meaning that only resources local to
 the server - memcache, object store, etc, are queried. This amounts to not
 setting up the subversion nor github file systems.
 '''
     branch_utility = ServerInstance._GetOrCreateBranchUtility()
     branch = branch_utility.GetBranchNumberForChannelName(channel)
     object_store_creator_factory = ObjectStoreCreator.Factory(
         GetAppVersion(), branch)
     # No svn nor github file systems. Rely on the crons to fill the caches, and
     # for the caches to exist.
     return ServerInstance(
         channel,
         object_store_creator_factory,
         CachingFileSystem(OfflineFileSystem(SubversionFileSystem),
                           object_store_creator_factory),
         # TODO(kalman): convert GithubFileSystem to be wrappable in a
         # CachingFileSystem so that it can be replaced with an
         # OfflineFileSystem. Currently GFS doesn't set the child versions of
         # stat requests so it doesn't.
         ServerInstance._GetOrCreateGithubFileSystem())
コード例 #11
0
 def GetAppVersion(self):
     return GetAppVersion()
コード例 #12
0
 def testWithoutChannel(self):
   store = self._creator.Create(_FooClass, channel=None)
   self.assertEqual('class=_FooClass&app_version=%s' % GetAppVersion(),
                    store.namespace)
   self.assertFalse(store.start_empty)
コード例 #13
0
 def testVanilla(self):
   store = self._creator.Create(_FooClass)
   self.assertEqual(
       'class=_FooClass&channel=trunk&app_version=%s' % GetAppVersion(),
       store.namespace)
   self.assertFalse(store.start_empty)
コード例 #14
0
 def __init__(self, create_file_system):
     self.file_systems = []
     # A callback taking a revision and returning a file system.
     self._create_file_system = create_file_system
     self._app_version = GetAppVersion()