Skip to content

Commit 57cb293

Browse files
committed
Add subcommand extract (qgis2qdt)
1 parent b17b7ac commit 57cb293

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

qgis_deployment_toolbelt/cli.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
__uri_homepage__,
2323
__version__,
2424
)
25-
from qgis_deployment_toolbelt.commands import parser_main_deployment, parser_upgrade
25+
from qgis_deployment_toolbelt.commands import (
26+
parser_extract_from_profile,
27+
parser_main_deployment,
28+
parser_upgrade,
29+
)
2630
from qgis_deployment_toolbelt.utils.journalizer import configure_logger
2731

2832
# #############################################################################
@@ -154,6 +158,19 @@ def main(in_args: list[str] = None):
154158
add_common_arguments(subcmd_deployment)
155159
parser_main_deployment(subcmd_deployment)
156160

161+
# Extractor
162+
subcmd_extract = subparsers.add_parser(
163+
"extract",
164+
aliases=[
165+
"qgis2qdt",
166+
],
167+
help="Generate profile ready for QDT from an existing QGIS profile.",
168+
formatter_class=main_parser.formatter_class,
169+
prog="upgrade",
170+
)
171+
add_common_arguments(subcmd_extract)
172+
parser_extract_from_profile(subcmd_extract)
173+
157174
# Upgrader
158175
subcmd_upgrade = subparsers.add_parser(
159176
"upgrade",

qgis_deployment_toolbelt/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
# submodules
44
from .deployment import parser_main_deployment # noqa: F401
5+
from .extract import parser_extract_from_profile # noqa: F401
56
from .upgrade import parser_upgrade # noqa: F401
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)