etwist/twctl.py
author Rémi Cardona <remi.cardona@logilab.fr>
Fri, 11 Sep 2015 17:40:23 +0200
changeset 10617 c36cda9074c5
parent 10237 1e030b1a5622
child 10898 c96d67251a9d
permissions -rw-r--r--
[py3k] io.StringIO
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6778
diff changeset
     1
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5814
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5752
diff changeset
    18
"""cubicweb-clt handlers for twisted"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
7619
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    20
from os.path import join
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    21
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    22
from logilab.common.shellutils import rm
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    23
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from cubicweb.toolsutils import CommandHandler
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    25
from cubicweb.web.webctl import WebCreateHandler, WebUpgradeHandler
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
# trigger configuration registration
6491
ee9a10b6620e pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
    28
import cubicweb.etwist.twconfig # pylint: disable=W0611
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
3820
52cd7432030d c-c create stopped asking if anonymous access should be activated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
    30
class TWCreateHandler(WebCreateHandler):
52cd7432030d c-c create stopped asking if anonymous access should be activated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
    31
    cfgname = 'twisted'
52cd7432030d c-c create stopped asking if anonymous access should be activated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
    32
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
class TWStartHandler(CommandHandler):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    cmdname = 'start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    cfgname = 'twisted'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
5442
3ed8afbbdf70 [webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    37
    def start_server(self, config):
2654
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2476
diff changeset
    38
        from cubicweb.etwist import server
7619
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    39
        config.info('clear ui caches')
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    40
        for cachedir in ('uicache', 'uicachehttps'):
0d0344fd5231 [etwist] clear ui cache at server startup time. Closes #1806933
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7140
diff changeset
    41
            rm(join(config.appdatahome, cachedir, '*'))
6778
7dd4835d5198 properly tell we've started an instance (close #1391262)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6491
diff changeset
    42
        return server.run(config)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
class TWStopHandler(CommandHandler):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
    cmdname = 'stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    cfgname = 'twisted'
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    47
5741
bbef88618fbb [twctl] add missing poststop method #1058268
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5424
diff changeset
    48
    def poststop(self):
bbef88618fbb [twctl] add missing poststop method #1058268
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5424
diff changeset
    49
        pass
bbef88618fbb [twctl] add missing poststop method #1058268
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5424
diff changeset
    50
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    51
class TWUpgradeHandler(WebUpgradeHandler):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    52
    cfgname = 'twisted'
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    53
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    54
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    from cubicweb.server import serverctl
3820
52cd7432030d c-c create stopped asking if anonymous access should be activated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
    57
    class AllInOneCreateHandler(serverctl.RepositoryCreateHandler,
52cd7432030d c-c create stopped asking if anonymous access should be activated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
    58
                                TWCreateHandler):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2395
diff changeset
    59
        """configuration to get an instance running in a twisted web server
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2395
diff changeset
    60
        integrating a repository server in the same process
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        cfgname = 'all-in-one'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6778
diff changeset
    64
        def bootstrap(self, cubes, automatic=False, inputlevel=0):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            """bootstrap this configuration"""
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6778
diff changeset
    66
            serverctl.RepositoryCreateHandler.bootstrap(self, cubes, automatic, inputlevel)
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6778
diff changeset
    67
            TWCreateHandler.bootstrap(self, cubes, automatic, inputlevel)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    68
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    class AllInOneStartHandler(TWStartHandler):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        cmdname = 'start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        cfgname = 'all-in-one'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
        subcommand = 'cubicweb-twisted'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
10237
1e030b1a5622 Remove leftover bits from start-repository command, and document its demise
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
    74
    class AllInOneStopHandler(CommandHandler):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        cmdname = 'stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        cfgname = 'all-in-one'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        subcommand = 'cubicweb-twisted'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
10237
1e030b1a5622 Remove leftover bits from start-repository command, and document its demise
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
    79
        def poststop(self):
1e030b1a5622 Remove leftover bits from start-repository command, and document its demise
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
    80
            pass
1e030b1a5622 Remove leftover bits from start-repository command, and document its demise
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
    81
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    82
    class AllInOneUpgradeHandler(TWUpgradeHandler):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    83
        cfgname = 'all-in-one'
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7619
diff changeset
    84
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
except ImportError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    pass