Skip to content

Commit

Permalink
Merge pull request #27 from bbtufty/rommover-logging
Browse files Browse the repository at this point in the history
Improved ROMMover logging
  • Loading branch information
bbtufty authored Aug 27, 2024
2 parents 6e79574 + c70986f commit af1431b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
23 changes: 14 additions & 9 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ DATParser

- Logging tidied up to make more readable

ROMChooser
~~~~~~~~~~

- Logging significantly improved to make it clear which ROMs have been excluded and why
- Fixed crash when a revision is just labelled "rev"
- Fixed bug where a version like "v.0.1" would cause a crash
- Fixed bug where letter at end of version could cause a crash
- Fixed bug where lettered version could cause a crash
- Fixed bugs with flagging and removing various editions

ROMDownloader
~~~~~~~~~

- Logging tidied up to make more readable

ROMSearch
ROMMover
~~~~~~~~~

- Logging tidied up to make more readable
Expand All @@ -32,15 +42,10 @@ ROMParser

- ROMParser will now correctly parse multiple regions/languages

ROMChooser
~~~~~~~~~~
ROMSearch
~~~~~~~~~

- Logging significantly improved to make it clear which ROMs have been excluded and why
- Fixed crash when a revision is just labelled "rev"
- Fixed bug where a version like "v.0.1" would cause a crash
- Fixed bug where letter at end of version could cause a crash
- Fixed bug where lettered version could cause a crash
- Fixed bugs with flagging and removing various editions
- Logging tidied up to make more readable

General
~~~~~~~
Expand Down
19 changes: 17 additions & 2 deletions romsearch/modules/romdownloader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import glob
import os
import re
import subprocess

import romsearch
Expand Down Expand Up @@ -365,12 +366,19 @@ def rclone_sync(self,
with subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as process:
for line in process.stdout:

# Replace any potential tabs in the line, strip whitespace and skip newline at the end
line = re.sub('\s+', ' ', line[:-1])
line = line.lstrip().rstrip()

if len(line) == 0:
continue

# Skip the warning about directory filters using regex
if "Can't figure out directory filters" in line:
continue

# Log each line of the output using the provided logger
self.logger.info(centred_string(line[:-1], # Exclude the newline character
self.logger.info(centred_string(line,
total_length=self.log_line_length)
)

Expand Down Expand Up @@ -436,6 +444,13 @@ def rclone_copy(self,
with subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as process:
for line in process.stdout:

# Replace any potential tabs in the line, strip whitespace and skip newline at the end
line = re.sub('\s+', ' ', line[:-1])
line = line.lstrip().rstrip()

if len(line) == 0:
continue

# Skip weird time notifications
if "Time may be set wrong" in line:
continue
Expand All @@ -447,7 +462,7 @@ def rclone_copy(self,
continue

# Log each line of the output using the provided logger
self.logger.info(centred_string(line[:-1], # Exclude the newline character
self.logger.info(centred_string(line, # Exclude the newline character
total_length=self.log_line_length)
)

Expand Down
21 changes: 17 additions & 4 deletions romsearch/modules/rommover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import shutil

import romsearch
from ..util import (load_yml,
from ..util import (centred_string,
load_yml,
setup_logger,
unzip_file,
load_json,
Expand All @@ -20,6 +21,8 @@ def __init__(self,
config=None,
platform_config=None,
logger=None,
log_line_sep="=",
log_line_length=100,
):
"""ROM Moving and cache updating tool
Expand All @@ -32,6 +35,7 @@ def __init__(self,
config (dict, optional): configuration dictionary. Defaults to None.
platform_config (dict, optional): platform configuration dictionary. Defaults to None.
logger (logging.Logger, optional): logger. Defaults to None.
log_line_length (int, optional): Line length of log. Defaults to 100
"""

if config_file is None and config is None:
Expand Down Expand Up @@ -85,6 +89,9 @@ def __init__(self,

self.unzip = self.platform_config.get("unzip", False)

self.log_line_sep = log_line_sep
self.log_line_length = log_line_length

def run(self,
rom_dict,
):
Expand All @@ -108,7 +115,9 @@ def move_roms(self, rom_dict):
)

if rom_dict[rom]["file_mod_time"] == cache_mod_time:
self.logger.info(f"No updates for {rom}, skipping")
self.logger.info(centred_string(f"No updates for {rom}, skipping",
total_length=self.log_line_length)
)
continue

if rom_no == 0:
Expand All @@ -120,7 +129,9 @@ def move_roms(self, rom_dict):
full_dir = os.path.join(self.raw_dir, self.platform)
full_rom = os.path.join(str(full_dir), rom)
self.move_file(full_rom, unzip=self.unzip, delete_folder=delete_folder)
self.logger.info(f"Moved {rom}")
self.logger.info(centred_string(f"Moved {rom}",
total_length=self.log_line_length)
)

# If there are additional file to move/unzip, do that now
if "additional_dirs" in self.platform_config:
Expand All @@ -130,7 +141,9 @@ def move_roms(self, rom_dict):
add_file = os.path.join(add_full_dir, rom)
if os.path.exists(add_file):
self.move_file(add_file, unzip=self.unzip)
self.logger.info(f"Moved {rom} {add_dir}")
self.logger.info(centred_string(f"Moved {rom} {add_dir}",
total_length=self.log_line_length)
)

# Update the cache
self.cache_update(file=rom, rom_dict=rom_dict)
Expand Down
9 changes: 9 additions & 0 deletions romsearch/modules/romsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ def run(self,
)
all_roms_dict[game][f]["file_mod_time"] = file_mod_time

self.logger.info(f"{log_line_sep * log_line_length}")
self.logger.info(centred_string("Running ROMMover",
total_length=log_line_length)
)
self.logger.info(f"{log_line_sep * log_line_length}")

for game in all_roms_dict:
rom_dict = all_roms_dict[game]

Expand All @@ -342,10 +348,13 @@ def run(self,
config=self.config,
platform_config=platform_config,
logger=self.logger,
log_line_length=log_line_length,
)
roms_moved = mover.run(rom_dict)
all_roms_moved.extend(roms_moved)

self.logger.info(f"{log_line_sep * log_line_length}")

# Post these to Discord in chunks of 10
if self.discord_url is not None and len(all_roms_moved) > 0:

Expand Down

0 comments on commit af1431b

Please sign in to comment.