Launch API Python

Adobe IO : Launch API : Translator Class

EDIT : Change in the documentation has been made. pylaunch is now called launchpy. You can now install it with pip command, doing :
pip install launchpy

The translator class is not a required class or group of methods for the launchpy module to work. You may want to rewrite some of the functionalities for your own use. However, as I was developing and using this wrapper, it became obvious that a method which will help me to translate the id of the extension or the rule from each individual property into other property extension id or rule id would be very helpful.

The translator class facilitate the copy paste of element from one property to another. It is useful especially for the Rule Component and Data Element creation where relationships with rule and extension id are required for creation.
I will try to explain how it work in the following paragraph.

The instantiation of the translator class is very basic as you would just need to call for it.

import launchpy

translator = launchpy.Translator()

Set Base Rule and Extensions ids

What is really required is the base property extensions and rules. The id of the elements from your “mother” property.
This is an assumption that I have when I created this facilitator, you would have a blueprint that you will use to copy elements from.

The translator class provide 2 methods to add base rule and base extension ids:

  • setBaseExtensions
    Pass all the extensions from the base property to start building the table.
    Arguments:
    • base_property : REQUIRED : list of all extensions retrieve through getExtensions method
    • property_name : REQUIRED : name of your base property.
  • setBaseRules
    Pass all the rules from the base property to start building the table.
    Arguments:
    • base_property : REQUIRED : list of all rules retrieve through getExtensions method
    • property_name : REQUIRED : name of your base property.

Set target Rule and Extensions ids

Once you have loaded the base Extension and Rules ids, the method will start to expand the table into multiple columns for matching. Underlying is the use of pandas dataframe to realize that matching.
You will need to be consistent with the naming of your target in order for the method to work properly.
The methods that allow extension of your table are the following:

  • extendExtensions
    Add the extensions id from a target property.
    Arguments:
    • new_property_extensions: REQUIRED : the extension list from your target property.
    • new_prop_name : REQUIRED : target property name.
  • extendRules
    Add the extensions id from a target property.
    Arguments:
    • new_property_rules: REQUIRED : the rules list from your target property.
    • new_prop_name : REQUIRED : target property name.

Translating elements

Every translator jobs is to translate, then the final method is actually the translate method.

  • translate
    change the id from the base element to the new property.
    Pre checked should be done beforehands (updating Extension & Rules elements)
    Arguments:
    • target_property : REQUIRED : property that is targeted to translate the element to.
    • data_element : OPTIONAL : if the elements passed are data elements.
    • rule_component : OPTIONAL : if the elements passed are rule components

Code Example

import launchpy
## retrieve the properties of your base and target properties 
## as base_prop and target_prop
## then create Property class from / for  them. 
## set Property and Core components posts for more info

base_extensions = base_prop.getExtensions()
target_extensions = target_prop.getExtensions()

base_rules = base_prop.getRules()
target_rules = target_prop.getRules()

translator = launchpy.Translator()
translator.setBaseExtensions(base_extensions,'base')
translator.extendExtensions(target_extensions,target_prop.name)

translator.setBaseRules(base_rules,'base')
translator.extendRules(target_rules,target_prop.name)

base_de = base_prop.getDataElements() ## get data elements

## trying to copy the setting from the base extension data element
new_de = []
for data_element in base_de:
    new_de.append(launchpy.copySettings(data_element))

## problem is that the id are having relationship to wrong extension id. 

new_de_translated = []
for de in new_de:
    new_de_translated.append(translator.translate(de))

## now you can use the information gathered in the new_de_translated list 
##  to create Data Element in the target property. 

I know that this class is not easy to comprehend and I would recommend you to watch the video tutorial if you have any doubt.
You can also use the the contact form or comment the article if you have any question.

I hope this post helps you to better understand the launchpy Translator class methods.
You may be interested in the articles that explains a bit more about the different components of the launchpy module.

ArticlesComments
Adobe IO : JWT authenticationHow to create JWT authentication with OpenSSL and python
Adobe IO : Launch API : Introduction to launchpyWhat you need to know about this module
Adobe IO : Launch API : Core Component The methods directly available from this module.
Adobe IO : Launch API : Property ClassWhat is the Property class and how to use it to manage your Launch properties
Adobe IO : Launch API : Library ClassHow to manage your publishing process through launchpy, in python
Adobe IO : Launch API : Translator ClassA Facilitator in launchpy in order to copy paste the element from one property to another.
Adobe IO : Launch API : TutorialVideo tutorial on some methods available from the launchpy module. Not everything is covered in the video.

Leave a Reply

Your email address will not be published. Required fields are marked *