--- a/cwctl.py Fri Jul 24 13:50:59 2009 +0200
+++ b/cwctl.py Fri Jul 24 14:33:37 2009 +0200
@@ -1,6 +1,6 @@
"""%%prog %s [options] %s
-CubicWeb main applications controller.
+CubicWeb main instances controller.
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
%s"""
@@ -45,11 +45,11 @@
return modes
-class ApplicationCommand(Command):
- """base class for command taking 0 to n application id as arguments
- (0 meaning all registered applications)
+class InstanceCommand(Command):
+ """base class for command taking 0 to n instance id as arguments
+ (0 meaning all registered instances)
"""
- arguments = '[<application>...]'
+ arguments = '[<instance>...]'
options = (
("force",
{'short': 'f', 'action' : 'store_true',
@@ -84,7 +84,7 @@
return allinstances
def run(self, args):
- """run the <command>_method on each argument (a list of application
+ """run the <command>_method on each argument (a list of instance
identifiers)
"""
if not args:
@@ -102,29 +102,29 @@
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
self.run_arg(appid)
def run_arg(self, appid):
- cmdmeth = getattr(self, '%s_application' % self.name)
+ cmdmeth = getattr(self, '%s_instance' % self.name)
try:
cmdmeth(appid)
except (KeyboardInterrupt, SystemExit):
print >> sys.stderr, '%s aborted' % self.name
sys.exit(2) # specific error code
except (ExecutionError, ConfigurationError), ex:
- print >> sys.stderr, 'application %s not %s: %s' % (
+ print >> sys.stderr, 'instance %s not %s: %s' % (
appid, self.actionverb, ex)
except Exception, ex:
import traceback
traceback.print_exc()
- print >> sys.stderr, 'application %s not %s: %s' % (
+ print >> sys.stderr, 'instance %s not %s: %s' % (
appid, self.actionverb, ex)
-class ApplicationCommandFork(ApplicationCommand):
- """Same as `ApplicationCommand`, but command is forked in a new environment
+class InstanceCommandFork(InstanceCommand):
+ """Same as `InstanceCommand`, but command is forked in a new environment
for each argument
"""
@@ -136,7 +136,7 @@
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
if forkcmd:
status = system('%s %s' % (forkcmd, appid))
@@ -148,10 +148,9 @@
# base commands ###############################################################
class ListCommand(Command):
- """List configurations, componants and applications.
+ """List configurations, cubes and instances.
- list available configurations, installed web and server componants, and
- registered applications
+ list available configurations, installed cubes, and registered instances
"""
name = 'list'
options = (
@@ -206,30 +205,30 @@
try:
regdir = cwcfg.registry_dir()
except ConfigurationError, ex:
- print 'No application available:', ex
+ print 'No instance available:', ex
print
return
instances = list_instances(regdir)
if instances:
- print 'Available applications (%s):' % regdir
+ print 'Available instances (%s):' % regdir
for appid in instances:
modes = cwcfg.possible_configurations(appid)
if not modes:
- print '* %s (BROKEN application, no configuration found)' % appid
+ print '* %s (BROKEN instance, no configuration found)' % appid
continue
print '* %s (%s)' % (appid, ', '.join(modes))
try:
config = cwcfg.config_for(appid, modes[0])
except Exception, exc:
- print ' (BROKEN application, %s)' % exc
+ print ' (BROKEN instance, %s)' % exc
continue
else:
- print 'No application available in %s' % regdir
+ print 'No instance available in %s' % regdir
print
-class CreateApplicationCommand(Command):
- """Create an application from a cube. This is an unified
+class CreateInstanceCommand(Command):
+ """Create an instance from a cube. This is an unified
command which can handle web / server / all-in-one installation
according to available parts of the software library and of the
desired cube.
@@ -238,11 +237,11 @@
the name of cube to use (list available cube names using
the "list" command). You can use several cubes by separating
them using comma (e.g. 'jpl,eemail')
- <application>
- an identifier for the application to create
+ <instance>
+ an identifier for the instance to create
"""
name = 'create'
- arguments = '<cube> <application>'
+ arguments = '<cube> <instance>'
options = (
("config-level",
{'short': 'l', 'type' : 'int', 'metavar': '<level>',
@@ -255,7 +254,7 @@
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>',
'choices': ('all-in-one', 'repository', 'twisted'),
'default': 'all-in-one',
- 'help': 'installation type, telling which part of an application \
+ 'help': 'installation type, telling which part of an instance \
should be installed. You can list available configurations using the "list" \
command. Default to "all-in-one", e.g. an installation embedding both the RQL \
repository and the web server.',
@@ -285,13 +284,13 @@
print '\navailable cubes:',
print ', '.join(cwcfg.available_cubes())
return
- # create the registry directory for this application
- print '\n'+underline_title('Creating the application %s' % appid)
+ # create the registry directory for this instance
+ print '\n'+underline_title('Creating the instance %s' % appid)
create_dir(config.apphome)
# load site_cubicweb from the cubes dir (if any)
config.load_site_cubicweb()
# cubicweb-ctl configuration
- print '\n'+underline_title('Configuring the application (%s.conf)' % configname)
+ print '\n'+underline_title('Configuring the instance (%s.conf)' % configname)
config.input_config('main', self.config.config_level)
# configuration'specific stuff
print
@@ -311,7 +310,7 @@
'continue anyway ?'):
print 'creation not completed'
return
- # create the additional data directory for this application
+ # create the additional data directory for this instance
if config.appdatahome != config.apphome: # true in dev mode
create_dir(config.appdatahome)
if config['uid']:
@@ -323,18 +322,18 @@
helper.postcreate()
-class DeleteApplicationCommand(Command):
- """Delete an application. Will remove application's files and
+class DeleteInstanceCommand(Command):
+ """Delete an instance. Will remove instance's files and
unregister it.
"""
name = 'delete'
- arguments = '<application>'
+ arguments = '<instance>'
options = ()
def run(self, args):
"""run the command with its specific arguments"""
- appid = pop_arg(args, msg="No application specified !")
+ appid = pop_arg(args, msg="No instance specified !")
configs = [cwcfg.config_for(appid, configname)
for configname in cwcfg.possible_configurations(appid)]
if not configs:
@@ -353,16 +352,16 @@
if ex.errno != errno.ENOENT:
raise
confignames = ', '.join([config.name for config in configs])
- print 'application %s (%s) deleted' % (appid, confignames)
+ print 'instance %s (%s) deleted' % (appid, confignames)
-# application commands ########################################################
+# instance commands ########################################################
-class StartApplicationCommand(ApplicationCommand):
- """Start the given applications. If no application is given, start them all.
+class StartInstanceCommand(InstanceCommand):
+ """Start the given instances. If no instance is given, start them all.
- <application>...
- identifiers of the applications to start. If no application is
+ <instance>...
+ identifiers of the instances to start. If no instance is
given, start them all.
"""
name = 'start'
@@ -374,7 +373,7 @@
("force",
{'short': 'f', 'action' : 'store_true',
'default': False,
- 'help': 'start the application even if it seems to be already \
+ 'help': 'start the instance even if it seems to be already \
running.'}),
('profile',
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>',
@@ -383,8 +382,8 @@
}),
)
- def start_application(self, appid):
- """start the application's server"""
+ def start_instance(self, appid):
+ """start the instance's server"""
# use get() since start may be used from other commands (eg upgrade)
# without all options defined
debug = self.get('debug')
@@ -403,31 +402,31 @@
print "starting server with command :"
print command
if system(command):
- print 'an error occured while starting the application, not started'
+ print 'an error occured while starting the instance, not started'
print
return False
if not debug:
- print 'application %s started' % appid
+ print 'instance %s started' % appid
return True
-class StopApplicationCommand(ApplicationCommand):
- """Stop the given applications.
+class StopInstanceCommand(InstanceCommand):
+ """Stop the given instances.
- <application>...
- identifiers of the applications to stop. If no application is
+ <instance>...
+ identifiers of the instances to stop. If no instance is
given, stop them all.
"""
name = 'stop'
actionverb = 'stopped'
def ordered_instances(self):
- instances = super(StopApplicationCommand, self).ordered_instances()
+ instances = super(StopInstanceCommand, self).ordered_instances()
instances.reverse()
return instances
- def stop_application(self, appid):
- """stop the application's server"""
+ def stop_instance(self, appid):
+ """stop the instance's server"""
config = cwcfg.config_for(appid)
helper = self.config_helper(config, cmdname='stop')
helper.poststop() # do this anyway
@@ -458,15 +457,15 @@
except OSError:
# already removed by twistd
pass
- print 'application %s stopped' % appid
+ print 'instance %s stopped' % appid
-class RestartApplicationCommand(StartApplicationCommand,
- StopApplicationCommand):
- """Restart the given applications.
+class RestartInstanceCommand(StartInstanceCommand,
+ StopInstanceCommand):
+ """Restart the given instances.
- <application>...
- identifiers of the applications to restart. If no application is
+ <instance>...
+ identifiers of the instances to restart. If no instance is
given, restart them all.
"""
name = 'restart'
@@ -476,18 +475,18 @@
regdir = cwcfg.registry_dir()
if not isfile(join(regdir, 'startorder')) or len(args) <= 1:
# no specific startorder
- super(RestartApplicationCommand, self).run_args(args, askconfirm)
+ super(RestartInstanceCommand, self).run_args(args, askconfirm)
return
print ('some specific start order is specified, will first stop all '
- 'applications then restart them.')
+ 'instances then restart them.')
# get instances in startorder
stopped = []
for appid in args:
if askconfirm:
print '*'*72
- if not confirm('%s application %r ?' % (self.name, appid)):
+ if not confirm('%s instance %r ?' % (self.name, appid)):
continue
- self.stop_application(appid)
+ self.stop_instance(appid)
stopped.append(appid)
forkcmd = [w for w in sys.argv if not w in args]
forkcmd[1] = 'start'
@@ -497,46 +496,46 @@
if status:
sys.exit(status)
- def restart_application(self, appid):
- self.stop_application(appid)
- if self.start_application(appid):
- print 'application %s %s' % (appid, self.actionverb)
+ def restart_instance(self, appid):
+ self.stop_instance(appid)
+ if self.start_instance(appid):
+ print 'instance %s %s' % (appid, self.actionverb)
-class ReloadConfigurationCommand(RestartApplicationCommand):
- """Reload the given applications. This command is equivalent to a
+class ReloadConfigurationCommand(RestartInstanceCommand):
+ """Reload the given instances. This command is equivalent to a
restart for now.
- <application>...
- identifiers of the applications to reload. If no application is
+ <instance>...
+ identifiers of the instances to reload. If no instance is
given, reload them all.
"""
name = 'reload'
- def reload_application(self, appid):
- self.restart_application(appid)
+ def reload_instance(self, appid):
+ self.restart_instance(appid)
-class StatusCommand(ApplicationCommand):
- """Display status information about the given applications.
+class StatusCommand(InstanceCommand):
+ """Display status information about the given instances.
- <application>...
- identifiers of the applications to status. If no application is
- given, get status information about all registered applications.
+ <instance>...
+ identifiers of the instances to status. If no instance is
+ given, get status information about all registered instances.
"""
name = 'status'
options = ()
@staticmethod
- def status_application(appid):
- """print running status information for an application"""
+ def status_instance(appid):
+ """print running status information for an instance"""
for mode in cwcfg.possible_configurations(appid):
config = cwcfg.config_for(appid, mode)
print '[%s-%s]' % (appid, mode),
try:
pidf = config['pid-file']
except KeyError:
- print 'buggy application, pid file not specified'
+ print 'buggy instance, pid file not specified'
continue
if not exists(pidf):
print "doesn't seem to be running"
@@ -551,22 +550,22 @@
print "running with pid %s" % (pid)
-class UpgradeApplicationCommand(ApplicationCommandFork,
- StartApplicationCommand,
- StopApplicationCommand):
- """Upgrade an application after cubicweb and/or component(s) upgrade.
+class UpgradeInstanceCommand(InstanceCommandFork,
+ StartInstanceCommand,
+ StopInstanceCommand):
+ """Upgrade an instance after cubicweb and/or component(s) upgrade.
For repository update, you will be prompted for a login / password to use
to connect to the system database. For some upgrades, the given user
should have create or alter table permissions.
- <application>...
- identifiers of the applications to upgrade. If no application is
+ <instance>...
+ identifiers of the instances to upgrade. If no instance is
given, upgrade them all.
"""
name = 'upgrade'
actionverb = 'upgraded'
- options = ApplicationCommand.options + (
+ options = InstanceCommand.options + (
('force-componant-version',
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z',
'default': None,
@@ -584,7 +583,7 @@
('nostartstop',
{'short': 'n', 'action' : 'store_true',
'default': False,
- 'help': 'don\'t try to stop application before migration and to restart it after.'}),
+ 'help': 'don\'t try to stop instance before migration and to restart it after.'}),
('verbosity',
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>',
@@ -595,7 +594,7 @@
('backup-db',
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>',
'default': None,
- 'help': "Backup the application database before upgrade.\n"\
+ 'help': "Backup the instance database before upgrade.\n"\
"If the option is ommitted, confirmation will be ask.",
}),
@@ -610,10 +609,10 @@
)
def ordered_instances(self):
- # need this since mro return StopApplicationCommand implementation
- return ApplicationCommand.ordered_instances(self)
+ # need this since mro return StopInstanceCommand implementation
+ return InstanceCommand.ordered_instances(self)
- def upgrade_application(self, appid):
+ def upgrade_instance(self, appid):
from logilab.common.changelog import Version
config = cwcfg.config_for(appid)
config.repairing = True # notice we're not starting the server
@@ -623,7 +622,7 @@
except AttributeError:
# not a server config
pass
- # get application and installed versions for the server and the componants
+ # get instance and installed versions for the server and the componants
print 'getting versions configuration from the repository...'
mih = config.migration_handler()
repo = mih.repo_connect()
@@ -654,13 +653,13 @@
if cubicwebversion > applcubicwebversion:
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion))
if not self.config.fs_only and not toupgrade:
- print 'no software migration needed for application %s' % appid
+ print 'no software migration needed for instance %s' % appid
return
for cube, fromversion, toversion in toupgrade:
print '**** %s migration %s -> %s' % (cube, fromversion, toversion)
# only stop once we're sure we have something to do
if not (cwcfg.mode == 'dev' or self.config.nostartstop):
- self.stop_application(appid)
+ self.stop_instance(appid)
# run cubicweb/componants migration scripts
mih.migrate(vcconf, reversed(toupgrade), self.config)
# rewrite main configuration file
@@ -681,9 +680,9 @@
return
mih.shutdown()
print
- print 'application migrated'
+ print 'instance migrated'
if not (cwcfg.mode == 'dev' or self.config.nostartstop):
- self.start_application(appid)
+ self.start_instance(appid)
print
@@ -693,11 +692,11 @@
argument may be given corresponding to a file containing commands to
execute in batch mode.
- <application>
- the identifier of the application to connect.
+ <instance>
+ the identifier of the instance to connect.
"""
name = 'shell'
- arguments = '<application> [batch command file]'
+ arguments = '<instance> [batch command file]'
options = (
('system-only',
{'short': 'S', 'action' : 'store_true',
@@ -717,7 +716,7 @@
)
def run(self, args):
- appid = pop_arg(args, 99, msg="No application specified !")
+ appid = pop_arg(args, 99, msg="No instance specified !")
config = cwcfg.config_for(appid)
if self.config.ext_sources:
assert not self.config.system_only
@@ -736,18 +735,18 @@
mih.shutdown()
-class RecompileApplicationCatalogsCommand(ApplicationCommand):
- """Recompile i18n catalogs for applications.
+class RecompileInstanceCatalogsCommand(InstanceCommand):
+ """Recompile i18n catalogs for instances.
- <application>...
- identifiers of the applications to consider. If no application is
- given, recompile for all registered applications.
+ <instance>...
+ identifiers of the instances to consider. If no instance is
+ given, recompile for all registered instances.
"""
name = 'i18ninstance'
@staticmethod
- def i18ninstance_application(appid):
- """recompile application's messages catalogs"""
+ def i18ninstance_instance(appid):
+ """recompile instance's messages catalogs"""
config = cwcfg.config_for(appid)
try:
config.bootstrap_cubes()
@@ -756,8 +755,8 @@
if ex.errno != errno.ENOENT:
raise
# bootstrap_cubes files doesn't exist
- # set creating to notify this is not a regular start
- config.creating = True
+ # notify this is not a regular start
+ config.repairing = True
# create an in-memory repository, will call config.init_cubes()
config.repository()
except AttributeError:
@@ -791,16 +790,16 @@
print cube
register_commands((ListCommand,
- CreateApplicationCommand,
- DeleteApplicationCommand,
- StartApplicationCommand,
- StopApplicationCommand,
- RestartApplicationCommand,
+ CreateInstanceCommand,
+ DeleteInstanceCommand,
+ StartInstanceCommand,
+ StopInstanceCommand,
+ RestartInstanceCommand,
ReloadConfigurationCommand,
StatusCommand,
- UpgradeApplicationCommand,
+ UpgradeInstanceCommand,
ShellCommand,
- RecompileApplicationCatalogsCommand,
+ RecompileInstanceCatalogsCommand,
ListInstancesCommand, ListCubesCommand,
))