# 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 from textwrap import dedent
from moz.l10n.paths.config import L10nConfigPaths from moz.l10n.paths.discover import L10nDiscoverPaths from moz.l10n.resource import UnsupportedResource, parse_resource, serialize_resource
log = logging.getLogger(__name__)
Result = Enum("Result", ("OK", "FIXED", "UNSUPPORTED", "FAIL"))
def cli() -> None:
parser = ArgumentParser(
description=dedent( """
Fix the formatting for localization resources.
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. """
),
formatter_class=RawDescriptionHelpFormatter,
)
parser.add_argument("-q", "--quiet", action="store_true", help="only log 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( "--continue",
action="store_true",
dest="continue_on_error",
help="do not stop at first parse error",
)
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 = fix(args.paths, args.config, args.continue_on_error)
sys.exit(res)
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.