Пример #1
0
def main():
    logging.basicConfig(level=logging.INFO)
    ap = argparse.ArgumentParser()
    ap.add_argument("root", nargs="+", help="Directory roots to recurse through")
    args = ap.parse_args()
    logging.info("Searching for files...")
    filenames = list(sanity_utils.find_files(
        roots=args.root,
        ignored_dirs=sanity_utils.IGNORED_DIRS + ["migrations"],
        allowed_extensions=set(m[0] for m in MAPPING)
    ))
    logging.info("Found %d files. Extracting messages...", len(filenames))

    static_catalog = Catalog(charset="UTF-8")
    js_catalog = Catalog(charset="UTF-8")
    for filename in filenames:
        for filename, lineno, message, comments in extract_from_file(filename):
            catalog = (js_catalog if filename.endswith(".js") else static_catalog)
            catalog.add(message, None, [(filename, lineno)], auto_comments=comments)
    with open("shoop-static.pot", "wb") as outf:
        write_po_wrap(outf, static_catalog)
        logging.info("Wrote %d static messages to %s.", len(static_catalog), outf.name)
    with open("shoop-js.pot", "wb") as outf:
        write_po_wrap(outf, js_catalog)
        logging.info("Wrote %d JavaScript messages to %s.", len(js_catalog), outf.name)
Пример #2
0
def main():
    logging.basicConfig(level=logging.INFO)
    ap = argparse.ArgumentParser()
    ap.add_argument("root",
                    nargs="+",
                    help="Directory roots to recurse through")
    args = ap.parse_args()
    logging.info("Searching for files...")
    filenames = list(
        sanity_utils.find_files(roots=args.root,
                                ignored_dirs=sanity_utils.IGNORED_DIRS +
                                ["migrations"],
                                allowed_extensions=set(m[0] for m in MAPPING)))
    logging.info("Found %d files. Extracting messages...", len(filenames))

    static_catalog = Catalog(charset="UTF-8")
    js_catalog = Catalog(charset="UTF-8")
    for filename in filenames:
        for filename, lineno, message, comments in extract_from_file(filename):
            catalog = (js_catalog
                       if filename.endswith(".js") else static_catalog)
            catalog.add(message,
                        None, [(filename, lineno)],
                        auto_comments=comments)
    with open("shoop-static.pot", "wb") as outf:
        write_po_wrap(outf, static_catalog)
        logging.info("Wrote %d static messages to %s.", len(static_catalog),
                     outf.name)
    with open("shoop-js.pot", "wb") as outf:
        write_po_wrap(outf, js_catalog)
        logging.info("Wrote %d JavaScript messages to %s.", len(js_catalog),
                     outf.name)
Пример #3
0
 def add_root(self, path):
     path = os.path.realpath(path)
     if os.path.isdir(path):
         for filepath in find_files(path, allowed_extensions=(".py", )):
             if filepath.startswith("test_"):
                 self.log.info("Info! Skipping: %s" % filepath)
                 continue
             self.filenames.add(filepath)
     elif path.endswith('.py'):
         self.filenames.add(path)
Пример #4
0
 def add_root(self, path):
     path = os.path.realpath(path)
     if os.path.isdir(path):
         for filepath in find_files(path, allowed_extensions=(".py",)):
             if filepath.startswith("test_"):
                 self.log.info("Skipping: %s" % filepath)
                 continue
             self.filenames.add(filepath)
     elif path.endswith('.py'):
         self.filenames.add(path)
Пример #5
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("root", nargs="?", default=".", help="Root directory (defaults to %(default)s)")
    args = ap.parse_args()
    generated_resources = set()
    paths = find_files(args.root, generated_resources)
    errors = check_sanity_of_files(paths, generated_resources)
    found_errors = False
    for error in errors:
        found_errors = True
        print(error)  # noqa
    if found_errors:
        raise SystemExit(1)
Пример #6
0
def find_files(roots, extensions):
    paths = set()
    generated_resources = set()
    for root in roots:
        for file in sanity_utils.find_files(
                root,
                generated_resources=generated_resources,
                allowed_extensions=extensions,
                ignored_dirs=sanity_utils.IGNORED_DIRS + ["migrations"]):
            if not is_file_ignored(file):
                paths.add(file)
    paths -= generated_resources
    return paths
Пример #7
0
def find_files(roots, extensions):
    paths = set()
    generated_resources = set()
    for root in roots:
        for file in sanity_utils.find_files(
            root,
            generated_resources=generated_resources,
            allowed_extensions=extensions,
            ignored_dirs=sanity_utils.IGNORED_DIRS + ["migrations"]
        ):
            if not is_file_ignored(file):
                paths.add(file)
    paths -= generated_resources
    return paths
Пример #8
0
def command(filenames, dirnames, checkers, group=False):
    error_count = 0
    all_filenames = chain(
        find_files(dirnames, allowed_extensions=(".py",), ignored_dirs=IGNORED_DIRS + ["migrations"]), filenames
    )
    checkers = [globals()[name] for name in checkers]
    for filename in all_filenames:
        file_errors = list(process_file(filename, checkers))
        if not file_errors:
            continue
        if group:
            print("%s:" % filename, file=sys.stderr)
            for error in file_errors:
                print("    %s" % error, file=sys.stderr)
                error_count += 1
            continue
        for error in file_errors:
            print("%s:%s" % (filename, error), file=sys.stderr)
            error_count += 1

    print("###########################")
    print("Total errors to handle: %d" % error_count)
    print("###########################")
Пример #9
0
def command(filenames, dirnames, checkers, group=False):
    error_count = 0
    all_filenames = chain(
        find_files(dirnames,
                   allowed_extensions=(".py", ),
                   ignored_dirs=IGNORED_DIRS + ["migrations"]), filenames)
    checkers = [globals()[name] for name in checkers]
    for filename in all_filenames:
        file_errors = list(process_file(filename, checkers))
        if not file_errors:
            continue
        if group:
            print("%s:" % filename, file=sys.stderr)
            for error in file_errors:
                print("    %s" % error, file=sys.stderr)
                error_count += 1
            continue
        for error in file_errors:
            print("%s:%s" % (filename, error), file=sys.stderr)
            error_count += 1

    print("###########################")
    print("Total errors to handle: %d" % error_count)
    print("###########################")
Пример #10
0
def gather_files(dirnames, filenames):
    files_to_process = []
    files_to_process.extend(filename for filename in filenames
                            if filename.endswith(".py"))
    files_to_process.extend(find_files(dirnames, allowed_extensions=(".py", )))
    return files_to_process
Пример #11
0
def find_files(root, extensions):
    for filepath in sanity_utils.find_files(root, allowed_extensions=extensions):
        if not is_file_ignored(filepath):
            yield filepath
Пример #12
0
def gather_files(dirnames, filenames):
    files_to_process = []
    files_to_process.extend(filename for filename in filenames if filename.endswith(".py"))
    files_to_process.extend(find_files(dirnames, allowed_extensions=(".py",)))
    return files_to_process
Пример #13
0
def command(filenames, dirnames):
    for filename in find_files(dirnames, allowed_extensions=(".py",)):
        for error in process_file(filename):
            print("%s: %s" % (filename, error), file=sys.stderr)
Пример #14
0
def find_files(root, extensions):
    for filepath in sanity_utils.find_files(root,
                                            allowed_extensions=extensions):
        if not is_file_ignored(filepath):
            yield filepath