[mythtv-users] User Jobs Problems Processing Command Line Options in Python

Ian Barton lists at manor-farm.org
Wed Oct 1 10:57:42 UTC 2008

I am writing a user job script in Python. This works correctly when run
from a terminal. However, as a user job the Python getopt library seems
to be throwing a wobbly.

Sample code (write_log_entry writes debugging stuff to a text file):


        opts, args = getopt.getopt(sys.argv[1:], "hfvcs:v", ["help",
"filename=", "video-dir=", "channel-id=", "start-time="])
        write_log_entry("Before opt")
        for opt, arg in opts:
            write_log_entry("arg" + arg)
            if opt in ("-h", "--help"):
            elif opt in ("-f", "--filename"):
                filename = arg
            elif opt in ("-v", "--video-dir"):
                videodir = arg
            elif opt in ("-c", "--channel-id"):
                channel = arg
            elif opt in ("-s", "--start-time"):
                starttime = arg
    except getopt.GetoptError, err:
        write_log_entry("Error parsing command line: " + str(err))
        print str(err)

My user job is:

/usr/local/bin/test.py -f %FILE% -v %DIR%  -c %CHANID%  -s "%STARTTIME%"

Sample output from the debug file:

2008-10-01 11:46:05: Before opt
2008-10-01 11:46:05: arg%FILENAME%
2008-10-01 11:46:05: arg
2008-10-01 11:46:05: After for opt

Python is only seeing one argument, not four and %FILE% isn't being
expanded into a file name. I presume that sys.argv doesn't contain what
I think it does. Anyone got any suggestions?


More information about the mythtv-users mailing list