First plugin - no log errors - doesn't show up on channel list

So I’m trying my hand at a very simple plugin that allows me to shutdown my linux media server from my roku or whatever else I’m watching it on at the time.



I downloaded VideoRip and used it as a basis since I want to do kind of the same, launch a linux CLI command. Figured the best way was to just edit something else and go from there.



I did all my code, only changed what I had to and removed the rest. I am a programmer by trade but not too versed in Python, so I’m probably missing something silly and simple ha ha.



I grepped the logs but there is nothing after I restart plexmediaserver from the cli:



…/Logs$: grep -R ‘Micro’ *



This returned nothing, so there are no logs as to my plugin not starting or anything, but it still won’t show up in my channel list. I tried adding VideoRip to my plugins dir and that does show up. So it’s not the starting point that’s bad.



For sake of simplicity I have just uploaded it to Github. Could someone give me a hand here at what in the world I am missing :frowning: Thanks.

GitHub - jfreak53/MicroShutDown.bundle



Gits being stupid right now so it might not come up right away :frowning:

I’m getting ready to start my first plugin, but real quick looking over your code you have:





dir.Append(Function(DirectoryItem(EjectDisc, title=“Shutdown”)))



Shouldn’t it be:



dir.Append(Function(DirectoryItem(ShutDown, title=“Shutdown”)))

DOH!!! I thought for sure I changed that line!! ha ha thanks, let me try it now to see if it works now :slight_smile: I’ll post back in a second.

Nope, still not in my list :frowning:



Only thing in my logs are:



Plex Media Server.old.log:Nov 30, 2012 14:04:52 [0xb23f5b40] DEBUG - Starting plug-in /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins/MicroShutDown.bundle.

I read somewhere if an unsupported plugin doesn’t show up in the list, you have to disable the capability checking. Could be your problem?

Let me give it a try, but doesn’t that mean that no-one else will ever be able to use it either without disabling compat checking? :frowning:

Nope still not there :frowning:

I’d install the original that you worked off of and see if that shows up and then slowly add your code back in. Other than that I’m not sure. I’m surprised its not kicking the error out.

The original I started with was VideoRip, and yeah as my OP said it works just fine when I add VideoRip. I’ll re-install it now and see if I can do it that way, thanks.

Ok, that worked :slight_smile: I was missing:

@handler("/applications/microshutdown", “Turn off Server”)



Ok so now that is working, I can even click on the icon in the list of channels and it goes to my channel and displays my title and a short bar to click on. Problem now is that when I click on the bar I get:

This channel is currently unavailable.



Again, I have grepped the logs and I can’t find anything for that plugin with an error :frowning:



I should mention I am doing this from the servers web interface: IP:32400/web



All other plugins work from here but this doesn’t. Any thoughts? Now it add’s itself but the script won’t run :frowning:

I deal much with helper scripts in plugins but, I believe they need to be in a specific directory structure within the Helpers folder. That may or may not be the only issue causing you trouble. As I recall, debug logging via the plugin framework for helper scripts is dodgy at best.



eg.


<br />
Plugin.bundle/<br />
	-Contents/<br />
		-Code/<br />
			-__init__.py<br />
		-Helpers/<br />
			-MacOSX/<br />
				-i386/<br />
					-helper_name.sh<br />
		-Resources/<br />
			-icon-default.png<br />
			-art-default.jpg<br />
		-Info.plist<br />


Well let me ask you this, the command I am running is a One Line Command :slight_smile: is there anything I can run instead of helpers.run to just run a system command?



I also found out that if I replace:



return



with


return "text"



I don't get the error, I just get a blank page. But the other thing is I decided to try and see if I could comment the entire function and run a string to return, so I ran this after commenting the entire function:


return MessageContainer("Title", "Text")



I didn't get anything back but a blank page! :) So what's wrong with this, shouldn't that display a message? From what I got from other plugins just return "text" should display that text right?

So two questions remain, one how do I return text to myself to check if the function is working? Two, is there something I can use instead of helper scripts to run a system command?

Thanks :)

I’m also getting this stupid blankness:



http://i.imgur.com/YaJHV.jpg



Instead of the text and icon for the menu item :frowning: So maybe it’s all botched up somehow :frowning:



EDIT: That blank line after the title is the button that I end up clicking, I guess supposed to be the menu item without text ha ha

To be perfectly honest, I have never developed a plugin using the web client for testing. Partially because the web client is so new and partially because I know that plugin support isn’t fully implemented yet so it’s hard to know at first if the issues are actual problems with the plugin or lack of support from the client. I almost always test my plugins using PMC (and iOS if there’s something specific I want to test for compatibility). If you want to make sure that something is doing what it should, or try to pin down where it’s failing, the plugin log is the best place to check. If you’re on a Mac, you can find it just by opening Console and browsing the folder of PMS plugin logs. On Windows, the log files are inside the application support folder for Plex Media Server. Check my sig for a link on how to find them. Simple Log() statements in the plugin code can be very useful for debugging.

In terms of a way to control the system directly via the plugin rather than using a helper script… I would look into what commands are available via Python’s “os” module. You’ll need to use the “elevated” code policy for your plugin (which I imagine VideoRip already was) to be able to import the module. I’m not sure it has the necessary capabilities but IMO it’s worth looking in to.

Well here’s what I found out last night :slight_smile: I ran it on PMC on my phone and the menu items come up just fine :slight_smile:



Settings menu item is there but when clicked nothing happens ha ha. The other menu item is there with an icon and text and all, yey! ha ha



But when clicked it just pops up a message that says the plugin can’t be found :frowning:



I have checked the logs and there are zero errors at all for this plugin, so it’s probably because there is no error it’s just bad code somehow ha ha. So how do I use the Log() function in my plugin to output something at least?



I am going to install PMC into my WinXP VirtualBox so I can test this thing, since I use pure Ubuntu for everything even my personal computers I don’t want to be using the beta Linux Client to test either.



Other problem I just found last night is that my plugin doesn’t appear in the channel list on my Roku?! Is this because I have it at “/applications/microshutdown”, should I make it for videos instead?? Will it still work if I do that?



The whole point of this thing is to use on my Roku or any other box around the house to shutdown the media center system at the end of the day :frowning:



Thanks for all the advise.



I did find the os.system(‘open’) code awhile back in AppTV but it wouldn’t work for me, so I’ll try it again and see what happens now when I use a client.



Thanks.

Ok, I changed helpers out for os.system, NOW IT WORKS! :slight_smile: I also had to edit sudoers and add plex user as a sudoer for shutdown but it works :slight_smile:



Two problems still, one is I can’t get into the preferences screen, the button is there but it won’t go in. I get an error on my droid client that it can’t find the server, if I ignore it goes back to the main screen of plex and I can go back in but preferences won’t come up :frowning:



Second problem is it still isn’t on the Roku channels list :frowning:



I have this in the Info.plist:



<key>PlexClientPlatforms</key><br />
<string>*</string>



But no go, do I need to change it to Video type instead of Applications type? Will the os commands still work like that? :(

Thanks, so never use helpers ha ha ha I have uploaded my most recent code to GIT for anyone who wants this sweet little thing :) I haven't made it work for Windows yet since I can't get preferences to work but as soon as that works I will make it work for windows also.

The Roku client doesn’t display “application”-type plugins. Switching it to video should make it available on the Roku. I’ll take a peak at your updated code to see if I can spot a reason for the Preferences failing.

Looking at the code, I can see a couple things that might cause problems. The first and the most likely culprit is that your Info.plist identifies the plugin as using v1 of the plugin framework. From the looks of it, the code is basically v2. That combined with the fact that you’ve got an empty “Defaults.xml” as well as the “DefaultPrefs.json” is likely confusing the plugin framework as to which one it’s supposed to try to read. IIRC, the Defaults.xml format is for v1 and the DefaultPrefs.json is for v21 and beyond. So, delete the Defaults.xml file and change the Info.plist:


<br />
<key>PlexFrameworkVersion</key><br />
<string>1</string><br />



to

<br />
<key>PlexFrameworkVersion</key><br />
<string>2</string><br />



Also, FYI, a lot of the stuff in the plist is garbage and can be removed for clarity's sake. It won't hurt anything by being there but if you want to do some cleanup, you can remove all the key-string pairs other than "CFBundleIdentifier", "PlexClientPlatforms", and "PlexFrameworkVersion".

As to your question about how to use the Log() function: All it takes is a string. ie. Log("Running Shutdown command") or Log("Done") . That will show up in the plugin log as long as the code is executed, whereas your

return "Done"

will likely confuse clients if it gets executed. I would suggest changing the final line of the Shutdown function to something like this:


<br />
return MessageContainer("MicroShutDown", "Shutdown command executed" Goodbye.")<br />



I don't know what kind of time delay there is between executing the os.system shutdown command and PMS becoming unavailable. There's a good chance that it doesn't really matter what you put in the return line since it won't get executed but, if it does get executed, then having a proper MessageContainer returned will be less likely to cause problems for PMS and the client(s).

Aha, so it’s like JS Console.log function and Java’s ha ha. Cool :slight_smile: thanks.



Now a new problem ha ha, I edited all you said and removed other’s. I left only the 3 you stated in the plist file. Now it won’t display on my Channel screen at all ha ha and I’m getting this error:



Plex Media Server.old.log:Dec 01, 2012 10:27:42 [0xb4bfab40] ERROR - Error reading from plug-in [com.plexapp.plugins.microshutdown], we're killing it (got: '').<br />
Plex Media Server.old.log:Dec 01, 2012 10:27:42 [0xb4bfab40] DEBUG - Stopping [com.plexapp.plugins.microshutdown].<br />
Plex Media Server.old.log:Dec 01, 2012 10:27:42 [0xb4bfab40] DEBUG - [com.plexapp.plugins.microshutdown] Killing.<br />
Plex Media Server.old.log:Dec 01, 2012 10:27:42 [0xb4bfab40] ERROR - Error received reading configuration for com.plexapp.plugins.microshutdown<br />
Plex Media Server.old.log:Dec 01, 2012 10:27:42 [0xb4bfab40] DEBUG - Stopping [com.plexapp.plugins.microshutdown].



So now it's actually reading the config file finally ha ha but now my app isn't there ha ha ha

Here is my config file:


[<br />
	{   <br />
		"id":           "system",<br />
		"label":        "Operating System",<br />
		"type":         "enum",<br />
		"values":       ["Linux", "Windows"],<br />
		"default":      "Linux"<br />
	}<br />
]



Not quite sure what's wrong in there :( I tried changing ID system to microos but still no go. I also tried removing the config file all together and same deal.

Any thoughts what I botched now :( I've uploaded my most recent code to Github also.

Man this is getting crazy! ha ha First it works then when it finally reads the Config file it doesn't ha ha.

Thanks for all your help with this, I promise next time I make one I won't be such a pain ha ha

Using your latest code from Github, I get the following error in the plugin log when trying to run it:


<br />
2012-12-01 11:05:28,291 (-53b255d8) :  CRITICAL (core:602) - Exception starting plug-in (most recent call last):<br />
  File "/Users/iMacDen/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/core.py", line 595, in start<br />
    self.sandbox.execute(self.init_code)<br />
  File "/Users/iMacDen/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 256, in execute<br />
    exec(code) in self.environment<br />
  File "/Users/iMacDen/Library/Application Support/Plex Media Server/Plug-ins/MicroShutDown.bundle/Contents/Code/__init__.py", line 2, in <module><br />
    from PMS import *<br />
  File "/Users/iMacDen/Library/Application Support/Plex Media Server/Plug-ins/Framework.bundle/Contents/Resources/Versions/2/Python/Framework/code/sandbox.py", line 345, in __import__<br />
    raise e<br />
ImportError: No module named PMS<br />





Which makes a little sense, since the other import lines you have are not necessary when using the v2 plugin framework:


<br />
from PMS import *<br />
from PMS.Objects import *<br />
from PMS.Shortcuts import *



Remove those lines and you should be up and running again.