Skip to content

Commit

Permalink
QGIS refactor - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jan 17, 2025
1 parent 5351d22 commit 39fdf2d
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 96 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ graph LR

[![pylint](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/blue-geo.svg)](https://pypi.org/project/blue-geo/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/blue-geo)](https://pypistats.org/packages/blue-geo)

built by 🌀 [`blue_options-4.190.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.958.1`](https://github.com/kamangir/blue-geo).
built by 🌀 [`blue_options-4.190.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.959.1`](https://github.com/kamangir/blue-geo).
34 changes: 15 additions & 19 deletions blue_geo/QGIS/console/QGIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


if not QGIS_is_live:
from log import log, log_error, verbose, hr
from logger import log, log_error, verbose, hr
from layer import layer
from project import project
from seed import seed
Expand All @@ -16,7 +16,7 @@
BLUE_GEO_VERSION = "1.1.1"
ABCLI_OBJECT_ROOT = ""

NAME = "blue_geo.QGIS"
NAME = "Q"


class ABCLI_QGIS(object):
Expand Down Expand Up @@ -54,7 +54,11 @@ def clear(self):

seed("clear")

def export(self, filename="", object_name=""):
def screenshot(
self,
filename="",
object_name="",
):
filename = self.file_path(
filename=filename if filename else "{}.png".format(self.timestamp()),
object_name=object_name,
Expand Down Expand Up @@ -94,11 +98,11 @@ def help(self, clear=False):
if clear:
self.clear()

log("Q.clear() | clear()", "clear Python Console.")
log("Q.clear()", "clear Python Console.")

layer.help()

log("Q.export([filename],[object_name])", "export.")
log("Q.screenshot([filename],[object_name])", "screenshot.")

if verbose:
log("Q.list_of_layers()", "list of layers.")
Expand All @@ -112,13 +116,16 @@ def help(self, clear=False):
log("Q.refresh()", "refresh.")
log("Q.reload()", "reload all layers.")

log("test(deep=True)", "run the test suite.")

if verbose:
log("Q.unload(layer_name)", "unload layer_name.")

log('Q.upload(" | <object-name> | layer | project | qgz")', "upload.")
log("verbose=True|False", "set verbose state.")

log("Q_test(deep=True)", f"test Q.")

log("verbose = True|False", "set verbose state.")
log("clear() = Q.clear()")
log("upload() = Q.upload()")

for app in self.app_list:
app.help()
Expand Down Expand Up @@ -304,14 +311,3 @@ def upload(self, what="object"):


QGIS = ABCLI_QGIS()


def clear():
QGIS.clear()


def upload(self, object_name=""):
QGIS.upload(object_name)


Q = QGIS
6 changes: 4 additions & 2 deletions blue_geo/QGIS/console/alias.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
if not QGIS_is_live:
from QGIS import QGIS

Q = QGIS


def clear():
QGIS.clear()


def upload(object_name=""):
QGIS.upload(object_name)
def upload(what=""):
QGIS.upload(what)
2 changes: 1 addition & 1 deletion blue_geo/QGIS/console/application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if not QGIS_is_live:
from log import log
from logger import log


class BLUE_GEO_QGIS_APPLICATION(object):
Expand Down
30 changes: 12 additions & 18 deletions blue_geo/QGIS/console/fileio.py → blue_geo/QGIS/console/file.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
import yaml
import shutil

if not QGIS_is_live:
from log import log_error, log
from logger import log_error, log


def copy_file(
def Q_copy_file(
source_filename: str,
destination_filename: str,
) -> bool:
Expand All @@ -16,7 +15,7 @@ def copy_file(
shutil.copyfile(source_filename, destination_filename)
except:
log_error(
"copy_file({},{}): failed.".format(
"Q_copy_file({},{}): failed.".format(
source_filename,
destination_filename,
)
Expand All @@ -32,30 +31,25 @@ def copy_file(
return True


def file_extension(filename: str) -> str:
def Q_add_extension(filename: str, extension: str) -> str:
filename, _ = os.path.splitext(filename)

return f"{filename}.{extension}"


def Q_get_file_extension(filename: str) -> str:
return os.path.splitext(filename)[1][1:]


def file_name(filename: str) -> str:
def Q_get_file_name(filename: str) -> str:
_, filename = os.path.split(filename)

return filename if "." not in filename else ".".join(filename.split(".")[:-1])


def file_name_and_extension(filename: str) -> str:
def Q_get_file_name_and_extension(filename: str) -> str:
return os.path.basename(filename)


def file_path(filename: str) -> str:
return os.path.split(filename)[0]


def load_yaml(filename):
with open(filename, "r") as file:
return yaml.safe_load(file)


def file_with_extension(filename: str, extension: str) -> str:
filename, _ = os.path.splitext(filename)

return f"{filename}.{extension}"
6 changes: 6 additions & 0 deletions blue_geo/QGIS/console/file_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import yaml


def Q_load_yaml(filename):
with open(filename, "r") as file:
return yaml.safe_load(file)
2 changes: 1 addition & 1 deletion blue_geo/QGIS/console/layer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

if not QGIS_is_live:
from log import log_error
from logger import log_error

ABCLI_OBJECT_ROOT = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
QGIS_is_live = True


def hr():
print(3 * ". .. ... .. ")
def hr(length: int = 3):
print(length * ". .. ... .. ")


def log(message, note="", icon="🌐"):
Expand Down
6 changes: 3 additions & 3 deletions blue_geo/QGIS/console/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

if not QGIS_is_live:
from log import verbose, log
from fileio import load_yaml
from logger import verbose, log
from file import Q_load_yaml


class ABCLI_QGIS_Project(object):
Expand Down Expand Up @@ -31,7 +31,7 @@ def metadata(self):
if not os.path.exists(filename):
return {"error": f"{filename}: file not found."}

return load_yaml(filename)
return Q_load_yaml(filename)

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion blue_geo/QGIS/console/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import random

if not QGIS_is_live:
from log import log
from logger import log

blue_geo_QGIS_path_server = os.path.join(
os.getenv("HOME", ""),
Expand Down
33 changes: 20 additions & 13 deletions blue_geo/QGIS/console/testing.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
if not QGIS_is_live:
from log import log, hr
from blue_geo.QGIS.console.tests.test_QGIS import (
test_logging,
test_QGIS_export,
from logger import log, hr

from tests.alias import test_aliases

# from tests.layer import test_layer...
from tests.logger import test_logging
from tests.QGIS import (
test_QGIS_get_property,
test_QGIS_logging,
test_QGIS_open,
test_QGIS_screenshot,
test_QGIS_upload,
)


list_of_tests = [
test_aliases,
test_logging,
test_QGIS_export,
test_QGIS_get_property,
test_QGIS_logging,
test_QGIS_open,
test_QGIS_screenshot,
test_QGIS_upload,
]


def test(deep: bool = False):
log("testing ...")
def Q_test(deep: bool = False):
description: str = "{} test(s): {}".format(
len(list_of_tests),
", ".join([test_function.__name__ for test_function in list_of_tests]),
)

log(f"running {description} ...")
hr()

for test_function in list_of_tests:
log(f"testing {test_function} ...")
test_function(deep=deep)
hr()

log(
"ran {} test(s): {}".format(
len(list_of_tests),
", ".join([test_function.__name__ for test_function in list_of_tests]),
)
)
log(f"ran {description}.")
26 changes: 7 additions & 19 deletions blue_geo/QGIS/console/tests/QGIS.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List

if not QGIS_is_live:
from log import log, log_error, verbose, hr
from QGIS import QGIS, clear, upload
from layer import layer
from project import project
from ..logger import log, log_error, verbose, hr
from ..QGIS import QGIS
from ..layer import layer
from ..project import project


def open_upload_test_assets(
Expand All @@ -28,26 +28,14 @@ def open_upload_test_assets(
return output


def test_logging(deep: bool = False):
clear()

def test_QGIS_logging(deep: bool = False):
QGIS.clear()

QGIS.intro()

log("some message")
log("some message", "some note")
log("some message", "some note", "🪄")

log_error("this is a test, don't panic! 😁")

assert isinstance(verbose, bool)

hr()


def test_QGIS_export(deep: bool = False):
QGIS.export()
def test_QGIS_screenshot(deep: bool = False):
QGIS.screenshot()


def test_QGIS_get_property(deep: bool = False):
Expand Down
12 changes: 12 additions & 0 deletions blue_geo/QGIS/console/tests/alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if not QGIS_is_live:
from ..alias import Q, clear, upload
from ..QGIS import ABCLI_QGIS


def test_aliases(deep: bool = False):
assert isinstance(Q, ABCLI_QGIS)
Q.clear()

clear()

upload()
8 changes: 8 additions & 0 deletions blue_geo/QGIS/console/tests/layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if not QGIS_is_live:
from logger import log, log_error, verbose, hr
from ..layer import layer


def test_layer_properties(
deep: bool = False,
): ...
17 changes: 17 additions & 0 deletions blue_geo/QGIS/console/tests/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if not QGIS_is_live:
from ..logger import hr, log, log_error, log_warning, verbose


def test_logging(deep: bool = False):
hr()
hr(length=5)

log("some message")
log("some message", "some note")
log("some message", "some note", "🔍")

log_error("this is a test, don't panic! 😁")

log_warning("this is a test, don't panic! 😁")

assert isinstance(verbose, bool)
5 changes: 3 additions & 2 deletions blue_geo/QGIS/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def generate_seed() -> str:
os.path.join(path, f"{module}.py")
for module in [
"dependency",
"console/log",
"console/logger",
"console/project",
"console/layer",
"console/fileio",
"console/file",
"console/file_load",
"console/application",
"console/seed",
"console/QGIS",
Expand Down
2 changes: 1 addition & 1 deletion blue_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DESCRIPTION = f"{ICON} AI for a Blue Planet."

VERSION = "4.958.1"
VERSION = "4.959.1"

REPO_NAME = "blue-geo"

Expand Down
Loading

0 comments on commit 39fdf2d

Please sign in to comment.