Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OD-1731: Misc. cleanup #37

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion efiction/chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def load_chapter_text_into_db(self, chapter_paths: List[dict]):
# check if encoding is valid
''.encode(encoding_text)
encoding = encoding_text
except:
except LookupError:
print(f"{encoding_text} is not a valid encoding, try again")
for old_chapter in old_chapters:
chapid = old_chapter['chapid']
Expand Down
9 changes: 4 additions & 5 deletions efiction/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
from configparser import ConfigParser
from logging import Logger
Expand Down Expand Up @@ -152,7 +151,7 @@ def _convert_story_tags(self, old_story):
def _convert_tags_join(self, new_story, tags, sql=None):
# Support using non-default sql connection for multithreaded workloads
sql = self.sql if sql is None else sql
full_query = f"INSERT INTO item_tags (item_id, item_type, tag_id) VALUES "
full_query = "INSERT INTO item_tags (item_id, item_type, tag_id) VALUES "
tag_query = []
for tag_list in tags.values():
for tag in tag_list:
Expand All @@ -176,7 +175,7 @@ def fetch_coauthors(self, new_story, sql=None):
# get a dict of coauthor IDs for the story
try:
authors = sql.execute_and_fetchall(self.working_original, full_query)
except Exception as e:
except Exception:
authors = None
self.logger.info("No coauthors table...")
# We only try to operate on this result if it is not None
Expand Down Expand Up @@ -219,12 +218,12 @@ def story_processor(old_story):
"""
sql.execute(self.working_open_doors, query)

self.logger.debug(f" tags...")
self.logger.debug(" tags...")
tags = self._convert_story_tags(old_story)
# pass the new sql to be used instead of the main one
self._convert_tags_join(new_story, tags, sql)

self.logger.debug(f" authors...")
self.logger.debug(" authors...")
self._convert_author_join(new_story, old_story['uid'], sql)
# Find if there are any coauthors for the work
coauthors = self.fetch_coauthors(new_story, sql)
Expand Down
1 change: 0 additions & 1 deletion efiction/original.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Step 01
"""
import os
from configparser import ConfigParser
from logging import Logger

Expand Down
1 change: 0 additions & 1 deletion efiction/simplified.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
from configparser import ConfigParser
from logging import Logger
Expand Down
4 changes: 2 additions & 2 deletions efiction/tag_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check_for_nonstandard_tag_tables(self) -> bool:
if tag_table_name == 'rating':
# Only one rating per story, so story rating should be single number
# that exactly matches rating id
query = f"SELECT count(*) as cnt FROM stories WHERE rid NOT IN (SELECT rid FROM ratings);"
query = "SELECT count(*) as cnt FROM stories WHERE rid NOT IN (SELECT rid FROM ratings);"
count: List[Dict[str, int]] = self.sql.execute_and_fetchall(self.working_original, query)
tag_tables['rating'] = bool(count and count[0]['cnt'] > 0)
else:
Expand All @@ -53,7 +53,7 @@ def check_for_nonstandard_tag_tables(self) -> bool:
tags = list(map(lambda story_tags: story_tags[id_name].replace(',', ''), tags))
int(''.join(tags))
tag_tables[tag_table_name] = False
except Exception as e:
except Exception:
# Non-integer in identifier
tag_tables[tag_table_name] = True
except Exception as e:
Expand Down
4 changes: 1 addition & 3 deletions efiction/tests/test_chapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@


from efiction.chapters import EFictionChapters
from opendoors.big_insert import BigInsert
from opendoors.config import ArchiveConfig
from opendoors.mysql import SqlDb
from opendoors.utils import get_full_path, normalize, remove_output_files
from opendoors.utils import get_full_path, normalize


def get_data():
Expand Down
6 changes: 1 addition & 5 deletions efiction/tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import datetime
from unittest import TestCase
from unittest.mock import MagicMock

from efiction.metadata import EFictionMetadata
from efiction.tests.test_utils import load_fixtures, create_efiction_converter
from opendoors.config import ArchiveConfig
from opendoors.mysql import SqlDb
from opendoors.utils import get_full_path, remove_output_files
from opendoors.utils import remove_output_files


class TestEFictionConverter(TestCase):
Expand Down
3 changes: 0 additions & 3 deletions efiction/tests/test_original.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import glob
import os
import re
from unittest import TestCase
from unittest.mock import MagicMock, patch

Expand Down
2 changes: 1 addition & 1 deletion opendoors/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def read_table_to_dict(self, database: str, tablename: str):
try:
cursor.execute(f"SELECT * FROM {database}.{tablename};")
return cursor.fetchall()
except Exception as e:
except Exception:
self.logger.info(f"No table {tablename} in {database}...")
return []

Expand Down
4 changes: 2 additions & 2 deletions opendoors/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def continue_from_last(config: ConfigParser, logger: Logger, sql: SqlDb, steps:
next_step = config['Processing']['next_step'] = step.next_step
update_done_steps(config, done_steps, step_to_run)
else:
restart_yn = input(f"All steps have been completed for this archive. Do you want to\n"
restart_yn = input("All steps have been completed for this archive. Do you want to\n"
"1. Restart from step 1\n"
"2. Exit (default - press Enter)\n>> ")
if restart_yn == "1":
next_step = "01"
else:
run_next = False
except Exception as e:
except Exception:
logger.error(traceback.format_exc())


Expand Down
5 changes: 2 additions & 3 deletions opendoors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import re
import shutil
import sys
from typing import Mapping
from pathlib import Path

Expand Down Expand Up @@ -136,7 +135,7 @@ def remove_output_files(path: str):
shutil.rmtree(file)
else:
os.remove(file)
except PermissionError as pe:
except PermissionError:
# We don't necessarily care that much
continue

Expand All @@ -161,4 +160,4 @@ def get_prefixed_path(step: str, path: str, filename: str=""):
if filename:
return os.path.join(path, f"{prefix}-{filename}")
else:
return os.path.join(path, prefix)
return os.path.join(path, prefix)
2 changes: 1 addition & 1 deletion steps/tests/test_step_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def tearDown(self) -> None:
shutil.rmtree(file)
else:
os.remove(file)
except PermissionError as pe:
except PermissionError:
# We don't necessarily care that much
continue

Expand Down
5 changes: 2 additions & 3 deletions steps/tests/test_step_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import shutil
from pathlib import Path
from unittest import TestCase
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

from opendoors.config import ArchiveConfig
from opendoors.step_base import StepInfo
from steps.step_01 import Step01
from steps.step_02 import Step02

test_logger = MagicMock()
Expand All @@ -26,7 +25,7 @@ def tearDown(self) -> None:
shutil.rmtree(file)
else:
os.remove(file)
except PermissionError as pe:
except PermissionError:
# We don't necessarily care that much
continue

Expand Down
Loading