pysys.utils.misc

Miscellanous utilities such as pysys.utils.misc.compareVersions, pysys.utils.misc.setInstanceVariablesFromDict, and pysys.utils.misc.quoteString.

quoteString

pysys.utils.misc.quoteString(s)[source]

Adds double quotation marks around the specified character or byte string, and additional escaping only if needed to make the meaning clear, but trying to avoid double-slashes unless actually needed since it makes paths harder to read.

If a byte string is provided then the repr() representation is used instead.

compareVersions

pysys.utils.misc.compareVersions(v1, v2)[source]

Compares two alphanumeric dotted version strings to see which is more recent.

See pysys.process.user.ProcessUser.compareVersions for more details.

getTypedValueOrDefault

pysys.utils.misc.getTypedValueOrDefault(key, value, default)[source]

Convert a string value to the required type matching the specified default value, or return the default if value is None.

New in version 1.6.0.

Parameters
  • key (str) – The name of the property for use in error messages.

  • value (str) –

    The value that will be converted to the type of default.

    If this is None, the default will be returned instead.

    If this is an empty string then depending on the type of default, a boolean False, empty list[] or empty string will be returned; if instead you wish empty string to result in the default being returned, pass value or default instead of value.

    List entries are delimited by newline and/or commas and stripped of whitespace.

  • default (bool/int/float/str/list[str]) – The default value to return if the property is not set or is an empty string. The type of the default parameter will be used to convert the property value from a string if it is provided. An exception will be raised if the value is non-empty but cannot be converted to the indicated type.

Returns

A value of the same type as default.

Raises

Exception – If the value cannot be converted to default.

setInstanceVariablesFromDict

pysys.utils.misc.setInstanceVariablesFromDict(obj, d, errorOnMissingVariables=False)[source]

Sets an instance variable for each item in the specified dictionary, with automatic conversion of bool/int/float/list[str] values from strings if a default value of that type was provided as a static variable on the object.

New in version 1.6.0.

Parameters
  • obj (object) – Any Python object.

  • d (dict[str,str]) – The properties to set

  • errorOnMissingVariables (bool) – Set this to True if you want an exception to be raised if the dictionary contains a key for which is there no corresponding variable on obj.