1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HME for Python

Discussion in 'Developers Corner' started by wmcbrine, Jan 28, 2008.

  1. jcthorne

    jcthorne Active Member

    2,720
    2
    Jan 28, 2002
    Houston
    Tried that on the first line of the script and the result was just one more

    : not foundle Storage/temp/scripts/startHME.sh: line 4:

    thanks
     
  2. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I assume you just have a command line prompt on the NAS.

    There are several editors for Linux - I use vi because I have years of muscle memory that make it second nature to me. It's quite arcane though and I wouldn't want to try to explain it.

    Most if not all linux/unix environments at least have good old ed line editor - this is what we used to program with years ago.

    make a copy of your file, and try the following:
    ed startHME.sh
    1,$s/.$//
    w
    q

    that should strip the last character off of every line - then give it a try
     
  3. jcthorne

    jcthorne Active Member

    2,720
    2
    Jan 28, 2002
    Houston
    ed is not found on the NAS. I did find vi and a pretty good tutorial on it online. For what little I need to do I think this will work. I opened the script with vi and there was a ^M at the end of each line. I removed them, saved the file and ran it from the command line. Executed without error, I think we are getting somewhere. I just rebooted the NAS with the script in place to run...


    SUCCESS!!!

    Thank you, Thank you, thank you.

    pytivo, HME for python with vidmgr all started from bootup and work!

    Whew.

    Next step is a java runtime for harmonium but I want to complete a backup of the server before going that far. I have a Java SE for x86 embeded from Oracle that another user has expressed sucess with so....

    but thanks again. to everyone. Learned alot in the last few days.
     
  4. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    I use vi (or actually, the updated version, vim) a lot, in Linux, Solaris, and HP-UX. If you intend to use ssh to manage the files on the NAS, I suggest you get familiar with vi / vim. You could also probably implement XDMCP or an X Client solution on the NAS server along with an X server like Xming running on a Windows machine. Another alternative, however is to implement a *nix friendly Windows editor along with an integrated FTP client in order to handle file editing on the Linux box. I recommend FileZilla and Edit Plus.
     
  5. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    Glad to have been of help
     
  6. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    Well, he has it working, but to respond to your question, the answer is, "Yes, but No."

    Unless they are doing something that I would not expect, the user login uses Busybox as its interactive shell, but init does not. Indeed, init does not employ an interactive shell. This means that inherently bootup procedures do not act in quite the same way as a user shell. That's one reason why for any service I want to start I create a run script with bash as the interpreter and call the run script from the init script. Things like nohup, environment variables, and redirection don't always work as one might expect in an init script. It also happens to be easier under Debian (or in your case, Ubuntu) to make very simple, fairly uniform modifications to the skeleton init script and then put all the details in the run script.
     
  7. jcthorne

    jcthorne Active Member

    2,720
    2
    Jan 28, 2002
    Houston
    Irhorer,

    I just wanted to say thanks for your detailed answers to my questions. I learned a lot from your posts. Some, I may not know what I learned until later but I will come back to them.
     
  8. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    That's lrhorer, if you please, not irhorer.

    You are very welcome. Linux is an extremely flexible and powerful operating system, but consequently it is also enormously sophisticated. Frequently it offers simple ways to skin any cat, but it also offers lots of them, which means there's a lot to know and a lot to learn.
     
  9. Jul 2, 2011 #189 of 231
    Iluvatar

    Iluvatar New Member

    377
    0
    Jul 22, 2006
    I have a suggestion for wmcbrine's code in pyhme. I have had issues running pyhme on startup with the full path command (eg. 'python /Applications/pyhme/start.py') which of course fails to properly read the config file. The default suggested way to run this is to change to the pyhme directory first and then run 'python start.py' but this gives difficulties when trying to start at login ( I know jcthorne had similar issues on his Synology NAS device)

    My suggested code change is this which should fix my issue and allow proper full path execution:

    In start.py at line 307 change
    Code:
    config = SafeConfigParser()
    config.read('config.ini')
    
    to
    Code:
    config = SafeConfigParser()
        
    p = os.path.dirname(__file__)
    config_file = [os.path.join(p, 'config.ini')]
    config.read(config_file)
    
    This fix seems to work great for me and allows me to use my startup scripts unedited with just the full path. This should work on other devices to such as jcthorne's Synology that he had trouble with getting to work.
     
  10. Jul 3, 2011 #190 of 231
    jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I run the delivered HME code, as is, on my Netgear readynas. I have a shell that, among other things, changes into the proper directory and then invokes "python start.py". The shell is what I invoke in my startup.
     
  11. Jul 4, 2011 #191 of 231
    Iluvatar

    Iluvatar New Member

    377
    0
    Jul 22, 2006
    It works for my specific situation and I just thought I would share. Since I have seen another user who had expressed the same issues I figured it may be useful.
     
  12. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    I'm having an isue with the applications not writing to the log file. Errors like traceback calls are properly logged, but the ordinary text output is not. I daemonize the app during startup, redirecting its output to a log file like so:

    Code:
    #! /bin/bash
    PIDFILE=/var/run/pyHME.pid
    RUNDIR=/usr/share/pyhme
    LOGFILE=/var/log/pyhme.log
    ERRFILE=/var/log/pyhme.err
    cd $RUNDIR
    /usr/bin/nohup $RUNDIR/start.py > $LOGFILE 2> $ERRFILE &
    echo $! > $PIDFILE
    exit 0
    I've tried both the above - writing to separate log files and also writing to a combined logfile by invoking 2>&1. Neither works properly

    One Linux guru has suggested it might be because the app is opening a tty, rather than writing to stdout. I don't think that's the case, because

    Code:
    $RUNDIR/start.py > $LOGFILE 2> $ERRFILE
    works just fine. The problem of course is that does not daemonize the application. Does anyone have any ideas?

    I do the same thing, BTW for pyTivo, the only obvious difference being with pyTivo, I invoke python directly in the nohup call, rather than running a script with python as the interpreter. I suppose I could try the same thing here, but I was wondering if anyone else had any ideas?

    Edit: I tried invoking Python, rather than using the embedded interpreter in the start.py file, but it doesn't seem to work.
     
  13. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    Perhaps it would help to clarify a bit. I do get some info. For example, I get this from vidmgr:

    Code:
    192.168.1.103:42051 - - [22/Jul/2011 18:07:50] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] "GET /vidmgr/ HTTP/1.1" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] Starting HME: vidmgr
    192.168.1.103:42052 - - [22/Jul/2011 18:08:13] Ending HME: vidmgr
    192.168.1.103:42094 - - [22/Jul/2011 18:08:17] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    I don't, however, get the plain text messages from vidmgr or the regular messages from HME like this:

    Code:
    HME Server for Python 0.19
    Fri Jul 22 18:10:23 2011 PyTivo Video Manager version 0.7b starting
    Loading thumbnail cache
    100 thumbnails loaded from cache
    Fri Jul 22 18:10:23 2011 Server Starts
    Registering: vidmgr
     
  14. wmcbrine

    wmcbrine Ziphead

    10,364
    22
    Aug 2, 2003
    So, your stderr is being redirected, but not your stdout? Because that's all stdout stuff there (which you're trying to send to pyhme.log).

    Probably just a question of buffering, then.
     
  15. jbernardis

    jbernardis New Member

    1,072
    0
    Oct 21, 2003
    Princeton NJ
    I could certainly add a flush to vidmgr to see if it was a buffering issue. I'm away for the weekend, but will be a able to try something sunday evening.
     
  16. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    Well, sort of. By default, nohup redirects stderr to stdin, so that any output sent to those two ports should get re-directed to the same target. Also by default, nohup creates a file named nohup.out where the outputs are sent. Explicitly redirecting any or all of these will override the default. This is all seemingly working properly, as long as I don't detach the process (using "&"). With no explicit redirection, nohup creates the nohup.out file and sends stdout and stderr to it. If I explicitly redirect only stdout, then nohup.out is not created and both streams go to the file specified by the redirection. If I explicitly redirect only stderr, then nohup.put is created and stdout goes to it, while stderr goes to the specified file. If I explicitly redirect both streams, then they each go to the file(s) specifically named in the redirect, and once again nohup.out is not created. This all works as documented in the nohup man page. When I detach the process using "&", however, the stdout evaporates.

    Wel, I don't know what it is supposed to be, but if I redirect stdout to pyhme.log and stderr to pyhme.err via the following

    Code:
    /usr/bin/nohup $RUNDIR/start.py > $LOGFILE 2> $ERRFILE
    then

    Code:
    HME Server for Python 0.19
    Fri Jul 22 18:10:23 2011 PyTivo Video Manager version 0.7b starting
    Loading thumbnail cache
    100 thumbnails loaded from cache
    Fri Jul 22 18:10:23 2011 Server Starts
    Registering: vidmgr
    shows up in pyhme.log, and

    Code:
    192.168.1.103:42051 - - [22/Jul/2011 18:07:50] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] "GET /vidmgr/ HTTP/1.1" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] Starting HME: vidmgr
    192.168.1.103:42052 - - [22/Jul/2011 18:08:13] Ending HME: vidmgr
    192.168.1.103:42094 - - [22/Jul/2011 18:08:17] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    shows up in pyhme.err. If I redirect both to pyhme.log via the following

    Code:
    /usr/bin/nohup $RUNDIR/start.py > $LOGFILE
    then both show up in pyhme.log, or if I don't redirect anything, then nohup shoves them both to nohup.out, all as it should be. When I detach the process using "&", then this

    Code:
    HME Server for Python 0.19
    Fri Jul 22 18:10:23 2011 PyTivo Video Manager version 0.7b starting
    Loading thumbnail cache
    100 thumbnails loaded from cache
    Fri Jul 22 18:10:23 2011 Server Starts
    Registering: vidmgr
    disappears.

    Howso?
     
  17. lrhorer

    lrhorer New Member

    6,922
    0
    Aug 31, 2003
    San...
    Hmm. Isn't this:

    Code:
    HME Server for Python 0.19
    from HME for Python, not vidmgr? If so, how would flushing the vidmgr buffers help, and why doesn't subsequent text from vidmgr come through? What's more, I am having trouble seeing how an unflushed buffer could eliminate text on both sides (separated by several minutes) of

    Code:
    192.168.1.103:42051 - - [22/Jul/2011 18:07:50] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] "GET /vidmgr/ HTTP/1.1" 200 -
    192.168.1.103:42052 - - [22/Jul/2011 18:07:55] Starting HME: vidmgr
    192.168.1.103:42052 - - [22/Jul/2011 18:08:13] Ending HME: vidmgr
    192.168.1.103:42094 - - [22/Jul/2011 18:08:17] "GET /vidmgr/icon.png HTTP/1.0" 200 -
    yet allows the stuff in the middle through.
     
  18. jwagner010

    jwagner010 New Member

    73
    0
    Dec 8, 2007
    Does anyone have a simple python program developed that shows a list of menu items on the Tivo that when selected executes a sub process that I can leverage?
     
  19. Mar 2, 2012 #199 of 231
    jwagner010

    jwagner010 New Member

    73
    0
    Dec 8, 2007
    I found a TIVO HME App that provides a Tivo menu based on a properties file that then executes URLs from that properties file. See URLMenu on this page http://david.blackledge.com/tivo/

    urlmenu.properties should have entries like so:
    My\ First\ Menu=http://url.to.be.executed.com/with/other?information
    My\ Second\ Menu=http://url.to.be.executed.com/with/other?information

    Problem is it is based on the the JAVA HME not Python HME. I would like to build a similar app/plugin for the Python HME but do not know Python. Does anyone know of a similar app or can point me in the right direction to try and figure it out bearing in mind I have very basic programing skills (1980's basic) and zero of that is with Python.

    PS. rather than execute URLs it would be good if it can execute OS commands, and if I want a URL to be executed I can do a wget or curl.
     
  20. Mar 2, 2012 #200 of 231
    wmcbrine

    wmcbrine Ziphead

    10,364
    22
    Aug 2, 2003
    OK. Why then?

    Take a look at HME/VLC for one way to do menus...
     

Share This Page