Skip to content

Instantly share code, notes, and snippets.

@tblong
Created September 28, 2016 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tblong/0f694647505ed090ba42ea77e71e2c06 to your computer and use it in GitHub Desktop.
Save tblong/0f694647505ed090ba42ea77e71e2c06 to your computer and use it in GitHub Desktop.
Migrates PX page history view related chart button hyperlinks to use new N4 ChartWidget view
#
# This script crawls through any PX files found under the directory in which
# this script is executed. Any BoundLabelBinding found in the PX page which is related to a history
# hyperlink pointing to a history view will be modified to use an EnhancedHyperlinkBinding
# from the vykonPro jar file. This is generally meant to be used when there is an AX supervisor converted
# to N4. This script essentially upgrades all chart buttons to use the new N4 history ChartWidget view.
#
# IMPORTANT: Backup all PX files before executing this script.
#
# Instructions:
# 1. Install python v2.7 on target machine
# 2. Place this script in the directory in which to search for all px files
# 3. BACKUP ALL PX PAGES
# 4. Modify script to use foxs in new attributes below if required
# 4. Execute this script
#
# @author tblong
# @license MIT
# @version 2016-09-27
#
import xml.etree.ElementTree as ET
import os
def find_px_files():
"""
:return: a list of px files in the current and child directories
where this program is executing.
"""
result = []
for root, dirs, files in os.walk(os.curdir):
for f in files:
if f.endswith('.px'):
result.append(os.path.join(root, f))
return result
def parse_px_file(px_file):
"""
:param px_file: the px file to parse
:return: None
"""
tree = ET.ElementTree(file=px_file)
chart_found = False
# find all BoundLabels first
bound_labels = tree.iter(tag='BoundLabel')
# check for a BoundLabelBinding child
for label in bound_labels:
blb = label.find('BoundLabelBinding')
if blb is not None:
# check if bound label binding has hyperlink attrib
hyperlink = blb.get('hyperlink')
if hyperlink:
# check if hyperlink attrib is history related
hyperlink_split = hyperlink.split('|')
if len(hyperlink_split) > 1 and hyperlink_split[1].startswith('view:history'):
# found a history related bound label binding
chart_found = True
# remove the original bound label binding
label.remove(blb)
# add new EnhancedHyperlinkBinding element
ord = hyperlink_split[0]
attribs = {
'ord': ord,
'hyperlinkFormat': 'local:|fox:|history:%historyConfig.id%'
}
enhanced_binding_elm = ET.Element(tag='EnhancedHyperlinkBinding', attrib=attribs)
label.append(enhanced_binding_elm)
# write to file if at least one history chart button found
if chart_found:
tree.write(px_file)
def main():
px_files = find_px_files()
for f in px_files:
parse_px_file(f)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment