Skip to content

Commit

Permalink
Fixed various linting errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
pint-sized committed May 13, 2024
1 parent ab8449e commit cbadc83
Show file tree
Hide file tree
Showing 28 changed files with 602 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .idea/TaskBridge.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

321 changes: 318 additions & 3 deletions .idea/inspectionProfiles/Project_Default.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Main_Code.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/scopes/Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions taskbridge/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This is the GUI package for TaskBridge.
- ``note.py`` - Contains the ``Note`` and ``Attachment`` classes that represent a note and its attachment respectively.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which contains
notes. Many sync operations are performed here.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which
contains notes. Many sync operations are performed here.
- ``notescript.py`` - Contains a list of AppleScript scripts for managing local notes.
"""
18 changes: 10 additions & 8 deletions taskbridge/gui/viewmodel/taskbridgeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TaskBridgeApp(QMainWindow):
- ``sync_notes`` - if '1', notes are synchronised and corresponding configuration is enabled.
- ``sync_reminders`` - if '1', reminders are synchronised and corresponding configuration is enabled.
- ``remote_notes_folder`` - path to the remote notes folder.
- ``remote_notes_folder`` - path to the remote note folder.
- ``associations`` - dictionary which contains list of notes to be synced bidirectionally in ``bi_directional`` and
others in ``local_to_remote`` and ``remote_to_local`` respectively.
- ``prune_reminders`` - if '1', completed reminders are deleted before synchronisation.
Expand Down Expand Up @@ -132,7 +132,7 @@ def load_settings() -> None:
conf_file = helpers.settings_folder() / 'conf.json'
if not os.path.exists(conf_file):
return
with open(helpers.settings_folder() / 'conf.json', 'r') as fp:
with open(helpers.settings_folder() / 'conf.json') as fp:
TaskBridgeApp.SETTINGS = json.load(fp)

@staticmethod
Expand Down Expand Up @@ -211,8 +211,8 @@ def save_settings(self, what: str | None = None, silent: bool = True) -> None:
"""
if (what == 'reminders' and not self.ui.cb_reminder_autoprune.isChecked) and not silent:
title = "Enable Completed Reminder Pruning?"
message = ("You have not selected to automatically prune completed reminders. This can significantly slow the "
"sync process. Do you want to enable automatic completed reminders pruning?")
message = ("You have not selected to automatically prune completed reminders. This can significantly slow "
"the sync process. Do you want to enable automatic completed reminders pruning?")
action = TaskBridgeApp._ask_question(title, message)
if action == QMessageBox.StandardButton.Yes:
self.ui.cb_reminder_autoprune.setChecked(True)
Expand Down Expand Up @@ -366,7 +366,8 @@ def eventFilter(self, widget: QWidget, event: QEvent | QKeyEvent) -> bool:
# Tabbing out of username with a NextCloud server automatically populates the reminder path
if (widget == self.ui.txt_reminder_username and self.ui.txt_reminder_username.text() and
self.ui.rb_server_nextcloud.isChecked()):
self.ui.txt_reminder_path.setText('/remote.php/dav/calendars/{}'.format(self.ui.txt_reminder_username.text()))
self.ui.txt_reminder_path.setText(
'/remote.php/dav/calendars/{}'.format(self.ui.txt_reminder_username.text()))

# Tabbing out of the password field triggers the login button being enabled
if event.type() == QEvent.Type.KeyRelease and widget == self.ui.txt_reminder_password:
Expand Down Expand Up @@ -587,7 +588,7 @@ def handle_note_checkbox(self, row, col) -> None:

def handle_folder_browse(self) -> None:
"""
Shows the folder chooser dialog for selecting the remote notes folder.
Shows the folder chooser dialog for selecting the remote note folder.
"""
remote_notes_folder = QFileDialog.getExistingDirectory(None, 'Select Remote Notes Folder')
TaskBridgeApp.SETTINGS['remote_notes_folder'] = remote_notes_folder
Expand Down Expand Up @@ -684,7 +685,8 @@ def display_reminders_table(self, container_list: List[ReminderContainer]) -> No
cbox = ReminderCheckbox(name, TaskBridgeApp.SETTINGS['reminder_sync'])
self.ui.tbl_reminders.insertRow(row)
self.ui.tbl_reminders.setItem(row, 0, QTableWidgetItem(name))
self.ui.tbl_reminders.setItem(row, 1, QTableWidgetItem(location_icon, None, QTableWidgetItem.ItemType.UserType))
self.ui.tbl_reminders.setItem(row, 1,
QTableWidgetItem(location_icon, None, QTableWidgetItem.ItemType.UserType))
self.ui.tbl_reminders.setItem(row, 2, cbox)

def apply_reminders_settings(self) -> None:
Expand Down Expand Up @@ -1009,7 +1011,7 @@ def sync_complete(self) -> None:
self.ui.btn_sync.setEnabled(True)
if TaskBridgeApp.SETTINGS['autosync'] == '1':
current_time = datetime.datetime.now()
next_sync = current_time + datetime.timedelta(0, TaskBridgeApp.SETTINGS['autosync_interval'])
next_sync = current_time + datetime.timedelta(seconds=TaskBridgeApp.SETTINGS['autosync_interval'])
self.ui.lbl_sync_status.setText('Synchronisation completed at {0}. Next Sync at {1}.'.format(
current_time.strftime('%H:%M:%S'),
next_sync.strftime('%H:%M:%S')
Expand Down
6 changes: 6 additions & 0 deletions taskbridge/gui/viewmodel/threadedtasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,14 @@ def run_continuously(interval=1) -> threading.Event():
cease_continuous_run = threading.Event()

class ScheduleThread(threading.Thread):
"""
Class to run continuous tasks
"""
@classmethod
def run(cls):
"""
Keep tasks running until cancelled
"""
while not cease_continuous_run.is_set():
schedule.run_pending()
time.sleep(interval)
Expand Down
4 changes: 2 additions & 2 deletions taskbridge/notes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This is the model package for the note-syncing part of TaskBridge. Here, you'll find the following:
- ``note.py`` - Contains the ``Note`` and ``Attachment`` classes that represent a note and its attachment respectively.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which contains
notes. Many sync operations are performed here.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which
contains notes. Many sync operations are performed here.
- ``notescript.py`` - Contains a list of AppleScript scripts for managing local notes.
"""
Expand Down
26 changes: 16 additions & 10 deletions taskbridge/notes/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def get_local_folders() -> tuple[bool, str]:
logging.critical(error)
return False, error
NoteController.LOCAL_NOTE_FOLDERS = data
debug_msg = 'Found local notes folders: {}'.format([str(folder) for folder in NoteController.LOCAL_NOTE_FOLDERS])
debug_msg = 'Found local notes folders: {}'.format(
[str(folder) for folder in NoteController.LOCAL_NOTE_FOLDERS])
logging.debug(debug_msg)
return True, debug_msg

Expand All @@ -65,7 +66,8 @@ def get_remote_folders() -> tuple[bool, str]:
logging.critical(error)
return False, error
NoteController.REMOTE_NOTE_FOLDERS = data
debug_msg = 'Found remote notes folders: {}'.format([str(folder) for folder in NoteController.REMOTE_NOTE_FOLDERS])
debug_msg = 'Found remote notes folders: {}'.format(
[str(folder) for folder in NoteController.REMOTE_NOTE_FOLDERS])
logging.debug(debug_msg)
return True, debug_msg

Expand All @@ -81,7 +83,8 @@ def sync_folder_deletions() -> tuple[bool, str]:
-data (:py:class:`str`) - error message on failure, or success message.
"""
success, data = NoteFolder.sync_folder_deletions(NoteController.LOCAL_NOTE_FOLDERS, NoteController.REMOTE_NOTE_FOLDERS)
success, data = NoteFolder.sync_folder_deletions(NoteController.LOCAL_NOTE_FOLDERS,
NoteController.REMOTE_NOTE_FOLDERS)
if not success:
error = 'Failed to sync folder deletions {}'.format(data)
logging.critical(error)
Expand All @@ -99,8 +102,8 @@ def associate_folders() -> tuple[bool, str] | tuple[bool, List[NoteFolder]]:
-success (:py:class:`bool`) - true if the folders are successfully associated.
-data (:py:class:`str` | :py:class:`List[NoteFolder]`) - error message on failure, or list of associations on
success.
-data (:py:class:`str` | :py:class:`List[NoteFolder]`) - error message on failure, or list of associations
on success.
"""
NoteFolder.reset_list()
Expand Down Expand Up @@ -134,8 +137,9 @@ def sync_deleted_notes() -> tuple[bool, str]:
error = 'Failed to synchronise note deletions {}'.format(data)
logging.critical(error)
return False, error
debug_msg = ("Deleted notes synchronisation:: Deleted Local: {} | Deleted Remote: {} | Remote Not Found: {} | Local "
"Not Found: {}").format(
debug_msg = (
"Deleted notes synchronisation:: Deleted Local: {} | Deleted Remote: {} | Remote Not Found: {} | Local "
"Not Found: {}").format(
','.join(data['local_deleted'] if 'local_deleted' in data else ['No local notes deleted']),
','.join(data['remote_deleted'] if 'remote_deleted' in data else ['No remote notes deleted']),
','.join(data['remote_not_found'] if 'remote_not_found' in data else ['All remote notes found']),
Expand All @@ -160,7 +164,8 @@ def sync_notes() -> tuple[bool, str] | tuple[bool, dict]:
-success (:py:class:`bool`) - true if notes are successfully synchronised.
-data (:py:class:`str` | :py:class:`dict`) - error message on failure, or :py:class:`dict` with results as above.
-data (:py:class:`str` | :py:class:`dict`) - error message on failure, or :py:class:`dict` with results as
above.
"""
data = None
Expand All @@ -171,8 +176,9 @@ def sync_notes() -> tuple[bool, str] | tuple[bool, dict]:
logging.critical(error)
return False, error

debug_msg = ("Notes synchronisation:: Remote Added: {} | Remote Updated: {} | Local Added: {} | Local Updated: {"
"}").format(
debug_msg = (
"Notes synchronisation:: Remote Added: {} | Remote Updated: {} | Local Added: {} | Local Updated: {"
"}").format(
','.join(data['remote_added'] if 'remote_added' in data else ['No remote notes added']),
','.join(data['remote_updated'] if 'remote_updated' in data else ['No remote notes updated']),
','.join(data['local_added'] if 'local_added' in data else ['No local notes added']),
Expand Down
4 changes: 2 additions & 2 deletions taskbridge/notes/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This is the model of the note-syncing part of TaskBridge. Here, you'll find the following:
- ``note.py`` - Contains the ``Note`` and ``Attachment`` classes that represent a note and its attachment respectively.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which contains
notes. Many sync operations are performed here.
- ``notefolder.py`` - Contains the ``NoteFolder`` class which represents a folder (either local or remote) which
contains notes. Many sync operations are performed here.
- ``notescript.py`` - Contains a list of AppleScript scripts for managing local notes.
"""

Expand Down
10 changes: 6 additions & 4 deletions taskbridge/notes/model/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_from_local(staged_content: str, staged_location: Path) -> Note:
Creates a Note instance from a staged file exported locally.
:param staged_content: the content of the staged file.
:param staged_location: the location of the staged file, used for adding attachments to a ``/.attachments`` directory.
:param staged_location: the location of the staged file, used for adding attachments to a ``/.attachments`` dir.
:return: a Note instance representing the content of the staged file.
"""
staged_lines = staged_content.splitlines()
Expand Down Expand Up @@ -179,7 +179,8 @@ def markdown_to_html(remote_lines: List[str], attachments: List[Attachment]) ->
"""
html = ""
remote_lines.pop(0) # First line is note name
image_list = [attachment for attachment in attachments if attachment and attachment.file_type == Attachment.TYPE_IMAGE]
image_list = [attachment for attachment in attachments if
attachment and attachment.file_type == Attachment.TYPE_IMAGE]
image_index = 0
for idx in range(len(remote_lines)):
line = remote_lines[idx]
Expand Down Expand Up @@ -303,7 +304,8 @@ class Attachment:
_SUPPORTED_IMAGE_TYPES = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.apng',
'.avif', '.bmp', '.ico', '.tiff', '.svg']

def __init__(self, file_type: int = '', file_name: str = '', url: str = '', b64_data: str | None = None, uuid: str = ''):
def __init__(self, file_type: int = '', file_name: str = '', url: str = '', b64_data: str | None = None,
uuid: str = ''):
"""
Creates a new instance of Attachment.
Expand Down Expand Up @@ -455,7 +457,7 @@ def _get_remote_image(url: str) -> str | None:
"""
try:
with open(url, "rb") as fp:
encoded_string = base64.b64encode(fp.read()).decode('utf-8')
encoded_string = base64.b64encode(fp.read()).decode()
return encoded_string if encoded_string != '' else None
except FileNotFoundError:
return None
Expand Down
8 changes: 6 additions & 2 deletions taskbridge/notes/model/notefolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ def sync_remote_deletions(discovered_remote: List[RemoteNoteFolder]) -> tuple[bo
return True, "Remote folder deletions synchronised."

@staticmethod
def sync_folder_deletions(discovered_local: List[LocalNoteFolder], discovered_remote: List[RemoteNoteFolder]) -> tuple[
bool, str]:
def sync_folder_deletions(discovered_local: List[LocalNoteFolder], discovered_remote: List[RemoteNoteFolder]) -> \
tuple[
bool, str]:
"""
Synchronises deletions to folders.
Expand Down Expand Up @@ -880,6 +881,9 @@ def sync_note_deletions(remote_folder: Path) -> tuple[bool, str] | tuple[bool, d

@staticmethod
def reset_list():
"""
Reset the folder list to empty.
"""
NoteFolder.FOLDER_LIST.clear()


Expand Down
4 changes: 4 additions & 0 deletions taskbridge/notes/model/notescript.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
AppleScript for Apple Notes.
"""

#: Get the list of notes from a folder and export as a staged file.
get_notes_script = """on run argv
set folder_name to item 1 of argv
Expand Down
3 changes: 2 additions & 1 deletion taskbridge/reminders/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import List

import caldav
from caldav.lib.error import AuthorizationError


from taskbridge import helpers
from taskbridge.reminders.model.remindercontainer import ReminderContainer
Expand Down Expand Up @@ -55,6 +55,7 @@ def fetch_local_reminders() -> tuple[bool, str]:
logging.debug(debug_msg)
return True, debug_msg

# noinspection PyUnresolvedReferences
@staticmethod
def connect_caldav() -> tuple[bool, str]:
"""
Expand Down
60 changes: 43 additions & 17 deletions taskbridge/reminders/model/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def upsert_local(self, container: model.ReminderContainer) -> tuple[bool, str]:
-success (:py:class:`bool`) - true if the reminder is successfully upserted.
-data (:py:class:`str`) - error message on failure, or note's UUID.
-data (:py:class:`str`) - error message on failure, or reminder's UUID.
"""
add_reminder_script = reminderscript.add_reminder_script
Expand All @@ -158,6 +158,46 @@ def upsert_local(self, container: model.ReminderContainer) -> tuple[bool, str]:
return True, stdout.strip()
return False, "Failed to upsert local reminder {0}: {1}".format(self.name, stderr)

def __get_tasks_in_caldav(self, container: model.ReminderContainer) -> caldav.CalendarObjectResource | None:
"""
Fetch an existing remote task in CalDav
:param container: The parameter to search
:return: the task in CalDAV matching this tasks UUID/name, or None.
"""

remote = None
tasks_in_caldav = container.remote_calendar.cal_obj.search(todo=True, uid=self.uuid)
if len(tasks_in_caldav) == 0:
tasks_in_caldav = container.remote_calendar.cal_obj.search(todo=True, summary=self.name)

if len(tasks_in_caldav) > 0:
remote = tasks_in_caldav[0]
return remote

def __get_task_due_date(self) -> tuple[bool, str]:
"""
Get the due date for this task in string format
:returns:
-success (:py:class:`bool`) - true if the due date is successfully retrieved.
-data (:py:class:`str`) - error message on failure, or task due date.
"""
try:
if not self.due_date:
due_date = None
elif self.due_date.strftime("%H:%M:%S") == "00:00:00":
due_date = DateUtil.convert('', self.due_date, DateUtil.CALDAV_DATE)
else:
due_date = DateUtil.convert('', self.due_date, DateUtil.CALDAV_DATETIME)
except AttributeError:
return False, "Invalid due date."
return True, due_date

def upsert_remote(self, container: model.ReminderContainer) -> tuple[bool, str]:
"""
Creates or updates a remote reminder.
Expand All @@ -171,13 +211,7 @@ def upsert_remote(self, container: model.ReminderContainer) -> tuple[bool, str]:
-data (:py:class:`str`) - error message on failure or success message.
"""
remote = None
tasks_in_caldav = container.remote_calendar.cal_obj.search(todo=True, uid=self.uuid)
if len(tasks_in_caldav) == 0:
tasks_in_caldav = container.remote_calendar.cal_obj.search(todo=True, summary=self.name)

if len(tasks_in_caldav) > 0:
remote = tasks_in_caldav[0]
remote = self.__get_tasks_in_caldav(container)

if remote is None:
# Add new remote task
Expand All @@ -189,15 +223,7 @@ def upsert_remote(self, container: model.ReminderContainer) -> tuple[bool, str]:
return True, 'Remote reminder added: {}'.format(self.name)
else:
# Update existing remote task
try:
if not self.due_date:
due_date = None
elif self.due_date.strftime("%H:%M:%S") == "00:00:00":
due_date = DateUtil.convert('', self.due_date, DateUtil.CALDAV_DATE)
else:
due_date = DateUtil.convert('', self.due_date, DateUtil.CALDAV_DATETIME)
except AttributeError:
return False, "Invalid due date."
due_date = self.__get_task_due_date()

if not self.remind_me_date:
alarm_trigger = None
Expand Down
Loading

0 comments on commit cbadc83

Please sign in to comment.