Example #1
0
def test_gather_dir():
    thisdir = os.path.dirname(__file__)
    test_gather = os.path.join(thisdir, 'test-gather')
    cwd = os.getcwd()

    os.chdir(test_gather)
    try:
       files = gather_filenames(('.',)) 
       assert files == ['./00-testme/x-script', './01-test/a', './01-test/b', './02-test2/c'] or \
	   files == ['.\\00-testme\\x-script', '.\\01-test\\a', '.\\01-test\\b', '.\\02-test2\\c'], files
    finally:
       os.chdir(cwd)
Example #2
0
def test_gather_dir():
    thisdir = os.path.dirname(__file__)
    test_gather = os.path.join(thisdir, 'test-gather')
    cwd = os.getcwd()

    os.chdir(test_gather)
    try:
        files = gather_filenames(('.', ))
        assert files == ['./00-testme/x-script', './01-test/a', './01-test/b', './02-test2/c'] or \
     files == ['.\\00-testme\\x-script', '.\\01-test\\a', '.\\01-test\\b', '.\\02-test2\\c'], files
    finally:
        os.chdir(cwd)
Example #3
0
def main():
    global twillargs, interactive
    
    import sys
    from twill import TwillCommandLoop, execute_file, __version__
    from twill.utils import gather_filenames
    from optparse import OptionParser
    from cStringIO import StringIO

    ###
    # make sure that the current working directory is in the path.  does this
    # work on Windows??

    if not '.' in sys.path:
        sys.path.append('.')
    ###

    #### OPTIONS

    parser = OptionParser()

    parser.add_option('-q', '--quiet', action="store_true", dest="quiet",
                      help = 'do not show normal output')

    parser.add_option('-i', '--interactive', action="store_true", dest="interact",
              help = 'drop into an interactive shell after running files (if any)')

    parser.add_option('-f', '--fail', action="store_true", dest="fail",
                      help = 'fail exit on first file to fail')

    parser.add_option('-n', '--never-fail', action="store_true",
                      dest="never_fail",
                      help = 'continue executing scripts past errors')

    parser.add_option('-v', '--version', action="store_true", dest="show_version",
                      help = 'show version information and exit')

    parser.add_option('-u', '--url', nargs=1, action="store", dest="url",
                      help="start at the given URL before each script")

    parser.add_option('-l', '--loglevel', nargs=1, action="store", dest="loglevel",
                      help="set the log level")

    parser.add_option('-L', '--logfile', nargs=1, action="store", dest="logfile",
                      help="use logfile as output for log, or discards log if value is 'none'")

    parser.add_option('-o', '--output', nargs=1, action="store", dest="outfile",
                      help="print output to outfile, or discards output if value is 'none'")

    parser.add_option('-t', '--tidy', nargs=1, action="store", dest="tidycmd",
                      help="uses tidycmd as the tidy command")
    ####

    # parse arguments.
    sysargs = sys.argv[1:]
    if '--' in sysargs:
        found = False
        for last in range(len(sysargs) - 1, -1, -1):
            if sysargs[last] == '--':
                found = True
                break

        if found:
            twillargs = sysargs[last + 1:]
            sysargs = sysargs[:last]

    (options, args) = parser.parse_args(sysargs)

    if options.show_version:
        print('twill version %s.' % __version__)
        sys.exit(0)

    if options.loglevel:
        if options.loglevel not in logconfig.loglevels:
            sys.exit("valid log levels are " + 
                    ", ".join(logconfig.loglevels.keys()))
        logconfig.logger.setLevel(logconfig.loglevels[options.loglevel])

    if options.logfile:
        try:
            path = options.logfile if options.logfile != 'none' else os.devnull
            logfile = open(path, 'w')
            logfile.write('')
            logconfig.set_handler_for_stream(logfile)
        except IOError as e:
            sys.exit("Invalid logfile '%s': %s", options.logfile, e)

    if options.outfile:
        try:
            path = options.outfile if options.outfile != 'none' else os.devnull
            outfile = open(path, 'w')
            outfile.write('')
            sys.stdout = outfile
        except IOError as e:
            sys.exit("Invalid output file '%s': %s", options.logfile, e)

    if options.quiet:
        if options.interact:
            logger.critical("interactive mode is incompatible with -q")
            sys.exit(1)
        if not args:
            sys.exit("interactive mode is incompatible with -q")

        old_stdout = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        logconfig.set_handler_for_stream(sys.stdout)
        
    if options.tidycmd:
        config.tidy_cmd = options.tidycmd

    # If run from the command line, find & run any scripts put on the command
    # line.  If none, drop into an interactive AutoShell.

    failed = False
    if len(args):
        success = []
        failure = []

        filenames = gather_filenames(args)

        for filename in filenames:
            logger.info('>> EXECUTING FILE %s', filename)

            try:
                interactive = False
                execute_file(filename,
                             initial_url=options.url,
                             never_fail=options.never_fail)
                success.append(filename)
            except Exception, e:
                if options.fail:
#                    import pdb
#                    _, _, tb = sys.exc_info()
#                    pdb.post_mortem(tb)
                    raise
                else:
                    logger.error('** UNHANDLED EXCEPTION: %s', str(e))
                    logger.debug(traceback.format_exc())
                    failure.append(filename)

        logger.info('--')
        logger.info('%d of %d files SUCCEEDED.', len(success),
                                             len(success) + len(failure))
        if len(failure):
            logger.error('Failed:\n\t')
            logger.error("\n\t".join(failure))
            failed = True
Example #4
0
def main():
    global twillargs, interactive
    
    import sys
    from twill import TwillCommandLoop, execute_file, __version__
    from twill.utils import gather_filenames
    from optparse import OptionParser
    from cStringIO import StringIO

    ###
    # make sure that the current working directory is in the path.  does this
    # work on Windows??

    if not '.' in sys.path:
        sys.path.append('.')
    ###

    #### OPTIONS

    parser = OptionParser()

    parser.add_option('-q', '--quiet', action="store_true", dest="quiet",
                      help = 'do not show normal output')

    parser.add_option('-i', '--interactive', action="store_true", dest="interact",
              help = 'drop into an interactive shell after running files (if any)')

    parser.add_option('-f', '--fail', action="store_true", dest="fail",
                      help = 'fail exit on first file to fail')

    parser.add_option('-n', '--never-fail', action="store_true",
                      dest="never_fail",
                      help = 'continue executing scripts past errors')

    parser.add_option('-v', '--version', action="store_true", dest="show_version",
                      help = 'show version information and exit')

    parser.add_option('-u', '--url', nargs=1, action="store", dest="url",
                      help="start at the given URL before each script")

    ####

    # parse arguments.
    sysargs = sys.argv[1:]
    if '--' in sysargs:
        found = False
        for last in range(len(sysargs) - 1, -1, -1):
            if sysargs[last] == '--':
                found = True
                break

        if found:
            twillargs = sysargs[last + 1:]
            sysargs = sysargs[:last]

    (options, args) = parser.parse_args(sysargs)

    if options.show_version:
        print 'twill version %s.' % (__version__,)
        sys.exit(0)

    if options.quiet:
        assert not options.interact, "interactive mode is incompatible with -q"
        assert args, "interactive mode is incompatible with -q"

        old_stdout = sys.stdout
        sys.stdout = StringIO()

    # If run from the command line, find & run any scripts put on the command
    # line.  If none, drop into an interactive AutoShell.

    failed = False
    if len(args):
        success = []
        failure = []

        filenames = gather_filenames(args)

        for filename in filenames:
            print '>> EXECUTING FILE', filename

            try:
                interactive = False
                execute_file(filename,
                             initial_url=options.url,
                             never_fail=options.never_fail)
                success.append(filename)
            except Exception, e:
                if options.fail:
#                    import pdb
#                    _, _, tb = sys.exc_info()
#                    pdb.post_mortem(tb)
                    raise
                else:
                    print '** UNHANDLED EXCEPTION:', str(e)
                    failure.append(filename)

        print '--'
        print '%d of %d files SUCCEEDED.' % (len(success),
                                             len(success) + len(failure),)
        if len(failure):
            print 'Failed:\n\t',
            print "\n\t".join(failure)
            failed = True
Example #5
0
def main():
    global twillargs, interactive
    
    import sys
    from twill import TwillCommandLoop, execute_file, __version__
    from twill.utils import gather_filenames
    from optparse import OptionParser
    from cStringIO import StringIO

    ###
    # make sure that the current working directory is in the path.  does this
    # work on Windows??

    if not '.' in sys.path:
        sys.path.append('.')
    ###

    #### OPTIONS

    parser = OptionParser()

    parser.add_option('-q', '--quiet', action="store_true", dest="quiet",
                      help = 'do not show normal output')

    parser.add_option('-i', '--interactive', action="store_true", dest="interact",
              help = 'drop into an interactive shell after running files (if any)')

    parser.add_option('-f', '--fail', action="store_true", dest="fail",
                      help = 'fail exit on first file to fail')

    parser.add_option('-n', '--never-fail', action="store_true",
                      dest="never_fail",
                      help = 'continue executing scripts past errors')

    parser.add_option('-v', '--version', action="store_true", dest="show_version",
                      help = 'show version information and exit')

    parser.add_option('-u', '--url', nargs=1, action="store", dest="url",
                      help="start at the given URL before each script")

    ####

    # parse arguments.
    sysargs = sys.argv[1:]
    if '--' in sysargs:
        found = False
        for last in range(len(sysargs) - 1, -1, -1):
            if sysargs[last] == '--':
                found = True
                break

        if found:
            twillargs = sysargs[last + 1:]
            sysargs = sysargs[:last]

    (options, args) = parser.parse_args(sysargs)

    if options.show_version:
        print 'twill version %s.' % (__version__,)
        sys.exit(0)

    if options.quiet:
        assert not options.interact, "interactive mode is incompatible with -q"
        assert args, "interactive mode is incompatible with -q"

        old_stdout = sys.stdout
        sys.stdout = StringIO()

    # If run from the command line, find & run any scripts put on the command
    # line.  If none, drop into an interactive AutoShell.

    failed = False
    if len(args):
        success = []
        failure = []

        filenames = gather_filenames(args)

        for filename in filenames:
            print '>> EXECUTING FILE', filename

            try:
                interactive = False
                execute_file(filename,
                             initial_url=options.url,
                             never_fail=options.never_fail)
                success.append(filename)
            except Exception, e:
                if options.fail:
#                    import pdb
#                    _, _, tb = sys.exc_info()
#                    pdb.post_mortem(tb)
                    raise
                else:
                    print '** UNHANDLED EXCEPTION:', str(e)
                    failure.append(filename)

        print '--'
        print '%d of %d files SUCCEEDED.' % (len(success),
                                             len(success) + len(failure),)
        if len(failure):
            print 'Failed:\n\t',
            print "\n\t".join(failure)
            failed = True