Permalink
Browse files

make coherent commands behavior by always using --config/-c for Paste…

…Deploy config files
  • Loading branch information...
1 parent 1c30c45 commit b24dddd4c6a779f061edb2cb321156cb2e73c288 @amol- amol- committed Dec 2, 2012
Showing with 34 additions and 29 deletions.
  1. +9 −2 README.rst
  2. +19 −23 gearbox/commands/serve.py
  3. +6 −4 gearbox/commands/setup_app.py
View
11 README.rst
@@ -25,6 +25,11 @@ Just by installing gearbox itself your TurboGears project will be able to use ge
commands like ``gearbox serve``, ``gearbox setup-app`` and ``gearbox makepackage`` commands.
These commands provide a replacement for the paster serve, paster setup-app and paster create commands.
+The main difference with the paster command is usually only that gearbox commands explicitly set the
+configuration file using the ``--config`` option instead of accepting it positionally. By default gearbox
+will always load a configuration file named `development.ini`, this mean you can simply run ``gearbox serve``
+in place of ``paster serve development.ini``
+
To have a list of the available commands simply run ``gearbox --help``::
$ gearbox --help
@@ -58,7 +63,7 @@ Then it is possible to ask for help for a given command by using ``gearbox help
[--pid-file FILENAME] [--reload]
[--reload-interval RELOAD_INTERVAL] [--monitor-restart]
[--status] [--user USERNAME] [--group GROUP]
- [--stop-daemon]
+ [--stop-daemon] [-c CONFIG_FILE]
[args [args ...]]
Serves a web application that uses a PasteDeploy configuration file
@@ -88,7 +93,9 @@ Then it is possible to ask for help for a given command by using ``gearbox help
--group GROUP Set the group (usually only possible when run as root)
--stop-daemon Stop a daemonized server (given a PID file, or default
gearbox.pid file)
-
+ -c CONFIG_FILE, --config CONFIG_FILE
+ application config file to read (default:
+ development.ini)
Development Tools Commands
View
42 gearbox/commands/serve.py
@@ -24,7 +24,7 @@
from gearbox.utils.log import setup_logging
from paste.deploy import loadapp, loadserver
-from cliff.command import Command
+from gearbox.command import Command
MAXFD = 1024
@@ -44,9 +44,21 @@ class DaemonizeException(Exception):
pass
class ServeCommand(Command):
+ _scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)
+
+ _reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
+ _monitor_environ_key = 'PASTE_MONITOR_SHOULD_RUN'
+
+ possible_subcommands = ('start', 'stop', 'restart', 'status')
+ verbose = 1
+
def get_parser(self, prog_name):
parser = super(ServeCommand, self).get_parser(prog_name)
+ parser.add_argument("-c", "--config",
+ help='application config file to read (default: development.ini)',
+ dest='config_file', default="development.ini")
+
parser.add_argument(
'-n', '--app-name',
dest='app_name',
@@ -121,14 +133,6 @@ def get_parser(self, prog_name):
return parser
- _scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)
-
- _reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
- _monitor_environ_key = 'PASTE_MONITOR_SHOULD_RUN'
-
- possible_subcommands = ('start', 'stop', 'restart', 'status')
- verbose = 1
-
def get_description(self):
return 'Serves a web application that uses a PasteDeploy configuration file'
@@ -148,29 +152,21 @@ def take_action(self, opts):
opts.set_user = opts.set_group = None
# @@: Is this the right stage to set the user at?
- self.change_user_group(
- opts.set_user, opts.set_group)
-
- if not opts.args:
- self.out('You must give a config file')
- return 2
+ self.change_user_group(opts.set_user, opts.set_group)
- app_spec = opts.args[0]
- if (len(opts.args) > 1
- and opts.args[1] in self.possible_subcommands):
- cmd = opts.args[1]
- restvars = opts.args[2:]
+ app_spec = opts.config_file
+ if opts.args and opts.args[0] in self.possible_subcommands:
+ cmd = opts.args[0]
+ restvars = opts.args[1:]
else:
cmd = None
- restvars = opts.args[1:]
+ restvars = opts.args[0:]
if opts.reload:
if os.environ.get(self._reloader_environ_key):
if self.verbose > 1:
self.out('Running reloading file monitor')
install_reloader(int(opts.reload_interval), [app_spec])
- # if self.requires_config_file:
- # watch_file(opts.args[0])
else:
return self.restart_with_reloader()
View
10 gearbox/commands/setup_app.py
@@ -2,7 +2,7 @@
import os
-from cliff.command import Command
+from gearbox.command import Command
from paste.deploy import appconfig
class SetupAppCommand(Command):
@@ -12,18 +12,20 @@ def get_description(self):
def get_parser(self, prog_name):
parser = super(SetupAppCommand, self).get_parser(prog_name)
+ parser.add_argument("-c", "--config",
+ help='application config file to read (default: development.ini)',
+ dest='config_file', default="development.ini")
+
parser.add_argument('--name',
action='store',
dest='section_name',
default=None,
help='The name of the section to set up (default: app:main)')
- parser.add_argument('args', nargs='*', default=['development.ini'])
-
return parser
def take_action(self, opts):
- config_spec = opts.args[0]
+ config_spec = opts.config_file
section = opts.section_name
if section is None:
if '#' in config_spec:

0 comments on commit b24dddd

Please sign in to comment.