cubicweb/web/webctl.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 21 Mar 2019 14:33:54 +0100
changeset 12530 9d88e1177c35
parent 12282 61a332a50a2b
child 12567 26744ad37953
permissions -rw-r--r--
Remove Twisted web server Twisted web server is not used anymore and has been superseded by pyramid many years ago. Furthermore, our usage is not compatible with Python 3. So we drop the "etwist" sub-package. As a consequence, "all-in-one" configuration type gets dropped as it was Twisted-specific. We resurrect it in cubicweb/pyramid/config.py by only keeping options used by the "pyramid". Similarly, we introduce a AllInOneCreateHandler in cubicweb/pyramid/pyramidctl.py that is basically the one that lived in cubicweb/etwist/twctl.py and is used to create the "all-in-one" instance. Added a TODO here about "pyramid.ini" that could be generated at the end of bootstrap() method. In cubicweb/devtools/httptest.py, CubicWebServerTC is now equivalent to CubicWebWsgiTC and the latter is dropped.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8669
62213a34726e [db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7275
diff changeset
     1
# copyright 2003-2012 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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
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: 5415
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""cubicweb-ctl commands and command handlers common to twisted/modpython
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
web configuration
7132
e9c92bb79787 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    20
"""
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10235
diff changeset
    21
from __future__ import print_function
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
12282
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    23
import os
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    24
import os.path as osp
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    25
from shutil import copy, rmtree
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    26
7132
e9c92bb79787 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    27
from logilab.common.shellutils import ASK
e9c92bb79787 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    28
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    29
from cubicweb import ExecutionError
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    30
from cubicweb.cwctl import CWCTL
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    31
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    32
from cubicweb.toolsutils import Command, CommandHandler, underline_title
12281
5cc17bac799e [web] Add missing import of _DATA_DIR in webctl
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12268
diff changeset
    33
from cubicweb.web.webconfig import _DATA_DIR
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    34
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
7275
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    36
try:
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    37
    from os import symlink as linkdir
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    38
except ImportError:
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    39
    from shutil import copytree as linkdir
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    40
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
    41
12140
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    42
def rmtreecontent(dst):
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    43
    """Delete the content of the dst directory (but NOT the directory
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    44
       itself)"""
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    45
    for fname in os.listdir(dst):
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    46
        fpath = osp.join(dst, fname)
12159
8a1306c43656 [web] Do not try to rmtree symlinks in rmtreecontent()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12140
diff changeset
    47
        if osp.isfile(fpath) or osp.islink(fpath):
12140
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    48
            os.unlink(fpath)
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    49
        else:
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    50
            rmtree(fpath)
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    51
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    52
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
class WebCreateHandler(CommandHandler):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    cmdname = 'create'
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
    55
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    56
    def bootstrap(self, cubes, automatic=False, inputlevel=0):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        """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: 7132
diff changeset
    58
        if not automatic:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10235
diff changeset
    59
            print('\n' + underline_title('Generic web configuration'))
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    60
            config = self.config
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    61
            config.input_config('web', inputlevel)
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    62
            if ASK.confirm('Allow anonymous access ?', False):
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    63
                config.global_set_option('anonymous-user', 'anon')
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    64
                config.global_set_option('anonymous-password', 'anon')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1132
diff changeset
    65
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7132
diff changeset
    66
    def postcreate(self, *args, **kwargs):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2395
diff changeset
    67
        """hooks called once instance's initialization has been completed"""
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    68
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    69
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    70
class GenStaticDataDirMixIn(object):
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    71
    """Create a directory merging all data directory content from cubes and CW.
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    72
    """
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    73
    def generate_static_dir(self, config, dest=None, ask_clean=False, repo=None):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    74
        if not dest:
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    75
            dest = config['staticdir-path']
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    76
        if not dest:
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    77
            dest = osp.join(config.appdatahome, 'data')
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    78
        if osp.exists(dest):
12282
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    79
            if (config.verbosity
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    80
                    and (not ask_clean
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    81
                         or not (config.verbosity
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    82
                                 and ASK.confirm('Remove existing data directory %s?' % dest)))):
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    83
                raise ExecutionError('Directory %s already exists. '
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    84
                                     'Remove it first.' % dest)
12140
20035170160c [cwctl] do only clean static data dir content (closes #17069762)
David Douard <david.douard@logilab.fr>
parents: 11767
diff changeset
    85
            rmtreecontent(dest)
12282
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    86
        config.quick_start = True  # notify this is not a regular start
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    87
        # list all resources (no matter their order)
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    88
        resources = set()
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
    89
        for datadir in self._datadirs(config, repo=repo):
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    90
            for dirpath, dirnames, filenames in os.walk(datadir):
12282
61a332a50a2b Flake8 cubicweb/web/webctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12281
diff changeset
    91
                rel_dirpath = dirpath[len(datadir) + 1:]
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    92
                resources.update(osp.join(rel_dirpath, f) for f in filenames)
11438
828483a88825 [webctl] set uid of file produced by gen-static-datadir (closes #11298794)
David Douard <david.douard@logilab.fr>
parents: 10589
diff changeset
    93
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    94
        # locate resources and copy them to destination
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
    95
        for resource in resources:
9306
8ab0e601d418 [web] don't rename resources in gen-static-datadir
Julien Cristau <julien.cristau@logilab.fr>
parents: 8669
diff changeset
    96
            dest_resource = osp.join(dest, resource)
8ab0e601d418 [web] don't rename resources in gen-static-datadir
Julien Cristau <julien.cristau@logilab.fr>
parents: 8669
diff changeset
    97
            dirname = osp.dirname(dest_resource)
8ab0e601d418 [web] don't rename resources in gen-static-datadir
Julien Cristau <julien.cristau@logilab.fr>
parents: 8669
diff changeset
    98
            if not osp.isdir(dirname):
8ab0e601d418 [web] don't rename resources in gen-static-datadir
Julien Cristau <julien.cristau@logilab.fr>
parents: 8669
diff changeset
    99
                os.makedirs(dirname)
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   100
            resource_dir, resource_path = config.locate_resource(resource)
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   101
            copy(osp.join(resource_dir, resource_path), dest_resource)
7275
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
   102
        # handle md5 version subdirectory
bb3bb8104134 put data version md5 into a new url segment to ease static serving
Florent Cayré <florent.cayre@gmail.com>
parents: 7274
diff changeset
   103
        linkdir(dest, osp.join(dest, config.instance_md5_version()))
11438
828483a88825 [webctl] set uid of file produced by gen-static-datadir (closes #11298794)
David Douard <david.douard@logilab.fr>
parents: 10589
diff changeset
   104
        # ensure generated files are owned by configured uid
828483a88825 [webctl] set uid of file produced by gen-static-datadir (closes #11298794)
David Douard <david.douard@logilab.fr>
parents: 10589
diff changeset
   105
        config.ensure_uid_directory(dest)
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10235
diff changeset
   106
        print('You can use apache rewrite rule below :\n'
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10235
diff changeset
   107
              'RewriteRule ^/data/(.*) %s/$1 [L]' % dest)
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   108
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   109
    def _datadirs(self, config, repo=None):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   110
        if repo is None:
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   111
            repo = config.repository()
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   112
        if config._cubes is None:
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   113
            # web only config
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   114
            config.init_cubes(repo.get_cubes())
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   115
        for cube in repo.get_cubes():
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   116
            cube_datadir = osp.join(cwcfg.cube_dir(cube), 'data')
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   117
            if osp.isdir(cube_datadir):
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   118
                yield cube_datadir
12268
d84bc85f7f70 [config] Avoid relying on shared_dir method when possible
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 12197
diff changeset
   119
        yield _DATA_DIR
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   120
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   121
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   122
class WebUpgradeHandler(CommandHandler, GenStaticDataDirMixIn):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   123
    cmdname = 'upgrade'
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   124
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   125
    def postupgrade(self, repo):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   126
        config = self.config
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   127
        if not config['generate-staticdir']:
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   128
            return
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   129
        self.generate_static_dir(config, ask_clean=True, repo=repo)
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   130
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   131
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   132
class GenStaticDataDir(Command, GenStaticDataDirMixIn):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   133
    """Create a directory merging all data directory content from cubes and CW.
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   134
    """
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   135
    name = 'gen-static-datadir'
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   136
    arguments = '<instance> [dirpath]'
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   137
    min_args = 1
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   138
    max_args = 2
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   139
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   140
    options = ()
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   141
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   142
    def run(self, args):
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   143
        appid = args.pop(0)
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   144
        config = cwcfg.config_for(appid)
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   145
        dest = None
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   146
        if args:
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   147
            dest = args[0]
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   148
        self.generate_static_dir(config, dest)
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   149
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9306
diff changeset
   150
7274
4653a2a5110b add cwctl command to generate a consolidated data directory with all cubes/ cubicweb data directories content to be delivered statically
Florent Cayré <florent.cayre@gmail.com>
parents: 7140
diff changeset
   151
CWCTL.register(GenStaticDataDir)