--- a/cwconfig.py Wed Apr 22 20:01:28 2009 +0200
+++ b/cwconfig.py Thu Apr 23 10:46:05 2009 +0200
@@ -64,44 +64,44 @@
'default': 'UTF-8',
'help': _('user interface encoding'),
'group': 'ui', 'sitewide': True,
- }),
+ }),
('language',
{'type' : 'string',
'default': 'en',
'vocabulary': Method('available_languages'),
'help': _('language of the user interface'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('date-format',
{'type' : 'string',
'default': '%Y/%m/%d',
'help': _('how to format date in the ui ("man strftime" for format description)'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('datetime-format',
{'type' : 'string',
'default': '%Y/%m/%d %H:%M',
'help': _('how to format date and time in the ui ("man strftime" for format description)'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('time-format',
{'type' : 'string',
'default': '%H:%M',
'help': _('how to format time in the ui ("man strftime" for format description)'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('float-format',
{'type' : 'string',
'default': '%.3f',
'help': _('how to format float numbers in the ui'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('default-text-format',
{'type' : 'choice',
'choices': ('text/plain', 'text/rest', 'text/html'),
'default': 'text/html', # use fckeditor in the web ui
'help': _('default text format for rich text fields.'),
- 'group': 'ui',
+ 'group': 'ui',
}),
('short-line-size',
{'type' : 'int',
@@ -114,7 +114,7 @@
def register_persistent_options(options):
global PERSISTENT_OPTIONS
PERSISTENT_OPTIONS = merge_options(PERSISTENT_OPTIONS + options)
-
+
CFGTYPE2ETYPE_MAP = {
'string': 'String',
'choice': 'String',
@@ -122,7 +122,7 @@
'int': 'Int',
'float' : 'Float',
}
-
+
class CubicWebNoAppConfiguration(ConfigurationMixIn):
"""base class for cubicweb configuration without a specific instance directory
"""
@@ -198,7 +198,7 @@
}),
)
# static and class methods used to get application independant resources ##
-
+
@staticmethod
def cubicweb_version():
"""return installed cubicweb version"""
@@ -207,7 +207,7 @@
version = __pkginfo__.numversion
assert len(version) == 3, version
return Version(version)
-
+
@staticmethod
def persistent_options_configuration():
return Configuration(options=PERSISTENT_OPTIONS)
@@ -220,7 +220,7 @@
if cls.mode in ('dev', 'test') and not os.environ.get('APYCOT_ROOT'):
return join(CW_SOFTWARE_ROOT, 'web')
return cls.cube_dir('shared')
-
+
@classmethod
def i18n_lib_dir(cls):
"""return application's i18n directory"""
@@ -236,7 +236,7 @@
if isdir(join(directory, cube)) and not cube in ('CVS', '.svn', 'shared', '.hg'):
cubes.add(cube)
return sorted(cubes)
-
+
@classmethod
def cubes_search_path(cls):
"""return the path of directories where cubes should be searched"""
@@ -251,7 +251,7 @@
if not cls.CUBES_DIR in path:
path.append(cls.CUBES_DIR)
return path
-
+
@classmethod
def cube_dir(cls, cube):
"""return the cube directory for the given cube id,
@@ -267,7 +267,7 @@
def cube_migration_scripts_dir(cls, cube):
"""cube migration scripts directory"""
return join(cls.cube_dir(cube), 'migration')
-
+
@classmethod
def cube_pkginfo(cls, cube):
"""return the information module for the given cube"""
@@ -280,7 +280,7 @@
@classmethod
def cube_version(cls, cube):
- """return the version of the cube located in the given directory
+ """return the version of the cube located in the given directory
"""
from logilab.common.changelog import Version
version = cls.cube_pkginfo(cube).numversion
@@ -343,7 +343,7 @@
except KeyError:
continue
return tuple(reversed(cubes))
-
+
@classmethod
def cls_adjust_sys_path(cls):
"""update python path if necessary"""
@@ -381,7 +381,7 @@
except:
cls.exception('while loading cube %s', cube)
else:
- cls.warning('no __init__ file in cube %s', cube)
+ cls.warning('no __init__ file in cube %s', cube)
@classmethod
def init_available_cubes(cls):
@@ -393,7 +393,7 @@
__import__('cubes.%s' % cube)
except Exception, ex:
cls.warning("can't init cube %s: %s", cube, ex)
-
+
cubicweb_vobject_path = set(['entities'])
cube_vobject_path = set(['entities'])
@@ -441,17 +441,17 @@
elif exists(path + '.py'):
vregpath.append(path + '.py')
return vregpath
-
+
def __init__(self):
ConfigurationMixIn.__init__(self)
self.adjust_sys_path()
self.load_defaults()
- self.translations = {}
+ self.translations = {}
def adjust_sys_path(self):
self.cls_adjust_sys_path()
-
- def init_log(self, logthreshold=None, debug=False,
+
+ def init_log(self, logthreshold=None, debug=False,
logfile=None, syslog=False):
"""init the log service"""
if logthreshold is None:
@@ -468,7 +468,7 @@
for application objects. By default return nothing in NoApp config.
"""
return []
-
+
def eproperty_definitions(self):
cfg = self.persistent_options_configuration()
for section, options in cfg.options_by_section():
@@ -481,7 +481,7 @@
'help': optdict['help'],
'sitewide': optdict.get('sitewide', False)}
yield key, pdef
-
+
def map_option(self, optdict):
try:
vocab = optdict['choices']
@@ -491,10 +491,10 @@
vocab = getattr(self, vocab.method, ())
return CFGTYPE2ETYPE_MAP[optdict['type']], vocab
-
+
class CubicWebConfiguration(CubicWebNoAppConfiguration):
"""base class for cubicweb server and web configurations"""
-
+
INSTANCE_DATA_DIR = None
if CubicWebNoAppConfiguration.mode == 'test':
root = os.environ['APYCOT_ROOT']
@@ -517,7 +517,7 @@
set_language = True
# set this to true to avoid false error message while creating an application
creating = False
-
+
options = CubicWebNoAppConfiguration.options + (
('log-file',
{'type' : 'string',
@@ -540,7 +540,7 @@
}),
('sender-name',
{'type' : 'string',
- 'default': Method('default_application_id'),
+ 'default': Method('default_application_id'),
'help': 'name used as HELO name for outgoing emails from the \
repository.',
'group': 'email', 'inputlevel': 2,
@@ -558,7 +558,7 @@
def runtime_dir(cls):
"""run time directory for pid file..."""
return env_path('CW_RUNTIME', cls.RUNTIME_DIR, 'run time')
-
+
@classmethod
def registry_dir(cls):
"""return the control directory"""
@@ -570,7 +570,7 @@
return env_path('CW_INSTANCE_DATA',
cls.INSTANCE_DATA_DIR or cls.REGISTRY_DIR,
'additional data')
-
+
@classmethod
def migration_scripts_dir(cls):
"""cubicweb migration scripts directory"""
@@ -583,7 +583,7 @@
config = config or guess_configuration(cls.application_home(appid))
configcls = configuration_cls(config)
return configcls(appid)
-
+
@classmethod
def possible_configurations(cls, appid):
"""return the name of possible configurations for the given
@@ -591,7 +591,7 @@
"""
home = cls.application_home(appid)
return possible_configurations(home)
-
+
@classmethod
def application_home(cls, appid):
"""return the home directory of the application with the given
@@ -610,9 +610,9 @@
def accept_mode(cls, mode):
#assert mode in cls.MODES, mode
return mode in cls.MCOMPAT[cls.name]
-
+
# default configuration methods ###########################################
-
+
def default_application_id(self):
"""return the application identifier, useful for option which need this
as default value
@@ -634,13 +634,13 @@
i += 1
return path
return '/var/log/cubicweb/%s-%s.log' % (self.appid, self.name)
-
+
def default_pid_file(self):
"""return default path to the pid file of the application'server"""
return join(self.runtime_dir(), '%s-%s.pid' % (self.appid, self.name))
-
+
# instance methods used to get application specific resources #############
-
+
def __init__(self, appid):
self.appid = appid
CubicWebNoAppConfiguration.__init__(self)
@@ -658,11 +658,11 @@
@property
def apphome(self):
return join(self.registry_dir(), self.appid)
-
+
@property
def appdatahome(self):
return join(self.instance_data_dir(), self.appid)
-
+
def init_cubes(self, cubes):
assert self._cubes is None
self._cubes = self.reorder_cubes(cubes)
@@ -675,7 +675,7 @@
self.load_file_configuration(self.main_config_file())
# configuration initialization hook
self.load_configuration()
-
+
def cubes(self):
"""return the list of cubes used by this instance
@@ -684,7 +684,7 @@
"""
assert self._cubes is not None
return self._cubes
-
+
def cubes_path(self):
"""return the list of path to cubes used by this instance, from outer
most to inner most cubes
@@ -696,11 +696,11 @@
if not isinstance(cubes, list):
cubes = list(cubes)
self._cubes = self.reorder_cubes(list(self._cubes) + cubes)
-
+
def main_config_file(self):
"""return application's control configuration file"""
return join(self.apphome, '%s.conf' % self.name)
-
+
def save(self):
"""write down current configuration"""
self.generate_config(open(self.main_config_file(), 'w'))
@@ -713,7 +713,7 @@
version = self.cube_version(pkg)
infos.append('%s-%s' % (pkg, version))
return md5.new(';'.join(infos)).hexdigest()
-
+
def load_site_cubicweb(self):
"""load (web?) application's specific site_cubicweb file"""
for path in reversed([self.apphome] + self.cubes_path()):
@@ -727,7 +727,7 @@
self._load_site_cubicweb(sitefile)
self._site_loaded.add(sitefile)
self.warning('site_erudi.py is deprecated, should be renamed to site_cubicweb.py')
-
+
def _load_site_cubicweb(self, sitefile):
context = {}
execfile(sitefile, context, context)
@@ -736,14 +736,14 @@
if context.get('options'):
self.register_options(context['options'])
self.load_defaults()
-
+
def load_configuration(self):
"""load application's configuration files"""
super(CubicWebConfiguration, self).load_configuration()
if self.apphome and self.set_language:
# init gettext
self._set_language()
-
+
def init_log(self, logthreshold=None, debug=False, force=False):
"""init the log service"""
if not force and hasattr(self, '_logging_initialized'):
@@ -769,7 +769,7 @@
lang = path.split(os.sep)[-3]
if lang != 'en':
yield lang
-
+
def _set_language(self):
"""set language for gettext"""
from gettext import translation
@@ -781,8 +781,8 @@
self.translations[language] = tr.ugettext
except (ImportError, AttributeError, IOError):
self.exception('localisation support error for language %s',
- language)
-
+ language)
+
def vregistry_path(self):
"""return a list of files or directories where the registry will look
for application objects
@@ -796,7 +796,7 @@
if not 'all' in sources:
print 'warning: ignoring specified sources, requires a repository '\
'configuration'
-
+
def migration_handler(self):
"""return a migration handler instance"""
from cubicweb.common.migration import MigrationHelper
@@ -814,7 +814,7 @@
return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration'))
-
+
# alias to get a configuration instance from an application id
-application_configuration = CubicWebConfiguration.config_for
+application_configuration = CubicWebConfiguration.config_for
--- a/cwctl.py Wed Apr 22 20:01:28 2009 +0200
+++ b/cwctl.py Thu Apr 23 10:46:05 2009 +0200
@@ -1,6 +1,6 @@
"""%%prog %s [options] %s
-CubicWeb main applications controller.
+CubicWeb main applications controller.
%s"""
import sys
@@ -12,7 +12,7 @@
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
from cubicweb.toolsutils import Command, main_run, rm, create_dir, confirm
-
+
def wait_process_end(pid, maxtry=10, waittime=1):
"""wait for a process to actually die"""
import signal
@@ -42,13 +42,13 @@
modes.append('web ui')
break
return modes
-
-
+
+
class ApplicationCommand(Command):
"""base class for command taking 0 to n application id as arguments
(0 meaning all registered applications)
"""
- arguments = '[<application>...]'
+ arguments = '[<application>...]'
options = (
("force",
{'short': 'f', 'action' : 'store_true',
@@ -58,7 +58,7 @@
),
)
actionverb = None
-
+
def ordered_instances(self):
"""return instances in the order in which they should be started,
considering $REGISTRY_DIR/startorder file if it exists (useful when
@@ -81,7 +81,7 @@
else:
allinstances = _allinstances
return allinstances
-
+
def run(self, args):
"""run the <command>_method on each argument (a list of application
identifiers)
@@ -96,7 +96,7 @@
else:
askconfirm = False
self.run_args(args, askconfirm)
-
+
def run_args(self, args, askconfirm):
for appid in args:
if askconfirm:
@@ -104,7 +104,7 @@
if not confirm('%s application %r ?' % (self.name, appid)):
continue
self.run_arg(appid)
-
+
def run_arg(self, appid):
cmdmeth = getattr(self, '%s_application' % self.name)
try:
@@ -143,7 +143,7 @@
sys.exit(status)
else:
self.run_arg(appid)
-
+
# base commands ###############################################################
class ListCommand(Command):
@@ -155,10 +155,10 @@
name = 'list'
options = (
('verbose',
- {'short': 'v', 'action' : 'store_true',
- 'help': "display more information."}),
+ {'short': 'v', 'action' : 'store_true',
+ 'help': "display more information."}),
)
-
+
def run(self, args):
"""run the command with its specific arguments"""
if args:
@@ -174,7 +174,7 @@
if not line:
continue
print ' ', line
- print
+ print
try:
cubesdir = pathsep.join(cwcfg.cubes_search_path())
namesize = max(len(x) for x in cwcfg.available_cubes())
@@ -219,7 +219,7 @@
print '* %s (%s)' % (appid, ', '.join(modes))
try:
config = cwcfg.config_for(appid, modes[0])
- except Exception, exc:
+ except Exception, exc:
print ' (BROKEN application, %s)' % exc
continue
else:
@@ -261,7 +261,7 @@
}
),
)
-
+
def run(self, args):
"""run the command with its specific arguments"""
from logilab.common.textutils import get_csv
@@ -323,14 +323,14 @@
print
helper.postcreate()
-
+
class DeleteApplicationCommand(Command):
"""Delete an application. Will remove application's files and
unregister it.
"""
name = 'delete'
arguments = '<application>'
-
+
options = ()
def run(self, args):
@@ -361,7 +361,7 @@
class StartApplicationCommand(ApplicationCommand):
"""Start the given applications. If no application is given, start them all.
-
+
<application>...
identifiers of the applications to start. If no application is
given, start them all.
@@ -414,19 +414,19 @@
class StopApplicationCommand(ApplicationCommand):
"""Stop the given applications.
-
+
<application>...
identifiers of the applications to stop. If no application is
given, stop them all.
"""
name = 'stop'
actionverb = 'stopped'
-
+
def ordered_instances(self):
instances = super(StopApplicationCommand, self).ordered_instances()
instances.reverse()
return instances
-
+
def stop_application(self, appid):
"""stop the application's server"""
config = cwcfg.config_for(appid)
@@ -460,12 +460,12 @@
# already removed by twistd
pass
print 'application %s stopped' % appid
-
+
class RestartApplicationCommand(StartApplicationCommand,
StopApplicationCommand):
"""Restart the given applications.
-
+
<application>...
identifiers of the applications to restart. If no application is
given, restart them all.
@@ -497,30 +497,30 @@
status = system('%s %s' % (forkcmd, appid))
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)
-
+
class ReloadConfigurationCommand(RestartApplicationCommand):
"""Reload the given applications. This command is equivalent to a
restart for now.
-
+
<application>...
identifiers of the applications to reload. If no application is
given, reload them all.
"""
name = 'reload'
-
+
def reload_application(self, appid):
self.restart_application(appid)
-
+
class StatusCommand(ApplicationCommand):
"""Display status information about the given applications.
-
+
<application>...
identifiers of the applications to status. If no application is
given, get status information about all registered applications.
@@ -576,7 +576,7 @@
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z',
'default': None,
'help': 'force migration from the indicated cubicweb version.'}),
-
+
('fs-only',
{'short': 's', 'action' : 'store_true',
'default': False,
@@ -586,13 +586,13 @@
{'short': 'n', 'action' : 'store_true',
'default': False,
'help': 'don\'t try to stop application before migration and to restart it after.'}),
-
+
('verbosity',
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>',
'default': 1,
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \
for everything."}),
-
+
('backup-db',
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>',
'default': None,
@@ -613,7 +613,7 @@
def ordered_instances(self):
# need this since mro return StopApplicationCommand implementation
return ApplicationCommand.ordered_instances(self)
-
+
def upgrade_application(self, appid):
from logilab.common.changelog import Version
if not (cwcfg.mode == 'dev' or self.config.nostartstop):
@@ -648,7 +648,7 @@
continue
if installedversion > applversion:
toupgrade.append( (cube, applversion, installedversion) )
- cubicwebversion = config.cubicweb_version()
+ cubicwebversion = config.cubicweb_version()
if self.config.force_cubicweb_version:
applcubicwebversion = Version(self.config.force_cubicweb_version)
vcconf['cubicweb'] = applcubicwebversion
@@ -706,7 +706,7 @@
'help': 'only connect to the system source when the instance is '
'using multiple sources. You can\'t use this option and the '
'--ext-sources option at the same time.'}),
-
+
('ext-sources',
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>',
'default': None,
@@ -715,7 +715,7 @@
will connect to all defined sources. If 'migration' is given, appropriate \
sources for migration will be automatically selected.",
}),
-
+
)
def run(self, args):
appid = pop_arg(args, 99, msg="No application specified !")
@@ -733,12 +733,12 @@
mih.scripts_session(args)
else:
mih.interactive_shell()
- mih.shutdown()
+ mih.shutdown()
class RecompileApplicationCatalogsCommand(ApplicationCommand):
"""Recompile i18n catalogs for applications.
-
+
<application>...
identifiers of the applications to consider. If no application is
given, recompile for all registered applications.
@@ -772,7 +772,7 @@
"""list available instances, useful for bash completion."""
name = 'listinstances'
hidden = True
-
+
def run(self, args):
"""run the command with its specific arguments"""
regdir = cwcfg.registry_dir()
@@ -784,7 +784,7 @@
"""list available componants, useful for bash completion."""
name = 'listcubes'
hidden = True
-
+
def run(self, args):
"""run the command with its specific arguments"""
for cube in cwcfg.available_cubes():
@@ -804,7 +804,7 @@
ListInstancesCommand, ListCubesCommand,
))
-
+
def run(args):
"""command line tool"""
cwcfg.load_cwctl_plugins()