Example #1
0
def apply_rules(rules, definitions=DEFAULT_DEFINITIONS, message_func=None):
    if message_func is None:
        message_func = _print
    files_to_check = defaultdict(set)
    for patterns, categories in rules:
        if not isinstance(patterns, list):
            patterns = [patterns]
        if not isinstance(categories, list):
            categories = [categories]
        for p in patterns:
            for filename in ant_glob(p):
                file_categories = files_to_check[filename]
                for category in categories:
                    if category.startswith('-'):
                        file_categories.discard(category[1:])
                    else:
                        file_categories.add(category)
    failures = defaultdict(set)
    for filename in sorted(files_to_check.keys()):
        for category in files_to_check[filename]:
            if not definitions[category](filename):
                failures[category].add(filename)
    message_func("{0} errors in {1} scanned files:".format(
        len(failures), len(files_to_check)))
    for category, filenames in sorted(failures.items()):
        if len(filenames) == 0:
            continue
        message_func("{0}, {1} files failed:".format(category, len(filenames)))
        for fname in sorted(filenames):
            print "    {0}".format(fname)
    return len(failures) == 0
Example #2
0
def main():
    if len(sys.argv) <= 1 or sys.argv[1] == '--help':
        print usage_text
        return
    with open(sys.argv[1]) as f:
        config = json.load(f)
    basedir = os.path.abspath(config['basedir'])
    os.chdir(basedir)
    output_directories = set()
    output_files = []
    for fileset in config['files']:
        os.chdir(basedir)
        os.chdir(fileset['source'])
        for pattern in fileset['patterns']:
            files = ant_glob(pattern)
            for filename in files:
                frompath = ntpath.normpath(
                    ntpath.join(fileset['source'], filename))
                topath = ntpath.normpath(
                    ntpath.join(fileset['target'], filename))
                output_directories.update(topath[:index + 1]
                                          for (index, ch) in enumerate(topath)
                                          if ch == '\\')
                output_files.append((frompath, topath))
    print "  <ItemGroup>"
    for dirname in sorted(output_directories):
        print "    <Folder Include={0} />".format(quoteattr(dirname))
    print "  </ItemGroup>"
    print "  <ItemGroup>"
    for (frompath, topath) in output_files:
        print "    <Content Include=\"{0}\">\n      <Link>{1}</Link>\n    </Content>".format(
            escape(frompath), escape(topath))
    print "  </ItemGroup>"
def main():
    if len(sys.argv) <= 1 or sys.argv[1] == '--help':
        print usage_text
        return
    with open(sys.argv[1]) as f:
        config = json.load(f)
    basedir = os.path.abspath(config['basedir'])
    os.chdir(basedir)
    output_directories = set()
    output_files = []
    for fileset in config['files']:
        os.chdir(basedir)
        os.chdir(fileset['source'])
        for pattern in fileset['patterns']:
            files = ant_glob(pattern)
            for filename in files:
                frompath = ntpath.normpath(ntpath.join(fileset['source'], filename))
                topath = ntpath.normpath(ntpath.join(fileset['target'], filename))
                output_directories.update(topath[:index+1] for (index, ch) in enumerate(topath) if ch=='\\')
                output_files.append((frompath, topath))
    print "  <ItemGroup>"
    for dirname in sorted(output_directories):
        print "    <Folder Include={0} />".format(quoteattr(dirname))
    print "  </ItemGroup>"
    print "  <ItemGroup>"
    for (frompath, topath) in output_files:
        print "    <Content Include=\"{0}\">\n      <Link>{1}</Link>\n    </Content>".format(escape(frompath), escape(topath))
    print "  </ItemGroup>"
Example #4
0
def apply_rules(rules, definitions = DEFAULT_DEFINITIONS, message_func=None):
    if message_func is None:
        message_func = _print
    files_to_check = defaultdict(set)
    for patterns, categories in rules:
        if not isinstance(patterns, list):
            patterns = [patterns]
        if not isinstance(categories, list):
            categories = [categories]
        for p in patterns:
            for filename in ant_glob(p):
                file_categories = files_to_check[filename]
                for category in categories:
                    if category.startswith('-'):
                        file_categories.discard(category[1:])
                    else:
                        file_categories.add(category)
    failures = defaultdict(set)
    for filename in sorted(files_to_check.keys()):
        for category in files_to_check[filename]:
            if not definitions[category](filename):
                failures[category].add(filename)
    message_func("{0} errors in {1} scanned files:".format(len(failures), len(files_to_check)))
    for category, filenames in sorted(failures.items()):
        if len(filenames) == 0:
            continue
        message_func("{0}, {1} files failed:".format(category, len(filenames)))
        for fname in sorted(filenames):
            print "    {0}".format(fname)
    return len(failures) == 0
Example #5
0
def main():
    options, args = parse_args()
    files_found = 0
    files_matched = 0
    for pattern in args:
        for fname in ant_glob(pattern):
            files_found += 1
            indent, endings = analyze_file(fname)
            should_show = (options.indent=="" and options.endings=="") or (match(indent, options.indent) and match(endings, options.endings))
            if should_show:
                files_matched += 1
                if (options.indent=="" and options.endings=="") or options.verbose:
                    print indent, "\t", endings, "\t", fname
                else:
                    print fname
    sys.exit(0 if files_matched>0 else 1 if files_found>0 else 2)
Example #6
0
def main():
    parser = make_parser()
    options, args = parser.parse_args()

    if len(args) < 2:
        parser.print_usage()
        return

    tf = tarfile.open(args[0], 'w:gz')
    try:
        os.chdir(options.basedir)
        for pattern in args[1:]:
            for fname in ant_glob(pattern):
                if fname.startswith('./'):
                    fname = fname[2:]
                tf.add(fname, options.prefix + fname)
    finally:
        tf.close()
Example #7
0
def main():
    options, args = parse_args()
    files_found = 0
    files_matched = 0
    for pattern in args:
        for fname in ant_glob(pattern):
            files_found += 1
            indent, endings = analyze_file(fname)
            should_show = (options.indent == "" and options.endings
                           == "") or (match(indent, options.indent)
                                      and match(endings, options.endings))
            if should_show:
                files_matched += 1
                if (options.indent == ""
                        and options.endings == "") or options.verbose:
                    print indent, "\t", endings, "\t", fname
                else:
                    print fname
    sys.exit(0 if files_matched > 0 else 1 if files_found > 0 else 2)
Example #8
0
def main():
    options, args = parse_args()
    for pattern in args:
        for fname in ant_glob(pattern):
            fix_file(fname, options.endings)
            print fname