forked from robotframework/SeleniumLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
105 lines (88 loc) · 3.36 KB
/
__main__.py
File metadata and controls
105 lines (88 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright 2008-2011 Nokia Networks
# Copyright 2011-2016 Ryan Tomac, Ed Manlove and contributors
# Copyright 2016- Robot Framework 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.
import json
from pathlib import Path
from typing import Optional
import click
from .get_versions import get_version
from .translation import compare_translation, get_library_translation
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
VERSION = get_version()
@click.group()
@click.version_option(VERSION)
def cli():
"""Robot Framework SeleniumLibrary command line tool.
Possible commands are:
translation
will generate template translation json file from library keywords.
See each command argument help for more details what (optional) arguments that command supports.
"""
pass
@cli.command()
@click.argument(
"filename",
type=click.Path(exists=False, dir_okay=False, path_type=Path),
required=True,
)
@click.option(
"--plugins",
help="Same as plugins argument in the library import.",
default=None,
type=str,
)
@click.option(
"--compare",
help="Compares the translation file sha256 sum to library documentation.",
default=False,
is_flag=True,
show_default=True,
)
def translation(
filename: Path,
plugins: Optional[str] = None,
compare: bool = False,
):
"""Default translation file from library keywords.
This will help users to create their own translation as Python plugins. Command
will populate json file with English language. To create proper translation
file, users needs to translate the keyword name and doc arguments values in
json file.
The filename argument will tell where the default json file is saved.
The --plugins argument will add plugin keywords in addition to the library keywords
into the default translation json file. It is used the same as plugins argument in
the library import.
If the --compare flag is set, then command does not generate template
translation file. Instead it compares sha256 sums from the filename
to the one read from the library documentation. It will print out a list
of keywords for which the documentation sha256 does not match. This will ease
translating projects to identify keywords which needs updating.
"""
lib_translation = get_library_translation(plugins)
if compare:
if table := compare_translation(filename, lib_translation):
print(
"Found differences between translation and library, see below for details."
)
for line in table:
print(line)
else:
print("Translation is valid, no updated needed.")
else:
with filename.open("w") as file:
json.dump(lib_translation, file, indent=4)
print(f"Translation file created in {filename.absolute()}")
if __name__ == "__main__":
cli()