mib_generator.generation package

This sub-package and the modules within it serve the purpose of turning previously interpreted and comprehended representations of Tc/Tm packets/etc. and their sketched out MIB tables into propertly constructed and verified (against criteria of type, uniqueness, etc…) MIB tables and finally saving these tables in the correct format into a desired location and documenting the output.

The submodules here are:
  • gener - The main generation module, chooses what should be generated, what tools should be used for that purpose and executes the generation.

  • gener_methods - Module holding methods used by the main generation module. These methods do all from checking and converting MIB tables to saving them in the correct location.

  • gener_doc - Module with methods that create a docx file with the list of entries in Tm and Tc packets from which the MIB tables were generated.

Submodules

mib_generator.generation.gener module

This module serves the purpose of generating MIB databases from inputed objects and checking their validity.

Methods in this module generate MIB databases from their representations previously generated by the mib_generator.construction package/modules and run finals checks on the results to ensure that the outputted tables/MIB files adhere to the requirements on the type, length, uniqueness and “mandatoriness”.

mib_generator.generation.gener.Tch_gen(typ, Tc_head)[source]

Choose how the given Tc-header MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

Parameters:
Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener.Tcp_gen(typ, Tc_packets)[source]

Choose how the given Tc-packet MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

Parameters:
Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener.Tmp_gen(typ, Tm_packets)[source]

Choose how the given Tm-packet MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

The special case here is with respect to the pic table in case of which, first a filter on the packet list have to be run since the entries in the pic table are a subset of those in pid/list of packages and hence otherwise false warning would be raised later (due to lack of uniqueness).

Parameters:
Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener.cal_gen(typ, calibrations)[source]

Choose how the given calibration MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

Parameters:
  • typ (str) – Name of the MIB table to be generated.

  • calibrations (list) – List of dictionaries of calibrations from which the table is to be constructed. Each calibration is of some type which is a child-class of mib_generator.construction.calib.calib.

Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener.dec_gen(typ, decalibrations)[source]

Choose how the given decalibration MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

Parameters:
  • typ (str) – Name of the MIB table to be generated.

  • decalibrations (list) – List of decalibrations from which the table is to be constructed. Each of type mib_generator.construction.calib.decalib.

Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener.generation_hub(Tm_packets=None, Tc_packets=None, calibrations=None, decalibrations=None, verifications=None, Tc_head=None, cfg=None)[source]

Take all constructed packets/calibrations/commands and call generation scripts for each table.

This method is the “main interface” for the generation process. It is passed various objects which have MIB tables associated to them and for each of them calls the appropriate generation methods (either one_generate for objects which have only one row of the given MIB table associated to them or two_generate in case of possibly multiple rows) with the correct parameters.

What tables are generated is determined by the contents of the ../data/config.json5 config file, or it can be overridden using the cfg argument. Because of this optionality, none of the arguments of this method are compulsory, since they are not needed for generation of some tables, which is what this method could be asked to do. However they have to be present if a table which is based on them is to be generated.

Parameters:
Returns:

A dictionary holding all the generated mib tables (in form of Python 2D lists) with their names as keys.

Return type:

dict

mib_generator.generation.gener.save_tables(tables)[source]

Reformat and save mib tables in the passed dictionary.

Goes through the passed dictionary holding mib tables and for each first reformats it into an appropriate ASCII string and then saves it to the specified folder with all mib tables.

Parameters:

tables (dict) – A dictionary containing mib tables in the form of 2D Python lists as values with their names as keys.

mib_generator.generation.gener.ver_gen(typ, verifications)[source]

Choose how the given verification MIB table should be constructed and construct it.

Based on its name, this function chooses what method to call in order to generate and check the given table. It then calls this method and returns the result.

Parameters:
Returns:

A 2D list (list of lists) representing the outputted MIB table (still in Python format).

Return type:

list

mib_generator.generation.gener_doc module

This module enables generation of a .docx file which documents in a human-readable way what was put in MIB tables for a given set of Tm and Tc packets.

The only (important) method in this module builds up the .docx file using the not so powerful python-docx library.

mib_generator.generation.gener_doc.gen_doc(Tm_packets=[], Tc_packets=[])[source]

Create a .docx document which sketches out what entries are in each of the Tm and Tc packets in the passed list.

This method goes through all passed Tm and Tc packets and for each adds an entry to the created .docx document including basic info about the packet and a table of entries within it. The format of the output tries to adhere to a standard scheme of an ICD document used normally for these purposes.

Parameters:
mib_generator.generation.gener_doc.to_bytes(bits)[source]

Give the number of bits in bytes and in some meaning full format.

Calculates how many bytes are in the passed bits, how many residual bits, and puts together this information into a meaningful-looking string.

Parameters:

bits (int) – Numeber of bits to be “translated”.

Returns:

The number of bits in bytes and residual bits in understandable form.

Return type:

str

mib_generator.generation.gener_methods module

Methods for generation of MIB tables and checking of their validity.

This module holds methods that help with generation, checking and saving of MIB tables from previously created Python representations of Tm/Tc packets, calibrations, etc..

mib_generator.generation.gener_methods.check(value, typ)[source]

Check whether the given value matches the given type.

This method checks whether the passed value matches the passed type (either integer number or ASCII string without a few characters).

Parameters:
  • value (str) – Value who’s type is to be checked.

  • typ (str) – The type the value should have.

Returns:

True if the value matches the type, False otherwise.

Return type:

bool

mib_generator.generation.gener_methods.delete_empty(table)[source]

Delete empty entries in arrays.

This function goes through list of dictionaries to be made into MIB tables, and removes every empty (equal to "") entry it finds. This is done so that the later tests trigger appropriate warnings.

Parameters:

table (list) – List of dictionaries, each one representing a row of an MIB table, which is to be cleaned from empty entries.

mib_generator.generation.gener_methods.exclude_repetition(table, typ)[source]

Exclude repetition in columns where there should be unique entries.

This function checks whether there is any repetition in columns where entries should be unique in the passed MIB table and if so, deletes the additional rows and raises a warning. (the required uniqueness of entries for a given MIB table is defined in mib_generator.data.longdata.unique_entries)

Parameters:
  • table (list) – List of dictionaries which represents the MIB database to be checked for repetition.

  • typ (str) – The name of the MIB database the passed table adheres to.

mib_generator.generation.gener_methods.generate(table_type, source)[source]

From a list of dictionaries (per rows) generate a MIB table of a given type.

This function generates and saves the MIB database in the following steps:

  1. Based on the passed MIB table name, looks up what entries/columns the generated table should have (it takes this information from mib_generator.data.longdata.tables_format).

  2. From the passed list of dictionaries it creates a 2D list (list of lists) mirroring the structure of the MIB table.

  3. While doing that it runs some checks of type and uniqueness of the entries.

Parameters:
  • table_type (str) – The name of the MIB database the passed table adheres to.

  • table (list) – List of dictionaries which correspond to the rows of the MIB table with the appropriate entries.

Returns:

A 2D list (list of lists) representing the generated MIB table

Return type:

list

mib_generator.generation.gener_methods.list_to_mib(lis)[source]

Convert a 2D list of values into a string formatted as MIB ASCII file.

From a 2D list (list in list) this functions creates one string by joining all the entries with a junction \n for entries in the “1D” list and with \t for the “nested” entries.

Parameters:

lis (list) – A 2D list (list of lists) to be joined into one string.

Returns:

A string which is created from the 2D list and is formatted as an MIB database.

Return type:

str

mib_generator.generation.gener_methods.mnemon_check(packets, typ)[source]

Check whether mnemonics for the set of passed packets and the given table are unique and existent.

This follows additional mib specifications by OHB Italia, which requires special mnemonic parameter to be saved into the description field for a few mib tables. The mnemonics are specified to be unique and present, which is what this method checks and raises warning if they aren’t.

Parameters:
mib_generator.generation.gener_methods.one_generate(lists, name)[source]

Generate MIB database of the given name from the passed list of objects.

This method does a few precursor steps to the generation process. For each of the objects in the passed list, it extracts the appropriate dictionary corresponding to the row in the MIB table associated to the object and appends this dictionary (alias row) to a list of all rows for this table. It then passes the resulting list through a “filter” which erases all entries left empty (method delete_empty) and calls the main generation method generate with this list.

Parameters:
  • lists (list) – List of the objects (these can be of many types) the rows of the MIB tables (as dictionaries) are associated to.

  • name (str) – Name of the MIB table that is to be generated from these objects.

Returns:

A 2D list (list of lists) representing the generated MIB table

Return type:

list

mib_generator.generation.gener_methods.pic_filter(packets)[source]

Check whether the information saved in the list of Tm-packet is self-consistent and prune it for generation of pic.

This function is an ad-hoc filter, that accounts for the fact that pic table has to have fewer entries than pid or other similar tables because of the fact that one entry in it corresponds only to one combination of packet type/subtype. However for a set of packets to be reducible to this single entry in pic, it has to be the case that they all share the same declaration of additional identification fields which set them apart but have the same position relative to the packet structure. This is hence also something that this filter checks and raises a warning whenever it encounters something suspicious. Finally it deletes all (valid) repetition in types/subtypes it finds, so that pic table can be directly generated from the output list of packets without raising further exceptions.

Parameters:

packets (list) – List of representations of Tm-packets, each of type mib_generator.construction.TM_packet.TM_packet. This list corresponds to the pid table.

Returns:

List of representations of Tm-packets, each of type mib_generator.construction.TM_packet.TM_packet This list corresponds to the pic table.

Return type:

list

mib_generator.generation.gener_methods.save_mib(mib, name)[source]

Save the string-MIB database into the specified folder.

This function saves the passed string into a file named with the passed name (+.dat ending) at the location specified in mib_generator.parsing.load.out_dir.

Parameters:
  • mib (str) – The string to be saved into a file

  • name (str) – Name of the file (+.dat) the string will be saved into.

mib_generator.generation.gener_methods.two_generate(lists, name)[source]

Generate MIB database of the given name from the passed list of objects.

This method does a few precursor steps to the generation process. For each of the objects in the passed list, it extracts the appropriate dictionaries (in a list) corresponding to the rows in the MIB table associated to the object and appends these dictionaries (alias rows) to a list of all rows for this table. It then passes the resulting list through a “filter” which erases all entries left empty (method delete_empty) and calls the main generation method generate with this list.

Parameters:
  • lists (list) – List of the objects (these can be of many types) the rows of the MIB tables (as dictionaries) are associated to.

  • name (str) – Name of the MIB table that is to be generated from these objects.

Returns:

A 2D list (list of lists) representing the generated MIB table

Return type:

list