Changeset - 0f9e7dbfa5d2
[Not reviewed]
default
0 5 0
Mads Kiilerich - 7 years ago 2018-11-18 19:57:40
mads@kiilerich.com
utils2: Move ask_ok out of paster_commands

The ask_ok function is still a mess and should be cleaned up ...
5 files changed with 16 insertions and 17 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_extensions.py
Show inline comments
 
@@ -23,13 +23,13 @@ import click
 
import kallithea.bin.kallithea_cli_base as cli_base
 

	
 
import os
 
import pkg_resources
 

	
 
import kallithea
 
from kallithea.lib.paster_commands.common import ask_ok
 
from kallithea.lib.utils2 import ask_ok
 

	
 
@cli_base.register_command(config_file=True)
 
def extensions_create():
 
    """Write template file for extending Kallithea in Python.
 

	
 
    An rcextensions directory with a __init__.py file will be created next to
kallithea/bin/kallithea_cli_repo.py
Show inline comments
 
@@ -24,15 +24,14 @@ import kallithea.bin.kallithea_cli_base 
 

	
 
import datetime
 
import os
 
import re
 
import shutil
 

	
 
from kallithea.lib.paster_commands.common import ask_ok
 
from kallithea.lib.utils import repo2db_mapper, REMOVED_REPO_PAT
 
from kallithea.lib.utils2 import safe_unicode, safe_str
 
from kallithea.lib.utils2 import safe_unicode, safe_str, ask_ok
 
from kallithea.model.db import Repository, Ui
 
from kallithea.model.meta import Session
 
from kallithea.model.scm import ScmModel
 

	
 
@cli_base.register_command(config_file_initialize_app=True)
 
@click.option('--remove-missing', is_flag=True,
kallithea/lib/db_manage.py
Show inline comments
 
@@ -74,13 +74,13 @@ class DbManage(object):
 

	
 
    def _ask_ok(self, msg):
 
        """Invoke ask_ok unless the force_ask option provides the answer"""
 
        force_ask = self.cli_args.get('force_ask')
 
        if force_ask is not None:
 
            return force_ask
 
        from kallithea.lib.paster_commands.common import ask_ok
 
        from kallithea.lib.utils2 import ask_ok
 
        return ask_ok(msg)
 

	
 
    def init_db(self, SESSION=None):
 
        if SESSION:
 
            self.sa = SESSION
 
        else:
kallithea/lib/paster_commands/common.py
Show inline comments
 
@@ -35,25 +35,12 @@ import gearbox.command
 
import kallithea.config.middleware
 
import kallithea.model.base
 
import kallithea.lib.utils2
 
import kallithea.lib.utils
 

	
 

	
 
def ask_ok(prompt, retries=4, complaint='Yes or no please!'):
 
    while True:
 
        ok = raw_input(prompt)
 
        if ok in ('y', 'ye', 'yes'):
 
            return True
 
        if ok in ('n', 'no', 'nop', 'nope'):
 
            return False
 
        retries = retries - 1
 
        if retries < 0:
 
            raise IOError
 
        print complaint
 

	
 

	
 
class BasePasterCommand(gearbox.command.Command):
 
    """
 
    Abstract Base Class for gearbox commands.
 
    """
 

	
 
    # override to control how much get_parser and run should do:
kallithea/lib/utils2.py
Show inline comments
 
@@ -678,6 +678,19 @@ def repo_name_slug(value):
 

	
 
    for c in """`?=[]\;'"<>,/~!@#$%^&*()+{}|: """:
 
        slug = slug.replace(c, '-')
 
    slug = recursive_replace(slug, '-')
 
    slug = collapse(slug, '-')
 
    return slug
 

	
 

	
 
def ask_ok(prompt, retries=4, complaint='Yes or no please!'):
 
    while True:
 
        ok = raw_input(prompt)
 
        if ok in ('y', 'ye', 'yes'):
 
            return True
 
        if ok in ('n', 'no', 'nop', 'nope'):
 
            return False
 
        retries = retries - 1
 
        if retries < 0:
 
            raise IOError
 
        print complaint
0 comments (0 inline, 0 general)