cubicweb/server/serverctl.py
changeset 12567 26744ad37953
parent 12146 d540defa0591
child 12576 3aa0c203747c
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """cubicweb-ctl commands and command handlers specific to the repository"""
    18 """cubicweb-ctl commands and command handlers specific to the repository"""
    19 from __future__ import print_function
       
    20 
       
    21 # *ctl module should limit the number of import to be imported as quickly as
    19 # *ctl module should limit the number of import to be imported as quickly as
    22 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    20 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    23 # completion). So import locally in command helpers.
    21 # completion). So import locally in command helpers.
       
    22 import sched
    24 import sys
    23 import sys
    25 import os
    24 import os
    26 from contextlib import contextmanager
    25 from contextlib import contextmanager
    27 
       
    28 from six import string_types
       
    29 from six.moves import input
       
    30 
    26 
    31 from logilab.common.configuration import Configuration, merge_options
    27 from logilab.common.configuration import Configuration, merge_options
    32 from logilab.common.shellutils import ASK, generate_password
    28 from logilab.common.shellutils import ASK, generate_password
    33 
    29 
    34 from logilab.database import get_db_helper, get_connection
    30 from logilab.database import get_db_helper, get_connection
  1004     )
  1000     )
  1005 
  1001 
  1006     def run(self, args):
  1002     def run(self, args):
  1007         from cubicweb.cwctl import init_cmdline_log_threshold
  1003         from cubicweb.cwctl import init_cmdline_log_threshold
  1008         from cubicweb.server.repository import Repository
  1004         from cubicweb.server.repository import Repository
  1009         from cubicweb.server.utils import scheduler
       
  1010         config = ServerConfiguration.config_for(args[0])
  1005         config = ServerConfiguration.config_for(args[0])
  1011         # Log to stdout, since the this command runs in the foreground.
  1006         # Log to stdout, since the this command runs in the foreground.
  1012         config.global_set_option('log-file', None)
  1007         config.global_set_option('log-file', None)
  1013         init_cmdline_log_threshold(config, self['loglevel'])
  1008         init_cmdline_log_threshold(config, self['loglevel'])
  1014         repo = Repository(config, scheduler())
  1009         repo = Repository(config, sched.scheduler())
  1015         repo.bootstrap()
  1010         repo.bootstrap()
  1016         try:
  1011         try:
  1017             repo.run_scheduler()
  1012             repo.run_scheduler()
  1018         finally:
  1013         finally:
  1019             repo.shutdown()
  1014             repo.shutdown()
  1093     defaulteperms = (PUB_SYSTEM_ENTITY_PERMS,)
  1088     defaulteperms = (PUB_SYSTEM_ENTITY_PERMS,)
  1094     # canonicalize vs str/unicode
  1089     # canonicalize vs str/unicode
  1095     for p in ('read', 'add', 'update', 'delete'):
  1090     for p in ('read', 'add', 'update', 'delete'):
  1096         rule = perms.get(p)
  1091         rule = perms.get(p)
  1097         if rule:
  1092         if rule:
  1098             perms[p] = tuple(str(x) if isinstance(x, string_types) else x
  1093             perms[p] = tuple(rule)
  1099                              for x in rule)
       
  1100     return perms, perms in defaultrelperms or perms in defaulteperms
  1094     return perms, perms in defaultrelperms or perms in defaulteperms
  1101 
  1095 
  1102 
  1096 
  1103 class SchemaDiffCommand(Command):
  1097 class SchemaDiffCommand(Command):
  1104     """Generate a diff between schema and fsschema description.
  1098     """Generate a diff between schema and fsschema description.