Skip to content

Commit 035d282

Browse files
GutsDucarouge
authored andcommitted
Add subcommand extract (qgis2qdt)
1 parent 311d94d commit 035d282

File tree

2 files changed

+114
-3
lines changed

2 files changed

+114
-3
lines changed

qgis_deployment_toolbelt/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
__uri_homepage__,
2626
__version__,
2727
)
28-
from qgis_deployment_toolbelt.commands.cmd_rules_context import (
29-
parser_rules_context_export,
30-
)
28+
from qgis_deployment_toolbelt.commands.cmd_rules_context import parser_rules_context_export
3129
from qgis_deployment_toolbelt.commands.deployment import parser_main_deployment
3230
from qgis_deployment_toolbelt.commands.upgrade import parser_upgrade
31+
from qgis_deployment_toolbelt.commands.extract import parser_extract_from_profile
3332
from qgis_deployment_toolbelt.utils.journalizer import configure_logger
3433

3534
# #############################################################################
@@ -180,6 +179,19 @@ def main(in_args: list[str] = None):
180179
)
181180
add_common_arguments(subcmd_rules_context)
182181
parser_rules_context_export(subcmd_rules_context)
182+
183+
# Extractor
184+
subcmd_extract = subparsers.add_parser(
185+
"extract",
186+
aliases=[
187+
"qgis2qdt",
188+
],
189+
help="Generate profile ready for QDT from an existing QGIS profile.",
190+
formatter_class=main_parser.formatter_class,
191+
prog="upgrade",
192+
)
193+
add_common_arguments(subcmd_extract)
194+
parser_extract_from_profile(subcmd_extract)
183195

184196
# Upgrader
185197
subcmd_upgrade = subparsers.add_parser(
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#! python3 # noqa: E265
2+
3+
"""
4+
Sub-command in charge of running the main logic.
5+
6+
Author: Julien M. (https://github.com/guts)
7+
"""
8+
9+
# #############################################################################
10+
# ########## Libraries #############
11+
# ##################################
12+
13+
# Standard library
14+
import argparse
15+
import logging
16+
from pathlib import Path
17+
18+
# submodules
19+
from qgis_deployment_toolbelt.profiles.qdt_profile import QdtProfile
20+
from qgis_deployment_toolbelt.utils.check_path import check_path
21+
22+
# #############################################################################
23+
# ########## Globals ###############
24+
# ##################################
25+
26+
logger = logging.getLogger(__name__)
27+
28+
29+
# ############################################################################
30+
# ########## CLI #################
31+
# ################################
32+
33+
34+
def parser_extract_from_profile(
35+
subparser: argparse.ArgumentParser,
36+
) -> argparse.ArgumentParser:
37+
"""Set the argument parser for deployment subcommand.
38+
39+
Args:
40+
subparser (argparse.ArgumentParser): parser to set up
41+
42+
Returns:
43+
argparse.ArgumentParser: parser ready to use
44+
"""
45+
subparser.add_argument(
46+
"-f",
47+
"--from",
48+
"--from-profile-path",
49+
dest="input_profile_path",
50+
help="Path to the QGIS profile to extract.",
51+
type=str,
52+
)
53+
54+
subparser.add_argument(
55+
"-t",
56+
"--to",
57+
"--to-profile-path",
58+
dest="output_profile_path",
59+
help="Path where to store the QDT profile.",
60+
type=str,
61+
)
62+
63+
subparser.set_defaults(func=run)
64+
65+
return subparser
66+
67+
68+
# ############################################################################
69+
# ########## MAIN ################
70+
# ################################
71+
72+
73+
def run(args: argparse.Namespace):
74+
"""Run the main logic.
75+
76+
Args:
77+
args (argparse.Namespace): arguments passed to the subcommand
78+
"""
79+
logger.debug(f"Running {args.command} with {args}")
80+
81+
# check input profile exists
82+
check_path(
83+
input_path=args.input_profile_path,
84+
must_be_a_file=False,
85+
must_be_a_folder=True,
86+
must_be_readable=True,
87+
raise_error=True,
88+
)
89+
input_qgis_profile_path = Path(args.input_profile_path)
90+
91+
# make sure output profile folder exists
92+
output_qdt_profile_path = Path(args.output_profile_path)
93+
output_qdt_profile_path.mkdir(parents=True, exist_ok=True)
94+
95+
src_profile: QdtProfile = QdtProfile.from_profile_folder(
96+
input_profile_folder=input_qgis_profile_path
97+
)
98+
99+
print(src_profile)

0 commit comments

Comments
 (0)