From faaa4deff572298bc8df0b130bb1db27c215923c Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 15:51:39 +0100
Subject: [PATCH 1/6] fixed references in sub modules
---
src/staticwordpress/core/constants.py | 2 +-
src/staticwordpress/core/crawler.py | 4 ++--
src/staticwordpress/core/errors.py | 2 +-
src/staticwordpress/core/github.py | 2 +-
src/staticwordpress/core/i18n.py | 2 +-
src/staticwordpress/core/project.py | 4 ++--
src/staticwordpress/core/redirects.py | 8 ++++----
src/staticwordpress/core/sitemaps.py | 4 ++--
src/staticwordpress/core/workflow.py | 20 ++++++++++----------
src/staticwordpress/gui/mainwindow.py | 3 +--
10 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/src/staticwordpress/core/constants.py b/src/staticwordpress/core/constants.py
index 3b869dd..a50f64e 100644
--- a/src/staticwordpress/core/constants.py
+++ b/src/staticwordpress/core/constants.py
@@ -38,7 +38,7 @@
VERSION_MAJOR = 0
VERSION_MINOR = 0
-VERSION_REVISION = 4
+VERSION_REVISION = 5
VERISON = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_REVISION}"
SHARE_FOLDER_PATH = Path(
diff --git a/src/staticwordpress/core/crawler.py b/src/staticwordpress/core/crawler.py
index 85e9a87..2cf0fe0 100644
--- a/src/staticwordpress/core/crawler.py
+++ b/src/staticwordpress/core/crawler.py
@@ -45,8 +45,8 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .utils import get_mock_response, get_remote_content, get_clean_url
-from .constants import CONFIGS, URL, LINK_REGEX
+from ..core.utils import get_mock_response, get_remote_content, get_clean_url
+from ..core.constants import CONFIGS, URL, LINK_REGEX
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
diff --git a/src/staticwordpress/core/errors.py b/src/staticwordpress/core/errors.py
index 254479e..e3ed6c5 100644
--- a/src/staticwordpress/core/errors.py
+++ b/src/staticwordpress/core/errors.py
@@ -29,5 +29,5 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-class SerpWingsResponseNotValid(Exception):
+class ResponseNotValid(Exception):
pass
diff --git a/src/staticwordpress/core/github.py b/src/staticwordpress/core/github.py
index 2770cd6..3fd7f69 100644
--- a/src/staticwordpress/core/github.py
+++ b/src/staticwordpress/core/github.py
@@ -27,9 +27,9 @@
# STANDARD LIBARY IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
+import logging
from datetime import datetime
from pathlib import Path
-import logging
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# 3rd PARTY LIBRARY IMPORTS
diff --git a/src/staticwordpress/core/i18n.py b/src/staticwordpress/core/i18n.py
index 2e2d4b2..02d2724 100644
--- a/src/staticwordpress/core/i18n.py
+++ b/src/staticwordpress/core/i18n.py
@@ -34,7 +34,7 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .constants import LANGUAGES, CONFIGS
+from ..core.constants import LANGUAGES, CONFIGS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
diff --git a/src/staticwordpress/core/project.py b/src/staticwordpress/core/project.py
index 3627e4f..a930e43 100644
--- a/src/staticwordpress/core/project.py
+++ b/src/staticwordpress/core/project.py
@@ -39,14 +39,14 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .constants import (
+from ..core.constants import (
PROJECT,
REDIRECTS,
HOST,
SOURCE,
+ USER_AGENT,
CONFIGS,
VERISON,
- USER_AGENT,
LINK_REGEX,
)
diff --git a/src/staticwordpress/core/redirects.py b/src/staticwordpress/core/redirects.py
index c083136..9b99137 100644
--- a/src/staticwordpress/core/redirects.py
+++ b/src/staticwordpress/core/redirects.py
@@ -36,8 +36,8 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .constants import HOST, REDIRECTS
-from .errors import SerpWingsResponseNotValid
+from ..core.constants import HOST, REDIRECTS
+from ..core.errors import ResponseNotValid
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
@@ -107,7 +107,7 @@ def get_from_plugin(self, redirects_api_path: str, wp_auth_token_: str) -> None:
)
if wp_api_response.status_code >= 400:
- raise SerpWingsResponseNotValid
+ raise ResponseNotValid
redirects_as_dict = json.loads(wp_api_response.content)
@@ -122,7 +122,7 @@ def get_from_plugin(self, redirects_api_path: str, wp_auth_token_: str) -> None:
source_=REDIRECTS.REDIRECTION.value,
)
)
- except SerpWingsResponseNotValid:
+ except ResponseNotValid:
logging.info(
f"Redirects are not valid. Make sure that redirection plug is properly configured."
)
diff --git a/src/staticwordpress/core/sitemaps.py b/src/staticwordpress/core/sitemaps.py
index 036df9a..422641a 100644
--- a/src/staticwordpress/core/sitemaps.py
+++ b/src/staticwordpress/core/sitemaps.py
@@ -40,8 +40,8 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .utils import get_clean_url, get_remote_content
-from .constants import CONFIGS
+from ..core.utils import get_clean_url, get_remote_content
+from ..core.constants import CONFIGS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
diff --git a/src/staticwordpress/core/workflow.py b/src/staticwordpress/core/workflow.py
index b145d66..b896302 100644
--- a/src/staticwordpress/core/workflow.py
+++ b/src/staticwordpress/core/workflow.py
@@ -46,14 +46,14 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .search import Search
-from .github import GitHub
-from .crawler import Crawler
-from .project import Project
-from .redirects import Redirects
-from .sitemaps import find_sitemap_location, extract_sitemap_paths
-from .utils import extract_zip_file, rm_dir_tree, update_links
-from .constants import (
+from ..core.search import Search
+from ..core.github import GitHub
+from ..core.crawler import Crawler
+from ..core.project import Project
+from ..core.redirects import Redirects
+from ..core.sitemaps import find_sitemap_location, extract_sitemap_paths
+from ..core.utils import extract_zip_file, rm_dir_tree, update_links
+from ..core.constants import (
CONFIGS,
SHARE_FOLDER_PATH,
URL,
@@ -101,10 +101,10 @@ def create_project(
host_type_: HOST = HOST.NETLIFY,
) -> None:
self._project.status = PROJECT.NEW
-
+
if src_type_ == SOURCE.ZIP:
self._project.redirects = REDIRECTS.REDIRECTION
-
+
self._project.name = project_name_
self._project.path = project_path_
self._project._404 = custom_404_
diff --git a/src/staticwordpress/gui/mainwindow.py b/src/staticwordpress/gui/mainwindow.py
index 742aa3f..c047301 100644
--- a/src/staticwordpress/gui/mainwindow.py
+++ b/src/staticwordpress/gui/mainwindow.py
@@ -40,7 +40,6 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
from PyQt5.QtWidgets import (
- QLineEdit,
QMainWindow,
QAction,
QApplication,
@@ -70,7 +69,7 @@
get_remote_content,
extract_urls_from_raw_text,
)
-from .workflow import WorkflowGUI
+from ..gui.workflow import WorkflowGUI
from ..gui.logger import LoggerWidget
from ..gui.rawtext import RawTextDialog
from ..gui.config import ConfigDialog
From cbd21ac0682d10528af53fd04159f8407f4c438c Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 17:14:35 +0100
Subject: [PATCH 2/6] code cleanup - refactoring
---
src/staticwordpress/core/constants.py | 2 +
src/staticwordpress/core/github.py | 4 +-
src/staticwordpress/core/i18n.py | 2 +-
src/staticwordpress/core/project.py | 34 ++--
src/staticwordpress/core/redirects.py | 25 ++-
src/staticwordpress/core/search.py | 2 +-
src/staticwordpress/core/sitemaps.py | 14 +-
src/staticwordpress/core/utils.py | 32 ++--
src/staticwordpress/core/workflow.py | 48 +++---
src/staticwordpress/gui/config.py | 10 +-
src/staticwordpress/gui/logger.py | 10 +-
src/staticwordpress/gui/mainwindow.py | 231 +++++++++++++-------------
src/staticwordpress/gui/project.py | 58 +++----
src/staticwordpress/gui/utils.py | 4 +-
src/staticwordpress/gui/workflow.py | 10 +-
tests/test_redirects.py | 2 +-
16 files changed, 254 insertions(+), 234 deletions(-)
diff --git a/src/staticwordpress/core/constants.py b/src/staticwordpress/core/constants.py
index a50f64e..002d459 100644
--- a/src/staticwordpress/core/constants.py
+++ b/src/staticwordpress/core/constants.py
@@ -92,6 +92,8 @@ class HOST(ExtendedEnum):
NETLIFY = "NETLIFY"
# CLOUDFLARE = "CLOUDFLARE"
# LOCALHOST = "LOCALHOST"
+ # GITHUB = "GITHUB"
+ # GITLAB = "GITLAB"
class URL(ExtendedEnum):
diff --git a/src/staticwordpress/core/github.py b/src/staticwordpress/core/github.py
index 3fd7f69..7db103e 100644
--- a/src/staticwordpress/core/github.py
+++ b/src/staticwordpress/core/github.py
@@ -81,12 +81,12 @@ def inner(self):
return inner
@check_gh_token
- def is_token_valid(self):
+ def is_token_valid(self) -> bool:
logging.info(f"Verifying Github Token.")
return self._gh_object.get_user().name != ""
@check_gh_token
- def is_repo_valid(self):
+ def is_repo_valid(self) -> bool:
logging.info(f"Verifying Github Repository.")
return self._gh_object.get_user().get_repo(self._gh_repo) is not None
diff --git a/src/staticwordpress/core/i18n.py b/src/staticwordpress/core/i18n.py
index 02d2724..745ad32 100644
--- a/src/staticwordpress/core/i18n.py
+++ b/src/staticwordpress/core/i18n.py
@@ -65,7 +65,7 @@ def language(self) -> LANGUAGES:
return self._lang
@language.setter
- def language(self, language_) -> None:
+ def language(self, language_: LANGUAGES) -> None:
self._lang = language_
diff --git a/src/staticwordpress/core/project.py b/src/staticwordpress/core/project.py
index a930e43..765fd3a 100644
--- a/src/staticwordpress/core/project.py
+++ b/src/staticwordpress/core/project.py
@@ -218,16 +218,16 @@ def save_as(self, path_: str = None) -> None:
def save(self) -> None:
if self.is_open() and self["path"]:
with self["path"].open("w") as f:
- _self_copy = deepcopy(self)
- _self_copy["path"] = str(self["path"])
- _self_copy["user-agent"] = self["user-agent"].value
- _self_copy["source"]["type"] = self["source"]["type"].value
- _self_copy["destination"]["host"] = self["destination"]["host"].value
- _self_copy["redirects"] = self["redirects"].value
- _self_copy["destination"]["output"] = str(self["destination"]["output"])
- _self_copy["status"] = PROJECT.SAVED.value
+ self_copy = deepcopy(self)
+ self_copy["path"] = str(self["path"])
+ self_copy["user-agent"] = self["user-agent"].value
+ self_copy["source"]["type"] = self["source"]["type"].value
+ self_copy["destination"]["host"] = self["destination"]["host"].value
+ self_copy["redirects"] = self["redirects"].value
+ self_copy["destination"]["output"] = str(self["destination"]["output"])
+ self_copy["status"] = PROJECT.SAVED.value
- json.dump(_self_copy, f, indent=4)
+ json.dump(self_copy, f, indent=4)
self["status"] = PROJECT.SAVED
@@ -328,8 +328,8 @@ def src_type(self) -> SOURCE:
return self["source"]["type"]
@src_type.setter
- def src_type(self, source_type_: str) -> None:
- self["source"]["type"] = source_type_
+ def src_type(self, src_type_: str) -> None:
+ self["source"]["type"] = src_type_
@property
def src_url(self) -> str:
@@ -344,16 +344,16 @@ def ss_archive(self) -> str:
return self["source"]["simply-static"]["archive"]
@ss_archive.setter
- def ss_archive(self, archive_name_: str) -> None:
- self["source"]["simply-static"]["archive"] = archive_name_
+ def ss_archive(self, ss_archive_name_: str) -> None:
+ self["source"]["simply-static"]["archive"] = ss_archive_name_
@property
def ss_folder(self) -> str:
return self["source"]["simply-static"]["folder"]
@ss_folder.setter
- def ss_folder(self, folder_: str) -> None:
- self["source"]["simply-static"]["folder"] = folder_
+ def ss_folder(self, ss_folder_: str) -> None:
+ self["source"]["simply-static"]["folder"] = ss_folder_
@property
def zip_file_url(self) -> str:
@@ -450,8 +450,8 @@ def search(self) -> str:
return self["search"]
@search.setter
- def search(self, search: str) -> None:
- self["search"] = search
+ def search(self, search_: str) -> None:
+ self["search"] = search_
@property
def search_path(self) -> Path:
diff --git a/src/staticwordpress/core/redirects.py b/src/staticwordpress/core/redirects.py
index 9b99137..80c820e 100644
--- a/src/staticwordpress/core/redirects.py
+++ b/src/staticwordpress/core/redirects.py
@@ -45,11 +45,19 @@
class Redirect:
- def __init__(self, from_, to_, query_, status, force_, source_) -> None:
+ def __init__(
+ self,
+ from_: str,
+ to_: str,
+ query_: str,
+ status_: int,
+ force_: bool,
+ source_: str,
+ ) -> None: # source should be REDIRECTS
self._from = from_
self._to = to_
self._query = query_
- self._status = status
+ self._status = status_
self._force = force_
self._source = source_
self._hash = hashlib.sha256(from_.encode("utf-8")).hexdigest()
@@ -100,10 +108,11 @@ def save(self, output_file_, host_: HOST) -> None:
else:
f.write(redirect.as_line(True))
- def get_from_plugin(self, redirects_api_path: str, wp_auth_token_: str) -> None:
+ def get_from_plugin(self, redirects_api_path_: str, wp_auth_token_: str) -> None:
try:
wp_api_response = requests.get(
- redirects_api_path, headers={"Authorization": "Basic " + wp_auth_token_}
+ redirects_api_path_,
+ headers={"Authorization": "Basic " + wp_auth_token_},
)
if wp_api_response.status_code >= 400:
@@ -116,7 +125,7 @@ def get_from_plugin(self, redirects_api_path: str, wp_auth_token_: str) -> None:
redirect_=Redirect(
from_=redirect_["url"],
to_=redirect_["action_data"]["url"],
- status=redirect_["action_code"],
+ status_=redirect_["action_code"],
query_=None,
force_=True,
source_=REDIRECTS.REDIRECTION.value,
@@ -127,12 +136,12 @@ def get_from_plugin(self, redirects_api_path: str, wp_auth_token_: str) -> None:
f"Redirects are not valid. Make sure that redirection plug is properly configured."
)
- def add_search(self, search_page: str) -> None:
+ def add_search(self, search_page_: str) -> None:
self.add_redirect(
Redirect(
from_="/*",
- to_=f"/{search_page}/",
- status=301,
+ to_=f"/{search_page_}/",
+ status_=301,
query_='{s = ":s"}',
force_=True,
source_=REDIRECTS.NONE.value,
diff --git a/src/staticwordpress/core/search.py b/src/staticwordpress/core/search.py
index 512111e..c9668da 100644
--- a/src/staticwordpress/core/search.py
+++ b/src/staticwordpress/core/search.py
@@ -129,7 +129,7 @@ def add(self, soup_: BeautifulSoup, url_path_: str) -> None:
}
)
- def copy_scripts(self):
+ def copy_scripts(self) -> None:
"""Copy Search.js into search folder"""
src = Path(f'{SHARE_FOLDER_PATH}/{CONFIGS["SEARCH"]["INDEX"]["src"]}')
if src.exists():
diff --git a/src/staticwordpress/core/sitemaps.py b/src/staticwordpress/core/sitemaps.py
index 422641a..4f5206a 100644
--- a/src/staticwordpress/core/sitemaps.py
+++ b/src/staticwordpress/core/sitemaps.py
@@ -40,15 +40,15 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from ..core.utils import get_clean_url, get_remote_content
from ..core.constants import CONFIGS
+from ..core.utils import get_clean_url, get_remote_content
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-def find_sitemap_location(home_url: str) -> str:
+def find_sitemap_location(home_url_: str) -> str:
"""Finding Sitemap Location Using Home Url
Args:
@@ -58,13 +58,13 @@ def find_sitemap_location(home_url: str) -> str:
str: Location of Sitemap
"""
for sitemap_path in CONFIGS["SITEMAP"]["SEARCH_PATHS"]:
- sitemap_url = get_clean_url(home_url, sitemap_path)
+ sitemap_url = get_clean_url(home_url_, sitemap_path)
response = get_remote_content(sitemap_url)
if response.status_code < 400:
return parse.urlparse(response.url).path
# robots.txt
- robots_txt = get_clean_url(home_url, "robots.txt")
+ robots_txt = get_clean_url(home_url_, "robots.txt")
response = get_remote_content(robots_txt)
if response:
for item in response.text.split("\n"):
@@ -72,7 +72,7 @@ def find_sitemap_location(home_url: str) -> str:
return item.split("Sitemap:")[-1].strip()
# check home page for link rel=sitemap
- response = get_remote_content(home_url)
+ response = get_remote_content(home_url_)
if response:
soup = BeautifulSoup(response.text, features="xml")
for link in soup.find_all("link"):
@@ -81,7 +81,7 @@ def find_sitemap_location(home_url: str) -> str:
return ""
-def extract_sitemap_paths(sitemap_url: str) -> list:
+def extract_sitemap_paths(sitemap_url_: str) -> list:
"""Extract Sub-Sitemap from Index Sitemap
Args:
@@ -91,7 +91,7 @@ def extract_sitemap_paths(sitemap_url: str) -> list:
list: List of Sub-Sitemaps
"""
sitemap_paths = []
- response = get_remote_content(sitemap_url)
+ response = get_remote_content(sitemap_url_)
for item in response.text.split("\n"):
if ".xsl" in item:
st = item.find("//")
diff --git a/src/staticwordpress/core/utils.py b/src/staticwordpress/core/utils.py
index 22f05fe..94d8ecb 100644
--- a/src/staticwordpress/core/utils.py
+++ b/src/staticwordpress/core/utils.py
@@ -49,7 +49,7 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .constants import CONFIGS, LINK_REGEX
+from ..core.constants import CONFIGS, LINK_REGEX
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -111,27 +111,27 @@ def get_clean_url(url_: str = "", path_: str = "", scheme_: str = "") -> str:
return url_
-def rm_dir_tree(dir_path: str = None, delete_root: bool = False) -> None:
+def rm_dir_tree(dir_path_: str = None, delete_root_: bool = False) -> None:
"""Delte Directry tree at dir_path
Args:
dir_path (Path | str, optional): Path/tree which need to be remvoed.
delete_root (bool, optional): If True then Parnt/root folder is not delted.
"""
- if dir_path and isinstance(dir_path, str):
- dir_path = Path(dir_path)
+ if dir_path_ and isinstance(dir_path_, str):
+ dir_path_ = Path(dir_path_)
- if not dir_path.exists():
+ if not dir_path_.exists():
return
- for _path in dir_path.glob("**/*"):
+ for _path in dir_path_.glob("**/*"):
if _path.is_file() and _path.stem not in [".gitignore", ".project"]:
_path.unlink()
elif _path.is_dir() and _path.stem != "._data":
shutil.rmtree(_path, onerror=rmtree_permission_error)
- if delete_root:
- dir_path.rmdir()
+ if delete_root_:
+ dir_path_.rmdir()
def get_mock_response(url_: str = None) -> Response:
@@ -189,7 +189,7 @@ def update_links(content: str, from_: str, to_: str) -> str:
return content.replace(from_, to_)
-def extract_urls_from_raw_text(raw_text: str, dest_url: str, src_url: str) -> list:
+def extract_urls_from_raw_text(raw_text_: str, dest_url_: str, src_url_: str) -> list:
"""Extract Urls form a Raw Text using Regex
Args:
@@ -201,27 +201,27 @@ def extract_urls_from_raw_text(raw_text: str, dest_url: str, src_url: str) -> li
list: List of Urls extracted
"""
new_additional_links = []
- for link in re.findall(LINK_REGEX, raw_text):
+ for link in re.findall(LINK_REGEX, raw_text_):
item = link[0].replace("\/", "/").split("?")[0]
item = re.sub("\(|\)|\[|\]", "", item)
- new_additional_link = update_links(item, dest_url, src_url)
+ new_additional_link = update_links(item, dest_url_, src_url_)
- if new_additional_link and src_url in new_additional_link:
+ if new_additional_link and src_url_ in new_additional_link:
new_additional_links.append(new_additional_link)
return new_additional_links
-def extract_zip_file(zip_file_path: Path, output_location: Path) -> None:
+def extract_zip_file(zip_file_path_: Path, output_location_: Path) -> None:
"""Extract ZipFile content to output_location Path
Args:
zip_file_path (Path): Zip File Path
output_location (Path): Ouput File Path
"""
- if output_location.is_dir() and zip_file_path.exists():
- with ZipFile(zip_file_path, "r") as zf:
- zf.extractall(output_location)
+ if output_location_.is_dir() and zip_file_path_.exists():
+ with ZipFile(zip_file_path_, "r") as zf:
+ zf.extractall(output_location_)
def is_url_valid(url_: str) -> bool:
diff --git a/src/staticwordpress/core/workflow.py b/src/staticwordpress/core/workflow.py
index b896302..2633f50 100644
--- a/src/staticwordpress/core/workflow.py
+++ b/src/staticwordpress/core/workflow.py
@@ -155,22 +155,22 @@ def set_project(self, project_: Project) -> None:
if self._project.src_type == SOURCE.ZIP:
self._project.update_ss()
- def stop_calculations(self):
+ def stop_calculations(self) -> None:
self._keep_running = False
logging.warn(f"Background Processings will Stop. Please wait!")
- def open_project(self):
+ def open_project(self) -> None:
pass
- def save_project(self):
+ def save_project(self) -> None:
pass
- def close_project(self):
+ def close_project(self) -> None:
pass
def download_zip_file(self) -> None:
if self._keep_running:
- rm_dir_tree(self._project.output, delete_root=False)
+ rm_dir_tree(self._project.output, delete_root_=False)
self._crawler = Crawler(loc_=self._project.zip_file_url, type_=URL.ZIP)
self._crawler.fetch()
self._crawler.save(full_output_folder=self._project.output)
@@ -179,7 +179,7 @@ def setup_zip_folders(self) -> None:
if self._keep_running:
extract_zip_file(
self._project.zip_file_path,
- output_location=Path(self._project.output),
+ output_location_=Path(self._project.output),
)
rm_dir_tree(Path(f"{self._project.output}/{self._project.ss_folder}"))
extracted_paths = glob.glob(
@@ -193,7 +193,7 @@ def setup_zip_folders(self) -> None:
zip_download_folder = archive_folder.relative_to(self._project.output)
rm_dir_tree(
Path(f"{self._project.output}/{zip_download_folder.parts[0]}"),
- delete_root=True,
+ delete_root_=True,
)
def add_search(self) -> None:
@@ -246,12 +246,12 @@ def add_redirects(self) -> None:
if self._keep_running:
if self._project.redirects != REDIRECTS.NONE:
self._redirects.get_from_plugin(
- redirects_api_path=self._project.redirects_api_url,
+ redirects_api_path_=self._project.redirects_api_url,
wp_auth_token_=self._project.wp_auth_token,
)
if self._project.search_path.exists():
- self._redirects.add_search(search_page=self._project.search)
+ self._redirects.add_search(search_page_=self._project.search)
redirect_ouputfile = f"{self._project.output}/{CONFIGS['REDIRECTS']['DESTINATION'][self._project.host.value]}"
self._redirects.save(
@@ -290,12 +290,14 @@ def find_sitemap(self) -> None:
def crawl_sitemap(self) -> None:
if self._project.sitemap:
- sitemap_paths = extract_sitemap_paths(sitemap_url=self._project.sitemap_url)
+ sitemap_paths = extract_sitemap_paths(
+ sitemap_url_=self._project.sitemap_url
+ )
for sitemap_path in sitemap_paths:
if self._keep_running:
self.crawl_url(loc_=sitemap_path)
- def crawl_url(self, loc_):
+ def crawl_url(self, loc_) -> None:
current_url = Crawler(loc_=loc_, scheme_=self._project.scheme)
if current_url.hash not in self._urls:
current_url.fetch()
@@ -318,21 +320,21 @@ def crawl_url(self, loc_):
self.crawl_url(internal_link)
# Project Verifications
- def verify_project_name(self):
+ def verify_project_name(self) -> bool:
logging.info(f"Verifying Project Name!")
return self._project.name != ""
- def verify_src_url(self):
+ def verify_src_url(self) -> bool:
logging.info(f"Verifying Source Url!")
current_url = Crawler(loc_=self._project.src_url, scheme_=self._project.scheme)
current_url.fetch()
return current_url.status_code < 399 # non error status codes
- def verify_output(self):
+ def verify_output(self) -> bool:
logging.info(f"Verifying Output Folder!")
return self._project.output.exists()
- def verify_wp_user(self):
+ def verify_wp_user(self) -> bool:
logging.info(f"Verifying WordPress User Name!")
response = requests.get(
@@ -341,7 +343,7 @@ def verify_wp_user(self):
)
return response.status_code < 399
- def verify_sitemap(self):
+ def verify_sitemap(self) -> bool:
logging.info(f"Verifying Sitemap!")
response = requests.get(
@@ -350,10 +352,10 @@ def verify_sitemap(self):
)
return response.status_code < 399
- def verify_github_token(self):
+ def verify_github_token(self) -> bool:
return self._github.is_token_valid()
- def verify_github_repo(self):
+ def verify_github_repo(self) -> bool:
return self._github.is_repo_valid()
def verify_simply_static(self):
@@ -370,22 +372,22 @@ def verify_simply_static(self):
return ss_found
# Github Actions
- def create_github_repositoy(self):
+ def create_github_repositoy(self) -> None:
if self._keep_running:
self._github.create()
- def delete_github_repositoy(self):
+ def delete_github_repositoy(self) -> None:
if self._keep_running:
self._github.delete()
- def init_git_repositoy(self):
+ def init_git_repositoy(self) -> None:
if self._keep_running:
self._github.initialize()
- def commit_git_repositoy(self):
+ def commit_git_repositoy(self) -> None:
if self._keep_running:
self._github.commit()
- def publish_github_repositoy(self):
+ def publish_github_repositoy(self) -> None:
if self._keep_running:
self._github.publish()
diff --git a/src/staticwordpress/gui/config.py b/src/staticwordpress/gui/config.py
index f0aa358..a49cc41 100644
--- a/src/staticwordpress/gui/config.py
+++ b/src/staticwordpress/gui/config.py
@@ -105,7 +105,7 @@ def paintEvent(self, event: QPaintEvent) -> None:
class ConfigDialog(QDialog):
def __init__(self, parent=None):
super(ConfigDialog, self).__init__(parent=parent)
- self.appConfigurations = QSettings(
+ self.app_configurations = QSettings(
CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"]
)
@@ -152,7 +152,7 @@ def __init__(self, parent=None):
self.pushbutton_color_success = QPushButton("")
self.pushbutton_color_success.setObjectName("success")
self.pushbutton_color_success.setFixedWidth(80)
- self.pushbutton_color_success.clicked.connect(self.openColorDialog)
+ self.pushbutton_color_success.clicked.connect(self.open_color_dialog)
self.pushbutton_color_success.setStyleSheet(
f"background-color: {CONFIGS['COLOR']['SUCCESS']}"
)
@@ -164,7 +164,7 @@ def __init__(self, parent=None):
self.pushbutton_color_warning = QPushButton("")
self.pushbutton_color_warning.setObjectName("warning")
self.pushbutton_color_warning.setFixedWidth(80)
- self.pushbutton_color_warning.clicked.connect(self.openColorDialog)
+ self.pushbutton_color_warning.clicked.connect(self.open_color_dialog)
self.pushbutton_color_warning.setStyleSheet(
f"background-color: {CONFIGS['COLOR']['WARNING']}"
)
@@ -176,7 +176,7 @@ def __init__(self, parent=None):
self.pushbotton_color_error = QPushButton("")
self.pushbotton_color_error.setObjectName("error")
self.pushbotton_color_error.setFixedWidth(80)
- self.pushbotton_color_error.clicked.connect(self.openColorDialog)
+ self.pushbotton_color_error.clicked.connect(self.open_color_dialog)
self.pushbotton_color_error.setStyleSheet(
f"background-color: {CONFIGS['COLOR']['ERROR']}"
)
@@ -363,7 +363,7 @@ def __init__(self, parent=None):
self.setWindowTitle("Default Configurations")
self.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- def openColorDialog(self):
+ def open_color_dialog(self):
color = QColorDialog.getColor()
if color.isValid():
diff --git a/src/staticwordpress/gui/logger.py b/src/staticwordpress/gui/logger.py
index 261c19a..69d34ae 100644
--- a/src/staticwordpress/gui/logger.py
+++ b/src/staticwordpress/gui/logger.py
@@ -42,14 +42,14 @@
class LoggerWidget(logging.Handler, QObject):
- appendPlainText = pyqtSignal(str)
+ append_text_message = pyqtSignal(str)
def __init__(self, parent):
super().__init__()
QObject.__init__(self)
- self.plainTextEdit = QPlainTextEdit(parent)
- self.plainTextEdit.setReadOnly(True)
- self.appendPlainText.connect(self.plainTextEdit.appendPlainText)
+ self.plaintext_edit = QPlainTextEdit(parent)
+ self.plaintext_edit.setReadOnly(True)
+ self.append_text_message.connect(self.plaintext_edit.appendPlainText)
def emit(self, msg):
- self.appendPlainText.emit(self.format(msg))
+ self.append_text_message.emit(self.format(msg))
diff --git a/src/staticwordpress/gui/mainwindow.py b/src/staticwordpress/gui/mainwindow.py
index c047301..e7b32c3 100644
--- a/src/staticwordpress/gui/mainwindow.py
+++ b/src/staticwordpress/gui/mainwindow.py
@@ -84,7 +84,7 @@
class StaticWordPressGUI(QMainWindow):
def __init__(self):
super().__init__()
- self.appConfigurations = QSettings(
+ self.app_configurations = QSettings(
CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"]
)
@@ -99,14 +99,14 @@ def __init__(self):
logging.getLogger().addHandler(self.text_edit_logging)
logging.getLogger().setLevel(logging.INFO)
- self.setCentralWidget(self.text_edit_logging.plainTextEdit)
+ self.setCentralWidget(self.text_edit_logging.plaintext_edit)
self.statusBar().showMessage(f"{CONFIGS['APPLICATION_NAME']} is Ready")
- self.progressBar = QProgressBar()
- self.progressBar.setAlignment(Qt.AlignCenter)
- self.progressBar.setFormat("No Brackground Process is running")
- self.progressBar.setFixedSize(QSize(300, 25))
- self.progressBar.setValue(0)
- self.statusBar().addPermanentWidget(self.progressBar)
+ self.progress_bar = QProgressBar()
+ self.progress_bar.setAlignment(Qt.AlignCenter)
+ self.progress_bar.setFormat("No Brackground Process is running")
+ self.progress_bar.setFixedSize(QSize(300, 25))
+ self.progress_bar.setValue(0)
+ self.statusBar().addPermanentWidget(self.progress_bar)
# ALL menus
for current_menu in GUI_SETTINGS["MENUS"]:
@@ -342,10 +342,10 @@ def new_project(self):
"""Closing current project will automatically start a new project."""
self.close_project()
- pdialog = ProjectDialog(self, self._project, title_="New Project")
- if pdialog.exec_():
- self._project = pdialog._project
- self.appConfigurations.setValue("last-project", self._project.output)
+ proj_dialog = ProjectDialog(self, self._project, title_="New Project")
+ if proj_dialog.exec_():
+ self._project = proj_dialog._project
+ self.app_configurations.setValue("last-project", self._project.output)
if Path(self._project.output).is_dir():
self._project.path.parent.mkdir(parents=True, exist_ok=True)
@@ -368,7 +368,7 @@ def open_project(self):
project_folder = QFileDialog.getExistingDirectory(
self,
"Select Static-WordPress Project Directory",
- str(self.appConfigurations.value("last-project")),
+ str(self.app_configurations.value("last-project")),
QFileDialog.ShowDirsOnly,
)
@@ -377,12 +377,12 @@ def open_project(self):
if project_path.exists():
self._project.open(project_path)
if self._project.is_open():
- pdialog = ProjectDialog(
+ project_dialog = ProjectDialog(
self, self._project, title_="Project Properties"
)
- if pdialog.exec_():
- self._project = pdialog._project
+ if project_dialog.exec_():
+ self._project = project_dialog._project
if not self._project.is_older_version():
logging.warning(
@@ -390,22 +390,22 @@ def open_project(self):
)
logging.info(f"Open Project {self._project.path} Successfully")
- self.appConfigurations.setValue("last-project", project_folder)
+ self.app_configurations.setValue("last-project", project_folder)
else:
- msgBox = QMessageBox(parent=self)
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setText(
f"Project cannot be opened or selected path invalid."
f"
Please try again with project folder."
)
- msgBox.addButton(QMessageBox.Ok).setIcon(
+ message_box.addButton(QMessageBox.Ok).setIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")
)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.setWindowTitle("Open Project")
- msgBox.exec()
+ message_box.setTextFormat(Qt.RichText)
+ message_box.setWindowTitle("Open Project")
+ message_box.exec()
logging.info(
"No New Project Opened. Unsaved project properties will be lost."
@@ -418,23 +418,25 @@ def open_project(self):
def show_project(self):
"""showing static-wordpress Project File"""
if self._project.is_open():
- pdialog = ProjectDialog(self, self._project, title_="Current Project")
- if pdialog.exec_():
- self._project = pdialog._project
+ project_dialog = ProjectDialog(
+ self, self._project, title_="Current Project"
+ )
+ if project_dialog.exec_():
+ self._project = project_dialog._project
self._project.save()
self.update_widgets()
else:
- msgBox = QMessageBox(parent=self)
- msgBox.setText(f"No Project Available.")
- msgBox.addButton(QMessageBox.Ok).setIcon(
+ message_box = QMessageBox(parent=self)
+ message_box.setText(f"No Project Available.")
+ message_box.addButton(QMessageBox.Ok).setIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")
)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.setWindowTitle("Project Settings")
- msgBox.exec()
+ message_box.setTextFormat(Qt.RichText)
+ message_box.setWindowTitle("Project Settings")
+ message_box.exec()
logging.info("No New Project found.")
@is_project_open
@@ -443,24 +445,25 @@ def close_project(self):
"""Assign new project and old properties will be lost.
Default is assigned as CLOSED project
"""
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle("Close Existing Project")
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle("Close Existing Project")
+ message_box.setText(
"Are you sure to close current project and open new one?.
All existing project properties will be lost!",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
-
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setWindowIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
+ )
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
self._project = Project()
self.update_widgets()
@@ -469,27 +472,27 @@ def start_batch_process(self):
"""Start Crawling"""
if not self._project.output.exists():
- msgBox = QMessageBox(parent=self)
- msgBox.setIcon(QMessageBox.Question)
- msgBox.setWindowTitle("Output Folder")
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setIcon(QMessageBox.Question)
+ message_box.setWindowTitle("Output Folder")
+ message_box.setText(
f"Following Output Folder doesnt not exit?.
{self._project.output}
Do You want to create it now?",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
os.mkdir(self._project.output)
else:
return
@@ -502,59 +505,61 @@ def start_batch_process(self):
if self._project.src_type == SOURCE.ZIP:
if not self._bg_worker._work_flow.verify_simply_static():
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle("ZIP File Missing")
- msgBox.setIcon(QMessageBox.Question)
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle("ZIP File Missing")
+ message_box.setIcon(QMessageBox.Question)
+ message_box.setText(
"ZIP File not found. Please check your project configurations?",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg")
+ )
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
return
self._bg_thread = QThread(parent=self)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.batch_processing)
self._bg_thread.start()
@is_project_open
def stop_process(self) -> None:
if self._bg_worker.is_running():
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle("Stop Crawling Process")
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle("Stop Crawling Process")
+ message_box.setText(
"Do you really want to Stop Crawling Thread?",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
self._bg_worker.stop_calcualations()
self.update_statusbar("Stoping Processing", 100)
@@ -568,7 +573,7 @@ def crawl_website(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.pre_processing)
self._bg_thread.start()
@@ -582,7 +587,7 @@ def crawl_additional_files(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.crawl_additional_files)
self._bg_thread.start()
@@ -596,7 +601,7 @@ def create_search_index(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.add_search)
self._bg_thread.start()
@@ -610,7 +615,7 @@ def create_404_page(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.add_404_page)
self._bg_thread.start()
@@ -624,7 +629,7 @@ def create_redirects(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.add_redirects)
self._bg_thread.start()
@@ -638,7 +643,7 @@ def create_robots_txt(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.add_robots_txt)
self._bg_thread.start()
@@ -653,7 +658,7 @@ def create_github_repositoy(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.create_github_repositoy)
self._bg_thread.start()
@@ -661,24 +666,26 @@ def create_github_repositoy(self) -> None:
def delete_github_repository(self) -> None:
""""""
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle("Deleting Repository on GitHub")
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle("Deleting Repository on GitHub")
+ message_box.setText(
f"Do you really want to delete {self._project.gh_repo} on GitHub?
This deletion is not reversible.",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setWindowIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
+ )
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
if self._bg_thread.isRunning():
self._bg_thread.quit()
@@ -687,7 +694,7 @@ def delete_github_repository(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.delete_github_repositoy)
self._bg_thread.start()
@@ -702,7 +709,7 @@ def initialize_repository(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.init_git_repositoy)
self._bg_thread.start()
@@ -717,7 +724,7 @@ def commit_repository(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.commit_git_repositoy)
self._bg_thread.start()
@@ -732,19 +739,19 @@ def publish_repository(self) -> None:
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
- self._bg_worker.signalProgress.connect(self.update_statusbar)
+ self._bg_worker.emit_progress.connect(self.update_statusbar)
self._bg_thread.started.connect(self._bg_worker.publish_github_repositoy)
self._bg_thread.start()
def update_statusbar(self, message_, percent_) -> None:
if percent_ >= 0:
- self.progressBar.setValue(percent_)
+ self.progress_bar.setValue(percent_)
self.statusBar().showMessage(message_)
else:
- self.progressBar.setFormat(message_)
+ self.progress_bar.setFormat(message_)
if percent_ >= 100:
- self.progressBar.setFormat(message_)
+ self.progress_bar.setFormat(message_)
def update_widgets(self) -> None:
self.findChild(QMenu, "menu_github").setEnabled(self._project.has_github())
diff --git a/src/staticwordpress/gui/project.py b/src/staticwordpress/gui/project.py
index 958238e..04f09cc 100644
--- a/src/staticwordpress/gui/project.py
+++ b/src/staticwordpress/gui/project.py
@@ -104,7 +104,7 @@ def __init__(self, parent, project_, title_="Project Settings"):
self.lineedit_src_url.setObjectName("src-url")
form_layout_general_settings.addRow(QLabel("Source Url"), self.lineedit_src_url)
- horizontal_Layout_output_directory = QHBoxLayout()
+ horizontal_layout_output_directory = QHBoxLayout()
self.lineedit_output = QLineEdit(str(self._project.output))
self.lineedit_output.setObjectName("output")
self.toolbutton_output_directory = QToolButton()
@@ -112,10 +112,10 @@ def __init__(self, parent, project_, title_="Project Settings"):
QIcon(f"{SHARE_FOLDER_PATH}/icons/three-dots.svg")
)
self.toolbutton_output_directory.clicked.connect(self.get_output_directory)
- horizontal_Layout_output_directory.addWidget(self.lineedit_output)
- horizontal_Layout_output_directory.addWidget(self.toolbutton_output_directory)
+ horizontal_layout_output_directory.addWidget(self.lineedit_output)
+ horizontal_layout_output_directory.addWidget(self.toolbutton_output_directory)
form_layout_general_settings.addRow(
- QLabel("Output Directory"), horizontal_Layout_output_directory
+ QLabel("Output Directory"), horizontal_layout_output_directory
)
horizontal_layout_crawl_delay_user_agent = QHBoxLayout()
@@ -169,45 +169,45 @@ def __init__(self, parent, project_, title_="Project Settings"):
widget_static_website_tab = QWidget()
form_layout_static_website_properties = QFormLayout()
- horizontal_Layout_project_scource = QHBoxLayout()
+ horizontal_layout_project_source = QHBoxLayout()
self.combobox_source_type = QComboBox()
self.combobox_source_type.setObjectName("source")
self.combobox_source_type.setMinimumWidth(120)
self.combobox_source_type.addItems([item.value for item in list(SOURCE)])
self.combobox_source_type.setCurrentText(self._project.src_type.value)
- horizontal_Layout_project_scource.addWidget(self.combobox_source_type)
- horizontal_Layout_project_scource.addStretch()
+ horizontal_layout_project_source.addWidget(self.combobox_source_type)
+ horizontal_layout_project_source.addStretch()
form_layout_static_website_properties.addRow(
- QLabel("Data Source"), horizontal_Layout_project_scource
+ QLabel("Data Source"), horizontal_layout_project_source
)
- horizontal_Layout_project_redirects = QHBoxLayout()
+ horizontal_layout_project_redirects = QHBoxLayout()
self.combobox_redirects = QComboBox()
self.combobox_redirects.setObjectName("redirects")
self.combobox_redirects.setMinimumWidth(120)
self.combobox_redirects.addItems([item.value for item in list(REDIRECTS)])
self.combobox_redirects.setCurrentText(self._project.redirects.value)
- horizontal_Layout_project_redirects.addWidget(self.combobox_redirects)
- horizontal_Layout_project_redirects.addStretch()
+ horizontal_layout_project_redirects.addWidget(self.combobox_redirects)
+ horizontal_layout_project_redirects.addStretch()
form_layout_static_website_properties.addRow(
- QLabel("Redirects Source"), horizontal_Layout_project_redirects
+ QLabel("Redirects Source"), horizontal_layout_project_redirects
)
- horizontal_Layout_project_destination = QHBoxLayout()
+ horizontal_layout_project_destination = QHBoxLayout()
self.combobox_project_destination = QComboBox()
self.combobox_project_destination.setObjectName("host")
self.combobox_project_destination.setMinimumWidth(120)
self.combobox_project_destination.addItems([item.value for item in list(HOST)])
self.combobox_project_destination.setCurrentText(self._project.host.value)
- horizontal_Layout_project_destination.addWidget(
+ horizontal_layout_project_destination.addWidget(
self.combobox_project_destination
)
- horizontal_Layout_project_destination.addStretch()
+ horizontal_layout_project_destination.addStretch()
form_layout_static_website_properties.addRow(
- QLabel("Destination Host"), horizontal_Layout_project_destination
+ QLabel("Destination Host"), horizontal_layout_project_destination
)
self.lineedit_dest_url = QLineEdit(self._project.dst_url)
@@ -229,7 +229,7 @@ def __init__(self, parent, project_, title_="Project Settings"):
)
widget_static_website_tab.setLayout(form_layout_static_website_properties)
- horizontal_Layout_sitemap = QHBoxLayout()
+ horizontal_layout_sitemap = QHBoxLayout()
self.lineedit_sitemap = QLineEdit(self._project.sitemap)
self.lineedit_sitemap.setObjectName("sitemap")
self.toolbutton_output_sitemap = QToolButton()
@@ -237,10 +237,10 @@ def __init__(self, parent, project_, title_="Project Settings"):
QIcon(f"{SHARE_FOLDER_PATH}/icons/search.svg")
)
self.toolbutton_output_sitemap.clicked.connect(self.get_sitemap_location)
- horizontal_Layout_sitemap.addWidget(self.lineedit_sitemap)
- horizontal_Layout_sitemap.addWidget(self.toolbutton_output_sitemap)
+ horizontal_layout_sitemap.addWidget(self.lineedit_sitemap)
+ horizontal_layout_sitemap.addWidget(self.toolbutton_output_sitemap)
form_layout_static_website_properties.addRow(
- QLabel("Sitemap Location"), horizontal_Layout_sitemap
+ QLabel("Sitemap Location"), horizontal_layout_sitemap
)
self.textedit_additional_urls = QTextEdit()
@@ -395,7 +395,7 @@ def get_sitemap_location(self):
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
self._bg_thread.started.connect(self._bg_worker.find_sitemap)
- self._bg_worker.signalSitemapLocation.connect(self.update_sitemap_location)
+ self._bg_worker.emit_sitemap_location.connect(self.update_sitemap_location)
self._bg_thread.start()
def update_sitemap_location(self, sitemap_location):
@@ -404,7 +404,7 @@ def update_sitemap_location(self, sitemap_location):
def check_project(self):
""""""
# TODO: Add checks for WP_API and Gh_API and if not present then disable them.
- # TODO: Move these checks to background thread
+ # TODO: Move these checks to background thread e.g. for WP_API or SRC_URL or SRC or DST Path
if not (self.lineedit_wp_api_token.text() and self.lineedit_wp_user.text()):
self.combobox_redirects.setCurrentText(REDIRECTS.NONE.value)
@@ -498,18 +498,18 @@ def accept(self) -> None:
else:
logging.info(f"Current Project Settings are not valid.")
- msgBox = QMessageBox(parent=self)
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setText(
"Cannot start this project.
Please check project settings."
)
- msgBox.addButton(QMessageBox.Ok).setIcon(
+ message_box.addButton(QMessageBox.Ok).setIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")
)
- msgBox.setWindowIcon(
+ message_box.setWindowIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
)
- msgBox.setTextFormat(Qt.RichText)
- msgBox.setWindowTitle(
+ message_box.setTextFormat(Qt.RichText)
+ message_box.setWindowTitle(
"Invalid Project Settings",
)
- msgBox.exec()
+ message_box.exec()
diff --git a/src/staticwordpress/gui/utils.py b/src/staticwordpress/gui/utils.py
index 588e437..55d58ea 100644
--- a/src/staticwordpress/gui/utils.py
+++ b/src/staticwordpress/gui/utils.py
@@ -68,8 +68,8 @@ def progress_decorator(message, percent=10):
def decorator(function):
def wrapper(cls):
logging.info(f"{message}")
- cls.signalProgress.emit(message, -1)
- cls.signalProgress.emit(message, percent)
+ cls.emit_progress.emit(message, -1)
+ cls.emit_progress.emit(message, percent)
result = function(cls)
return result
diff --git a/src/staticwordpress/gui/workflow.py b/src/staticwordpress/gui/workflow.py
index fba1b90..33b6f2a 100644
--- a/src/staticwordpress/gui/workflow.py
+++ b/src/staticwordpress/gui/workflow.py
@@ -45,9 +45,9 @@
class WorkflowGUI(QObject):
- signalSitemapLocation = pyqtSignal(str)
- signalProgress = pyqtSignal(str, int)
- signalVerification = pyqtSignal(dict)
+ emit_sitemap_location = pyqtSignal(str)
+ emit_progress = pyqtSignal(str, int)
+ emit_verification = pyqtSignal(dict)
_work_flow = Workflow()
@@ -58,7 +58,7 @@ def set_project(self, project_: Project) -> None:
@progress_decorator("Verifying Project Settings", 100)
@logging_decorator
def verify_project(self):
- self.signalVerification.emit(
+ self.emit_verification.emit(
{
"name": self._work_flow.verify_project_name(),
"src-url": self._work_flow.verify_src_url(),
@@ -131,7 +131,7 @@ def add_search(self) -> None:
@logging_decorator
def find_sitemap(self) -> None:
self._work_flow.find_sitemap()
- self.signalSitemapLocation.emit(self._work_flow.sitemap)
+ self.emit_sitemap_location.emit(self._work_flow.sitemap)
@progress_decorator("Crawling Sitemap", 100)
@logging_decorator
diff --git a/tests/test_redirects.py b/tests/test_redirects.py
index f860e47..dc0dcac 100644
--- a/tests/test_redirects.py
+++ b/tests/test_redirects.py
@@ -35,7 +35,7 @@ def test_redirect():
red = Redirect(
from_="/",
to_="https://seowings.org",
- status=200,
+ status_=200,
query_=None,
force_=True,
source_=REDIRECTS.REDIRECTION,
From bc121722a701a7a9b5854100f83f95335ae21692 Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 18:09:32 +0100
Subject: [PATCH 3/6] optimized sitemap search
---
src/staticwordpress/core/sitemaps.py | 46 ++++++++++++++-------------
src/staticwordpress/core/utils.py | 10 ++++--
src/staticwordpress/gui/mainwindow.py | 5 +--
src/staticwordpress/gui/project.py | 11 ++++---
4 files changed, 41 insertions(+), 31 deletions(-)
diff --git a/src/staticwordpress/core/sitemaps.py b/src/staticwordpress/core/sitemaps.py
index 4f5206a..32bb085 100644
--- a/src/staticwordpress/core/sitemaps.py
+++ b/src/staticwordpress/core/sitemaps.py
@@ -41,7 +41,7 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
from ..core.constants import CONFIGS
-from ..core.utils import get_clean_url, get_remote_content
+from ..core.utils import get_clean_url, get_remote_content, is_url_valid
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
@@ -57,27 +57,29 @@ def find_sitemap_location(home_url_: str) -> str:
Returns:
str: Location of Sitemap
"""
- for sitemap_path in CONFIGS["SITEMAP"]["SEARCH_PATHS"]:
- sitemap_url = get_clean_url(home_url_, sitemap_path)
- response = get_remote_content(sitemap_url)
- if response.status_code < 400:
- return parse.urlparse(response.url).path
-
- # robots.txt
- robots_txt = get_clean_url(home_url_, "robots.txt")
- response = get_remote_content(robots_txt)
- if response:
- for item in response.text.split("\n"):
- if item.startswith("Sitemap:"):
- return item.split("Sitemap:")[-1].strip()
-
- # check home page for link rel=sitemap
- response = get_remote_content(home_url_)
- if response:
- soup = BeautifulSoup(response.text, features="xml")
- for link in soup.find_all("link"):
- if link.has_attr("sitemap"):
- return link["href"]
+ if is_url_valid(home_url_):
+ for sitemap_path in CONFIGS["SITEMAP"]["SEARCH_PATHS"]:
+ sitemap_url = get_clean_url(home_url_, sitemap_path)
+ response = get_remote_content(sitemap_url)
+ if response.status_code < 400:
+ return parse.urlparse(response.url).path
+
+ # robots.txt
+ robots_txt = get_clean_url(home_url_, "robots.txt")
+ response = get_remote_content(robots_txt)
+ if response:
+ for item in response.text.split("\n"):
+ if item.startswith("Sitemap:"):
+ return item.split("Sitemap:")[-1].strip()
+
+ # check home page for link rel=sitemap
+ response = get_remote_content(home_url_)
+ if response:
+ soup = BeautifulSoup(response.text, features="xml")
+ for link in soup.find_all("link"):
+ if link.has_attr("sitemap"):
+ return link["href"]
+ return ""
return ""
diff --git a/src/staticwordpress/core/utils.py b/src/staticwordpress/core/utils.py
index 94d8ecb..f629bfa 100644
--- a/src/staticwordpress/core/utils.py
+++ b/src/staticwordpress/core/utils.py
@@ -228,6 +228,12 @@ def is_url_valid(url_: str) -> bool:
url_parsed_ = parse.urlparse(url_)
if all([url_parsed_.scheme, url_parsed_.netloc]):
- return get_remote_content(url_parsed_, max_retires=1).status_code < 399
-
+ from urllib.request import urlopen
+
+ # print(url_parsed_)
+ # # return get_remote_content(url_parsed_, max_retires=1).status_code < 399
+ try:
+ return urlopen(url_).getcode() < 399
+ except:
+ return False
return False
diff --git a/src/staticwordpress/gui/mainwindow.py b/src/staticwordpress/gui/mainwindow.py
index e7b32c3..08b812e 100644
--- a/src/staticwordpress/gui/mainwindow.py
+++ b/src/staticwordpress/gui/mainwindow.py
@@ -378,7 +378,7 @@ def open_project(self):
self._project.open(project_path)
if self._project.is_open():
project_dialog = ProjectDialog(
- self, self._project, title_="Project Properties"
+ parent=self, project_=self._project, title_="Project Properties"
)
if project_dialog.exec_():
@@ -756,7 +756,8 @@ def update_statusbar(self, message_, percent_) -> None:
def update_widgets(self) -> None:
self.findChild(QMenu, "menu_github").setEnabled(self._project.has_github())
self.findChild(QMenu, "menu_wordpress").setEnabled(
- self._project.has_wordpress() or self._project.can_crawl()
+ self._project.is_open()
+ and (self._project.has_wordpress() or self._project.can_crawl())
)
self.findChild(QToolBar, "toolbar_github").setEnabled(
self._project.has_github()
diff --git a/src/staticwordpress/gui/project.py b/src/staticwordpress/gui/project.py
index 04f09cc..1f9f157 100644
--- a/src/staticwordpress/gui/project.py
+++ b/src/staticwordpress/gui/project.py
@@ -323,7 +323,7 @@ def __init__(self, parent, project_, title_="Project Settings"):
self.pushbutton_verify.setIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/check_project.svg")
)
- self.pushbutton_verify.clicked.connect(self.check_project)
+ self.pushbutton_verify.clicked.connect(self.verify_project_settings)
self.pushbutton_save = QPushButton("&Save")
self.pushbutton_save.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
@@ -398,10 +398,11 @@ def get_sitemap_location(self):
self._bg_worker.emit_sitemap_location.connect(self.update_sitemap_location)
self._bg_thread.start()
- def update_sitemap_location(self, sitemap_location):
- self.lineedit_sitemap.setText(sitemap_location)
+ def update_sitemap_location(self, sitemap_location_):
+ if sitemap_location_:
+ self.lineedit_sitemap.setText(sitemap_location_)
- def check_project(self):
+ def verify_project_settings(self):
""""""
# TODO: Add checks for WP_API and Gh_API and if not present then disable them.
# TODO: Move these checks to background thread e.g. for WP_API or SRC_URL or SRC or DST Path
@@ -455,7 +456,7 @@ def accept(self) -> None:
[
self.lineedit_project_name.text(),
self.lineedit_output.text(),
- is_url_valid(self.lineedit_src_url.text()),
+ # is_url_valid(self.lineedit_src_url.text()),
Path(self.lineedit_output.text()).is_dir(),
]
):
From d6b28aef5cfe8f610b15b1a565bf8787c242dc60 Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 22:17:57 +0100
Subject: [PATCH 4/6] included ipython widget via qtconsole
---
.gitignore | 1 +
setup.py | 4 +-
src/staticwordpress/gui/__init__.py | 2 +-
src/staticwordpress/gui/config.py | 8 +-
src/staticwordpress/gui/editor.py | 61 ++++++++
src/staticwordpress/gui/logger.py | 2 +-
.../gui/{mainwindow.py => main.py} | 132 +++++++++++-------
src/staticwordpress/gui/project.py | 10 +-
src/staticwordpress/gui/rawtext.py | 4 +-
src/staticwordpress/gui/workflow.py | 2 +-
src/staticwordpress/share/gui.json | 13 ++
src/staticwordpress/share/icons/python.svg | 38 +++++
12 files changed, 207 insertions(+), 70 deletions(-)
create mode 100644 src/staticwordpress/gui/editor.py
rename src/staticwordpress/gui/{mainwindow.py => main.py} (89%)
create mode 100644 src/staticwordpress/share/icons/python.svg
diff --git a/.gitignore b/.gitignore
index 981373b..bb4075c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -124,6 +124,7 @@ celerybeat.pid
# Environments
.env
.venv
+.venv10
env/
venv/
ENV/
diff --git a/setup.py b/setup.py
index b570531..758cb9d 100644
--- a/setup.py
+++ b/setup.py
@@ -73,9 +73,7 @@
"mkdocstrings[python]",
"pymdown-extensions",
],
- "gui": [
- "pyqt5",
- ],
+ "gui": ["pyqt5", "qtconsole"],
}
extras_require["all"] = list(
{rq for target in extras_require.keys() for rq in extras_require[target]}
diff --git a/src/staticwordpress/gui/__init__.py b/src/staticwordpress/gui/__init__.py
index ee98d5b..096bdd6 100644
--- a/src/staticwordpress/gui/__init__.py
+++ b/src/staticwordpress/gui/__init__.py
@@ -27,4 +27,4 @@
# INTERNAL IMPORTS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-from .mainwindow import main
+from .main import main
diff --git a/src/staticwordpress/gui/config.py b/src/staticwordpress/gui/config.py
index a49cc41..6aa2852 100644
--- a/src/staticwordpress/gui/config.py
+++ b/src/staticwordpress/gui/config.py
@@ -69,7 +69,7 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class ConfigTabBar(QTabBar):
+class SWConfigTabBar(QTabBar):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
return
@@ -102,15 +102,15 @@ def paintEvent(self, event: QPaintEvent) -> None:
return
-class ConfigDialog(QDialog):
+class SWConfigDialog(QDialog):
def __init__(self, parent=None):
- super(ConfigDialog, self).__init__(parent=parent)
+ super(SWConfigDialog, self).__init__(parent=parent)
self.app_configurations = QSettings(
CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"]
)
self.tabswidget_configs = QTabWidget()
- self.tabswidget_configs.setTabBar(ConfigTabBar())
+ self.tabswidget_configs.setTabBar(SWConfigTabBar())
self.tabswidget_configs.setTabPosition(QTabWidget.West)
self.tab_general = QWidget()
diff --git a/src/staticwordpress/gui/editor.py b/src/staticwordpress/gui/editor.py
new file mode 100644
index 0000000..9a55246
--- /dev/null
+++ b/src/staticwordpress/gui/editor.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+
+"""
+STATIC WORDPRESS: WordPress as Static Site Generator
+A Python Package for Converting WordPress Installation to a Static Website
+https://github.com/serpwings/staticwordpress
+
+ src\staticwordpress\gui\editor.py
+
+ Copyright (C) 2020-2023 Faisal Shahzad
+
+
+The contents of this file are subject to version 3 of the
+GNU General Public License (GPL-3.0). You may not use this file except in
+compliance with the License. You may obtain a copy of the License at
+https://www.gnu.org/licenses/gpl-3.0.txt
+https://github.com/serpwings/staticwordpress/blob/master/LICENSE
+
+
+Software distributed under the License is distributed on an "AS IS" basis,
+WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
+specific language governing rights and limitations under the License.
+
+"""
+
+
+# +++++++++++++++++++++++++++++++++++++++++++++++++++++
+# 3rd PARTY LIBRARY IMPORTS
+# +++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+from qtconsole.rich_jupyter_widget import RichJupyterWidget
+from qtconsole.inprocess import QtInProcessKernelManager
+from IPython.lib import guisupport
+
+
+# +++++++++++++++++++++++++++++++++++++++++++++++++++++
+# IMPLEMENATIONS
+# +++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+
+class SWIPythonWidget(RichJupyterWidget):
+ def __init__(self, interface_: dict = {"iface": None}, *args, **kwargs):
+ super(SWIPythonWidget, self).__init__(*args, **kwargs)
+
+ self.ipython_kernal_manager = QtInProcessKernelManager()
+ self.ipython_kernal_manager.start_kernel()
+ self.kernel_client = self.ipython_kernal_manager.client()
+ self.kernel_client.start_channels()
+
+ import_custom_modules = ["import requests"]
+ for module in import_custom_modules:
+ self._execute(module, hidden=True)
+
+ self.ipython_kernal_manager.kernel.shell.push(interface_)
+
+ def stop():
+ self.kernel_client.stop_channels()
+ self.ipython_kernal_manager.shutdown_kernel()
+ guisupport.get_app_qt4().exit()
+
+ self.exit_requested.connect(stop)
diff --git a/src/staticwordpress/gui/logger.py b/src/staticwordpress/gui/logger.py
index 69d34ae..f132af1 100644
--- a/src/staticwordpress/gui/logger.py
+++ b/src/staticwordpress/gui/logger.py
@@ -41,7 +41,7 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class LoggerWidget(logging.Handler, QObject):
+class SWLoggerWidget(logging.Handler, QObject):
append_text_message = pyqtSignal(str)
def __init__(self, parent):
diff --git a/src/staticwordpress/gui/mainwindow.py b/src/staticwordpress/gui/main.py
similarity index 89%
rename from src/staticwordpress/gui/mainwindow.py
rename to src/staticwordpress/gui/main.py
index 08b812e..130fa3b 100644
--- a/src/staticwordpress/gui/mainwindow.py
+++ b/src/staticwordpress/gui/main.py
@@ -48,6 +48,7 @@
QProgressBar,
QMenu,
QToolBar,
+ QDockWidget,
)
from PyQt5.QtGui import QIcon, QDesktopServices
from PyQt5.QtCore import Qt, QThread, QSize, QSettings, QUrl
@@ -69,19 +70,20 @@
get_remote_content,
extract_urls_from_raw_text,
)
-from ..gui.workflow import WorkflowGUI
-from ..gui.logger import LoggerWidget
-from ..gui.rawtext import RawTextDialog
-from ..gui.config import ConfigDialog
-from ..gui.project import ProjectDialog
-from ..gui.utils import GUI_SETTINGS, logging_decorator
+from .workflow import SWWorkflowObject
+from .logger import SWLoggerWidget
+from .editor import SWIPythonWidget
+from .rawtext import SWRawTextDialog
+from .config import SWConfigDialog
+from .project import SWProjectDialog
+from .utils import GUI_SETTINGS, logging_decorator
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class StaticWordPressGUI(QMainWindow):
+class SWMainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.app_configurations = QSettings(
@@ -90,16 +92,16 @@ def __init__(self):
self._project = Project()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
- self.text_edit_logging = LoggerWidget(self)
+ self.text_edit_logging = SWLoggerWidget(self)
self.text_edit_logging.setFormatter(
logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
)
logging.getLogger().addHandler(self.text_edit_logging)
logging.getLogger().setLevel(logging.INFO)
-
self.setCentralWidget(self.text_edit_logging.plaintext_edit)
+
self.statusBar().showMessage(f"{CONFIGS['APPLICATION_NAME']} is Ready")
self.progress_bar = QProgressBar()
self.progress_bar.setAlignment(Qt.AlignCenter)
@@ -159,6 +161,13 @@ def __init__(self):
if current_toolbar:
current_toolbar.addAction(action)
+ # docked widgets
+ self.dockwidget_ipython = QDockWidget("IPython Console", self)
+ self.dockwidget_ipython.setFloating(False)
+ self.dockwidget_ipython.hide()
+ self.addDockWidget(Qt.RightDockWidgetArea, self.dockwidget_ipython)
+ self.ipython_console = None
+
self.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
self.setWindowTitle(f"{CONFIGS['APPLICATION_NAME']} Version - {VERISON}")
self.setMinimumSize(QSize(1366, 768))
@@ -229,14 +238,16 @@ def clean_output_directory(self):
@is_new_project
@logging_decorator
def extract_url_from_raw_text(self):
- rtp = RawTextDialog(
+ raw_text_dialog = SWRawTextDialog(
parent=self, src_url=self._project.src_url, dest_url=self._project.dst_url
)
- if rtp.exec_():
- raw_text = rtp.textedit_raw_text_with_links.toPlainText()
+ if raw_text_dialog.exec_():
+ raw_text = raw_text_dialog.textedit_raw_text_with_links.toPlainText()
if raw_text:
new_additional_links = extract_urls_from_raw_text(
- raw_text, rtp.lineedit_dest_url.text(), rtp.linedit_src_url.text()
+ raw_text,
+ raw_text_dialog.lineedit_dest_url.text(),
+ raw_text_dialog.linedit_src_url.text(),
)
logging.info(f" {len(new_additional_links)} Additional Urls Found")
self._project.additional += new_additional_links
@@ -251,31 +262,33 @@ def clear_cache(self):
def closeEvent(self, event):
""" """
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle(f"Exiting {CONFIGS['APPLICATION_NAME']}")
- msgBox.setIcon(QMessageBox.Question)
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle(f"Exiting {CONFIGS['APPLICATION_NAME']}")
+ message_box.setIcon(QMessageBox.Question)
+ message_box.setText(
"Do you really want to exit?.
Any unsaved changes will be lost!",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
+ pushbuttonOk = message_box.addButton("OK", QMessageBox.YesRole)
pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
+ pushbuttonNo = message_box.addButton("Cancel", QMessageBox.NoRole)
pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbuttonOk)
- msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setWindowIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
+ )
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbuttonOk:
if self._bg_thread.isRunning():
self._bg_thread.quit()
del self._bg_thread
del self._bg_worker
- super(StaticWordPressGUI, self).closeEvent(event)
+ super(SWMainWindow, self).closeEvent(event)
event.accept()
@@ -313,38 +326,51 @@ def help(self):
if not QDesktopServices.openUrl(url):
QMessageBox.warning(self, "Open Help URL", "Could not open Help URL")
+ def startIPython(self):
+ """ """
+ if self.findChild(QAction, "action_ipython_widget").isChecked():
+ if self.ipython_console is None:
+ self.ipython_console = SWIPythonWidget(interface_={"iface": self})
+ self.dockwidget_ipython.setWidget(self.ipython_console)
+
+ self.dockwidget_ipython.show()
+ else:
+ self.dockwidget_ipython.hide()
+
@logging_decorator
def show_configs(self):
"""Interface with System Configurations"""
- w = ConfigDialog(parent=self)
- if w.exec_():
+ config_dialog = SWConfigDialog(parent=self)
+ if config_dialog.exec_():
logging.info("Saved/Updated Default Configurations")
def about(self):
""" """
- msgBox = QMessageBox(parent=self)
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setText(
f"Copyright {date.today().year} - SERP Wings"
f"
{CONFIGS['APPLICATION_NAME']} Version - {VERISON}"
"
This work is an opensource project under
GNU General Public License v3 or later (GPLv3+)"
f"
More Information at {CONFIGS['ORGANIZATION_NAME']}"
)
- msgBox.addButton(QMessageBox.Ok).setIcon(
+ message_box.addButton(QMessageBox.Ok).setIcon(
QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg")
)
- msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- msgBox.setTextFormat(Qt.RichText)
- msgBox.setWindowTitle("About Us")
- msgBox.exec()
+ message_box.setWindowIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
+ )
+ message_box.setTextFormat(Qt.RichText)
+ message_box.setWindowTitle("About Us")
+ message_box.exec()
@logging_decorator
def new_project(self):
"""Closing current project will automatically start a new project."""
self.close_project()
- proj_dialog = ProjectDialog(self, self._project, title_="New Project")
- if proj_dialog.exec_():
- self._project = proj_dialog._project
+ project_dialog = SWProjectDialog(self, self._project, title_="New Project")
+ if project_dialog.exec_():
+ self._project = project_dialog._project
self.app_configurations.setValue("last-project", self._project.output)
if Path(self._project.output).is_dir():
@@ -377,7 +403,7 @@ def open_project(self):
if project_path.exists():
self._project.open(project_path)
if self._project.is_open():
- project_dialog = ProjectDialog(
+ project_dialog = SWProjectDialog(
parent=self, project_=self._project, title_="Project Properties"
)
@@ -418,7 +444,7 @@ def open_project(self):
def show_project(self):
"""showing static-wordpress Project File"""
if self._project.is_open():
- project_dialog = ProjectDialog(
+ project_dialog = SWProjectDialog(
self, self._project, title_="Current Project"
)
if project_dialog.exec_():
@@ -500,7 +526,7 @@ def start_batch_process(self):
if self._bg_thread.isRunning():
self._bg_thread.quit()
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
if self._project.src_type == SOURCE.ZIP:
@@ -569,7 +595,7 @@ def crawl_website(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -583,7 +609,7 @@ def crawl_additional_files(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -597,7 +623,7 @@ def create_search_index(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -611,7 +637,7 @@ def create_404_page(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -625,7 +651,7 @@ def create_redirects(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -639,7 +665,7 @@ def create_robots_txt(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -654,7 +680,7 @@ def create_github_repositoy(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -689,7 +715,7 @@ def delete_github_repository(self) -> None:
if self._bg_thread.isRunning():
self._bg_thread.quit()
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
@@ -705,7 +731,7 @@ def initialize_repository(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -720,7 +746,7 @@ def commit_repository(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -735,7 +761,7 @@ def publish_repository(self) -> None:
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
@@ -791,7 +817,7 @@ def update_widgets(self) -> None:
def main():
app = QApplication(sys.argv)
- wind = StaticWordPressGUI()
+ wind = SWMainWindow()
sys.exit(app.exec_())
diff --git a/src/staticwordpress/gui/project.py b/src/staticwordpress/gui/project.py
index 1f9f157..b5b6dc1 100644
--- a/src/staticwordpress/gui/project.py
+++ b/src/staticwordpress/gui/project.py
@@ -72,23 +72,23 @@
from ..core.project import Project
from ..core.utils import is_url_valid
-from ..gui.workflow import WorkflowGUI
+from ..gui.workflow import SWWorkflowObject
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPLEMENATIONS
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class ProjectDialog(QDialog):
+class SWProjectDialog(QDialog):
def __init__(self, parent, project_, title_="Project Settings"):
- super(ProjectDialog, self).__init__(parent=parent)
+ super(SWProjectDialog, self).__init__(parent=parent)
self.appConfigurations = QSettings(
CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"]
)
self._project = project_
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
vertical_layout_project = QVBoxLayout()
groupbox_general_settings = QGroupBox("General Settings")
@@ -390,7 +390,7 @@ def get_sitemap_location(self):
self._bg_thread.quit()
self._bg_thread = QThread(parent=self)
- self._bg_worker = WorkflowGUI()
+ self._bg_worker = SWWorkflowObject()
self._bg_worker.set_project(project_=self._project)
self._bg_worker.moveToThread(self._bg_thread)
self._bg_thread.finished.connect(self._bg_worker.deleteLater)
diff --git a/src/staticwordpress/gui/rawtext.py b/src/staticwordpress/gui/rawtext.py
index 6f422d9..184a6db 100644
--- a/src/staticwordpress/gui/rawtext.py
+++ b/src/staticwordpress/gui/rawtext.py
@@ -51,9 +51,9 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class RawTextDialog(QDialog):
+class SWRawTextDialog(QDialog):
def __init__(self, parent, src_url: str, dest_url: str):
- super(RawTextDialog, self).__init__(parent=parent)
+ super(SWRawTextDialog, self).__init__(parent=parent)
self.appConfigurations = QSettings(
CONFIGS["APPLICATION_NAME"], CONFIGS["APPLICATION_NAME"]
)
diff --git a/src/staticwordpress/gui/workflow.py b/src/staticwordpress/gui/workflow.py
index 33b6f2a..80c4a93 100644
--- a/src/staticwordpress/gui/workflow.py
+++ b/src/staticwordpress/gui/workflow.py
@@ -44,7 +44,7 @@
# +++++++++++++++++++++++++++++++++++++++++++++++++++++
-class WorkflowGUI(QObject):
+class SWWorkflowObject(QObject):
emit_sitemap_location = pyqtSignal(str)
emit_progress = pyqtSignal(str, int)
emit_verification = pyqtSignal(dict)
diff --git a/src/staticwordpress/share/gui.json b/src/staticwordpress/share/gui.json
index 28c5c22..0b889e6 100644
--- a/src/staticwordpress/share/gui.json
+++ b/src/staticwordpress/share/gui.json
@@ -164,6 +164,19 @@
"seperator": false,
"toolbar": "toolbar_edit"
},
+ {
+ "icon": "/icons/python.svg",
+ "name": "action_ipython_widget",
+ "visible": true,
+ "text": "&IPython",
+ "shortcut": "F10",
+ "tooltip": "IPython (F10)",
+ "function": "self.startIPython",
+ "setCheckable": true,
+ "menu": "menu_edit",
+ "seperator": false,
+ "toolbar": "toolbar_edit"
+ },
{
"icon": "/icons/configs.svg",
"name": "action_file_project_close",
diff --git a/src/staticwordpress/share/icons/python.svg b/src/staticwordpress/share/icons/python.svg
new file mode 100644
index 0000000..71e7688
--- /dev/null
+++ b/src/staticwordpress/share/icons/python.svg
@@ -0,0 +1,38 @@
+
+
From b8b75eea4a2aac9d81d1e551be1a1c5ced07798a Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 22:38:47 +0100
Subject: [PATCH 5/6] added debuig clear action/button
---
src/staticwordpress/share/gui.json | 45 ++++++++++++-------
src/staticwordpress/share/icons/clear_all.svg | 38 ++++++++++++++++
2 files changed, 67 insertions(+), 16 deletions(-)
create mode 100644 src/staticwordpress/share/icons/clear_all.svg
diff --git a/src/staticwordpress/share/gui.json b/src/staticwordpress/share/gui.json
index 0b889e6..e2f1874 100644
--- a/src/staticwordpress/share/gui.json
+++ b/src/staticwordpress/share/gui.json
@@ -138,6 +138,32 @@
"seperator": false,
"toolbar": ""
},
+ {
+ "icon": "/icons/clear_all.svg",
+ "name": "action_clear_debug_logs",
+ "visible": true,
+ "text": "&Clear All",
+ "shortcut": "F2",
+ "tooltip": "Clear All (F2)",
+ "function": "self.text_edit_logging.plaintext_edit.clear",
+ "setCheckable": false,
+ "menu": "menu_edit",
+ "seperator": true,
+ "toolbar": "toolbar_edit"
+ },
+ {
+ "icon": "/icons/python.svg",
+ "name": "action_ipython_widget",
+ "visible": true,
+ "text": "&IPython",
+ "shortcut": "F4",
+ "tooltip": "IPython (F4)",
+ "function": "self.start_ipython_console",
+ "setCheckable": true,
+ "menu": "menu_edit",
+ "seperator": false,
+ "toolbar": "toolbar_edit"
+ },
{
"icon": "/icons/bug-outline.svg",
"name": "action_edit_debug",
@@ -156,22 +182,9 @@
"name": "action_edit_expert_mode",
"visible": true,
"text": "&Expert Mode",
- "shortcut": "F8",
- "tooltip": "Expert Mode (F8)",
- "function": "self.set_expert_mode",
- "setCheckable": true,
- "menu": "menu_edit",
- "seperator": false,
- "toolbar": "toolbar_edit"
- },
- {
- "icon": "/icons/python.svg",
- "name": "action_ipython_widget",
- "visible": true,
- "text": "&IPython",
"shortcut": "F10",
- "tooltip": "IPython (F10)",
- "function": "self.startIPython",
+ "tooltip": "Expert Mode (F10)",
+ "function": "self.set_expert_mode",
"setCheckable": true,
"menu": "menu_edit",
"seperator": false,
@@ -187,7 +200,7 @@
"function": "self.show_configs",
"setCheckable": false,
"menu": "menu_edit",
- "seperator": true,
+ "seperator": false,
"toolbar": "toolbar_edit"
},
{
diff --git a/src/staticwordpress/share/icons/clear_all.svg b/src/staticwordpress/share/icons/clear_all.svg
new file mode 100644
index 0000000..e93e6a9
--- /dev/null
+++ b/src/staticwordpress/share/icons/clear_all.svg
@@ -0,0 +1,38 @@
+
+
From 44cfbc07c18f8f3ec62785d0fc4aef6a47fd2e48 Mon Sep 17 00:00:00 2001
From: Faisal Shahzad <84210709+seowings@users.noreply.github.com>
Date: Fri, 22 Dec 2023 22:54:49 +0100
Subject: [PATCH 6/6] Actions are turned off/on with Project Status
---
src/staticwordpress/gui/main.py | 41 ++++++++++++++++++------------
src/staticwordpress/share/gui.json | 8 +++---
2 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/src/staticwordpress/gui/main.py b/src/staticwordpress/gui/main.py
index 130fa3b..db84b0c 100644
--- a/src/staticwordpress/gui/main.py
+++ b/src/staticwordpress/gui/main.py
@@ -212,24 +212,26 @@ def inner(self):
def clean_output_directory(self):
"""Clean Output Directory"""
- msgBox = QMessageBox(parent=self)
- msgBox.setWindowTitle("Clean Output Folder Content")
- msgBox.setText(
+ message_box = QMessageBox(parent=self)
+ message_box.setWindowTitle("Clean Output Folder Content")
+ message_box.setText(
f"Existing content in Output folder will be delete?
{self._project.output}",
)
- pushbuttonOk = msgBox.addButton("OK", QMessageBox.YesRole)
- pushbuttonOk.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
+ pushbutton_ok = message_box.addButton("OK", QMessageBox.YesRole)
+ pushbutton_ok.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/ok.svg"))
- pushbuttonNo = msgBox.addButton("Cancel", QMessageBox.NoRole)
- pushbuttonNo.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
+ pushbutton_no = message_box.addButton("Cancel", QMessageBox.NoRole)
+ pushbutton_no.setIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/cancel.svg"))
- msgBox.setDefaultButton(pushbuttonOk)
+ message_box.setDefaultButton(pushbutton_ok)
- msgBox.setWindowIcon(QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg"))
- msgBox.setTextFormat(Qt.RichText)
- msgBox.exec_()
+ message_box.setWindowIcon(
+ QIcon(f"{SHARE_FOLDER_PATH}/icons/static-wordpress.svg")
+ )
+ message_box.setTextFormat(Qt.RichText)
+ message_box.exec_()
- if msgBox.clickedButton() == pushbuttonOk:
+ if message_box.clickedButton() == pushbutton_ok:
rm_dir_tree(self._project.output)
logging.info(
f"Content of output folder at {self._project.output} are deleted"
@@ -255,7 +257,7 @@ def extract_url_from_raw_text(self):
@is_new_project
@logging_decorator
- def clear_cache(self):
+ def clear_crawl_cache(self):
"""Clearing Crawl Cache"""
logging.info(f"Clearing Crawl Cache")
get_remote_content.cache_clear()
@@ -326,7 +328,7 @@ def help(self):
if not QDesktopServices.openUrl(url):
QMessageBox.warning(self, "Open Help URL", "Could not open Help URL")
- def startIPython(self):
+ def start_ipython_console(self):
""" """
if self.findChild(QAction, "action_ipython_widget").isChecked():
if self.ipython_console is None:
@@ -780,11 +782,14 @@ def update_statusbar(self, message_, percent_) -> None:
self.progress_bar.setFormat(message_)
def update_widgets(self) -> None:
+ # Show Menus
self.findChild(QMenu, "menu_github").setEnabled(self._project.has_github())
self.findChild(QMenu, "menu_wordpress").setEnabled(
self._project.is_open()
and (self._project.has_wordpress() or self._project.can_crawl())
)
+
+ # Show Toolbarss
self.findChild(QToolBar, "toolbar_github").setEnabled(
self._project.has_github()
)
@@ -792,7 +797,7 @@ def update_widgets(self) -> None:
self._project.has_wordpress() or self._project.can_crawl()
)
- # update menu items
+ # Show Menubar Icons
if self._project.src_type == SOURCE.ZIP:
self.findChild(QAction, "action_wordpress_webpages").setText(
"&Download Zip File"
@@ -808,10 +813,14 @@ def update_widgets(self) -> None:
self.findChild(QAction, "action_edit_expert_mode").isChecked()
)
+ for project_tool in [
+ "action_utilities_clean_output_folder",
+ ]:
+ self.findChild(QAction, project_tool).setVisible(self._project.is_open())
+
new_window_title = (
f"{self._project.name} - {CONFIGS['APPLICATION_NAME']} Version - {VERISON}"
)
-
self.setWindowTitle(new_window_title)
diff --git a/src/staticwordpress/share/gui.json b/src/staticwordpress/share/gui.json
index e2f1874..be9c037 100644
--- a/src/staticwordpress/share/gui.json
+++ b/src/staticwordpress/share/gui.json
@@ -374,13 +374,13 @@
},
{
"icon": "/icons/web-remove.svg",
- "name": "action_utilities_clear_cache",
+ "name": "action_utilities_clear_crawl_cache",
"visible": true,
- "text": "C&lear Cache",
+ "text": "C&lear Crawl Cache",
"shortcut": "Ctrl+F2",
"tooltip": "Clear Cache (Ctrl+F2)",
"seperator": false,
- "function": "self.clear_cache",
+ "function": "self.clear_crawl_cache",
"setCheckable": false,
"menu": "menu_tools",
"toolbar": ""
@@ -401,7 +401,7 @@
{
"icon": "/icons/delete-outline.svg",
"name": "action_utilities_clean_output_folder",
- "visible": true,
+ "visible": false,
"text": "Clean &Output Directory",
"shortcut": "Ctrl+F5",
"tooltip": "Clean output directory (Ctrl+F5)",