Exemple #1
0
def main():
    try:
        ensure_api_compat(__name__, REQUIRED_CEMENT_API)    
        lay_cement(config=default_config, banner=BANNER)
    
        log = get_logger(__name__)
        log.debug("Cement Framework Initialized!")

        if not len(sys.argv) > 1:
            sys.argv.append('default')

        config = get_config()
        
        # create the lock file
        if os.path.exists(config['lockfile']):
            raise SatCLIRuntimeError, \
                "lock file exists, is satcli already running?"
        else:
            f = open(config['lockfile'], 'w+')
            f.write(get_timestamp())
            f.close()

        run_command(sys.argv[1])
            
    except CementArgumentError, e:
        print("CementArgumentError > %s" % e)
        sys.exit(e.code)
Exemple #2
0
def main(args=None):
    try:
        lay_cement(config=default_config, banner=BANNER, args=args)

        log = get_logger(__name__)
        log.debug("Cement Framework Initialized!")

        if not len(sys.argv) > 1:
            sys.argv.append('default')

        run_command(sys.argv[1])

    except CementArgumentError, e:
        # Display the apps exception names instead for the Cement exceptions.
        print("CementTestArgumentError > %s" % e)
        sys.exit(e.code)
Exemple #3
0
def simulate(args):
    """
    Simulate running a command at command line.  Requires args to have
    the exact args set to it as would be passed at command line.
    
    Required arguments:
    
        args
            The args to pass to sys.argv
            
    Usage:
    
    .. code-block:: python
    
        import sys
        from cement.core.testing import simulate
        
        args = ['helloworld', 'example', 'cmd1', '--test-option']
        res = simulate(args)
        
    """
    if not len(sys.argv) >= 1:
        raise CementRuntimeError, "args must be set properly."

    sys.argv = args
    try:
        cmd = re.sub('-', '_', sys.argv[1])
    except IndexError:
        cmd = 'default'

    (res_dict, output_txt) = run_command(cmd_name=cmd, ignore_conflicts=True)
    return (res_dict, output_txt)
Exemple #4
0
def main(args=None):
    try:    
        lay_cement(config=default_config, banner=BANNER, args=args)
    
        log = get_logger(__name__)
        log.debug("Cement Framework Initialized!")

        if not len(sys.argv) > 1:
            sys.argv.append('default')
        
        run_command(sys.argv[1])
            
    except CementArgumentError, e:
        # Display the apps exception names instead for the Cement exceptions.
        print("CementTestArgumentError > %s" % e)
        sys.exit(e.code)
Exemple #5
0
def nose_main(args, test_config):
    """
    This function provides an alternative to main() that is more friendly for 
    nose tests as it doesn't catch any exceptions.
    
    Required Arguments:
        
        args
            The args to pass to lay_cement
        
        test_config
            A test config to pass to lay_cement
    
    Usage:
    
    .. code-block:: python
    
        from iustools.core.appmain import nose_main
        from iustools.core.config import get_nose_config
        
        args = [__file__, 'nosetests', '--quiet']
        (res_dict, output_text) = nose_main(args, get_nose_config())
        
    """
    
    lay_cement(config=test_config, banner=BANNER, args=args)
    log = get_logger(__name__)
    log.debug("Cement Framework Initialized!")

    if not len(args) > 1:
        args.append('default')

    (res, output_txt) = run_command(args[1])
    return (res, output_txt)
Exemple #6
0
def simulate(args):
    """
    Simulate running a command at command line.  Requires args to have
    the exact args set to it as would be passed at command line.
    
    Required arguments:
    
        args
            The args to pass to sys.argv
            
    Usage:
    
    .. code-block:: python
    
        import sys
        from cement.core.testing import simulate
        
        args = ['helloworld', 'example', 'cmd1', '--test-option']
        res = simulate(args)
        
    """
    if not len(sys.argv) >= 1:
        raise CementRuntimeError, "args must be set properly."
        
    sys.argv = args
    try:
        cmd = re.sub('-', '_', sys.argv[1])
    except IndexError:
        cmd = 'default'
        
    (res_dict, output_txt) = run_command(cmd_name=cmd, ignore_conflicts=True)
    return (res_dict, output_txt)
Exemple #7
0
def main(args=None):
    try:
        if not args:
            args = sys.argv
            
        lay_cement(config=default_config, banner=BANNER, args=args, 
                   version=VERSION)
    
        log = get_logger(__name__)
        log.debug("Cement Framework Initialized!")

        if not len(args) > 1:
            args.append('default')
        
        run_command(args[1])
            
    except MFConfigError, e:
        print("MFConfigError > %s" % e)
        sys.exit(e.code)
Exemple #8
0
def main():
    ensure_abi_compat(__name__, REQUIRED_CEMENT_ABI)
    
    # Warning: You shouldn't modify below this point unless you know what 
    # you're doing.
    
    lay_cement(default_config, version_banner=BANNER)
    
    log = get_logger(__name__)
    log.debug("Cement Framework Initialized!")
    
    # react to the passed command.  command should be the first arg always
    try:
        if not len(sys.argv) > 1:
            raise CementArgumentError, "A command is required. See --help?"
        
        run_command(sys.argv[1])
            
    except CementArgumentError, e:
        print("CementArgumentError > %s" % e)
Exemple #9
0
def process_args(args):
    """
    Process the arg (command line) and pass off to command.run_command.
    
    Returns: (result_dict, output_txt)
    
    """
    if not len(args) > 1:
        args.append('default')

    (res, output_txt) = run_command(args[1])
    return (res, output_txt)
Exemple #10
0
def nose_main(args, test_config):
    """
    This function provides an alternative to main() that is more friendly for 
    nose tests as it doesn't catch any exceptions.
    """

    lay_cement(config=test_config, banner=BANNER, args=args)
    log = get_logger(__name__)
    log.debug("Cement Framework Initialized!")

    if not len(args) > 1:
        args.append('default')

    (res, output_txt) = run_command(args[1])
    return (res, output_txt)
Exemple #11
0
def nose_main(args, test_config):
    """
    This function provides an alternative to main() that is more friendly for 
    nose tests as it doesn't catch any exceptions.
    """

    lay_cement(config=test_config, banner=BANNER, args=args)
    log = get_logger(__name__)
    log.debug("Cement Framework Initialized!")

    if not len(args) > 1:
        args.append('default')

    (res, output_txt) = run_command(args[1])
    return (res, output_txt)
Exemple #12
0
def test_run_command_namespace():  
    # raises cause example is a namespace
    run_command('example2')
def test_run_unknown_command():
    # raises cause blah doesn't exist
    run_command('blah')
def test_run_command():
    # raises cause example is a namespace
    run_command('cmd1')
def test_run_command_namespace_help():
    # raises cause example is a namespace
    run_command('example-help')
def test_run_command_namespace():
    # raises cause example is a namespace
    run_command('example2')
Exemple #17
0
def test_run_unknown_command():  
    # raises cause blah doesn't exist
    run_command('blah')
Exemple #18
0
def test_run_command():  
    # raises cause example is a namespace
    run_command('cmd1')
Exemple #19
0
def test_run_command_namespace_help():  
    # raises cause example is a namespace
    run_command('example-help')