BasePacket
basic class.
ppms.migration
.
success()
, fail()
and skip()
methods.
Note
start_migration.py
files (under /py/planta_de/ppms and /py/system/ppms) must not be changed.
# -*- coding: utf-8 -*- from ppms import ppms from ppms.migration.packet import * class ExamplePacket(BasePacket): '''Short 80 character line summarizing what this packet does A longer description that goes more into detail and explains what corner cases one could run into ''' wi_number = None # The workitem number this packet belongs to. Only relevant for packets by PLANTA version = 1 done_after_success = True # Sets the "completed" flag after running successfully run_on_startup = True # Runs this migration packet when the server is started in migration mode category = PacketCategory.CATEGORY_MANDATORY # Categorizes the packet def fix(self, runner): # do something useful if errors: return self.fail('Encountered errors') return self.success()
Note
done_after_success = False
is recommendable for (help)pakets that check the customizing, so that they will be displayed further on in the Packets to be executed area after execution.
StopMigrationProcessException
class can be imported from ppms.migration
. If this exception is raised by a packet, no more packets are executed afterwards.
ppms.migration
package also comes with two decorators for simply skipping packets: skipIf
and skipUnless
.
@skipIf(dbms_name == 'Oracle', 'Not necessary on an Oracle db') def fix(self, packet_runner): ... @skipUnless(dbms_name == 'Oracle', 'Only necessary with a Oracle db') def fix(self, packet_runner): ...
property Default value logging_prefix
Returns a time stamp by default, which is written before every log entry logfile_suffix
Sets the extension of the logfile to .log by default
success()
or fail()
at the end of the fix()
method, according to the number of errors.
rollback()
method of the packet should be implemented in order to be able to undo the changes if necessary.
fix()
method.
AbstractPacketRunner
under ppms.migration.framework
.
Specialized framework classes included in the PLANTA delivery
Class | Use |
---|---|
StartupRunner | Reads all packets from the file system and carries them all out with Upon system start = ![]() ![]() |
DefaultRunner | Carries out all packets for which Completed = ![]() |
SinglePacketRunner | Carries out an individual packet |
RegtestRunner | Carries out an arbitrary number of packets but does not write entries in the history table |
RegtestRunnerWithHistory | Modified version of the RegtestRunner , which also makes entries in the history table |
Class attributes
Attribute![]() |
Expected type | Function |
---|---|---|
done_after_success |
Boolean | Sets the checkmark in the Completed field if the migration packet has run successfully |
run_on_startup |
Boolean | Carries out the packet when the server is started in migration mode |
version |
Integer | Specifies the version of the packet |
Abstract methods
Method | Function | Must be implemented |
---|---|---|
fix(self, packet_runner) |
fix() is opened by the migration framework. This method contains the actual logic of the packet | Yes |
update(self, packet_runner, previous_packet_uuid) |
The update() method is opened if a packet has already been executed with a lower version | No |
rollback(self) |
This method is opened by the framework after the fix() or update() method if the packet has failed |
No |
Useful methods
Method | Function |
---|---|
log(self, text) |
Writes a handed over text in the logfile of the packet. Exception instances can also be handed over to the method in order to log them with complete traceback. try: ... # do something that might raise an error except Exception as err: self.log(err) # Call log() from the except clause to get the correct stack frame! |
log_heading(self, text, level=0) |
Writes a heading in the logfile. level must be an integer between 0 and 4. The higher, the "smaller" the heading |
Class attributes
Attribute | Value |
---|---|
sql_planta_de_dbms |
Path to the sql/planta_de/<dbms> directory, whereas <dbms> is replaced by the respective database system (oracle/mssql) |
sql_planta_ch_dbms |
Path to the sql/planta_ch/<dbms> directory, whereas <dbms> is replaced by the respective database system (oracle/mssql) |
sql_customer_dbms |
Path to the sql/customer/<dbms> directory, whereas <dbms> is replaced by the respective database system (oracle/mssql) |
sql_planta_de_ansi |
Path to the sql/planta_de/<ansi> directory, |
sql_planta_ch_ansi |
Path to the sql/planta_ch/<ansi> directory, |
sql_customer_ansi |
Path to the sql/customer/<ansi> directory, |
Methods
Method | Function |
---|---|
get_queries_from_file(self, fpath) |
Reads the file at the specified path, splits the content at the semicolon and returns the result to the list. |
modify_and_log(self, query) |
Carries out the handed over statement with db_modify and returns the number of lines. As a result, the statement as well as the number of changed lines are written into the logfile. |
fix()
method is not implemented for this class!
Abstract methods
Method | Function |
---|---|
get_matching_objects(self, iterable_to_filter) |
This method receives a list of instances. These instances have a source attribute which contains the source text of the object. The method must return a list of these instances that contain the obsolete Python code |
introduction(self) |
The introduction method is opened before the code is searched and can be used to write a short text in the logfile |
Properties
property | Function |
---|---|
custom_server_folder_blacklist |
A tuple of folder names that are to be omitted in the search |
custom_server_file_blacklist |
A tuple of folder names that are to be omitted in the search |
Attributes
The following attributes are constants that are passed on as parameters to the migrate_python
method.
Attribute | Field that is to be changed |
---|---|
CU_TYPE_DATAITEM | Value range |
CU_TYPE_IRONPYTHON | IronPython script |
CU_TYPE_DF_CONFIG | Data field configuration |
CU_TYPE_MODULE | Macro |
CU_TYPE_PROCESS_RULE | Rules |
CU_TYPE_GLOBAL_SETTING | Template code |
Methods
Method | Function |
---|---|
migrate_python(self, before_hash, after_hash, cu_type, keys, fix_func) |
Checks whether the system condition is as expected, makes changes to the system, and checks whether the target condition meets the expectations. before_hash : Md5 hash that is expected in the system after_hash : Md5 hash that is expected in the system after the change has been made cu_type : One of the constants listed above keys : See below fix_func : A function that accepts the source code as an argument and returns it corrected. |
Values for the keys
parameter
cu_type | Expected data type | Expected value |
---|---|---|
CU_TYPE_DATAITEM | String | DI |
CU_TYPE_IRONPYTHON | List | DA as a string, DF as an integer |
CU_TYPE_DF_CONFIG | List | DA as a string, DF as an integer |
CU_TYPE_MODULE | String | MOD |
CU_TYPE_PROCESS_RULE | String | Process rules |
CU_TYPE_GLOBAL_SETTING | UUID |
Method | Function |
---|---|
get_record(self, dt_num, key_list, di_list) |
A wrapper for the ppms.search_record method that has been extended by logging. Either returns DTPRecord or None |
verify_value(self, record, attribute, value) |
Function for checking the value of arbitrary attributes of a record. The attribute parameter is the DI Python ID of the field to be checked. Returns True or False |
change_value(self, record, attribute, old_value, new_value) |
Checks the system condition, makes the change, and checks whether the change has been saved correctly. The attribute parameter is the DI Python ID of the field to be changed. Returns True or False . |