cwctl.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 24 Sep 2015 11:26:11 +0200
changeset 10921 977def81780a
parent 10736 8d49849ec2a6
child 11104 269317987dc6
permissions -rw-r--r--
[migration] don't handle data deletion anymore on schema changes In most cases when we want to drop some entity/relation type, we don't care whether hooks are called on their deletion. There is even low chances that some hooks still exists, based on an old version of the schema. Last but not least, this is horribly inefficient. So this should be clearly documented and handled by application's programmer if desired. This patch removes unnecessary deletion (because table or column will be later dropped) and reimplements the case of partial deletion (only one relation definition among several, hence the database structure isn't modified) using sql. Only one test regarding deletion of inlined relation def is added as other cases seem to be covered by existing tests. Closes #7023315
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10235
684215aca046 Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10109
diff changeset
     1
# copyright 2003-2014 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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
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: 5288
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
4720
ddf4f19eb07a don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4718
diff changeset
    18
"""the cubicweb-ctl tool, based on logilab.common.clcommands to
ddf4f19eb07a don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4718
diff changeset
    19
provide a pluggable commands system.
5814
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
    20
"""
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
    21
from __future__ import print_function
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
4720
ddf4f19eb07a don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4718
diff changeset
    23
__docformat__ = "restructuredtext en"
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
4718
3dc3ad02d091 avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4684
diff changeset
    25
# *ctl module should limit the number of import to be imported as quickly as
3dc3ad02d091 avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4684
diff changeset
    26
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
3dc3ad02d091 avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4684
diff changeset
    27
# completion). So import locally in command helpers.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
import sys
10321
a4af502191d5 [cwctl] don't filter DeprecationWarnings
Julien Cristau <julien.cristau@logilab.fr>
parents: 10235
diff changeset
    29
from warnings import warn, filterwarnings
3115
29262ba01464 minimal steps to have cw running on windows
Aurélien Campéas
parents: 2905
diff changeset
    30
from os import remove, listdir, system, pathsep
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: 8564
diff changeset
    31
from os.path import exists, join, isfile, isdir, dirname, abspath
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
    32
3115
29262ba01464 minimal steps to have cw running on windows
Aurélien Campéas
parents: 2905
diff changeset
    33
try:
3562
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3560
diff changeset
    34
    from os import kill, getpgid
3115
29262ba01464 minimal steps to have cw running on windows
Aurélien Campéas
parents: 2905
diff changeset
    35
except ImportError:
4721
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4720
diff changeset
    36
    def kill(*args):
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4720
diff changeset
    37
        """win32 kill implementation"""
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4720
diff changeset
    38
    def getpgid():
8f63691ccb7f pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4720
diff changeset
    39
        """win32 getpgid implementation"""
3115
29262ba01464 minimal steps to have cw running on windows
Aurélien Campéas
parents: 2905
diff changeset
    40
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10589
diff changeset
    41
from six.moves.urllib.parse import urlparse
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10589
diff changeset
    42
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
    43
from logilab.common.clcommands import CommandLine
2615
1ea41b7c0836 F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2532
diff changeset
    44
from logilab.common.shellutils import ASK
9002
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
    45
from logilab.common.configuration import merge_options
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
    46
2790
968108e16066 move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2743
diff changeset
    47
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
6914
5be96d9cbedc [c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6845
diff changeset
    48
from cubicweb.utils import support_args
3638
648d6dbec630 system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3619
diff changeset
    49
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
    50
from cubicweb.toolsutils import Command, rm, create_dir, underline_title
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
    51
from cubicweb.__pkginfo__ import version
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
    52
9371
1348202527a6 [cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents: 9340
diff changeset
    53
# don't check duplicated commands, it occurs when reloading site_cubicweb
1348202527a6 [cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents: 9340
diff changeset
    54
CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
1348202527a6 [cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents: 9340
diff changeset
    55
                    version=version, check_duplicated_command=False)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
    56
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
def wait_process_end(pid, maxtry=10, waittime=1):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    """wait for a process to actually die"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    import signal
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
    from time import sleep
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    nbtry = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
    while nbtry < maxtry:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
            kill(pid, signal.SIGUSR1)
3117
32686ae66c75 mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents: 3115
diff changeset
    65
        except (OSError, AttributeError): # XXX win32
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
            break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
        nbtry += 1
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        sleep(waittime)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        raise ExecutionError('can\'t kill process %s' % pid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
def list_instances(regdir):
6505
ac4cecb26813 [distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6145
diff changeset
    73
    if isdir(regdir):
ac4cecb26813 [distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6145
diff changeset
    74
        return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir)))
ac4cecb26813 [distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6145
diff changeset
    75
    else:
ac4cecb26813 [distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6145
diff changeset
    76
        return []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
def detect_available_modes(templdir):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    modes = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    for fname in ('schema', 'schema.py'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        if exists(join(templdir, fname)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
            modes.append('repository')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
            break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    for fname in ('data', 'views', 'views.py'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        if exists(join(templdir, fname)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
            modes.append('web ui')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
            break
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
    return modes
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
    89
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
    90
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
    91
class InstanceCommand(Command):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
    92
    """base class for command taking 0 to n instance id as arguments
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
    93
    (0 meaning all registered instances)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
    """
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
    95
    arguments = '[<instance>...]'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
    options = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
        ("force",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
         {'short': 'f', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
          'default': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
          'help': 'force command without asking confirmation',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
          }
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
         ),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    actionverb = None
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   105
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    def ordered_instances(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        """return instances in the order in which they should be started,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        considering $REGISTRY_DIR/startorder file if it exists (useful when
3619
af81a4f7053e enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3562
diff changeset
   109
        some instances depends on another as external source).
af81a4f7053e enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3562
diff changeset
   110
af81a4f7053e enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3562
diff changeset
   111
        Instance used by another one should appears first in the file (one
af81a4f7053e enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3562
diff changeset
   112
        instance per line)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        """
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
   114
        regdir = cwcfg.instances_dir()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
        _allinstances = list_instances(regdir)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
        if isfile(join(regdir, 'startorder')):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            allinstances = []
10614
57dfde80df11 [py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
   118
            for line in open(join(regdir, 'startorder')):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
                line = line.strip()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                if line and not line.startswith('#'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
                    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
                        _allinstances.remove(line)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
                        allinstances.append(line)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                    except ValueError:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   125
                        print('ERROR: startorder file contains unexistant '
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   126
                              'instance %s' % line)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
            allinstances += _allinstances
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
            allinstances = _allinstances
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
        return allinstances
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   131
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    def run(self, args):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   133
        """run the <command>_method on each argument (a list of instance
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        identifiers)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        if not args:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
            args = self.ordered_instances()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
                askconfirm = not self.config.force
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
            except AttributeError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
                # no force option
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
                askconfirm = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
            askconfirm = False
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
        self.run_args(args, askconfirm)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   146
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
    def run_args(self, args, askconfirm):
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   148
        status = 0
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        for appid in args:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
            if askconfirm:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   151
                print('*'*72)
2743
b0e79a77ad67 [c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   152
                if not ASK.confirm('%s instance %r ?' % (self.name, appid)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
                    continue
7593
0c1024b3e7fc [c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7538
diff changeset
   154
            try:
0c1024b3e7fc [c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7538
diff changeset
   155
                status = max(status, self.run_arg(appid))
0c1024b3e7fc [c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7538
diff changeset
   156
            except (KeyboardInterrupt, SystemExit):
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   157
                sys.stderr.write('%s aborted\n' % self.name)
7593
0c1024b3e7fc [c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7538
diff changeset
   158
                return 2 # specific error code
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   159
        sys.exit(status)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   160
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
    def run_arg(self, appid):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   162
        cmdmeth = getattr(self, '%s_instance' % self.name)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        try:
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   164
            status = cmdmeth(appid)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   165
        except (ExecutionError, ConfigurationError) as ex:
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   166
            sys.stderr.write('instance %s not %s: %s\n' % (
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   167
                    appid, self.actionverb, ex))
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   168
            status = 4
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   169
        except Exception as ex:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
            import traceback
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
            traceback.print_exc()
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   172
            sys.stderr.write('instance %s not %s: %s\n' % (
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   173
                    appid, self.actionverb, ex))
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   174
            status = 8
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   175
        return status
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   177
class InstanceCommandFork(InstanceCommand):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   178
    """Same as `InstanceCommand`, but command is forked in a new environment
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    for each argument
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
    def run_args(self, args, askconfirm):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
        if len(args) > 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
            forkcmd = ' '.join(w for w in sys.argv if not w in args)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
            forkcmd = None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        for appid in args:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   188
            if askconfirm:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   189
                print('*'*72)
2743
b0e79a77ad67 [c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   190
                if not ASK.confirm('%s instance %r ?' % (self.name, appid)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   191
                    continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
            if forkcmd:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   193
                status = system('%s %s' % (forkcmd, appid))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
                if status:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   195
                    print('%s exited with status %s' % (forkcmd, status))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   197
                self.run_arg(appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   198
3180
6bab5746ebf5 [c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2905
diff changeset
   199
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
# base commands ###############################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   202
class ListCommand(Command):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   203
    """List configurations, cubes and instances.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   205
    List available configurations, installed cubes, and registered instances.
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   206
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   207
    If given, the optional argument allows to restrict listing only a category of items.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
    name = 'list'
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   210
    arguments = '[all|cubes|configurations|instances]'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
    options = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
        ('verbose',
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   213
         {'short': 'v', 'action' : 'store_true',
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   214
          'help': "display more information."}),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        )
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   216
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
    def run(self, args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
        """run the command with its specific arguments"""
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   219
        if not args:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   220
            mode = 'all'
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   221
        elif len(args) == 1:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   222
            mode = args[0]
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   223
        else:
5608
f9ab62103ad4 proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 5498
diff changeset
   224
            raise BadCommandUsage('Too many arguments')
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   225
5027
d688daf0a62c [config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5026
diff changeset
   226
        from cubicweb.migration import ConfigurationProblem
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   227
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   228
        if mode == 'all':
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   229
            print('CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode))
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   230
            print()
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   231
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   232
        if mode in ('all', 'config', 'configurations'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   233
            print('Available configurations:')
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   234
            for config in CONFIGURATIONS:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   235
                print('*', config.name)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   236
                for line in config.__doc__.splitlines():
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   237
                    line = line.strip()
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   238
                    if not line:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   239
                        continue
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   240
                    print('   ', line)
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   241
            print()
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   242
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   243
        if mode in ('all', 'cubes'):
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   244
            cfgpb = ConfigurationProblem(cwcfg)
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   245
            try:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   246
                cubesdir = pathsep.join(cwcfg.cubes_search_path())
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   247
                namesize = max(len(x) for x in cwcfg.available_cubes())
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   248
            except ConfigurationError as ex:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   249
                print('No cubes available:', ex)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   250
            except ValueError:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   251
                print('No cubes available in %s' % cubesdir)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   252
            else:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   253
                print('Available cubes (%s):' % cubesdir)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   254
                for cube in cwcfg.available_cubes():
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   255
                    try:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   256
                        tinfo = cwcfg.cube_pkginfo(cube)
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   257
                        tversion = tinfo.version
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   258
                        cfgpb.add_cube(cube, tversion)
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   259
                    except (ConfigurationError, AttributeError) as ex:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   260
                        tinfo = None
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   261
                        tversion = '[missing cube information: %s]' % ex
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   262
                    print('* %s %s' % (cube.ljust(namesize), tversion))
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   263
                    if self.config.verbose:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   264
                        if tinfo:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   265
                            descr = getattr(tinfo, 'description', '')
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   266
                            if not descr:
9255
46f41c3e1443 remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9251
diff changeset
   267
                                descr = tinfo.__doc__
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5021
diff changeset
   268
                            if descr:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   269
                                print('    '+ '    \n'.join(descr.splitlines()))
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   270
                        modes = detect_available_modes(cwcfg.cube_dir(cube))
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   271
                        print('    available modes: %s' % ', '.join(modes))
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   272
            print()
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   273
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   274
        if mode in ('all', 'instances'):
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   275
            try:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   276
                regdir = cwcfg.instances_dir()
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   277
            except ConfigurationError as ex:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   278
                print('No instance available:', ex)
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   279
                print()
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   280
                return
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   281
            instances = list_instances(regdir)
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   282
            if instances:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   283
                print('Available instances (%s):' % regdir)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   284
                for appid in instances:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   285
                    modes = cwcfg.possible_configurations(appid)
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   286
                    if not modes:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   287
                        print('* %s (BROKEN instance, no configuration found)' % appid)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   288
                        continue
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   289
                    print('* %s (%s)' % (appid, ', '.join(modes)))
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   290
                    try:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   291
                        config = cwcfg.config_for(appid, modes[0])
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   292
                    except Exception as exc:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   293
                        print('    (BROKEN instance, %s)' % exc)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   294
                        continue
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   295
            else:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   296
                print('No instance available in %s' % regdir)
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   297
            print()
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   298
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   299
        if mode == 'all':
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   300
            # configuration management problem solving
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   301
            cfgpb.solve()
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   302
            if cfgpb.warnings:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   303
                print('Warnings:\n', '\n'.join('* '+txt for txt in cfgpb.warnings))
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   304
            if cfgpb.errors:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   305
                print('Errors:')
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   306
                for op, cube, version, src in cfgpb.errors:
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   307
                    if op == 'add':
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   308
                        print('* cube', cube, end=' ')
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   309
                        if version:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   310
                            print(' version', version, end=' ')
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   311
                        print('is not installed, but required by %s' % src)
8829
bb14dc9848ec [c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents: 8718
diff changeset
   312
                    else:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   313
                        print('* cube %s version %s is installed, but version %s is required by %s' % (
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   314
                            cube, cfgpb.cubes[cube], version, src))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   316
def check_options_consistency(config):
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   317
    if config.automatic and config.config_level > 0:
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   318
        raise BadCommandUsage('--automatic and --config-level should not be '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   319
                              'used together')
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   320
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   321
class CreateInstanceCommand(Command):
9704
43c9896d0e9f an -> a (misc)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9700
diff changeset
   322
    """Create an instance from a cube. This is a unified
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   323
    command which can handle web / server / all-in-one installation
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   324
    according to available parts of the software library and of the
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   325
    desired cube.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
    <cube>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   328
      the name of cube to use (list available cube names using
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   329
      the "list" command). You can use several cubes by separating
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   330
      them using comma (e.g. 'jpl,email')
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   331
    <instance>
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   332
      an identifier for the instance to create
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    name = 'create'
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   335
    arguments = '<cube> <instance>'
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
   336
    min_args = max_args = 2
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
    options = (
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   338
        ('automatic',
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   339
         {'short': 'a', 'action' : 'store_true',
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   340
          'default': False,
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   341
          'help': 'automatic mode: never ask and use default answer to every '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   342
          'question. this may require that your login match a database super '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   343
          'user (allowed to create database & all).',
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   344
          }),
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   345
        ('config-level',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   346
         {'short': 'l', 'type' : 'int', 'metavar': '<level>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
          'default': 0,
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   348
          'help': 'configuration level (0..2): 0 will ask for essential '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   349
          'configuration parameters only while 2 will ask for all parameters',
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   350
          }),
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   351
        ('config',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   352
         {'short': 'c', 'type' : 'choice', 'metavar': '<install type>',
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9013
diff changeset
   353
          'choices': ('all-in-one', 'repository'),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
          'default': 'all-in-one',
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   355
          'help': 'installation type, telling which part of an instance '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   356
          'should be installed. You can list available configurations using the'
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   357
          ' "list" command. Default to "all-in-one", e.g. an installation '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   358
          'embedding both the RQL repository and the web server.',
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   359
          }),
9001
328c24289253 [cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8930
diff changeset
   360
        ('no-db-create',
328c24289253 [cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8930
diff changeset
   361
         {'short': 'S',
8851
0020aa12af07 [c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents: 8829
diff changeset
   362
          'action': 'store_true',
0020aa12af07 [c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents: 8829
diff changeset
   363
          'default': False,
9001
328c24289253 [cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8930
diff changeset
   364
          'help': 'stop after creation and do not continue with db-create',
8851
0020aa12af07 [c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents: 8829
diff changeset
   365
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   366
        )
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   367
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   368
    def run(self, args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
        """run the command with its specific arguments"""
2633
bc9386c3b2c9 get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2615
diff changeset
   370
        from logilab.common.textutils import splitstrip
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   371
        check_options_consistency(self.config)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
        configname = self.config.config
6144
40af8e328e64 [c-c create] argument inversed accidentally
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6138
diff changeset
   373
        cubes, appid = args
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
   374
        cubes = splitstrip(cubes)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   375
        # get the configuration and helper
7129
455b503fb7ff [config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7028
diff changeset
   376
        config = cwcfg.config_for(appid, configname, creating=True)
2104
b4ffcea3275b change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2032
diff changeset
   377
        cubes = config.expand_cubes(cubes)
b4ffcea3275b change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2032
diff changeset
   378
        config.init_cubes(cubes)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
        helper = self.config_helper(config)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
        # check the cube exists
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        try:
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   382
            templdirs = [cwcfg.cube_dir(cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   383
                         for cube in cubes]
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   384
        except ConfigurationError as ex:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   385
            print(ex)
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   386
            print('\navailable cubes:', end=' ')
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   387
            print(', '.join(cwcfg.available_cubes()))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   388
            return
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   389
        # create the registry directory for this instance
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   390
        print('\n'+underline_title('Creating the instance %s' % appid))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   391
        create_dir(config.apphome)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   392
        # cubicweb-ctl configuration
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   393
        if not self.config.automatic:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   394
            print('\n'+underline_title('Configuring the instance (%s.conf)'
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   395
                                       % configname))
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   396
            config.input_config('main', self.config.config_level)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   397
        # configuration'specific stuff
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   398
        print()
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   399
        helper.bootstrap(cubes, self.config.automatic, self.config.config_level)
4610
7bf205b9a845 when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4609
diff changeset
   400
        # input for cubes specific options
9923
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   401
        if not self.config.automatic:
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   402
            sections = set(sect.lower() for sect, opt, odict in config.all_options()
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   403
                           if 'type' in odict
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   404
                           and odict.get('level') <= self.config.config_level)
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   405
            for section in sections:
10235
684215aca046 Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10109
diff changeset
   406
                if section not in ('main', 'email', 'web'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   407
                    print('\n' + underline_title('%s options' % section))
9923
da09975300aa [cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents: 9704
diff changeset
   408
                    config.input_config(section, self.config.config_level)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
        # write down configuration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   410
        config.save()
4064
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   411
        self._handle_win32(config, appid)
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   412
        print('-> generated config %s' % config.main_config_file())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   413
        # handle i18n files structure
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   414
        # in the first cube given
4021
280c910c8710 move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   415
        from cubicweb import i18n
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   416
        langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   417
        errors = config.i18ncompile(langs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   418
        if errors:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   419
            print('\n'.join(errors))
7140
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   420
            if self.config.automatic \
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   421
                   or not ASK.confirm('error while compiling message catalogs, '
ba51dac1115d [c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7131
diff changeset
   422
                                      'continue anyway ?'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   423
                print('creation not completed')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   424
                return
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   425
        # create the additional data directory for this instance
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   426
        if config.appdatahome != config.apphome: # true in dev mode
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   427
            create_dir(config.appdatahome)
2489
37a747ad6fd4 #344772: instance backups should be done in instance_data_dir
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2476
diff changeset
   428
        create_dir(join(config.appdatahome, 'backup'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   429
        if config['uid']:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
            from logilab.common.shellutils import chown
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   431
            # this directory should be owned by the uid of the server process
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   432
            print('set %s as owner of the data directory' % config['uid'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   433
            chown(config.appdatahome, config['uid'])
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   434
        print('\n-> creation done for %s\n' % repr(config.apphome)[1:-1])
9001
328c24289253 [cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8930
diff changeset
   435
        if not self.config.no_db_create:
9013
b4bcabf55e77 3.17 is the new stable
David Douard <david.douard@logilab.fr>
parents: 8994 9002
diff changeset
   436
            helper.postcreate(self.config.automatic, self.config.config_level)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   437
4064
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   438
    def _handle_win32(self, config, appid):
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   439
        if sys.platform != 'win32':
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   440
            return
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   441
        service_template = """
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   442
import sys
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   443
import win32serviceutil
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   444
sys.path.insert(0, r"%(CWPATH)s")
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   445
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   446
from cubicweb.etwist.service import CWService
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   447
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   448
classdict = {'_svc_name_': 'cubicweb-%(APPID)s',
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   449
             '_svc_display_name_': 'CubicWeb ' + '%(CNAME)s',
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   450
             'instance': '%(APPID)s'}
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   451
%(CNAME)sService = type('%(CNAME)sService', (CWService,), classdict)
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   452
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   453
if __name__ == '__main__':
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   454
    win32serviceutil.HandleCommandLine(%(CNAME)sService)
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   455
"""
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   456
        open(join(config.apphome, 'win32svc.py'), 'wb').write(
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   457
            service_template % {'APPID': appid,
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   458
                                'CNAME': appid.capitalize(),
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   459
                                'CWPATH': abspath(join(dirname(__file__), '..'))})
3b12e4192983 be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents: 3715
diff changeset
   460
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   461
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   462
class DeleteInstanceCommand(Command):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   463
    """Delete an instance. Will remove instance's files and
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
    unregister it.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   465
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   466
    name = 'delete'
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   467
    arguments = '<instance>'
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
   468
    min_args = max_args = 1
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   469
    options = ()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   470
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
    def run(self, args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   472
        """run the command with its specific arguments"""
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
   473
        appid = args[0]
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   474
        configs = [cwcfg.config_for(appid, configname)
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   475
                   for configname in cwcfg.possible_configurations(appid)]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   476
        if not configs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   477
            raise ExecutionError('unable to guess configuration for %s' % appid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   478
        for config in configs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   479
            helper = self.config_helper(config, required=False)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
            if helper:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   481
                helper.cleanup()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   482
        # remove home
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   483
        rm(config.apphome)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   484
        # remove instance data directory
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   485
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   486
            rm(config.appdatahome)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   487
        except OSError as ex:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   488
            import errno
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   489
            if ex.errno != errno.ENOENT:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   490
                raise
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   491
        confignames = ', '.join([config.name for config in configs])
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   492
        print('-> instance %s (%s) deleted.' % (appid, confignames))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   493
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   494
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   495
# instance commands ########################################################
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   496
3180
6bab5746ebf5 [c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2905
diff changeset
   497
class StartInstanceCommand(InstanceCommandFork):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   498
    """Start the given instances. If no instance is given, start them all.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   499
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   500
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   501
      identifiers of the instances to start. If no instance is
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   502
      given, start them all.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   503
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   504
    name = 'start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   505
    actionverb = 'started'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   506
    options = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   507
        ("debug",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
         {'short': 'D', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   509
          'help': 'start server in debug mode.'}),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   510
        ("force",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   511
         {'short': 'f', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   512
          'default': False,
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   513
          'help': 'start the instance even if it seems to be already \
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   514
running.'}),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   515
        ('profile',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   516
         {'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   517
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
          'help': 'profile code and use the specified file to store stats',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   519
          }),
2654
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2633
diff changeset
   520
        ('loglevel',
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2633
diff changeset
   521
         {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2633
diff changeset
   522
          'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2633
diff changeset
   523
          'help': 'debug if -D is set, error otherwise',
6512522860aa [twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2633
diff changeset
   524
          }),
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   525
        ('param',
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   526
         {'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2',
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   527
          'default': {},
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   528
          'help': 'override <key> configuration file option with <value>.',
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   529
         }),
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   530
       )
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   531
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   532
    def start_instance(self, appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   533
        """start the instance's server"""
10109
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   534
        try:
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   535
            import twisted  # noqa
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   536
        except ImportError:
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   537
            msg = (
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   538
                "Twisted is required by the 'start' command\n"
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   539
                "Either install it, or use one of the alternative commands:\n"
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   540
                "- '{ctl} wsgi {appid}'\n"
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   541
                "- '{ctl} pyramid {appid}' (requires the pyramid cube)\n")
479190f019cc [pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents: 10106
diff changeset
   542
            raise ExecutionError(msg.format(ctl='cubicweb-ctl', appid=appid))
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: 5436
diff changeset
   543
        config = cwcfg.config_for(appid, debugmode=self['debug'])
10474
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   544
        # override config file values with cmdline options
1dcc52f5e340 [cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents: 10321
diff changeset
   545
        config.cmdline_options = self.config.param
5814
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   546
        init_cmdline_log_threshold(config, self['loglevel'])
3182
76ad941f694e cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3180
diff changeset
   547
        if self['profile']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   548
            config.global_set_option('profile', self.config.profile)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   549
        helper = self.config_helper(config, cmdname='start')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   550
        pidf = config['pid-file']
5814
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   551
        if exists(pidf) and not self['force']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   552
            msg = "%s seems to be running. Remove %s by hand if necessary or use \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   553
the --force option."
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   554
            raise ExecutionError(msg % (appid, pidf))
6778
7dd4835d5198 properly tell we've started an instance (close #1391262)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6675
diff changeset
   555
        if helper.start_server(config) == 1:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   556
            print('instance %s started' % appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   557
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   558
5814
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   559
def init_cmdline_log_threshold(config, loglevel):
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   560
    if loglevel is not None:
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   561
        config.global_set_option('log-threshold', loglevel.upper())
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   562
        config.init_log(config['log-threshold'], force=True)
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   563
51cc4b61f9ae [repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5811
diff changeset
   564
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   565
class StopInstanceCommand(InstanceCommand):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   566
    """Stop the given instances.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   567
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   568
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   569
      identifiers of the instances to stop. If no instance is
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   570
      given, stop them all.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   571
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   572
    name = 'stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   573
    actionverb = 'stopped'
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   574
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   575
    def ordered_instances(self):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   576
        instances = super(StopInstanceCommand, self).ordered_instances()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   577
        instances.reverse()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   578
        return instances
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   579
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   580
    def stop_instance(self, appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   581
        """stop the instance's server"""
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   582
        config = cwcfg.config_for(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   583
        helper = self.config_helper(config, cmdname='stop')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   584
        helper.poststop() # do this anyway
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   585
        pidf = config['pid-file']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   586
        if not exists(pidf):
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   587
            sys.stderr.write("%s doesn't exist.\n" % pidf)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   588
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   589
        import signal
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   590
        pid = int(open(pidf).read().strip())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   591
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   592
            kill(pid, signal.SIGTERM)
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7595
diff changeset
   593
        except Exception:
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   594
            sys.stderr.write("process %s seems already dead.\n" % pid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   595
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   596
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   597
                wait_process_end(pid)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   598
            except ExecutionError as ex:
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7815
diff changeset
   599
                sys.stderr.write('%s\ntrying SIGKILL\n' % ex)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   600
                try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   601
                    kill(pid, signal.SIGKILL)
7815
2a164a9cf81c [exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7595
diff changeset
   602
                except Exception:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   603
                    # probably dead now
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   604
                    pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   605
                wait_process_end(pid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   606
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   607
            remove(pidf)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   608
        except OSError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   609
            # already removed by twistd
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   610
            pass
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   611
        print('instance %s stopped' % appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   612
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   613
3180
6bab5746ebf5 [c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2905
diff changeset
   614
class RestartInstanceCommand(StartInstanceCommand):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   615
    """Restart the given instances.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   616
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   617
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   618
      identifiers of the instances to restart. If no instance is
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   619
      given, restart them all.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   620
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   621
    name = 'restart'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   622
    actionverb = 'restarted'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   623
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   624
    def run_args(self, args, askconfirm):
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
   625
        regdir = cwcfg.instances_dir()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   626
        if not isfile(join(regdir, 'startorder')) or len(args) <= 1:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   627
            # no specific startorder
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   628
            super(RestartInstanceCommand, self).run_args(args, askconfirm)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   629
            return
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   630
        print ('some specific start order is specified, will first stop all '
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   631
               'instances then restart them.')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   632
        # get instances in startorder
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   633
        for appid in args:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   634
            if askconfirm:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   635
                print('*'*72)
2743
b0e79a77ad67 [c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   636
                if not ASK.confirm('%s instance %r ?' % (self.name, appid)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   637
                    continue
6145
528be1e059aa more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6144
diff changeset
   638
            StopInstanceCommand(self.logger).stop_instance(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   639
        forkcmd = [w for w in sys.argv if not w in args]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   640
        forkcmd[1] = 'start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   641
        forkcmd = ' '.join(forkcmd)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   642
        for appid in reversed(args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   643
            status = system('%s %s' % (forkcmd, appid))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   644
            if status:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   645
                sys.exit(status)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   646
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   647
    def restart_instance(self, appid):
6145
528be1e059aa more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6144
diff changeset
   648
        StopInstanceCommand(self.logger).stop_instance(appid)
3180
6bab5746ebf5 [c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2905
diff changeset
   649
        self.start_instance(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   650
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   651
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   652
class ReloadConfigurationCommand(RestartInstanceCommand):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   653
    """Reload the given instances. This command is equivalent to a
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   654
    restart for now.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   655
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   656
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   657
      identifiers of the instances to reload. If no instance is
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   658
      given, reload them all.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   659
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   660
    name = 'reload'
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   661
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   662
    def reload_instance(self, appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   663
        self.restart_instance(appid)
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   664
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   665
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   666
class StatusCommand(InstanceCommand):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   667
    """Display status information about the given instances.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   668
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   669
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   670
      identifiers of the instances to status. If no instance is
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   671
      given, get status information about all registered instances.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   672
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   673
    name = 'status'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   674
    options = ()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   675
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   676
    @staticmethod
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   677
    def status_instance(appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   678
        """print running status information for an instance"""
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   679
        status = 0
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   680
        for mode in cwcfg.possible_configurations(appid):
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   681
            config = cwcfg.config_for(appid, mode)
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   682
            print('[%s-%s]' % (appid, mode), end=' ')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   683
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   684
                pidf = config['pid-file']
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   685
            except KeyError:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   686
                print('buggy instance, pid file not specified')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   687
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   688
            if not exists(pidf):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   689
                print("doesn't seem to be running")
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   690
                status = 1
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   691
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   692
            pid = int(open(pidf).read().strip())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   693
            # trick to guess whether or not the process is running
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   694
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   695
                getpgid(pid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   696
            except OSError:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   697
                print("should be running with pid %s but the process can not be found" % pid)
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   698
                status = 1
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   699
                continue
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   700
            print("running with pid %s" % (pid))
5380
a4e7e87d315f [c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5323
diff changeset
   701
        return status
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   702
3180
6bab5746ebf5 [c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2905
diff changeset
   703
class UpgradeInstanceCommand(InstanceCommandFork):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   704
    """Upgrade an instance after cubicweb and/or component(s) upgrade.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   705
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   706
    For repository update, you will be prompted for a login / password to use
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   707
    to connect to the system database.  For some upgrades, the given user
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   708
    should have create or alter table permissions.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   709
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   710
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   711
      identifiers of the instances to upgrade. If no instance is
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   712
      given, upgrade them all.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   713
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   714
    name = 'upgrade'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   715
    actionverb = 'upgraded'
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   716
    options = InstanceCommand.options + (
7028
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   717
        ('force-cube-version',
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   718
         {'short': 't', 'type' : 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   719
          'default': None,
7028
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   720
          'help': 'force migration from the indicated version for the specified cube(s).'}),
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   721
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   722
        ('force-cubicweb-version',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   723
         {'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   724
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   725
          'help': 'force migration from the indicated cubicweb version.'}),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   726
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   727
        ('fs-only',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   728
         {'short': 's', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   729
          'default': False,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   730
          'help': 'only upgrade files on the file system, not the database.'}),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   731
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   732
        ('nostartstop',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   733
         {'short': 'n', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   734
          'default': False,
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   735
          'help': 'don\'t try to stop instance before migration and to restart it after.'}),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   736
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   737
        ('verbosity',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   738
         {'short': 'v', 'type' : 'int', 'metavar': '<0..2>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   739
          'default': 1,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   740
          'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   741
for everything."}),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   742
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   743
        ('backup-db',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   744
         {'short': 'b', 'type' : 'yn', 'metavar': '<y or n>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   745
          'default': None,
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   746
          'help': "Backup the instance database before upgrade.\n"\
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   747
          "If the option is ommitted, confirmation will be ask.",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   748
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   749
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   750
        ('ext-sources',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   751
         {'short': 'E', 'type' : 'csv', 'metavar': '<sources>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   752
          'default': None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   753
          'help': "For multisources instances, specify to which sources the \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   754
repository should connect to for upgrading. When unspecified or 'migration' is \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   755
given, appropriate sources for migration will be automatically selected \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   756
(recommended). If 'all' is given, will connect to all defined sources.",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   757
          }),
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   758
        )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   759
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   760
    def upgrade_instance(self, appid):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   761
        print('\n' + underline_title('Upgrading the instance %s' % appid))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   762
        from logilab.common.changelog import Version
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   763
        config = cwcfg.config_for(appid)
9315
5298cfb132e6 [cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9013
diff changeset
   764
        instance_running = exists(config['pid-file'])
2473
490f88fb99b6 new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2395
diff changeset
   765
        config.repairing = True # notice we're not starting the server
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   766
        config.verbosity = self.config.verbosity
7577
9892937d9041 [all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7538
diff changeset
   767
        set_sources_mode = getattr(config, 'set_sources_mode', None)
9892937d9041 [all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7538
diff changeset
   768
        if set_sources_mode is not None:
9892937d9041 [all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7538
diff changeset
   769
            set_sources_mode(self.config.ext_sources or ('migration',))
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   770
        # get instance and installed versions for the server and the componants
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   771
        mih = config.migration_handler()
10569
af47954c1015 [migration] remove repo_connect and use config.repository() instead
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10474
diff changeset
   772
        repo = mih.repo
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   773
        vcconf = repo.get_versions()
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9371
diff changeset
   774
        helper = self.config_helper(config, required=False)
7028
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   775
        if self.config.force_cube_version:
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
   776
            for cube, version in self.config.force_cube_version.items():
7028
e8855733b125 [c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6914
diff changeset
   777
                vcconf[cube] = Version(version)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   778
        toupgrade = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   779
        for cube in config.cubes():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   780
            installedversion = config.cube_version(cube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   781
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   782
                applversion = vcconf[cube]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   783
            except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   784
                config.error('no version information for %s' % cube)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   785
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   786
            if installedversion > applversion:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   787
                toupgrade.append( (cube, applversion, installedversion) )
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   788
        cubicwebversion = config.cubicweb_version()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   789
        if self.config.force_cubicweb_version:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   790
            applcubicwebversion = Version(self.config.force_cubicweb_version)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   791
            vcconf['cubicweb'] = applcubicwebversion
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   792
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   793
            applcubicwebversion = vcconf.get('cubicweb')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   794
        if cubicwebversion > applcubicwebversion:
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2156
diff changeset
   795
            toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
1404
971b19de6b85 stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents: 1219
diff changeset
   796
        # only stop once we're sure we have something to do
9315
5298cfb132e6 [cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9013
diff changeset
   797
        if instance_running and not (CWDEV or self.config.nostartstop):
6145
528be1e059aa more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6144
diff changeset
   798
            StopInstanceCommand(self.logger).stop_instance(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   799
        # run cubicweb/componants migration scripts
7538
849c04098f3f [migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7372
diff changeset
   800
        if self.config.fs_only or toupgrade:
849c04098f3f [migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7372
diff changeset
   801
            for cube, fromversion, toversion in toupgrade:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   802
                print('-> migration needed from %s to %s for %s' % (fromversion, toversion, cube))
9511
241b1232ed7f Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
   803
            with mih.cnx:
9556
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   804
                with mih.cnx.security_enabled(False, False):
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   805
                    mih.migrate(vcconf, reversed(toupgrade), self.config)
7538
849c04098f3f [migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7372
diff changeset
   806
        else:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   807
            print('-> no data migration needed for instance %s.' % appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   808
        # rewrite main configuration file
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   809
        mih.rewrite_configuration()
5796
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   810
        mih.shutdown()
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   811
        # handle i18n upgrade
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   812
        if not self.i18nupgrade(config):
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   813
            return
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   814
        print()
9372
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9371
diff changeset
   815
        if helper:
e87a808a4c32 [webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9371
diff changeset
   816
            helper.postupgrade(repo)
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   817
        print('-> instance migrated.')
9315
5298cfb132e6 [cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9013
diff changeset
   818
        if instance_running and not (CWDEV or self.config.nostartstop):
5796
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   819
            # restart instance through fork to get a proper environment, avoid
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   820
            # uicfg pb (and probably gettext catalogs, to check...)
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   821
            forkcmd = '%s start %s' % (sys.argv[0], appid)
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   822
            status = system(forkcmd)
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   823
            if status:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   824
                print('%s exited with status %s' % (forkcmd, status))
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   825
        print()
5796
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   826
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   827
    def i18nupgrade(self, config):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   828
        # handle i18n upgrade:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   829
        # * install new languages
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   830
        # * recompile catalogs
5092
e126becc1263 [upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5043
diff changeset
   831
        # XXX search available language in the first cube given
4021
280c910c8710 move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3720
diff changeset
   832
        from cubicweb import i18n
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   833
        templdir = cwcfg.cube_dir(config.cubes()[0])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   834
        langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   835
        errors = config.i18ncompile(langs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   836
        if errors:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   837
            print('\n'.join(errors))
2743
b0e79a77ad67 [c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2654
diff changeset
   838
            if not ASK.confirm('Error while compiling message catalogs, '
5796
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   839
                               'continue anyway?'):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   840
                print('-> migration not completed.')
5796
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   841
                return False
351e84e18a61 closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5608
diff changeset
   842
        return True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   843
7591
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   844
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   845
class ListVersionsInstanceCommand(InstanceCommand):
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   846
    """List versions used by an instance.
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   847
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   848
    <instance>...
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   849
      identifiers of the instances to list versions for.
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   850
    """
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   851
    name = 'versions'
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   852
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   853
    def versions_instance(self, appid):
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   854
        config = cwcfg.config_for(appid)
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   855
        # should not raise error if db versions don't match fs versions
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   856
        config.repairing = True
9875
d4f6f4c77e9c [cwctl] make cubicweb-ctl versions lighter (closes #4002158)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9770
diff changeset
   857
        # no need to load all appobjects and schema
d4f6f4c77e9c [cwctl] make cubicweb-ctl versions lighter (closes #4002158)
Julien Cristau <julien.cristau@logilab.fr>
parents: 9770
diff changeset
   858
        config.quick_start = True
7591
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   859
        if hasattr(config, 'set_sources_mode'):
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   860
            config.set_sources_mode(('migration',))
10569
af47954c1015 [migration] remove repo_connect and use config.repository() instead
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10474
diff changeset
   861
        vcconf = config.repository().get_versions()
7591
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   862
        for key in sorted(vcconf):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   863
            print(key+': %s.%s.%s' % vcconf[key])
7591
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
   864
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   865
class ShellCommand(Command):
3700
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   866
    """Run an interactive migration shell on an instance. This is a python shell
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   867
    with enhanced migration commands predefined in the namespace. An additional
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   868
    argument may be given corresponding to a file containing commands to execute
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   869
    in batch mode.
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   870
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   871
    By default it will connect to a local instance using an in memory
9700
da7d341cca76 an URL -> a URL
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9372
diff changeset
   872
    connection, unless a URL to a running instance is specified.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   873
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   874
    Arguments after bare "--" string will not be processed by the shell command
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   875
    You can use it to pass extra arguments to your script and expect for
5436
2455ca3a2a3a [c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name.
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5430
diff changeset
   876
    them in '__args__' afterwards.
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   877
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   878
    <instance>
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   879
      the identifier of the instance to connect.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   880
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   881
    name = 'shell'
5430
ed8f71e244f8 [shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5426
diff changeset
   882
    arguments = '<instance> [batch command file(s)] [-- <script arguments>]'
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
   883
    min_args = 1
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   884
    options = (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   885
        ('system-only',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   886
         {'short': 'S', 'action' : 'store_true',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   887
          'help': 'only connect to the system source when the instance is '
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   888
          'using multiple sources. You can\'t use this option and the '
3700
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   889
          '--ext-sources option at the same time.',
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   890
          'group': 'local'
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   891
         }),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   892
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   893
        ('ext-sources',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   894
         {'short': 'E', 'type' : 'csv', 'metavar': '<sources>',
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   895
          'help': "For multisources instances, specify to which sources the \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   896
repository should connect to for upgrading. When unspecified or 'all' given, \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   897
will connect to all defined sources. If 'migration' is given, appropriate \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   898
sources for migration will be automatically selected.",
3700
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   899
          'group': 'local'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   900
          }),
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   901
2905
b23bbb31368c backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2743
diff changeset
   902
        ('force',
b23bbb31368c backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2743
diff changeset
   903
         {'short': 'f', 'action' : 'store_true',
3700
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   904
          'help': 'don\'t check instance is up to date.',
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   905
          'group': 'local'
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   906
          }),
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   907
8352
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   908
        ('repo-uri',
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   909
         {'short': 'H', 'type' : 'string', 'metavar': '<protocol>://<[host][:port]>',
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   910
          'help': 'URI of the CubicWeb repository to connect to. URI can be \
10235
684215aca046 Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10109
diff changeset
   911
a ZMQ URL or inmemory:// (default) use an in-memory repository. THIS OPTION IS DEPRECATED, \
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: 8564
diff changeset
   912
directly give URI as instance id instead',
3700
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   913
          'group': 'remote'
fd550e4dc515 #481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3638
diff changeset
   914
          }),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   915
        )
2905
b23bbb31368c backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2743
diff changeset
   916
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   917
    def _handle_inmemory(self, appid):
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   918
        """ returns migration context handler & shutdown function """
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   919
        config = cwcfg.config_for(appid)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   920
        if self.config.ext_sources:
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   921
            assert not self.config.system_only
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   922
            sources = self.config.ext_sources
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   923
        elif self.config.system_only:
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   924
            sources = ('system',)
8352
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   925
        else:
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   926
            sources = ('all',)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   927
        config.set_sources_mode(sources)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   928
        config.repairing = self.config.force
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   929
        mih = config.migration_handler()
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   930
        return mih, lambda: mih.shutdown()
8352
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   931
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   932
    def _handle_networked(self, appuri):
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   933
        """ returns migration context handler & shutdown function """
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   934
        from cubicweb import AuthenticationError
9511
241b1232ed7f Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
   935
        from cubicweb.repoapi import connect, get_repository
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   936
        from cubicweb.server.utils import manager_userpasswd
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   937
        from cubicweb.server.migractions import ServerMigrationHelper
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   938
        while True:
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   939
            try:
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   940
                login, pwd = manager_userpasswd(msg=None)
9511
241b1232ed7f Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
   941
                repo = get_repository(appuri)
241b1232ed7f Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
   942
                cnx = connect(repo, login=login, password=pwd, mulcnx=False)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
   943
            except AuthenticationError as ex:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   944
                print(ex)
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   945
            except (KeyboardInterrupt, EOFError):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
   946
                print()
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   947
                sys.exit(0)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   948
            else:
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   949
                break
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   950
        cnx.load_appobjects()
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   951
        repo = cnx._repo
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   952
        mih = ServerMigrationHelper(None, repo=repo, cnx=cnx, verbosity=0,
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   953
                                    # hack so it don't try to load fs schema
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   954
                                    schema=1)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   955
        return mih, lambda: cnx.close()
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   956
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   957
    def run(self, args):
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: 8564
diff changeset
   958
        appuri = args.pop(0)
8352
0e3b41118631 [dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents: 7896
diff changeset
   959
        if self.config.repo_uri:
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: 8564
diff changeset
   960
            warn('[3.16] --repo-uri option is deprecated, directly give the URI as instance id',
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: 8564
diff changeset
   961
                 DeprecationWarning)
10235
684215aca046 Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10109
diff changeset
   962
            if urlparse(self.config.repo_uri).scheme == 'inmemory':
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: 8564
diff changeset
   963
                appuri = '%s/%s' % (self.config.repo_uri.rstrip('/'), appuri)
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   964
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   965
        from cubicweb.utils import parse_repo_uri
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   966
        protocol, hostport, appid = parse_repo_uri(appuri)
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   967
        if protocol == 'inmemory':
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   968
            mih, shutdown_callback = self._handle_inmemory(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   969
        else:
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   970
            mih, shutdown_callback = self._handle_networked(appuri)
3709
e67ade20bf80 properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3707
diff changeset
   971
        try:
9511
241b1232ed7f Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents: 9372
diff changeset
   972
            with mih.cnx:
9556
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   973
                with mih.cnx.security_enabled(False, False):
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   974
                    if args:
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   975
                        # use cmdline parser to access left/right attributes only
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   976
                        # remember that usage requires instance appid as first argument
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   977
                        scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   978
                        for script in scripts:
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   979
                                mih.cmd_process_script(script, scriptargs=args)
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   980
                                mih.commit()
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   981
                    else:
12ee310541bb [server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents: 9511
diff changeset
   982
                        mih.interactive_shell()
3709
e67ade20bf80 properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3707
diff changeset
   983
        finally:
8682
20bd1cdf86ae [cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8669
diff changeset
   984
            shutdown_callback()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   985
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   986
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   987
class RecompileInstanceCatalogsCommand(InstanceCommand):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   988
    """Recompile i18n catalogs for instances.
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
   989
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   990
    <instance>...
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   991
      identifiers of the instances to consider. If no instance is
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   992
      given, recompile for all registered instances.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   993
    """
1898
39b37f90a8a4 [cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1477
diff changeset
   994
    name = 'i18ninstance'
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   995
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   996
    @staticmethod
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   997
    def i18ninstance_instance(appid):
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2473
diff changeset
   998
        """recompile instance's messages catalogs"""
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
   999
        config = cwcfg.config_for(appid)
5043
fe52dd3936cf [repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5042
diff changeset
  1000
        config.quick_start = True # notify this is not a regular start
5042
cc062bb09abb fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
  1001
        repo = config.repository()
cc062bb09abb fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
  1002
        if config._cubes is None:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1003
            # web only config
5042
cc062bb09abb fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
  1004
            config.init_cubes(repo.get_cubes())
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1005
        errors = config.i18ncompile()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1006
        if errors:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
  1007
            print('\n'.join(errors))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1008
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1009
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1010
class ListInstancesCommand(Command):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1011
    """list available instances, useful for bash completion."""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1012
    name = 'listinstances'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1013
    hidden = True
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
  1014
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1015
    def run(self, args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1016
        """run the command with its specific arguments"""
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4798
diff changeset
  1017
        regdir = cwcfg.instances_dir()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1018
        for appid in sorted(listdir(regdir)):
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
  1019
            print(appid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1020
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1021
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1022
class ListCubesCommand(Command):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1023
    """list available componants, useful for bash completion."""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1024
    name = 'listcubes'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1025
    hidden = True
1446
e951a860eeaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1342
diff changeset
  1026
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1027
    def run(self, args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1028
        """run the command with its specific arguments"""
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
  1029
        for cube in cwcfg.available_cubes():
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
  1030
            print(cube)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1031
9002
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1032
class ConfigureInstanceCommand(InstanceCommand):
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1033
    """Configure instance.
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1034
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1035
    <instance>...
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1036
      identifier of the instance to configure.
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1037
    """
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1038
    name = 'configure'
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1039
    actionverb = 'configured'
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1040
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1041
    options = merge_options(InstanceCommand.options +
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1042
                            (('param',
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1043
                              {'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2',
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1044
                               'default': None,
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1045
                               'help': 'set <key> to <value> in configuration file.',
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1046
                               }),
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1047
                             ))
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1048
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1049
    def configure_instance(self, appid):
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1050
        if self.config.param is not None:
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1051
            appcfg = cwcfg.config_for(appid)
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10614
diff changeset
  1052
            for key, value in self.config.param.items():
9002
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1053
                try:
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1054
                    appcfg.global_set_option(key, value)
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1055
                except KeyError:
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1056
                    raise ConfigurationError('unknown configuration key "%s" for mode %s' % (key, appcfg.name))
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1057
            appcfg.save()
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1058
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1059
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1060
# WSGI #########
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1061
10104
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1062
WSGI_CHOICES = {}
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1063
from cubicweb.wsgi import server as stdlib_server
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1064
WSGI_CHOICES['stdlib'] = stdlib_server
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1065
try:
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1066
    from cubicweb.wsgi import wz
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1067
except ImportError:
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1068
    pass
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1069
else:
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1070
    WSGI_CHOICES['werkzeug'] = wz
10106
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1071
try:
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1072
    from cubicweb.wsgi import tnd
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1073
except ImportError:
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1074
    pass
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1075
else:
3117f1736f00 [wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents: 10104
diff changeset
  1076
    WSGI_CHOICES['tornado'] = tnd
10104
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1077
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1078
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1079
def wsgichoices():
10104
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1080
    return tuple(WSGI_CHOICES)
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1081
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1082
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1083
class WSGIStartHandler(InstanceCommand):
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1084
    """Start an interactive wsgi server """
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1085
    name = 'wsgi'
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1086
    actionverb = 'started'
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1087
    arguments = '<instance>'
10104
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1088
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1089
    @property
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1090
    def options(self):
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1091
        return (
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1092
        ("debug",
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1093
         {'short': 'D', 'action': 'store_true',
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1094
          'default': False,
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1095
          'help': 'start server in debug mode.'}),
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1096
        ('method',
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1097
         {'short': 'm',
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1098
          'type': 'choice',
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1099
          'metavar': '<method>',
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1100
          'default': 'stdlib',
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1101
          'choices': wsgichoices(),
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1102
          'help': 'wsgi utility/method'}),
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1103
        ('loglevel',
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1104
         {'short': 'l',
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1105
          'type': 'choice',
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1106
          'metavar': '<log level>',
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1107
          'default': None,
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1108
          'choices': ('debug', 'info', 'warning', 'error'),
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1109
          'help': 'debug if -D is set, error otherwise',
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1110
          }),
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1111
        )
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1112
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1113
    def wsgi_instance(self, appid):
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1114
        config = cwcfg.config_for(appid, debugmode=self['debug'])
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1115
        init_cmdline_log_threshold(config, self['loglevel'])
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1116
        assert config.name == 'all-in-one'
9288
823cf14bcc37 [wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9287
diff changeset
  1117
        meth = self['method']
10104
cdc0b0216da2 [cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents: 9990
diff changeset
  1118
        server = WSGI_CHOICES[meth]
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1119
        return server.run(config)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1120
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1121
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1122
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1123
for cmdcls in (ListCommand,
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1124
               CreateInstanceCommand, DeleteInstanceCommand,
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1125
               StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand,
9945
cf5b0d0f5731 [wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents: 9770
diff changeset
  1126
               WSGIStartHandler,
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1127
               ReloadConfigurationCommand, StatusCommand,
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1128
               UpgradeInstanceCommand,
7591
cb6ece9cdb78 [cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7577
diff changeset
  1129
               ListVersionsInstanceCommand,
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1130
               ShellCommand,
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1131
               RecompileInstanceCatalogsCommand,
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1132
               ListInstancesCommand, ListCubesCommand,
9002
f98d1c46ed9f [cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 9001
diff changeset
  1133
               ConfigureInstanceCommand,
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1134
               ):
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1135
    CWCTL.register(cmdcls)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1136
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1137
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents: 9255
diff changeset
  1138
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1139
def run(args):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1140
    """command line tool"""
6562
34be5986bca0 make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6505
diff changeset
  1141
    import os
10321
a4af502191d5 [cwctl] don't filter DeprecationWarnings
Julien Cristau <julien.cristau@logilab.fr>
parents: 10235
diff changeset
  1142
    filterwarnings('default', category=DeprecationWarning)
1132
96752791c2b6 pylint cleanup
sylvain.thenault@logilab.fr
parents: 151
diff changeset
  1143
    cwcfg.load_cwctl_plugins()
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1144
    try:
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1145
        CWCTL.run(args)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
  1146
    except ConfigurationError as err:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
  1147
        print('ERROR: ', err)
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1148
        sys.exit(1)
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8682
diff changeset
  1149
    except ExecutionError as err:
10589
7c23b7de2b8d [py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents: 10569
diff changeset
  1150
        print(err)
6138
65f5e488f983 update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5814
diff changeset
  1151
        sys.exit(2)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1152
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1153
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
  1154
    run(sys.argv[1:])