|
| 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