~bzr/bzr-webserve/webserve-dev

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# web interface to a bazaar repository
#
# Copyright 2006 Goffredo Baroncelli <kreijack@inwind.it>
#
# This file is part of bazaar-webserve.
#
# bazaar-webserve is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bazaar-webserve is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bazaar-webserve; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import bzrlib
from bzrlib.option import Option

class cmd_webserve(bzrlib.commands.Command):
    """Start the 'webserve' web interface"""

    takes_options = [
        Option('templates', type=str),
        Option('address', type=str),
        Option('port', type=int),
        Option('ipv6'),
        Option('acceslog', type=str),
        Option('errorlog', type=str),
        Option('lock'),
        Option('profile'),
        Option('tararchive'),
        Option('style', type=str),
        Option('fileserver'),
        Option('commentfilter', type=str),
        Option('encoding', type=str),
    ]
    takes_args = ['name?', 'rootrepository?']

    def run(self, name = None, rootrepository = None,
            templates = None, address = "", port = 8088, ipv6 = None,
            accesslog = '', errorlog = '', lock=None, profile=None,
            tararchive=None, style="", fileserver=None, commentfilter=None,
            encoding=None):

        import hgweb
        import os

        if rootrepository == None:
            rootrepository = os.getcwd()
        if name == None:
            name = os.path.basename(rootrepository)
        #if templates == None:
        #    templates = os.path.join( rootrepository, "templates")

        if style:
            style = "map-"+style
        else:
            style = "map"

        httpd = hgweb.create_server(
                 path=rootrepository,
                 name=name,
                 templates=templates,
                 address=address,
                 port=port,
                 use_ipv6=ipv6,
                 accesslog=accesslog,
                 errorlog=errorlog,
                 # dolock=lock, removed  22/12/2007
                 tararchive=tararchive,
                 profile=profile,
                 mapfile=style,
                 option_provide_file=fileserver,
                 commentfilter=commentfilter and commentfilter.split(";;") or [],
                 encoding=encoding)
        httpd.serve_forever()


bzrlib.commands.register_command(cmd_webserve)


def _iter_test_suite( ):
    from bzrlib.bzrdir import format_registry

    for k in format_registry.keys():
        if k == 'default':
            continue
        info = format_registry.get_info(k)
        if not info.hidden and not info.deprecated:
            fmtname = k.replace('-','_').replace('.','_')
            yield fmtname, {'format': k }

def test_suite():
    """Generate suite containing all parameterized tests"""

    from bzrlib.tests import (
        multiply_tests_from_modules,
        TestScenarioApplier,
        iter_suite_tests,
    )
    from bzrlib.tests.TestUtil import (
                          TestSuite,
                          TestLoader,
                          )

    import test_webserve_repo
    import test_webserve_general


    loader = TestLoader()
    suite = TestSuite()
    adapter = TestScenarioApplier()
    adapter.scenarios = list(_iter_test_suite())

    for test in iter_suite_tests(loader.loadTestsFromModule(test_webserve_repo)):
        suite.addTests(adapter.adapt(test))

    suite.addTests(loader.loadTestsFromModule(test_webserve_general))

    return suite