Skip to content

Commit

Permalink
- Adds foundation for API 3.2.
Browse files Browse the repository at this point in the history
- Adds some clarity on how to handle filenames with spaces in them.
- Code cleanup.
  • Loading branch information
DaveL17 committed May 13, 2023
1 parent a90e1ec commit a62ee5d
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 520 deletions.
4 changes: 2 additions & 2 deletions GhostXML.indigoPlugin/Contents/Info.plist
Expand Up @@ -3,9 +3,9 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2022.1.1</string>
<string>2022.2.1</string>
<key>ServerApiVersion</key>
<string>3.0</string>
<string>3.2</string>
<key>IwsApiVersion</key>
<string>1.0.0</string>
<key>LoadPriority</key>
Expand Down
6 changes: 3 additions & 3 deletions GhostXML.indigoPlugin/Contents/Server Plugin/Devices.xml
Expand Up @@ -68,7 +68,7 @@
</Field>

<Field id="label1" type="label" fontSize="small" alignWithControl="true">
<Label>Examples:&#xA;URL: http://www.ip_address.com/filename.xml&#xA;URL: https://www.ip_address.com/filename.xml&#xA;URL: ftp://www.ip_address.com/filename.xml&#xA;Local file: file:///folder_path/filename.json</Label>
<Label>Examples:&#xA;URL: http://www.ip_address.com/filename.xml&#xA;URL: https://www.ip_address.com/filename.xml&#xA;URL: ftp://www.ip_address.com/filename.xml&#xA;Local file: file:///folder_path/filename.json&#xA;Local file: file:///folder_path/filename%20with%20spaces.json</Label>
</Field>

<!-- Authentication -->
Expand Down Expand Up @@ -290,7 +290,7 @@
</Field>

<Field id="label1" type="label" fontSize="small" alignWithControl="true">
<Label>Examples:&#xA;URL: http://www.ip_address.com/filename.xml&#xA;URL: https://www.ip_address.com/filename.xml&#xA;URL: ftp://www.ip_address.com/filename.xml&#xA;Local file: file:///folder_path/filename.json</Label>
<Label>Examples:&#xA;URL: http://www.ip_address.com/filename.xml&#xA;URL: https://www.ip_address.com/filename.xml&#xA;URL: ftp://www.ip_address.com/filename.xml&#xA;Local file: file:///folder_path/filename.json&#xA;Local file: file:///folder_path/filename%20with%20spaces.json</Label>
</Field>

<!-- Authentication -->
Expand Down Expand Up @@ -383,7 +383,7 @@
</Field>

<Field id="subExample" type="label" fontSize="small" alignWithControl="true" visibleBindingId="doSubs" visibleBindingValue="true">
<Label>Examples:&#xA;URL: https://www.ip_address.com/[A].xml&#xA;Local file: file:///[A]/[B].json</Label>
<Label>Examples:&#xA;URL: http://www.ip_address.com/filename.xml&#xA;URL: https://www.ip_address.com/filename.xml&#xA;URL: ftp://www.ip_address.com/filename.xml&#xA;Local file: file:///folder_path/filename.json&#xA;Local file: file:///folder_path/filename%20with%20spaces.json</Label>
</Field>

<!-- Curl Substitutions -->
Expand Down
5 changes: 5 additions & 0 deletions GhostXML.indigoPlugin/Contents/Server Plugin/MenuItems.xml
Expand Up @@ -11,6 +11,11 @@
<CallbackMethod>comms_unkill_all</CallbackMethod>
</MenuItem>

<MenuItem id="print_environment_info" uiPath="plugin_tools">
<Name>Display Plugin Information</Name>
<CallbackMethod>log_plugin_environment</CallbackMethod>
</MenuItem>

<MenuItem id="titleSeparator" type="separator"/>

<MenuItem id="refresh_data">
Expand Down
Expand Up @@ -59,7 +59,7 @@
<Field id="space07" type="label" fontSize="mini" alignWithControl="True">
<Label>Debugging Messages - Step by step plugin logging.
Informational Messages - Useful information about plugin health.
Warning Messages - Typically temporary conditions.
Warning Messages - Typically temporary conditions (recommended).
Error Messages - Conditions you might want to address.
Critical Errors Only - Critical errors should probably be reported.
</Label>
Expand Down
30 changes: 11 additions & 19 deletions GhostXML.indigoPlugin/Contents/Server Plugin/iterateXML.py
Expand Up @@ -7,7 +7,6 @@
Credit for update_shim(): https://stackoverflow.com/users/3871670/adam-clark
Credit for flatten_dict(): https://codereview.stackexchange.com/users/1659/winston-ewert
"""
# import xml.etree.ElementTree as ElementTree # FIXME - delete
from xml.etree import ElementTree

try:
Expand Down Expand Up @@ -41,8 +40,8 @@ def __init__(self, parent_element):
# This line modded to use new element.tag + '_Attribs'.
self.update_shim({element_tag_attribs: dict(element.items())})
else:
# WAS: _self.update_shim({element.tag: element.text.strip()})_ with strip(),
# the function will choke on some XML. 'NoneType' object has no attribute 'strip'.
# WAS: _self.update_shim({element.tag: element.text.strip()})_ with strip(), the function will choke on
# some XML. 'NoneType' object has no attribute 'strip'.
self.update_shim({element.tag: element.text})

def update_shim(self, a_dict): # noqa
Expand Down Expand Up @@ -94,53 +93,46 @@ def iterate_main(root): # noqa

final_dict[key] = value

# See if any 'value' is another list. These lists may contain information for more
# values we want--for example, when there are multiple instances of the same tag
# (with different attributes or values.)
# See if any 'value' is another list. These lists may contain information for more values we want--for
# example, when there are multiple instances of the same tag (with different attributes or values.)
if isinstance(value, list):

# If any lists found contain a dictionary, iterate over that dictionary and make
# more key/value pairs. Also, this may need more counters depending on the
# depth of the source XML data. Right now it only goes so deep.
# If any lists found contain a dictionary, iterate over that dictionary and make more key/value pairs.
# Also, this may need more counters depending on the depth of the source XML data. Right now it only
# goes so deep.
counter = 1
for value_item in value:

if isinstance(value_item, dict):
for (value_key1, value1) in value_item.items():
# new_key1 = u'%s_%s_%s' % (key, counter, value_key1) # FIXME - delete
new_key1 = f"{key}_{counter}_{value_key1}"
final_dict[new_key1] = value1

if isinstance(value1, dict):
for (value_key2, value2) in value1.items():
# new_key2 = u'%s_%s_%s_%s' % (key, counter, value_key1, value_key2) # FIXME - delete
new_key2 = f"{key}_{counter}_{value_key1}_{value_key2}"
final_dict[new_key2] = value2

if isinstance(value2, dict):
for (value_key3, value3) in value2.items():
# new_key3 = u'%s_%s_%s_%s' % (key, counter, value_key2, value_key3) # FIXME - delete
new_key3 = f"{key}_{counter}_{value_key2}_{value_key3}"
final_dict[new_key3] = value3
counter += 1

# We may be left with values that contain lists of duplicates. Take the first one
# and leave the rest.
# We may be left with values that contain lists of duplicates. Take the first one and leave the rest.
for (key, value) in final_dict.items():
if isinstance(value, list):
final_dict[key] = value[0]

# Find any remaining dicts, and delete them. This operation should ultimately
# determine if all the dict items have already been pulled out to ensure that we
# don't lose anything.
# Find any remaining dicts, and delete them. This operation should ultimately determine if all the dict items
# have already been pulled out to ensure that we don't lose anything.
iter_dict = final_dict.copy()
for (key, value) in iter_dict.items():
if isinstance(value, dict):

del final_dict[key]

# Now that we're done, get rid of the placeholder Attribs tag component since we don't
# need it anymore.
# Now that we're done, get rid of the placeholder Attribs tag component since we don't need it anymore.
iter_dict = final_dict.copy()
for (key, value) in iter_dict.items():
del final_dict[key]
Expand Down

0 comments on commit a62ee5d

Please sign in to comment.