# Copyright Mozilla Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
from __future__ import annotations
import logging import sys from argparse import ArgumentParser, RawDescriptionHelpFormatter from collections.abc import Iterable from enum import Enum from glob import glob from os import getcwd from os.path import abspath, isdir, relpath, splitext from textwrap import dedent
from moz.l10n.formats import UnsupportedFormat, l10n_extensions from moz.l10n.paths.config import L10nConfigPaths from moz.l10n.paths.discover import L10nDiscoverPaths from moz.l10n.resource import parse_resource
log = logging.getLogger(__name__)
Result = Enum("Result", ("OK", "SKIP", "UNSUPPORTED", "FAIL"))
If `paths` is a single directory, it is iterated with L10nConfigPaths if --config is set, or L10nDiscoverPaths otherwise.
If `paths` isnot a single directory, its values are treated as glob expressions, with ** support.
FIXME: Currently only checks that files can be parsed, and does not check their contents more deeply. """
),
formatter_class=RawDescriptionHelpFormatter,
)
parser.add_argument( "-q", "--quiet", action="store_true", help="only log input argument errors"
)
parser.add_argument( "-v", "--verbose", action="count", default=0, help="increase logging verbosity"
)
parser.add_argument( "--config", metavar="PATH", type=str, help="path to l10n.toml config file"
)
parser.add_argument( "-u", "--skip-unknown",
action="store_true",
help="skip files without a known L10n extension",
)
parser.add_argument("paths", nargs="*", type=str, help="directory or files to fix")
args = parser.parse_args()
log_level = (
logging.ERROR if args.quiet else (
logging.WARNING if args.verbose == 0 else logging.INFO if args.verbose == 1 else logging.DEBUG
)
)
logging.basicConfig(format="%(message)s", level=log_level)
res = lint(
args.paths,
config_path=args.config,
skip_unknown=args.skip_unknown,
)
sys.exit(res)
If a single directory is given,
it is iterated with `L10nConfigPaths` if `config_path` is set, or `L10nDiscoverPaths` otherwise.
If `file_paths` isnot a single directory,
the paths are treated as glob expressions.
Returns 0 on success, 1 on parse error, or2 on argument error. """ if config_path: if file_paths:
log.error("With --config, paths must not be set.") return2
cfg_paths = L10nConfigPaths(config_path)
root_dir = abspath(cfg_paths.base)
path_iter: Iterable[str] = cfg_paths.ref_paths elif len(file_paths) == 1and isdir(file_paths[0]):
root_dir = abspath(file_paths[0])
path_iter = L10nDiscoverPaths(root_dir, ref_root=".").ref_paths elif file_paths:
root_dir = getcwd()
path_iter = (path for fp in file_paths for path in glob(fp, recursive=True)) else:
log.error("Either paths of --config is required") return2
ok = 0
unsupported = 0
failed = 0 for path in path_iter:
res = lint_file(root_dir, path, skip_unknown) if res == Result.SKIP: pass elif res == Result.UNSUPPORTED:
unsupported += 1 elif res == Result.FAIL:
failed += 1 else:
ok += 1 ifnot ok andnot unsupported andnot failed:
log.warning("Found no localization resources") return1if failed or unsupported else0
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.