spinn_utilities.make_tools package

Submodules

spinn_utilities.make_tools.converter module

spinn_utilities.make_tools.converter.convert(src: str, dest: str, new_dict: bool) None[source]

Converts a whole directory including sub-directories.

Parameters:
  • src – Full source directory

  • dest – Full destination directory

  • new_dict – Whether we should generate a new dictionary/DB. If not, we add to the existing one.

spinn_utilities.make_tools.log_sqllite_database module

class spinn_utilities.make_tools.log_sqllite_database.LogSqlLiteDatabase(new_dict: bool = False)[source]

Bases: AbstractContextManager

Specific implementation of the Database for SQLite 3.

Note

Not thread-safe on the same database. Threads can access different DBs just fine.

Note

This totally relies on the way SQLite’s type affinities function. You can’t port to a different database engine without a lot of work.

Connects to a log dict. The location of the file can be overridden using the C_LOGS_DICT environment variable.

Parameters:

new_dict – Flag to say if this is a new dict or not. If True, clears and previous values. If False, makes sure the dict exists.

check_original(original: str) None[source]

Checks that an original log line has been added to the database.

Mainly used for testing

Parameters:

original

Raises:

ValueError – If the original is not in the database

close() None[source]

Finalises and closes the database.

get_directory_id(src_path: str, dest_path: str) int[source]

gets the Ids for this directory. Making a new one if needed

Parameters:
  • src_path

  • dest_path

Returns:

The ID for this directory.

get_file_id(directory_id: int, file_name: str) int[source]

Gets the id for this file, making a new one if needed.

Parameters:
  • directory_id

  • file_name

Returns:

The ID for this file

get_log_info(log_id: str) Tuple[int, str, str, str] | None[source]

Gets the data needed to replace a short log back to the original.

Parameters:

log_id – The int id as a String

Returns:

log level, file name, line number and the original text

get_max_log_id() int | None[source]
Returns:

the max id of any log message, or None it there none

set_log_info(log_level: int, line_num: int, original: str, file_id: int) int[source]

Saves the data needed to replace a short log back to the original.

Parameters:
  • log_level

  • line_num

  • original

  • file_id

Returns:

ID for this log message

spinn_utilities.make_tools.replacer module

class spinn_utilities.make_tools.replacer.Replacer(new_dict: bool = False)[source]

Bases: LogSqlLiteDatabase

Performs replacements.

Connects to a log dict. The location of the file can be overridden using the C_LOGS_DICT environment variable.

Parameters:

new_dict – Flag to say if this is a new dict or not. If True, clears and previous values. If False, makes sure the dict exists.

replace(short: str) str[source]

Apply the replacements to a short message.

Parameters:

short – The short string as read of the machine

Returns:

The message as it would if short codes where not used.

Module contents

class spinn_utilities.make_tools.FileConverter[source]

Bases: object

Converts a file. See convert().

__call__(src: str, dest: str, log_file_id: int, log_database: LogSqlLiteDatabase) None[source]

Creates the file_convertor to convert one file.

Parameters:
  • src – Absolute path to source file

  • dest – Absolute path to destination file

  • log_file_id – Id in the database for this file

  • log_database – The database which handles the mapping of id to log messages.

static convert(src_dir: str, dest_dir: str, file_name: str) None[source]

Static method to create Object and do the conversion.

Parameters:
  • src_dir – Source directory

  • dest_dir – Destination directory

  • file_name – The name of the file to convert within the source directory; it will be made with the same name in the destination directory.