Exemplo n.º 1
0
    def test_parse_result(self):
        # short ver
        args = shlex.split('decanter -c setup.py \
-h example.com -p 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')

        # change arguments
        args = shlex.split('decanter -c setup.py \
-h foo.bar -p 8080 stop')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'stop')

        # change order
        args = shlex.split('decanter status -p 8080 \
-h foo.bar -c setup.py')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'status')

        # omit arguments
        args = shlex.split('decanter -c setup.py restart')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'localhost')
        self.assertEqual(result.port, 9000)
        self.assertEqual(result.command, 'restart')

        # long ver
        args = shlex.split('decanter --config setup.py \
--hostname example.com --port 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')

        # change arguments
        args = shlex.split('decanter --config setup.py \
--hostname foo.bar --port 8080 stop')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'stop')

        # change order
        args = shlex.split('decanter status --port 8080 \
--hostname foo.bar --config setup.py')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'status')

        # omit arguments
        args = shlex.split('decanter --config setup.py restart')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'localhost')
        self.assertEqual(result.port, 9000)
        self.assertEqual(result.command, 'restart')

        # mix short and long
        args = shlex.split('decanter -c setup.py \
--hostname example.com -p 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')
Exemplo n.º 2
0
    def test_parse_result(self):
        # short ver
        args = shlex.split('decanter -c setup.py \
-h example.com -p 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')

        # change arguments
        args = shlex.split('decanter -c setup.py \
-h foo.bar -p 8080 stop')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'stop')

        # change order
        args = shlex.split('decanter status -p 8080 \
-h foo.bar -c setup.py')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'status')

        # omit arguments
        args = shlex.split('decanter -c setup.py restart')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'localhost')
        self.assertEqual(result.port, 9000)
        self.assertEqual(result.command, 'restart')

        # long ver
        args = shlex.split('decanter --config setup.py \
--hostname example.com --port 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')

        # change arguments
        args = shlex.split('decanter --config setup.py \
--hostname foo.bar --port 8080 stop')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'stop')

        # change order
        args = shlex.split('decanter status --port 8080 \
--hostname foo.bar --config setup.py')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'foo.bar')
        self.assertEqual(result.port, 8080)
        self.assertEqual(result.command, 'status')

        # omit arguments
        args = shlex.split('decanter --config setup.py restart')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.hostname, 'localhost')
        self.assertEqual(result.port, 9000)
        self.assertEqual(result.command, 'restart')

        # mix short and long
        args = shlex.split('decanter -c setup.py \
--hostname example.com -p 8000 start')
        result = decanter.parse_args(source=args)
        self.assertEqual(result.config, 'setup.py')
        self.assertEqual(result.hostname, 'example.com')
        self.assertEqual(result.port, 8000)
        self.assertEqual(result.command, 'start')
Exemplo n.º 3
0
# -*- coding: utf-8 -*-

from gevent import monkey
monkey.patch_all()

import os
import bottle
from datetime import date

from decanter.decanter import parse_args, Decanter
from decanter.lib.middleware import Dispatcher, StripPath
from decanter.lib.config import Config
from decanter.lib.logger import Log

if __name__ == '__main__':
    args = parse_args(filepath=__file__)

    config = Config(args.config)
    app = Dispatcher(StripPath(bottle.default_app()), config)
    pidfile = config.pidfile.format(args.port)

    # make directory to put pid file
    piddir = os.path.dirname(pidfile)
    if not os.path.isdir(piddir):
        os.makedirs(piddir)

    logfile = config.logger['filepath'].format(args.port, date.today())
    # initialize logger
    log = Log(logfile)
    decanter = Decanter(app, args.hostname, args.port, pidfile)