Reference/API

ROMSearch

class romsearch.ROMSearch(config_file=None, config=None, default_config=None, regex_config=None, logger=None)[source]

General search tool to get ROMs downloaded and organized into files

Parameters:
  • config_file (str, optional) – path to config file. Defaults to None.

  • config (dict, optional) – configuration dictionary. Defaults to None.

  • default_config (dict, optional) – default configuration dictionary. Defaults to None.

  • regex_config (dict, optional) – regex configuration dictionary. Defaults to None.

run(log_line_sep='=', log_line_length=100)[source]

Run ROMSearch

Parameters:
  • log_line_sep (str, optional) – log line separator. Defaults to “=”.

  • log_line_length (int, optional) – log line length. Defaults to 100.

ROMDownloader

class romsearch.ROMDownloader(platform=None, config_file=None, config=None, platform_config=None, rclone_method='sync', copy_files=None, logger=None, include_filter_wildcard=True, log_line_sep='=', log_line_length=100)[source]

Downloader tool via rclone

This works per-platform, so must be specified here.

For this, we can either sync an entire directory (rclone_method=’sync’), or copy individual files (rclone_method=’copy’). If the method is copy, then copy_files must be set as a list

Parameters:
  • platform (str, optional) – Platform name. Defaults to None, which will throw a ValueError

  • config_file (str, optional) – Configuration file. Defaults to None

  • config (dict, optional) – Configuration dictionary. Defaults to None

  • platform_config (dict, optional) – Platform configuration dictionary. Defaults to None

  • rclone_method (str, optional) – Should be one of ‘sync’ or ‘copy’. Defaults to ‘sync’

  • copy_files (list, optional) – Must be set if rclone_method is ‘copy’. Determines the filenames to copy over. Defaults to None

  • logger (logging.Logger, optional) – Logger instance. Defaults to None

  • include_filter_wildcard (bool, optional) – If set, will include wildcards in rclone filters. Defaults to True.

  • log_line_length (int, optional) – Line length of log. Defaults to 100

post_to_discord(start_files, end_files, name, max_per_message=10)[source]

Create a discord post summarising files added and removed

Parameters:
  • start_files (list) – list of files at the start of the rclone

  • end_files (list) – list of files at the end of the rclone

  • name (string) – Name of the post title

  • max_per_message (int, optional) – Maximum number of items per post. Defaults to 10.

rclone_copy(remote_dir, out_dir=None, max_retries=5)[source]

Use rclone to copy files one-by-one

Parameters:
  • remote_dir – rclone remote path

  • out_dir – directory to download to

  • max_retries – maximum number of retries

rclone_download(remote_dir, out_dir=None, max_retries=5)[source]

Download from rclone, either via sync or copy

Parameters:
  • remote_dir – rclone remote path

  • out_dir – directory to download to

  • max_retries – maximum number of retries

rclone_sync(remote_dir, out_dir=None, transfers=5, max_retries=5)[source]

Use rclone to sync an entire directory

Parameters:
  • remote_dir – rclone remote path

  • out_dir – directory to download to

  • transfers – number of simultaneous transfers

  • max_retries – maximum number of retries

run()[source]

Run Rclone downloader tool

Utilities

romsearch.util.centred_string(str_to_centre, total_length=80, str_prefix='')[source]

Centre string for a logger

Parameters:
  • str_to_centre – String to centre

  • total_length – Total length of the string. Defaults to 80.

  • str_prefix – Will include this at the start of any string. Defaults to “”

romsearch.util.discord_push(url, name, fields)[source]

Post a message to Discord

romsearch.util.get_bracketed_file_pattern(str_to_match)[source]

Get file pattern to match bracketed things

This is a little tricky since sometimes things can be matched a little unusually. What we do here is allow for matches of letters, commas or spaces before and after, but ensure there’s no text immediately after the match. So “De” will match for a language but not “Demo”

romsearch.util.get_file_pattern(str_to_match)[source]
romsearch.util.get_file_time(f, datetime_format='%Y/%m/%d, %H:%M:%S', return_as_str=True)[source]

Get created file time from the file itself

Parameters:
  • f (str) – Filename

  • datetime_format (str, optional) – Date and time format. Defaults to “%Y/%m/%d %H:%M:%S”

  • return_as_str (bool, optional) – Return string or full datetime. Defaults to True

romsearch.util.get_game_name(f)[source]

Get game name, which is just everything up to the first bracket

romsearch.util.get_parent_name(game_name, dupe_dict)[source]

Get the parent name recursively searching through a dupe dict

romsearch.util.get_short_name(f, regex_config=None, default_config=None)[source]

Get short game name from the ROM file naming convention

romsearch.util.left_aligned_string(str_to_align, total_length=80, str_prefix='')[source]

Left-align string for a logger

Parameters:
  • str_to_align – String to align

  • total_length – Total length of the string

  • str_prefix – Will include this at the start of any string. Defaults to “”

romsearch.util.load_json(file)[source]

Load json file

romsearch.util.load_yml(f)[source]

Load YAML file

romsearch.util.save_json(data, out_file)[source]

Save json in a pretty way

romsearch.util.save_yml(f, data)[source]

Save YAML file

romsearch.util.setup_logger(log_level, script_name, log_dir, additional_dir='', max_logs=9)[source]

Set up the logger.

Parameters:
  • log_level (str) – The log level to use

  • script_name (str) – The name of the script

  • log_dir (str) – The directory to save logs to

  • additional_dir (str) – Any additional directories to keep log files tidy

  • max_logs (int) – Maximum number of log files to keep

Returns:

A logger object for logging messages.

romsearch.util.split(full_list, chunk_size=10)[source]

Split a list in chunks of size chunk_size

Parameters:
  • full_list (list) – list to split

  • chunk_size (int, optional) – size of each chunk. Defaults to 10

romsearch.util.unzip_file(zip_file_name, out_dir)[source]

Unzip a file