Utils subpackage

General purpose functions and classes used in other subpackages.

To avoid circular dependencies, this subpackage does not depend on any other subpackages of the eprcontrol package, but it can be imported into every other subpackage.

class eprcontrol.utils.Distribution

Bases: handle

Create distribution for package

Sometimes, for distributing the package it is desired to only share p-coded files rather than the actual source code. However, it would be rather tedious to create the p-coded files each time manually. Furthermore, one would like to have a full distribution including the README and LICENSE files as well as the documentation.

target_directory

directory used to create the distribution in

Type

string

docs_directory

directory the documentation is located in

Here, it is assumed that the documentation is built using Sphinx and that the built documentation resides in the _built/html subdirectory.

Make sure to build the documentation first using Sphinx before building the distribution, to allow the documentation in the distribution to be up to date.

Type

string

create()

Create distribution for package

The distribution will be created in the target directory set in the object’s properties. All MATLAB® m files will be p-coded and converted into p files (obfuscated).

Furthermore, all subdirectories containing libraries and additional files will be copied as well.

Eventually, the documentation and the files residing in the root directory of the whole package are copied as well.

Note

Due to pcode creating the files in the current directory, this method changes into the distribution directory, builds all p files and copies all other files, and afterwards returns to the previous directory.

However, if anything goes wrong, usually you are left in the distribution directory and need to manually change back to the original directory.

class eprcontrol.utils.System

Bases: handle

General information on the system used

operating_system

Details of the operating system

Type

string

user

Name of the user currently logged in

Type

string

home_dir

User directory ($HOME, ~)

Type

string

install_dir

Directory the toolbox is installed to

Type

string

matlab

Information on the MATLAB version used

Fields: “Name”, “Version”, “Release”, “Date”

Type

struct

toolbox

Information on the eprcontrol toolbox used

Fields: “Name”, “Version”, “Release”, “Date”

Type

struct

class eprcontrol.utils.YAML

Bases: handle

Class reading from and writing to YAML files.

YAML file contents are read into a struct.

dict

Contents read from/written to a YAML file

Type

dict

Part of this code is derived from the “YAMLMatlab” project available at https://code.google.com/archive/p/yamlmatlab/ and developed by Energocentrum PLUS, s.r.o. and Czech Technical University (CTU) in Prague. The code is available under terms of the MIT license.

The actual magic is delegated to the Java library snakeyaml by Anrey Somov, available under terms of the Apache 2.0 license. See http://www.snakeyaml.org/ for details.

read(char_vector)

Read from YAML character vector.

Parameters

char_vector – Character vector containing YAML code.

read_from(filename)

Read from YAML file.

Parameters

filename – Name of the YAML file to read from.

write_to(filename)

Write to YAML file.

Parameters

filename – Name of the YAML file to write to.

transform_map(raw_yaml)

Transforms Java Map to MATLAB struct running transform() recursively for the content of every Map field.

If a field is recognized as >import keyword<, an attempt is made to import the file given by the field content.

The result of import is so far stored as a content of the item named ‘import’.

transform_list(raw_yaml)

Transform Java List to MATLAB cell column running scan(…) recursively for all ListS items.

perform_import(raw_yaml)

Transform input hierarchy the usual way.

If the result is a char, try to load the file denoted by this char. If the result is a cell, try to do the same for each cell item.

static transform_string(raw_yaml)

Transform Java String to MATLAB char

static transform_numeric(raw_yaml)

Transform Java double to MATLAB double

static transform_logical(raw_yaml)

Transform Java boolean to MATLAB logical

static transform_datetime(raw_yaml)

Transform Java Date class to MATLAB DateTime class

static is_import_keyword(raw_yaml)

Determine whether r contains a keyword denoting import.