view kallithea/lib/paster_commands/ishell.py @ 6065:e0f31c7d0f5e

paster: split paster specifics out of kallithea.lib.utils BasePasterCommand and ask_ok are only useful in a Paster/command-line context, and can thus be removed from the already overly cluttered main utils module. (The new common.py has been added to Mercurial as a copy of utils.py, preserving its file history, but creating a somewhat bewildering diff.)
author Søren Løvborg <sorenl@unity3d.com>
date Thu, 28 Jul 2016 14:21:08 +0200
parents 037efd94e955
children 9c5f794df7cd
line wrap: on
line source

# -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
kallithea.lib.paster_commands.ishell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

interactive shell paster command for Kallithea

This file was forked by the Kallithea project in July 2014.
Original author and date, and relevant copyright and licensing information is below:
:created_on: Apr 4, 2013
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH, and others.
:license: GPLv3, see LICENSE.md for more details.
"""


import os
import sys

from kallithea.lib.paster_commands.common import BasePasterCommand

# Add location of top level folder to sys.path
from os.path import dirname
rc_path = dirname(dirname(dirname(os.path.realpath(__file__))))
sys.path.append(rc_path)


class Command(BasePasterCommand):

    max_args = 1
    min_args = 1

    usage = "CONFIG_FILE"
    group_name = "Kallithea"
    takes_config_file = -1
    parser = BasePasterCommand.standard_parser(verbose=True)
    summary = "Interactive shell"

    def command(self):
        #get SqlAlchemy session
        self._init_session()

        # imports, used in IPython shell
        import os
        import sys
        import time
        import shutil
        import datetime
        from kallithea.model.db import *

        try:
            from IPython import embed
            from IPython.config.loader import Config
            cfg = Config()
            cfg.InteractiveShellEmbed.confirm_exit = False
            embed(config=cfg, banner1="Kallithea IShell.")
        except ImportError:
            print 'IPython installation is required for ishell'
            sys.exit(-1)

    def update_parser(self):
        pass