diff --git a/.gitignore b/.gitignore
index 7dca336..fbf7309 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,7 +25,7 @@ DEV
cwa.db
# Dev files
-dev_changelog.md
+changelogs/
*.txz
# Distribution / packaging
diff --git a/root/app/calibre-web/cps/cwa_functions.py b/root/app/calibre-web/cps/cwa_functions.py
index cb3d986..d3295a5 100644
--- a/root/app/calibre-web/cps/cwa_functions.py
+++ b/root/app/calibre-web/cps/cwa_functions.py
@@ -90,12 +90,13 @@ def set_cwa_settings():
"auto_convert"]
string_settings = ["auto_convert_target_format"]
for format in ignorable_formats:
- string_settings.append(f"ignore_{format}")
+ string_settings.append(f"ignore_import_{format}")
+ string_settings.append(f"ignore_convert_{format}")
if request.method == 'POST':
cwa_db = CWA_DB()
if request.form['submit_button'] == "Submit":
- result = {"cwa_ignored_formats":[]}
+ result = {"auto_convert_ignored_formats":[], "auto_import_ignored_formats":[]}
# set boolean_settings
for setting in boolean_settings:
value = request.form.get(setting)
@@ -107,21 +108,33 @@ def set_cwa_settings():
# set string settings
for setting in string_settings:
value = request.form.get(setting)
- if setting[:7] == "ignore_":
+ if setting[:14] == "ignore_convert":
if value == None:
continue
else:
- result["cwa_ignored_formats"].append(value)
+ result["auto_convert_ignored_formats"].append(value)
continue
- elif setting == "auto_convert_target_format" and value == None:
- value = cwa_db.cwa_settings['auto_convert_target_format']
+ elif setting[:13] == "ignore_import":
+ if value == None:
+ continue
+ else:
+ result["auto_import_ignored_formats"].append(value)
+ continue
+ elif setting == "auto_import_target_format" and value == None:
+ value = cwa_db.cwa_settings['auto_import_target_format']
result |= {setting:value}
+
+ # Prevent ignoring of target format
+ if result['auto_convert_target_format'] in result['auto_convert_ignored_formats']:
+ result['auto_convert_ignored_formats'].remove(result['auto_convert_target_format'])
+ if result['auto_convert_target_format'] in result['auto_import_ignored_formats']:
+ result['auto_import_ignored_formats'].remove(result['auto_convert_target_format'])
# DEBUGGING
with open("/config/post_request" ,"w") as f:
for key in result.keys():
- if key == "cwa_ignored_formats":
+ if key == "auto_convert_ignored_formats" or key == "auto_import_ignored_formats":
f.write(f"{key} - {', '.join(result[key])}\n")
else:
f.write(f"{key} - {result[key]}\n")
diff --git a/root/app/calibre-web/cps/templates/cwa_settings.html b/root/app/calibre-web/cps/templates/cwa_settings.html
index 64ef06b..be4b287 100644
--- a/root/app/calibre-web/cps/templates/cwa_settings.html
+++ b/root/app/calibre-web/cps/templates/cwa_settings.html
@@ -76,14 +76,50 @@
CWA Auto-Convert - Ignored Formats
font-size: inherit;
line-height: normal;
padding-left: 10px;
- max-width: 90rem;">The formats selected here will be ignored by CWA's auto-conversion feature when it's active
+ max-width: 90rem;">The formats selected here will be ignored by CWA's Auto-Conversion feature when it's active
{% for format in ignorable_formats -%}
-
+
+
CWA Auto-Import - Ignored Formats
+
The formats selected here will be ignored by CWA's Auto-Import feature
+
+ {% for format in ignorable_formats -%}
+
+ {% if format in cwa_settings['auto_import_ignored_formats'] %}
+ {% if format == cwa_settings['auto_convert_target_format'] %}
+
+ {% else %}
+
+ {% endif %}
+ {% else %}
+ {% if format == cwa_settings['auto_convert_target_format'] %}
+
+ {% else %}
+
+ {% endif %}
{% endif %}
{{ format }}
diff --git a/scripts/cwa_db.py b/scripts/cwa_db.py
index a6d19e3..b908e0a 100644
--- a/scripts/cwa_db.py
+++ b/scripts/cwa_db.py
@@ -26,7 +26,8 @@ def __init__(self, verbose=False):
"cwa_update_notifications": 1,
"auto_convert": 1,
"auto_convert_target_format": "epub",
- "cwa_ignored_formats":""}
+ "auto_convert_ignored_formats":"",
+ "auto_import_ignored_formats":""}
self.tables, self.schema = self.make_tables()
self.ensure_schema_match()
@@ -36,6 +37,7 @@ def __init__(self, verbose=False):
self.cwa_settings = self.get_cwa_settings()
+
def temp_disable_split_library(self): # Temporary measure to disable split library functionality until it can be supported in V2.2.0
con = sqlite3.connect("/config/app.db")
cur = con.cursor()
@@ -63,6 +65,7 @@ def connect_to_db(self) -> tuple[sqlite3.Connection, sqlite3.Cursor] | None:
print("[cwa-db]: Connection with the CWA Enforcement DB Successful!")
return con, cur
+
def make_tables(self) -> None:
"""Creates the tables for the CWA DB if they don't already exist"""
schema = []
@@ -77,9 +80,11 @@ def make_tables(self) -> None:
tables[x] = tables[x] + ";"
for table in tables:
self.cur.execute(table)
+ self.con.commit()
return tables, schema
+
def ensure_schema_match(self) -> None:
self.cur.execute("SELECT * FROM cwa_settings")
cwa_setting_names = [header[0] for header in self.cur.description]
@@ -106,6 +111,7 @@ def ensure_schema_match(self) -> None:
self.con.commit()
print(f"[cwa_db] Deprecated setting found from previous version of CWA, deleting setting '{setting}' from cwa.db...")
+
def set_default_settings(self, force=False) -> None:
"""Sets default settings for new tables and keeps track if the user is using the default settings or not.\n\n
If the argument 'force' is set to True, the function instead sets all settings to their default values"""
@@ -113,39 +119,44 @@ def set_default_settings(self, force=False) -> None:
for setting in self.cwa_default_settings:
if type(self.cwa_default_settings[setting]) == int:
self.cur.execute(f"UPDATE cwa_settings SET {setting}={self.cwa_default_settings[setting]};")
+ self.con.commit()
else:
self.cur.execute(f'UPDATE cwa_settings SET {setting}="{self.cwa_default_settings[setting]}";')
-
- print("[cwa-db] CWA Default Settings successfully applied.")
-
- current_settings = self.cur.execute("SELECT * FROM cwa_settings")
- setting_names = [header[0] for header in self.cur.description]
- cwa_settings = [dict(zip(setting_names,row)) for row in self.cur.fetchall()][0]
-
- if current_settings == []:
- print("[cwa-db]: New DB detected, applying default CWA settings...")
+ self.con.commit()
+ print("[cwa-db] CWA Default Settings successfully applied!")
+ return
+ try:
+ self.cur.execute("SELECT * FROM cwa_settings")
+ setting_names = [header[0] for header in self.cur.description]
+ current_settings = [dict(zip(setting_names,row)) for row in self.cur.fetchall()][0]
+
+ except IndexError:
+ print("[cwa-db]: No existing CWA settings detected, applying default CWA settings...")
for setting in self.cwa_default_settings:
if type(self.cwa_default_settings[setting]) == int:
self.cur.execute(f"UPDATE cwa_settings SET {setting}={self.cwa_default_settings[setting]};")
else:
self.cur.execute(f'UPDATE cwa_settings SET {setting}="{self.cwa_default_settings[setting]}";')
- else:
- default_check = True
- for setting in setting_names:
- if setting == "default_settings":
- continue
- elif cwa_settings[setting] != self.cwa_default_settings[setting]:
- default_check = False
- self.cur.execute("UPDATE cwa_settings SET default_settings=0 WHERE default_settings=1;")
- self.con.commit()
- break
-
- if default_check:
- self.cur.execute("UPDATE cwa_settings SET default_settings=1 WHERE default_settings=0;")
self.con.commit()
+ print("[cwa-db] CWA Default Settings successfully applied!")
+ return
+
+ default_check = True
+ for setting in setting_names:
+ if setting == "default_settings":
+ continue
+ elif current_settings[setting] != self.cwa_default_settings[setting]:
+ default_check = False
+ self.cur.execute("UPDATE cwa_settings SET default_settings=0 WHERE default_settings=1;")
+ self.con.commit()
+ break
+ if default_check:
+ self.cur.execute("UPDATE cwa_settings SET default_settings=1 WHERE default_settings=0;")
+ self.con.commit()
+
+ if self.verbose:
+ print("[cwa-db] CWA Settings loaded successfully")
- if self.verbose:
- print("[cwa-db] CWA Settings loaded successfully")
def get_cwa_settings(self) -> dict[str:bool|str]:
"""Gets the current cwa_settings values from the table of the same name in cwa.db and returns them as a dict"""
@@ -156,14 +167,16 @@ def get_cwa_settings(self) -> dict[str:bool|str]:
for header in headers:
if type(cwa_settings[header]) == int:
cwa_settings[header] = bool(cwa_settings[header])
- cwa_settings['cwa_ignored_formats'] = cwa_settings['cwa_ignored_formats'].split(',')
+ cwa_settings['auto_convert_ignored_formats'] = cwa_settings['auto_convert_ignored_formats'].split(',')
+ cwa_settings['auto_import_ignored_formats'] = cwa_settings['auto_import_ignored_formats'].split(',')
return cwa_settings
+
def update_cwa_settings(self, result) -> None:
"""Sets settings using POST request from set_cwa_settings()"""
for setting in result.keys():
- if setting == "cwa_ignored_formats":
+ if setting == "auto_convert_ignored_formats" or setting == "auto_import_ignored_formats":
result[setting] = ','.join(result[setting])
if type(result[setting]) == int:
@@ -173,21 +186,25 @@ def update_cwa_settings(self, result) -> None:
self.con.commit()
self.set_default_settings()
+
def enforce_add_entry_from_log(self, log_info: dict):
"""Adds an entry to the db from a change log file"""
self.cur.execute("INSERT INTO cwa_enforcement(timestamp, book_id, book_title, author, epub_path, trigger_type) VALUES (?, ?, ?, ?, ?, ?);", (log_info['timestamp'], log_info['book_id'], log_info['book_title'], log_info['author_name'], log_info['epub_path'], 'auto -log'))
self.con.commit()
+
def enforce_add_entry_from_dir(self, book_info: dict):
"""Adds an entry to the db when cover-enforcer is ran with a directory"""
self.cur.execute("INSERT INTO cwa_enforcement(timestamp, book_id, book_title, author, epub_path, trigger_type) VALUES (?, ?, ?, ?, ?, ?);", (book_info['timestamp'], book_info['book_id'], book_info['book_title'], book_info['author_name'], book_info['epub_path'], 'manual -dir'))
self.con.commit()
+
def enforce_add_entry_from_all(self, book_info: dict):
"""Adds an entry to the db when cover-enforcer is ran with the -all flag"""
self.cur.execute("INSERT INTO cwa_enforcement(timestamp, book_id, book_title, author, epub_path, trigger_type) VALUES (?, ?, ?, ?, ?, ?);", (book_info['timestamp'], book_info['book_id'], book_info['book_title'], book_info['author_name'], book_info['epub_path'], 'manual -all'))
self.con.commit()
+
def enforce_show(self, paths: bool, verbose: bool, web_ui=False):
results_no_path = self.cur.execute("SELECT timestamp, book_id, book_title, author, trigger_type FROM cwa_enforcement ORDER BY timestamp DESC;").fetchall()
results_with_path = self.cur.execute("SELECT timestamp, book_id, epub_path FROM cwa_enforcement ORDER BY timestamp DESC;").fetchall()
@@ -246,6 +263,7 @@ def get_import_history(self, verbose: bool):
break
return newest_ten, headers
+
def get_conversion_history(self, verbose: bool):
headers = ["Timestamp", "Filename", "Original Format", "Original Backed Up?"]
results = self.cur.execute("SELECT timestamp, filename, original_format, original_backed_up FROM cwa_conversions ORDER BY timestamp DESC;").fetchall()
@@ -262,11 +280,13 @@ def get_conversion_history(self, verbose: bool):
break
return newest_ten, headers
+
def import_add_entry(self, filename, original_backed_up):
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.cur.execute("INSERT INTO cwa_import(timestamp, filename, original_backed_up) VALUES (?, ?, ?);", (timestamp, filename, original_backed_up))
self.con.commit()
-
+
+
def conversion_add_entry(self, filename, original_format, original_backed_up):
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.cur.execute("INSERT INTO cwa_conversions(timestamp, filename, original_format, original_backed_up) VALUES (?, ?, ?, ?);", (timestamp, filename, original_format, original_backed_up))
diff --git a/scripts/cwa_schema.sql b/scripts/cwa_schema.sql
index c64c23d..6a4b093 100644
--- a/scripts/cwa_schema.sql
+++ b/scripts/cwa_schema.sql
@@ -28,5 +28,6 @@ CREATE TABLE IF NOT EXISTS cwa_settings(
cwa_update_notifications SMALLINT DEFAULT 1 NOT NULL,
auto_convert SMALLINT DEFAULT 1 NOT NULL,
auto_convert_target_format TEXT DEFAULT "epub" NOT NULL,
- cwa_ignored_formats TEXT DEFAULT "" NOT NULL
+ auto_convert_ignored_formats TEXT DEFAULT "" NOT NULL,
+ auto_import_ignored_formats TEXT DEFAULT "" NOT NULL
);
\ No newline at end of file