Ejemplo n.º 1
0
    def test_00_repo_is_root_bare(self):
        _base_path = os.path.join(self.base_path,"projects","demorepoone")
        _rpc_tree = dict(grm.assemble_methods_list(_base_path))
        _m = _rpc_tree['browser.path_summary']

        r1 = _m('')
        r2 = _m('/')
        r3 = _m('\\')
        self.assertEquals(
            r1,
            r2
        )
        self.assertEquals(
            r2,
            r3
        )
        self.assertEquals(
            r1,
            {'data': {'endpoints': [{'branches': ['master'], 'author': 'D.Dotsenko', 'author_email': '*****@*****.**', 'tags': [], 'summary': 'Adding submodule for testing.', 'time': 'Sun Oct 31 05:15:14 2010 UTC', 'auth_time': 'Sat Oct 30 08:20:33 2010 UTC', 'id': '3408e8f7720eff4a1fd16e9bf654332036c39bf8'}, {'branches': ['experimental'], 'author': 'D. Dotsenko', 'author_email': '*****@*****.**', 'tags': [], 'summary': 'Starting evern more radical feature.', 'time': 'Mon Oct 18 01:22:24 2010 UTC', 'auth_time': 'Mon Oct 18 01:22:24 2010 UTC', 'id': '885f5a29f0bede312686c9cabcef1dcd9c418fb4'}, {'branches': ['stable'], 'author': 'D. Dotsenko', 'author_email': '*****@*****.**', 'tags': ['0.2'], 'summary': 'Adding new feature.', 'time': 'Mon Oct 18 01:18:55 2010 UTC', 'auth_time': 'Mon Oct 18 01:18:55 2010 UTC', 'id': '263e545b2227821bd7254bfb60fb11dae3aa9d0b'}, {'branches': [], 'author': 'D. Dotsenko', 'author_email': '*****@*****.**', 'tags': ['0.1'], 'summary': 'Changed firstdoc.txt', 'time': 'Mon Oct 18 01:17:21 2010 UTC', 'auth_time': 'Mon Oct 18 01:17:21 2010 UTC', 'id': '457c6388d3d6f2608038a543e272e7fc1dfc2082'}], 'description': "Unnamed repository; edit this file 'description' to name the repository."}, 'meta': {'path': '', 'repo_path': '/'}, 'type': 'repo'}
        )
Ejemplo n.º 2
0
def assemble_ges_app(*args, **kw):
    '''
    Assembles G.E.S. WSGI application.

    path_prefix = '.',
    static_content_path = './static'
    repo_uri_marker = ''

    path_prefix (Defaults to '.' = "current" directory)
        The path to the folder that will be the root of served files. Accepts relative paths.

    repo_uri_marker (Defaults to '')
        Acts as a "virtual folder" separator between decorative URI portion and
        the actual (relative to path_prefix) path that will be appended to
        path_prefix and used for pulling an actual file.

        the URI does not have to start with contents of repo_uri_marker. It can
        be preceeded by any number of "virtual" folders. For --repo_uri_marker 'my'
        all of these will take you to the same repo:
            http://localhost/my/HEAD
            http://localhost/admysf/mylar/zxmy/my/HEAD
        This WSGI hanlder will cut and rebase the URI when it's time to read from file system.

        Default of '' means that no cutting marker is used, and whole URI after FQDN is
        used to find file relative to path_prefix.

    returns WSGI application instance.
    '''

    default_options = [
        ['content_path','.'],
        ['static_content_path', './static'],
        ['uri_marker','']
    ]
    options = dict(default_options)
    options.update(kw)

    # this unfolds args into options in order of default_options
    args = list(args) # need this to allow .pop method on it.
    while default_options and args:
        _d = default_options.pop(0)
        _a = args.pop(0)
        options[_d[0]] = _a
    for _e in ['content_path','static_content_path']:
        options[_e] = os.path.abspath(options[_e].decode('utf8'))
    options['uri_marker'] = options['uri_marker'].decode('utf8')
    if not os.path.isfile(os.path.join(options['static_content_path'],'favicon.ico')):
        raise Exception('G.E.S.: Specified static content directory - "%s" - does not contain expected files. Please, provide correct "static_content_path" variable value.' % options['static_content_path'])

    # assembling JSONRPC WSGI app
    # it has two parts:
    #  (a) ges-specific RPC methods that return JSON-compatible objects
    #  (b) generic WSGI JSONRPC wrapper for stuff like (a)
    _methods_list = ges_rpc_methods.assemble_methods_list(
        options['content_path']
        )
    _jsonrpc_app = jrpc.WSGIJSONRPCApplication()
    for path, method_pointer in _methods_list:
        _jsonrpc_app.add_method(path, method_pointer)

    _serve_index_file = serve_index_file.ServeIndexFile(**options)

    # assembling static file server WSGI app
    _static_server_app = git_http_backend.StaticWSGIServer(content_path = options['static_content_path'])

    # git_http_backend-specific server components.
    git_inforefs_handler = git_http_backend.GitHTTPBackendInfoRefs(**options)
    git_rpc_handler = git_http_backend.GitHTTPBackendSmartHTTP(**options)
    fuzzy_handler = fuzzy_path_handler.FuzzyPathHandler(**options)

    if options['uri_marker']:
        marker_regex = r'(?P<decorative_path>.*?)(?:/'+ options['uri_marker'] + ')'
    else:
        marker_regex = r''
    selector = git_http_backend.WSGIHandlerSelector()
    selector.add(
        (marker_regex or '/') + '$',
        _serve_index_file)
    selector.add(
        marker_regex + r'/rpc[/]*$',
        _jsonrpc_app)
    selector.add(
        marker_regex + r'/favicon.ico$',
        GET = _static_server_app,
        HEAD = _static_server_app)
    selector.add(
        marker_regex + r'/static/(?P<working_path>.*)$',
        GET = _static_server_app,
        HEAD = _static_server_app)
    selector.add(
        marker_regex + r'/(?P<working_path>.*?)/info/refs\?.*?service=(?P<git_command>git-[^&]+).*$',
        GET = git_inforefs_handler,
        HEAD = git_inforefs_handler
        )
    selector.add(
        marker_regex + r'/(?P<working_path>.*)/(?P<git_command>git-[^/]+)$',
        POST = git_rpc_handler
        )
    selector.add(
        marker_regex + r'/(?P<working_path>.*)$',
        GET = fuzzy_handler,
        HEAD = fuzzy_handler)

    if 'devel' in options or 'debug' in options:
        import wsgilog
        return wsgilog.WsgiLog(selector, tostream=True, toprint=True)
    return selector
Ejemplo n.º 3
0
 def setUp(self):
     _p = tempfile.mkdtemp()
     zipfile.ZipFile('./test/sample_tree_of_repos_v2.zip').extractall(_p)
     self.base_path = os.path.join(_p, 'reposbase')
     self._rpc_tree = dict(grm.assemble_methods_list(self.base_path))
Ejemplo n.º 4
0
def assemble_ges_app(*args, **kw):
    '''
    Assembles G.E.S. WSGI application.

    path_prefix = '.',
    static_content_path = './static'
    repo_uri_marker = ''

    path_prefix (Defaults to '.' = "current" directory)
        The path to the folder that will be the root of served files. Accepts relative paths.

    repo_uri_marker (Defaults to '')
        Acts as a "virtual folder" separator between decorative URI portion and
        the actual (relative to path_prefix) path that will be appended to
        path_prefix and used for pulling an actual file.

        the URI does not have to start with contents of repo_uri_marker. It can
        be preceeded by any number of "virtual" folders. For --repo_uri_marker 'my'
        all of these will take you to the same repo:
            http://localhost/my/HEAD
            http://localhost/admysf/mylar/zxmy/my/HEAD
        This WSGI hanlder will cut and rebase the URI when it's time to read from file system.

        Default of '' means that no cutting marker is used, and whole URI after FQDN is
        used to find file relative to path_prefix.

    returns WSGI application instance.
    '''

    default_options = [['content_path', '.'],
                       ['static_content_path', './static'], ['uri_marker', '']]
    options = dict(default_options)
    options.update(kw)

    # this unfolds args into options in order of default_options
    args = list(args)  # need this to allow .pop method on it.
    while default_options and args:
        _d = default_options.pop(0)
        _a = args.pop(0)
        options[_d[0]] = _a
    for _e in ['content_path', 'static_content_path']:
        options[_e] = os.path.abspath(options[_e].decode('utf8'))
    options['uri_marker'] = options['uri_marker'].decode('utf8')
    if not os.path.isfile(
            os.path.join(options['static_content_path'], 'favicon.ico')):
        raise Exception(
            'G.E.S.: Specified static content directory - "%s" - does not contain expected files. Please, provide correct "static_content_path" variable value.'
            % options['static_content_path'])

    # assembling JSONRPC WSGI app
    # it has two parts:
    #  (a) ges-specific RPC methods that return JSON-compatible objects
    #  (b) generic WSGI JSONRPC wrapper for stuff like (a)
    _methods_list = ges_rpc_methods.assemble_methods_list(
        options['content_path'])
    _jsonrpc_app = jrpc.WSGIJSONRPCApplication()
    for path, method_pointer in _methods_list:
        _jsonrpc_app.add_method(path, method_pointer)

    _serve_index_file = serve_index_file.ServeIndexFile(**options)

    # assembling static file server WSGI app
    _static_server_app = git_http_backend.StaticWSGIServer(
        content_path=options['static_content_path'])

    # git_http_backend-specific server components.
    git_inforefs_handler = git_http_backend.GitHTTPBackendInfoRefs(**options)
    git_rpc_handler = git_http_backend.GitHTTPBackendSmartHTTP(**options)
    fuzzy_handler = fuzzy_path_handler.FuzzyPathHandler(**options)

    if options['uri_marker']:
        marker_regex = r'(?P<decorative_path>.*?)(?:/' + options[
            'uri_marker'] + ')'
    else:
        marker_regex = r''
    selector = git_http_backend.WSGIHandlerSelector()
    selector.add((marker_regex or '/') + '$', _serve_index_file)
    selector.add(marker_regex + r'/rpc[/]*$', _jsonrpc_app)
    selector.add(marker_regex + r'/favicon.ico$',
                 GET=_static_server_app,
                 HEAD=_static_server_app)
    selector.add(marker_regex + r'/static/(?P<working_path>.*)$',
                 GET=_static_server_app,
                 HEAD=_static_server_app)
    selector.add(
        marker_regex +
        r'/(?P<working_path>.*?)/info/refs\?.*?service=(?P<git_command>git-[^&]+).*$',
        GET=git_inforefs_handler,
        HEAD=git_inforefs_handler)
    selector.add(marker_regex +
                 r'/(?P<working_path>.*)/(?P<git_command>git-[^/]+)$',
                 POST=git_rpc_handler)
    selector.add(marker_regex + r'/(?P<working_path>.*)$',
                 GET=fuzzy_handler,
                 HEAD=fuzzy_handler)

    if 'devel' in options or 'debug' in options:
        import wsgilog
        return wsgilog.WsgiLog(selector, tostream=True, toprint=True)
    return selector