Пример #1
0
def main():
    command = None
    patterns = []
    arguments = sys.argv[1:]

    program_settings_file = os.path.expanduser('~/.specto')

    usage = "usage: %prog [options] command"
    parser = optparse.OptionParser(usage=usage)

    parser.add_option('-p', '--pattern',
                    help='Pattern for files that should be watched for changes',
                    dest='patterns',
                    type='string',
                    action='callback',
                    callback=pattern_callback
                    )
    parser.add_option('-e', '--exclude',
                    help='Pattern for files that should be excluded when watching',
                    dest='exclude_patterns',
                    type='string',
                    action='callback',
                    callback=pattern_callback
                    )
    parser.add_option('--no-color',
                    help='Do not show colored output',
                    action='store_true',
                    dest='no_color'
                    )
    parser.add_option('--no-start',
                    help='Do not run command on startup',
                    action='store_true',
                    default=False,
                    dest='no_start'
                    )
    parser.add_option('--no-stdout',
                    help='Do not print any stdout information from process',
                    action='store_true',
                    default=False,
                    dest='no_stdout'
                    )
    parser.add_option('--no-stderr',
                    help='Do not print any stderr information from process',
                    action='store_true',
                    default=False,
                    dest='no_stderr'
                    )
    parser.add_option('--progress',
                    help='Print a progess message every 60 seconds if process is still running',
                    action='store_true',
                    default=False,
                    dest='progress'
                    )
    parser.add_option('-v', '--verbose',
                    help='Verbose output',
                    action='store_true',
                    dest='verbose'
                    )
    standard_patterns = add_standard_pattern_options(parser)

    # TODO
    # --project  - use project setting in config file
    # --pwd      - change current working dir

    # Load user settings file
    if os.path.exists(program_settings_file):
        args = parse_program_settings_file(program_settings_file)
        arguments.extend(args)

    (opts, args) = parser.parse_args(args=arguments)

    d = opts.__dict__
    for row in standard_patterns:
        for typ in row[0]:
            if typ[2:] in d and d[typ[2:]] is True:
                patterns.extend(row[1])
                break

    if opts.patterns is not None:
        patterns.extend(opts.patterns)

    if len(patterns) == 0:
        print "No file matching patterns found!"
        print
        parser.print_help()
        sys.exit(1)

    if len(args) == 0:
        print "You need to specify a command!"
        print
        parser.print_help()
        sys.exit(1)
    else:
        command = args[0]

    if opts.no_color is True:
        colored.disable()

    try:
        w = Watcher()
        w.run(command, patterns, opts)
    except KeyboardInterrupt:
        w.stop()
        print "Bye!"
Пример #2
0
def disable_color():
    """ Disable all colors

    """
    if IS_CLINT:
        colored.disable()
Пример #3
0
def disable_color():
    """ Disable all colors

    """
    if IS_CLINT:
        colored.disable()