--- a/server/serverctl.py Fri Aug 20 17:08:08 2010 +0200
+++ b/server/serverctl.py Wed Aug 25 09:42:55 2010 +0200
@@ -26,11 +26,11 @@
import os
from logilab.common.configuration import Configuration
-from logilab.common.clcommands import register_commands, cmd_run, pop_arg
from logilab.common.shellutils import ASK
from cubicweb import AuthenticationError, ExecutionError, ConfigurationError
from cubicweb.toolsutils import Command, CommandHandler, underline_title
+from cubicweb.cwctl import CWCTL
from cubicweb.server import SOURCE_TYPES
from cubicweb.server.serverconfig import (USER_OPTIONS, ServerConfiguration,
SourceConfiguration)
@@ -217,7 +217,7 @@
def postcreate(self):
if ASK.confirm('Run db-create to create the system database ?'):
verbosity = (self.config.mode == 'installed') and 'y' or 'n'
- cmd_run('db-create', self.config.appid, '--verbose=%s' % verbosity)
+ CWCTL.run(['db-create', self.config.appid, '--verbose=%s' % verbosity])
else:
print ('-> nevermind, you can do it later with '
'"cubicweb-ctl db-create %s".' % self.config.appid)
@@ -299,7 +299,7 @@
"""
name = 'db-create'
arguments = '<instance>'
-
+ min_args = max_args = 1
options = (
('create-db',
{'short': 'c', 'type': 'yn', 'metavar': '<y or n>',
@@ -323,7 +323,7 @@
from logilab.database import get_db_helper
verbose = self.get('verbose')
automatic = self.get('automatic')
- appid = pop_arg(args, msg='No instance specified !')
+ appid = args.pop()
config = ServerConfiguration.config_for(appid)
source = config.sources()['system']
dbname = source['db-name']
@@ -371,7 +371,7 @@
print '-> database for instance %s created and necessary extensions installed.' % appid
print
if automatic or ASK.confirm('Run db-init to initialize the system database ?'):
- cmd_run('db-init', config.appid)
+ CWCTL.run(['db-init', config.appid])
else:
print ('-> nevermind, you can do it later with '
'"cubicweb-ctl db-init %s".' % config.appid)
@@ -389,7 +389,7 @@
"""
name = 'db-init'
arguments = '<instance>'
-
+ min_args = max_args = 1
options = (
('drop',
{'short': 'd', 'action': 'store_true',
@@ -402,7 +402,7 @@
print '\n'+underline_title('Initializing the system database')
from cubicweb.server import init_repository
from logilab.database import get_connection
- appid = pop_arg(args, msg='No instance specified !')
+ appid = args[0]
config = ServerConfiguration.config_for(appid)
try:
system = config.sources()['system']
@@ -431,7 +431,7 @@
"""
name = 'db-grant-user'
arguments = '<instance> <user>'
-
+ min_args = max_args = 2
options = (
('set-owner',
{'short': 'o', 'type' : 'yn', 'metavar' : '<yes or no>',
@@ -442,8 +442,7 @@
def run(self, args):
"""run the command with its specific arguments"""
from cubicweb.server.sqlutils import sqlexec, sqlgrants
- appid = pop_arg(args, 1, msg='No instance specified !')
- user = pop_arg(args, msg='No user specified !')
+ appid, user = args
config = ServerConfiguration.config_for(appid)
source = config.sources()['system']
set_owner = self.config.set_owner
@@ -475,7 +474,7 @@
def run(self, args):
"""run the command with its specific arguments"""
from cubicweb.server.utils import crypt_password, manager_userpasswd
- appid = pop_arg(args, 1, msg='No instance specified !')
+ appid = args[0]
config = ServerConfiguration.config_for(appid)
sourcescfg = config.read_sources_file()
try:
@@ -526,7 +525,7 @@
"""
name = 'start-repository'
arguments = '<instance>'
-
+ min_args = max_args = 1
options = (
('debug',
{'short': 'D', 'action' : 'store_true',
@@ -542,7 +541,7 @@
from logilab.common.daemon import daemonize
from cubicweb.cwctl import init_cmdline_log_threshold
from cubicweb.server.server import RepositoryServer
- appid = pop_arg(args, msg='No instance specified !')
+ appid = args[0]
debug = self['debug']
if sys.platform == 'win32' and not debug:
from logging import getLogger
@@ -673,7 +672,7 @@
"""
name = 'db-dump'
arguments = '<instance>'
-
+ min_args = max_args = 1
options = (
('output',
{'short': 'o', 'type' : 'string', 'metavar' : '<file>',
@@ -688,7 +687,7 @@
)
def run(self, args):
- appid = pop_arg(args, 1, msg='No instance specified !')
+ appid = args[0]
if ':' in appid:
host, appid = appid.split(':')
_remote_dump(host, appid, self.config.output, self.config.sudo)
@@ -704,6 +703,7 @@
"""
name = 'db-restore'
arguments = '<instance> <backupfile>'
+ min_args = max_args = 2
options = (
('no-drop',
@@ -721,8 +721,7 @@
)
def run(self, args):
- appid = pop_arg(args, 1, msg='No instance specified !')
- backupfile = pop_arg(args, msg='No backup file or timestamp specified !')
+ appid, backupfile = args
_local_restore(appid, backupfile,
drop=not self.config.no_drop,
systemonly=not self.config.restore_all)
@@ -740,7 +739,7 @@
"""
name = 'db-copy'
arguments = '<src-instance> <dest-instance>'
-
+ min_args = max_args = 2
options = (
('no-drop',
{'short': 'n', 'action' : 'store_true',
@@ -762,8 +761,7 @@
def run(self, args):
import tempfile
- srcappid = pop_arg(args, 1, msg='No source instance specified !')
- destappid = pop_arg(args, msg='No destination instance specified !')
+ srcappid, destappid = args
fd, output = tempfile.mkstemp()
os.close(fd)
if ':' in srcappid:
@@ -786,7 +784,7 @@
"""
name = 'db-check'
arguments = '<instance>'
-
+ min_args = max_args = 1
options = (
('checks',
{'short': 'c', 'type' : 'csv', 'metavar' : '<check list>',
@@ -816,8 +814,7 @@
)
def run(self, args):
- from cubicweb.server.checkintegrity import check
- appid = pop_arg(args, 1, msg='No instance specified !')
+ appid = args[0]
config = ServerConfiguration.config_for(appid)
config.repairing = self.config.force
repo, cnx = repo_cnx(config)
@@ -833,12 +830,11 @@
"""
name = 'db-rebuild-fti'
arguments = '<instance>'
-
- options = ()
+ min_args = max_args = 1
def run(self, args):
from cubicweb.server.checkintegrity import reindex_entities
- appid = pop_arg(args, 1, msg='No instance specified !')
+ appid = args[0]
config = ServerConfiguration.config_for(appid)
repo, cnx = repo_cnx(config)
session = repo._get_session(cnx.sessionid, setpool=True)
@@ -857,9 +853,10 @@
"""
name = 'schema-sync'
arguments = '<instance>'
+ min_args = max_args = 1
def run(self, args):
- appid = pop_arg(args, msg='No instance specified !')
+ appid = args[0]
config = ServerConfiguration.config_for(appid)
mih = config.migration_handler()
mih.cmd_synchronize_schema()
@@ -885,24 +882,19 @@
def run(self, args):
from cubicweb.server.checkintegrity import check_mapping
from cubicweb.server.sources.pyrorql import load_mapping_file
- appid = pop_arg(args, 1, msg='No instance specified !')
- mappingfile = pop_arg(args, msg='No mapping file specified !')
+ appid, mappingfile = args
config = ServerConfiguration.config_for(appid)
config.quick_start = True
mih = config.migration_handler(connect=False, verbosity=1)
repo = mih.repo_connect() # necessary to get cubes
check_mapping(config.load_schema(), load_mapping_file(mappingfile))
-register_commands( (CreateInstanceDBCommand,
- InitInstanceCommand,
- GrantUserOnInstanceCommand,
- ResetAdminPasswordCommand,
- StartRepositoryCommand,
- DBDumpCommand,
- DBRestoreCommand,
- DBCopyCommand,
- CheckRepositoryCommand,
- RebuildFTICommand,
- SynchronizeInstanceSchemaCommand,
- CheckMappingCommand,
- ) )
+for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
+ GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
+ StartRepositoryCommand,
+ DBDumpCommand, DBRestoreCommand, DBCopyCommand,
+ CheckRepositoryCommand, RebuildFTICommand,
+ SynchronizeInstanceSchemaCommand,
+ CheckMappingCommand,
+ ):
+ CWCTL.register(cmdclass)