mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
[view] refactoring: URL regex
This commit is contained in:
3
bauh/commons/regex.py
Normal file
3
bauh/commons/regex.py
Normal file
@@ -0,0 +1,3 @@
|
||||
import re
|
||||
|
||||
RE_URL = re.compile(r"^https?://.+$")
|
||||
@@ -1,5 +1,3 @@
|
||||
import re
|
||||
import re
|
||||
import shutil
|
||||
import time
|
||||
import traceback
|
||||
@@ -17,6 +15,7 @@ from bauh.api.abstract.view import TabGroupComponent, MessageType
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.regex import RE_URL
|
||||
from bauh.commons.util import sanitize_command_input
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.core.settings import GenericSettingsManager
|
||||
@@ -25,8 +24,6 @@ from bauh.view.util import resource
|
||||
from bauh.view.util.resource import get_path
|
||||
from bauh.view.util.util import clean_app_files, restart_app
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
|
||||
|
||||
class GenericUpgradeRequirements(UpgradeRequirements):
|
||||
|
||||
@@ -163,7 +160,7 @@ class GenericSoftwareManager(SoftwareManager, SettingsController):
|
||||
self.logger.info(f"Search query: {norm_query}")
|
||||
|
||||
if norm_query:
|
||||
is_url = bool(RE_IS_URL.match(norm_query))
|
||||
is_url = bool(RE_URL.match(norm_query))
|
||||
disk_loader = self.disk_loader_factory.new()
|
||||
disk_loader.start()
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ from bauh.api.exception import NoInternetException
|
||||
from bauh.api.paths import LOGS_DIR
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.internet import InternetChecker
|
||||
from bauh.commons.regex import RE_URL
|
||||
from bauh.commons.system import ProcessHandler, SimpleProcess
|
||||
from bauh.commons.view_utils import get_human_size_str
|
||||
from bauh.view.core import timeshift
|
||||
@@ -1115,7 +1116,6 @@ class StartAsyncAction(QThread):
|
||||
class URLFileDownloader(QThread):
|
||||
|
||||
signal_downloaded = pyqtSignal(str, bytes, object)
|
||||
pattern_is_url: Pattern = re.compile(r"^https?://.+$")
|
||||
|
||||
def __init__(self, max_workers: int = 50, request_timeout: int = 30, inactivity_timeout: int = 3,
|
||||
max_downloads: int = -1, parent: Optional[QWidget] = None):
|
||||
@@ -1159,7 +1159,7 @@ class URLFileDownloader(QThread):
|
||||
final_url = url.strip() if url else None
|
||||
|
||||
if final_url:
|
||||
if self.pattern_is_url.match(final_url):
|
||||
if RE_URL.match(final_url):
|
||||
self._queue.put((final_url, id_))
|
||||
else:
|
||||
self.signal_downloaded.emit(final_url, None, id_)
|
||||
|
||||
Reference in New Issue
Block a user