ait.core.gds module

AIT Ground Data System

The ait.core.gds module provides utility functions specific to GDS command-line tools.

ait.core.gds.arg_parse()

Parses the arguments using argparse. Returns a Namespace object. The arguments dictionary should match the argparse expected data structure:

For positional arguments, be sure to pass in an OrderedDict:

ait.core.gds.compress(input_filename, output_filename=None, verbose=False) → integer

Uses zlib to compress input_filename and store the result in output_filename. The size of output_filename is returned on success; zero is returned on failure.

The input file is compressed in one fell swoop. The output_filename defaults to input_filename + “.ait-zlib”.

If verbose is True, compress() will use ait.core.log.info() to report compression statistics.

ait.core.gds.exit([status])

Calls ait.core.log.end()

Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure).

ait.core.gds.extant_file(file)

‘Type’ for argparse - checks that file exists but does not open.

ait.core.gds.getip()

Returns the IP address of the computer. Helpful for those hosts that might sit behind gateways and report a hostname that is a little strange (I’m looking at you oco3-sim1).

ait.core.gds.hexdump(bytes[, addr[, preamble[, printfunc[, stepsize=16]]]])

Outputs bytes in hexdump format lines similar to the following (here preamble=’Bank1’, stepsize=8, and len(bytes) == 15):

Bank1: 0xFD020000: 7f45  4c46  0102  0100  *.ELF....*
Bank1: 0xFD020008: 0000  0000  0000  00    *....... *

Where stepsize controls the number of bytes per line. If addr is omitted, the address portion of the hexdump will not be output. Lines will be passed to printfunc for output, or Python’s builtin print, if printfunc is omitted.

If a byte is not in the range [32, 127), a period will rendered for the character portion of the output.

ait.core.gds.hexdumpLine(bytes[, length])

Returns a single hexdump formatted line for bytes. If length is greater than len(bytes), the line will be padded with ASCII space characters to indicate no byte data is present.

Used by hexdump().

ait.core.gds.parseArgs(argv, defaults) -> (dict, list)

Parses command-line arguments according to the given defaults. For every key in defaults, an argument of the form –key=value will be parsed. Numeric arguments are converted from strings with errors reported via ait.core.log.error() and default values used instead.

Returns a copy of defaults with parsed option values and a list of any non-flag arguments.

ait.core.gds.usage([exit])

Prints the usage statement at the top of a Python program. A usage statement is any comment at the start of a line that begins with a double hash marks (##). The double hash marks are removed before the usage statement is printed. If exit is True, the program is terminated with a return code of 2 (GNU standard status code for incorrect usage).