-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
__email__ = '[email protected]' | ||
|
||
import argparse | ||
import logging | ||
import os | ||
|
||
from pathlib import Path | ||
|
||
from qgis_plugin_manager.__about__ import __version__ | ||
from qgis_plugin_manager.__about__ import __title_clean__, __version__ | ||
from qgis_plugin_manager.definitions import Level | ||
from qgis_plugin_manager.local_directory import LocalDirectory | ||
from qgis_plugin_manager.remote import Remote | ||
|
@@ -23,6 +24,16 @@ def main() -> int: | |
) | ||
parser.add_argument("-v", "--version", action="version", version=__version__) | ||
|
||
parser.add_argument( | ||
"-v", | ||
"-v", | ||
"--verbose", | ||
action="count", | ||
default=1, | ||
dest="verbosity", | ||
help="Verbosity level: None = WARNING, -v = INFO, -vv = DEBUG", | ||
) | ||
|
||
subparsers = parser.add_subparsers( | ||
title="commands", description="qgis-plugin-manager command", dest="command", | ||
) | ||
|
@@ -73,6 +84,23 @@ def main() -> int: | |
|
||
args = parser.parse_args() | ||
|
||
# set log level depending on verbosity argument | ||
# by default 1 => | ||
args.verbosity = 40 - (10 * args.verbosity) if args.verbosity > 0 else 0 | ||
logging.basicConfig( | ||
level=args.verbosity, | ||
# format="%(asctime)s||%(levelname)s||%(module)s||%(message)s", | ||
format='%(levelname)s:%(message)s', | ||
# datefmt="%Y-%m-%d %H:%M:%S", | ||
) | ||
|
||
console = logging.StreamHandler() | ||
console.setLevel(args.verbosity) | ||
|
||
# add the handler to the root logger | ||
logger = logging.getLogger(__title_clean__) | ||
logger.debug(f"Log level set: {logging}") | ||
|
||
# if no command is passed, print the help and exit | ||
if not args.command: | ||
parser.print_help() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
__email__ = '[email protected]' | ||
|
||
import configparser | ||
import logging | ||
import os | ||
import shutil | ||
import stat | ||
|
@@ -22,6 +23,8 @@ | |
to_bool, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class LocalDirectory: | ||
|
||
|
@@ -45,14 +48,14 @@ def init(self) -> bool: | |
""" Init this qgis-plugin-manager by creating the default sources.list.""" | ||
source_file = sources_file(self.folder) | ||
if source_file.exists(): | ||
print(f"{Level.Alert}{source_file.absolute()} is already existing. Quit{Level.End}") | ||
logger.warning(f"{Level.Alert}{source_file.absolute()} is already existing. Quit{Level.End}") | ||
return False | ||
|
||
if self.qgis_version: | ||
version = "[VERSION]" | ||
print("Init https://plugins.qgis.org") | ||
logger.info("Init https://plugins.qgis.org") | ||
else: | ||
print( | ||
logger.warning( | ||
f"{Level.Alert}" | ||
f"QGIS version is unknown, creating with a default {DEFAULT_QGIS_VERSION}" | ||
f"{Level.End}", | ||
|
@@ -182,21 +185,21 @@ def remove(self, plugin_name: str) -> bool: | |
try: | ||
shutil.rmtree(plugin_path) | ||
except Exception as e: | ||
print(f"{Level.Critical}Plugin {plugin_name} could not be removed : {e!s}") | ||
logger.error(f"{Level.Critical}Plugin {plugin_name} could not be removed : {e!s}") | ||
|
||
if not Path(self.folder.joinpath(plugin_folder)).exists(): | ||
print(f"{Level.Success}Plugin {plugin_name} removed") | ||
logger.info(f"{Level.Success}Plugin {plugin_name} removed") | ||
restart_qgis_server() | ||
return True | ||
else: | ||
print( | ||
logger.error( | ||
f"{Level.Alert}" | ||
f"Plugin {plugin_name} using folder {plugin_folder} could not be removed " | ||
f"for unknown reason" | ||
f"{Level.End}", | ||
) | ||
break | ||
print(f"{Level.Alert}Plugin name '{plugin_name}' not found{Level.End}") | ||
logger.error(f"{Level.Alert}Plugin name '{plugin_name}' not found{Level.End}") | ||
|
||
all_names = list(set(all_names)) | ||
similarity = similar_names(plugin_name.lower(), all_names) | ||
|
@@ -321,13 +324,13 @@ def print_table(self, current_directory: bool = True): | |
if len(data): | ||
print(pretty_table(data, headers)) | ||
else: | ||
print( | ||
f"{Level.Alert}No plugin found in the current directory {self.folder.absolute()}{Level.End}", | ||
logger.error( | ||
f"{Level.Alert}No plugin found in the current directory {self.folder.absolute()}{Level.End}" | ||
) | ||
|
||
if len(list_of_owners) > 1: | ||
list_of_owners = [f"'{i}'" for i in list_of_owners] | ||
print( | ||
logger.error( | ||
f"{Level.Alert}" | ||
f"Different rights have been detected : {','.join(list_of_owners)}" | ||
f"{Level.End}. " | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
__email__ = '[email protected]' | ||
|
||
import base64 | ||
import logging | ||
import os | ||
import re | ||
import shutil | ||
|
@@ -43,7 +44,7 @@ def remote_is_ready(self) -> bool: | |
source_list = sources_file(self.folder) | ||
if not source_list.exists(): | ||
if not self.setting_error: | ||
print(f"{Level.Critical}The {source_list.absolute()} file does not exist{Level.End}") | ||
logger.error(f"{Level.Critical}The {source_list.absolute()} file does not exist{Level.End}") | ||
print("Use the 'init' command to create the file") | ||
self.setting_error = True | ||
return False | ||
|