- Code: Select all
import sys, subprocess
print "sys.argv: %s " % str(sys.argv)
if len(sys.argv) != 2:
print "Usage: restart_plugin.py /path/to/plugin/plugin.indigoPlugin\n"
else:
plugin_id = sys.argv[1]
print "calling restart_plugin with '%s'" % plugin_id
plugin_script = '''plugin = indigo.server.getPlugin("%s")
if plugin.isEnabled():
plugin.restart()
return "Plugin %s restarted"
else:
return "Plugin %s isn't enabled"
''' % (plugin_id, plugin_id, plugin_id)
plugin_host_path = "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/MacOS/IndigoPluginHost"
subprocess.call([plugin_host_path, "-e", plugin_script])
Save it to your hard drive somewhere. I call it restart_plugin.py. Basically, it's a wrapper around an Indigo script to restart a plugin. Of course, Indigo Python scripts have to be run in a IndigoPluginHost process, not a regular Python interpreter. So, the script just takes a plugin ID from the command line, substitutes it into the Indigo Python script, and executes it from the IndigoPluginHost process.
Once you have it saved somewhere, open your plugin in PyCharm and create a run configuration by selecting the Run->Edit Configurations menu item. You'll get the Run/Debug Configurations dialog:
You probably won't have any configurations, so you'll just see Defaults in the left outline view. Click the "+" button above that outline view, and select the Python option from the list. That will create an Unnamed configuration. On the right side, give it a name (I call mine restart_plugin), then click the "..." button after the Script label and select the file you created above. Insert your plugin's ID into the Script parameters field. Finally, from the Python interpreter field, select the Python 2.7 (or 2.6) interpreter. Apply and OK the dialog. Now, in the icon bar at the top right, you should see your configuration in the popup beside the run and debug buttons. Click the run button and it'll restart your plugin.
Have fun!