utils Package

This is the pyNastran.utils.rst file.

gui_choices Module

gui_io Module

pyNastran.utils.gui_io._main()[source]

helps to test the functions

pyNastran.utils.gui_io.load_file_dialog(Title, wx_wildcard, qt_wildcard, dirname='')[source]

creates a load file dialog in wx or PyQt4/PySide

pyNastran.utils.gui_io.radio_pullown_dialog(Title, button_dict, nwide=3)[source]
buttons = [
[header, ‘checkbox’, A’, ‘B’, ‘C’], [header2, ‘pulldown’, ‘A’, ‘B’],

]

A B C x

header2 v

pyNastran.utils.gui_io.save_file_dialog(Title, wx_wildcard, qt_wildcard, dirname='')[source]

creates a save file dialog in wx or PyQt4/PySide

log Module

Inheritance diagram of pyNastran.utils.log

class pyNastran.utils.log.SimpleLogger(level='debug', log_func=<function stderr_logging at 0x7ff6186662a8>)[source]

Bases: object

Simple logger object. In future might be changed to use Python logging module. Two levels are supported: ‘debug’ and ‘info’. Info level discards debug messages, ‘debug’ level displays all messages.

Note

Logging module is currently not supported because I don’t know how to repoint the log file if the program is called a second time. Poor logging can result in:

  1. double logging to a single file
  2. all longging going to one file

This is really only an issue when calling logging multiple times, such as in an optimization loop or testing.

Parameters:
  • level – level of logging: ‘info’ or ‘debug’
  • log_func – funtion that will be used to print log. It should take one argument: string that is produces by a logger. Default: print messages to stderr using @see stderr_logging function.
critical(msg)[source]

Log CRITICAL message :param msg: message to be logged

debug(msg)[source]

Log DEBUG message :param msg: message to be logged

error(msg)[source]

Log ERROR message :param msg: message to be logged

exception(msg)[source]

Log EXCEPTION message :param msg: message to be logged

info(msg)[source]

Log INFO message :param msg: message to be logged

msg_typ(typ, msg)[source]

Log message of a given type :param typ: type of a message (e.g. INFO) :param msg: message to be logged

properties()[source]

Return tuple: line number and filename

simple_msg(msg, typ=None)[source]

Log message directly without any altering. :param msg: message to be looged without any alteration.

warning(msg)[source]

Log WARNING message :param msg: message to be logged

pyNastran.utils.log.get_logger(log=None, level='debug')[source]

This function is useful as it will instantiate a simpleLogger object if log=None. :param log: a logger object or None :param level: level of logging: ‘info’ or ‘debug’

pyNastran.utils.log.get_logger2(log=None, debug=True)[source]

This function is useful as it will instantiate a SimpleLogger object if log=None. :param log: a python logging module object;

if log is set, debug is ignored and uses the settings the logging object has
Parameters:debug – used to set the logger if no logger is passed in True: logs debug/info/error messages False: logs info/error messages None: logs error messages
Returns log:log or a SimpleLogger
pyNastran.utils.log.make_log(display=False)[source]

Creates ‘pyNastran.log’ file with information about working environment, such as Python version, platform, architecture, etc. Useful for debugging.

Parameters:display – do not only create file but also print log information
pyNastran.utils.log.stderr_logging(typ, msg)[source]

Default logging function. Takes a text and outputs to stderr. :param typ: messeage type :param msg: message to be displayed

Message will have format ‘typ: msg’

mathematics Module

dev Module

pyNastran.utils.dev.get_files_of_type(dirname, extension='.txt', maxSize=100.0)[source]

Gets the list of all the files with a given extension in the specified directory

Parameters:
  • dirname – the directory name
  • extension – list of filetypes to get (default=’.txt’)
  • maxSize – size in MB for max file size
Returns:

list of all the files with a given extension in the specified directory

pyNastran.utils.dev.list_print(lst, float_fmt='%-4.2f')[source]

Prints a list, numpy array, or numpy matrix in an abbreviated format. Supported element types: None, string, numbers. Useful for debugging.

Parameters:lst – list, numpy array or numpy matrix
Returns:the clean string representation of the object
pyNastran.utils.dev.write_array(a, nspaces=0)[source]
pyNastran.utils.dev.write_class(name, obj, nspaces=0, nbase=0)[source]
pyNastran.utils.dev.write_dict(obj, nspaces, nbase, isClass)[source]
pyNastran.utils.dev.write_list(obj, nspaces, nbase, isClass)[source]
pyNastran.utils.dev.write_object_attributes(attr, obj, nspaces, nbase=0, isClass=False)[source]
pyNastran.utils.dev.write_tuple(obj, nspaces, nbase, isClass)[source]

__init__ Module

pyNastran.utils.__init__.__object_attr(obj, mode, attr_type)[source]

list object attributes of a given type

pyNastran.utils.__init__.is_binary_file(filename)[source]

Return true if the given filename is binary.

Raises:IOError if the file cannot be opened.
Returns:True if filename is a binary file (contains null byte) and False otherwise.

Based on the idea (.. seealso:: http://bytes.com/topic/python/answers/21222-determine-file-type-binary-text) that file is binary if it contains null.

Warning

this may not work for unicode.

pyNastran.utils.__init__.object_attributes(obj, mode='public')[source]

List the names of attributes of a class as strings. Returns public attributes as default.

Parameters:
  • obj – the object for checking
  • mode – defines what kind of attributes will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all attributes that are defined for the object
Returns:

sorted list of the names of attributes of a given type or None if the mode is wrong

pyNastran.utils.__init__.object_methods(obj, mode='public')[source]

List the names of methods of a class as strings. Returns public methods as default.

Parameters:
  • obj – the object for checking
  • mode – defines what kind of methods will be listed * “public” - names that do not begin with underscore * “private” - names that begin with single underscore * “both” - private and public * “all” - all methods that are defined for the object
Returns:

sorted list of the names of methods of a given type or None if the mode is wrong

pyNastran.utils.__init__.print_bad_path(path)[source]

Prints information about the existence (access possibility) of the parts of the given path. Useful for debugging when the path to a given file is wrong.

Parameters:path – path to check
Returns:string with informations whether access to parts of the path is possible
pyNastran.utils.__init__.write_object_attributes(name, obj, nspaces=0, nbase=0, isClass=True, debug=False)[source]

Writes a series of nested objects