-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface and app data folder detection
- Loading branch information
Showing
12 changed files
with
286 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>500</width> | ||
<height>200</height> | ||
</rect> | ||
</property> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="0" column="0" colspan="2"> | ||
<widget class="QGroupBox" name="groupBox"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="title"> | ||
<string/> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout_2"> | ||
<item row="0" column="0"> | ||
<widget class="QRadioButton" name="data_folder_checkbox"> | ||
<property name="toolTip"> | ||
<string>AnkiApp data folder</string> | ||
</property> | ||
<property name="text"> | ||
<string>Data folder</string> | ||
</property> | ||
<property name="checked"> | ||
<bool>true</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLineEdit" name="data_folder"/> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="choose_data_folder"> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="database_file_checkbox"> | ||
<property name="toolTip"> | ||
<string>AnkiApp's SQLite database file. If you only have access to a single database file, you can use this, otherwise it's recommended to specify the data folder instead to allow the add-on to import more data</string> | ||
</property> | ||
<property name="text"> | ||
<string>Database file</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
<item> | ||
<widget class="QLineEdit" name="database_file"> | ||
<property name="enabled"> | ||
<bool>false</bool> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="choose_database_file"> | ||
<property name="enabled"> | ||
<bool>false</bool> | ||
</property> | ||
<property name="text"> | ||
<string>...</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QPushButton" name="import_button"> | ||
<property name="text"> | ||
<string>Import</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QCheckBox" name="remote_media"> | ||
<property name="text"> | ||
<string>Try to download missing media from AnkiApp servers</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ankiutils @ git+https://github.com/abdnh/ankiutils@c699f193f35dcd5d8995ddc78b22d03642927018 | ||
ankiutils @ git+https://github.com/abdnh/ankiutils@a287daa1d0f84b08c623165d4ccdd4637e2d714c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
ankiutils @ git+https://github.com/abdnh/ankiutils@c699f193f35dcd5d8995ddc78b22d03642927018 | ||
ankiutils @ git+https://github.com/abdnh/ankiutils@a287daa1d0f84b08c623165d4ccdd4637e2d714c | ||
# via -r requirements/bundle.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import functools | ||
import os | ||
import sqlite3 | ||
from pathlib import Path | ||
from typing import List, Optional, Union | ||
|
||
try: | ||
from anki.utils import is_mac, is_win | ||
except ImportError: | ||
from anki.utils import isMac as is_mac # type: ignore | ||
from anki.utils import isWin as is_win # type: ignore | ||
|
||
|
||
def get_ankiapp_data_folder() -> Optional[str]: | ||
path = None | ||
if is_win: | ||
from aqt.winpaths import get_appdata | ||
|
||
path = os.path.join(get_appdata(), "AnkiApp") | ||
elif is_mac: | ||
path = os.path.expanduser("~/Library/Application Support/AnkiApp") | ||
if not os.path.exists(path): | ||
# App store verison | ||
path = os.path.expanduser( | ||
"~/Library/Containers/com.ankiapp.client/Data/Documents/ankiapp" | ||
) | ||
|
||
if path is not None and os.path.exists(path): | ||
return path | ||
return None | ||
|
||
|
||
# pylint: disable=too-few-public-methods | ||
class AnkiAppData: | ||
def __init__(self, path: Union[Path, str]): | ||
self.path = Path(path) | ||
|
||
@functools.cached_property | ||
def sqlite_dbs(self) -> List[Path]: | ||
databases_path = self.path / "databases" | ||
databases_db_path = databases_path / "Databases.db" | ||
if not databases_db_path.exists(): | ||
return [] | ||
with sqlite3.connect(databases_db_path) as conn: | ||
db_paths = [] | ||
for row in conn.execute("select origin from Databases"): | ||
# Use the first file found in the database subfolder | ||
# TODO: inevstigate whether this can cause problems | ||
db_path = next((databases_path / str(row[0])).iterdir(), None) | ||
if db_path: | ||
db_paths.append(db_path) | ||
return db_paths | ||
|
||
|
||
if __name__ == "__main__": | ||
appdata = AnkiAppData(get_ankiapp_data_folder()) | ||
print(appdata.sqlite_dbs) |
Empty file.
Oops, something went wrong.