Ejemplo n.º 1
0
def mpdallexit():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1  and  (sys.argv[1] == '-h'  or  sys.argv[1] == '--help') :
        print __doc__
        sys.exit(-1)
    mpd_set_my_id(myid='mpdallexit')

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd' : 'mpdallexit' }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=8.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
    elif msg['cmd'] != 'mpdallexit_ack':
        mpd_print(1,'unexpected msg from mpd :%s:' % (msg) )
        sys.exit(-1)
    conSock.close()
Ejemplo n.º 2
0
def mpdtrace():
    import sys  # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1:
        if (sys.argv[1] == '-h'
                or sys.argv[1] == '--help') or (sys.argv[1] != '-l'):
            usage()
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdtrace')

    parmdb = MPDParmDB(
        orderedSources=['cmdline', 'xml', 'env', 'rcfile', 'thispgm'])
    parmsToOverride = {
        'MPD_USE_ROOT_MPD': 0,
        'MPD_SECRETWORD': '',
    }
    for (k, v) in parmsToOverride.items():
        parmdb[('thispgm', k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os, 'getuid')
            and os.getuid() == 0) or parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(
            sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName, 'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,
                                   secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {'cmd': 'mpdtrace'}
    conSock.send_dict_msg(msgToSend)
    # Main Loop
    done = 0
    while not done:
        msg = conSock.recv_dict_msg(timeout=5.0)
        if not msg:  # also get this on ^C
            mpd_print(1, 'got eof on console')
            sys.exit(-1)
        elif not msg.has_key('cmd'):
            print 'mpdtrace: unexpected msg from mpd=:%s:' % (msg)
            sys.exit(-1)
        if msg['cmd'] == 'mpdtrace_info':
            if len(sys.argv) > 1 and sys.argv[1] == '-l':
                print '%s (%s)' % (msg['id'], msg['ifhn'])
            else:
                pos = msg['id'].find('.')
                if pos < 0:
                    pos = msg['id'].rfind('_')
                print msg['id'][:pos]  # strip off domain and port
        elif msg['cmd'] == 'mpdtrace_trailer':
            done = 1
    conSock.close()
Ejemplo n.º 3
0
def mpdkilljob():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) < 2  or  sys.argv[1] == '-h'  or  sys.argv[1] == '--help':
        usage()
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdkilljob')
    mpdid = ''
    if sys.argv[1] == '-a':
        jobalias = sys.argv[2]
        jobnum = '0'
    else:
        jobalias = ''
        jobid = sys.argv[1]
        sjobid = jobid.split('@')
        jobnum = sjobid[0]
        if len(sjobid) > 1:
            mpdid = sjobid[1]

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd':'mpdkilljob', 'jobnum' : jobnum, 'mpdid' : mpdid,
                  'jobalias' : jobalias, 'username' : mpd_get_my_username() }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
        sys.exit(-1)
    if msg['cmd'] != 'mpdkilljob_ack':
        if msg['cmd'] == 'already_have_a_console':
            print 'mpd already has a console (e.g. for long ringtest); try later'
        else:
            print 'unexpected message from mpd: %s' % (msg)
        sys.exit(-1)
    if not msg['handled']:
        print 'job not found'
        sys.exit(-1)
    conSock.close()
Ejemplo n.º 4
0
def mpdallexit():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1  and  (sys.argv[1] == '-h'  or  sys.argv[1] == '--help') :
        print __doc__
        sys.exit(-1)
    mpd_set_my_id(myid='mpdallexit')

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd' : 'mpdallexit' }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=8.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
    elif msg['cmd'] != 'mpdallexit_ack':
        mpd_print(1,'unexpected msg from mpd :%s:' % (msg) )
        sys.exit(-1)
    conSock.close()
Ejemplo n.º 5
0
def mpdringtest():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1  and  ( sys.argv[1] == '-h'  or  sys.argv[1] == '--help' ) :
        usage()
    if len(sys.argv) < 2: 
	numLoops = 1
    else:
	numLoops = int(sys.argv[1])
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdringtest')

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd' : 'mpdringtest', 'numloops' : numLoops }
    conSock.send_dict_msg(msgToSend)
    starttime = time()
    msg = conSock.recv_dict_msg()
    etime = time() - starttime
    if not msg:
        print 'mpdringtest terminated early'
    elif msg['cmd'] != 'mpdringtest_done':
        if msg['cmd'] == 'already_have_a_console':
            print 'mpd already has a console (e.g. for long ringtest); try later'
        else:
            print 'unexpected message from mpd: %s' % (msg)
    else:
	print 'time for %d loops =' % numLoops, etime, 'seconds' 
Ejemplo n.º 6
0
def mpdexit():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if (len(sys.argv) > 1  and  (sys.argv[1] == '-h'  or  sys.argv[1] == '--help')) or \
       (len(sys.argv) < 2):
	print __doc__
        sys.exit(-1)
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdexit')

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd' : 'mpdexit', 'mpdid' : sys.argv[1] }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
        sys.exit(-1)
    elif msg['cmd'] == 'already_have_a_console':
        mpd_print(1,'mpd already has a console (e.g. for long ringtest); try later')
        sys.exit(-1)
    if not msg.has_key('cmd'):
        mpd_print(1,'mpdexit: INVALID msg=:%s:' % (msg))
        sys.exit(-1)
    if msg['cmd'] != 'mpdexit_ack':
        mpd_print(1,'mpdexit failed; may have wrong mpdid')
        sys.exit(-1)
Ejemplo n.º 7
0
def mpdkilljob():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) < 2  or  sys.argv[1] == '-h'  or  sys.argv[1] == '--help':
        usage()
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdkilljob')
    mpdid = ''
    if sys.argv[1] == '-a':
        jobalias = sys.argv[2]
        jobnum = '0'
    else:
        jobalias = ''
        jobid = sys.argv[1]
        sjobid = jobid.split('@')
        jobnum = sjobid[0]
        if len(sjobid) > 1:
            mpdid = sjobid[1]

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd':'mpdkilljob', 'jobnum' : jobnum, 'mpdid' : mpdid,
                  'jobalias' : jobalias, 'username' : mpd_get_my_username() }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
        sys.exit(-1)
    if msg['cmd'] != 'mpdkilljob_ack':
        if msg['cmd'] == 'already_have_a_console':
            print 'mpd already has a console (e.g. for long ringtest); try later'
        else:
            print 'unexpected message from mpd: %s' % (msg)
        sys.exit(-1)
    if not msg['handled']:
        print 'job not found'
        sys.exit(-1)
    conSock.close()
Ejemplo n.º 8
0
def mpdtrace():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1:
        if (sys.argv[1] == '-h' or sys.argv[1] == '--help') or (sys.argv[1] != '-l'):
            usage()
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdtrace')

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os,'getuid')  and  os.getuid() == 0)  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = { 'cmd' : 'mpdtrace' }
    conSock.send_dict_msg(msgToSend)
    # Main Loop
    done = 0
    while not done:
        msg = conSock.recv_dict_msg(timeout=5.0)
        if not msg:    # also get this on ^C
            mpd_print(1, 'got eof on console')
            sys.exit(-1)
        elif not msg.has_key('cmd'):
            print 'mpdtrace: unexpected msg from mpd=:%s:' % (msg)
            sys.exit(-1)
        if msg['cmd'] == 'mpdtrace_info':
            if len(sys.argv) > 1 and sys.argv[1] == '-l':
                print '%s (%s)' % (msg['id'],msg['ifhn'])
            else:
                pos = msg['id'].find('.')
                if pos < 0:
                    pos = msg['id'].rfind('_')
                print msg['id'][:pos]    # strip off domain and port
        elif msg['cmd'] == 'mpdtrace_trailer':
            done = 1
    conSock.close()
Ejemplo n.º 9
0
def mpdexit():
    import sys  # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if (len(sys.argv) > 1  and  (sys.argv[1] == '-h'  or  sys.argv[1] == '--help')) or \
       (len(sys.argv) < 2):
        print __doc__
        sys.exit(-1)
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdexit')

    parmdb = MPDParmDB(
        orderedSources=['cmdline', 'xml', 'env', 'rcfile', 'thispgm'])
    parmsToOverride = {
        'MPD_USE_ROOT_MPD': 0,
        'MPD_SECRETWORD': '',
    }
    for (k, v) in parmsToOverride.items():
        parmdb[('thispgm', k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os, 'getuid')
            and os.getuid() == 0) or parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(
            sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName, 'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,
                                   secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {'cmd': 'mpdexit', 'mpdid': sys.argv[1]}
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1, 'no msg recvd from mpd before timeout')
        sys.exit(-1)
    elif msg['cmd'] == 'already_have_a_console':
        mpd_print(
            1, 'mpd already has a console (e.g. for long ringtest); try later')
        sys.exit(-1)
    if not msg.has_key('cmd'):
        mpd_print(1, 'mpdexit: INVALID msg=:%s:' % (msg))
        sys.exit(-1)
    if msg['cmd'] != 'mpdexit_ack':
        mpd_print(1, 'mpdexit failed; may have wrong mpdid')
        sys.exit(-1)
Ejemplo n.º 10
0
def mpdringtest():
    import sys  # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(sys.argv) > 1 and (sys.argv[1] == '-h' or sys.argv[1] == '--help'):
        usage()
    if len(sys.argv) < 2:
        numLoops = 1
    else:
        numLoops = int(sys.argv[1])
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdringtest')

    parmdb = MPDParmDB(
        orderedSources=['cmdline', 'xml', 'env', 'rcfile', 'thispgm'])
    parmsToOverride = {
        'MPD_USE_ROOT_MPD': 0,
        'MPD_SECRETWORD': '',
    }
    for (k, v) in parmsToOverride.items():
        parmdb[('thispgm', k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os, 'getuid')
            and os.getuid() == 0) or parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(
            sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName, 'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,
                                   secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {'cmd': 'mpdringtest', 'numloops': numLoops}
    conSock.send_dict_msg(msgToSend)
    starttime = time()
    msg = conSock.recv_dict_msg()
    etime = time() - starttime
    if not msg:
        print 'mpdringtest terminated early'
    elif msg['cmd'] != 'mpdringtest_done':
        if msg['cmd'] == 'already_have_a_console':
            print 'mpd already has a console (e.g. for long ringtest); try later'
        else:
            print 'unexpected message from mpd: %s' % (msg)
    else:
        print 'time for %d loops =' % numLoops, etime, 'seconds'
Ejemplo n.º 11
0
def mpdlistjobs():
    import sys  # to get access to excepthook in next line

    sys.excepthook = mpd_uncaught_except_tb
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid="mpdlistjobs")
    uname = ""
    jobid = ""
    sjobid = ""
    jobalias = ""
    sssPrintFormat = 0
    if len(sys.argv) > 1:
        aidx = 1
        while aidx < len(sys.argv):
            if sys.argv[aidx] == "-h" or sys.argv[aidx] == "--help":
                usage()
            if sys.argv[aidx] == "-u":  # or --user=
                uname = sys.argv[aidx + 1]
                aidx += 2
            elif sys.argv[aidx].startswith("--user"):
                splitArg = sys.argv[aidx].split("=")
                try:
                    uname = splitArg[1]
                except:
                    print "mpdlistjobs: invalid argument:", sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == "-j":  # or --jobid=
                jobid = sys.argv[aidx + 1]
                aidx += 2
                sjobid = jobid.split("@")  # jobnum and originating host
            elif sys.argv[aidx].startswith("--jobid"):
                splitArg = sys.argv[aidx].split("=")
                try:
                    jobid = splitArg[1]
                    sjobid = jobid.split("@")  # jobnum and originating host
                except:
                    print "mpdlistjobs: invalid argument:", sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == "-a":  # or --alias=
                jobalias = sys.argv[aidx + 1]
                aidx += 2
            elif sys.argv[aidx].startswith("--alias"):
                splitArg = sys.argv[aidx].split("=")
                try:
                    jobalias = splitArg[1]
                except:
                    print "mpdlistjobs: invalid argument:", sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == "--sss":
                sssPrintFormat = 1
                aidx += 1
            else:
                print "unrecognized arg: %s" % sys.argv[aidx]
                sys.exit(-1)

    parmdb = MPDParmDB(orderedSources=["cmdline", "xml", "env", "rcfile", "thispgm"])
    parmsToOverride = {"MPD_USE_ROOT_MPD": 0, "MPD_SECRETWORD": ""}
    for (k, v) in parmsToOverride.items():
        parmdb[("thispgm", k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os, "getuid") and os.getuid() == 0) or parmdb["MPD_USE_ROOT_MPD"]:
        fullDirName = os.path.abspath(os.path.split(sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName, "mpdroot")
        conSock = MPDConClientSock(mpdroot=mpdroot, secretword=parmdb["MPD_SECRETWORD"])
    else:
        conSock = MPDConClientSock(secretword=parmdb["MPD_SECRETWORD"])

    msgToSend = {"cmd": "mpdlistjobs"}
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1, "no msg recvd from mpd before timeout")
    if msg["cmd"] != "local_mpdid":  # get full id of local mpd for filters later
        mpd_print(1, "did not recv local_mpdid msg from local mpd; instead, recvd: %s" % msg)
    else:
        if len(sjobid) == 1:
            sjobid.append(msg["id"])
    done = 0
    while not done:
        msg = conSock.recv_dict_msg()
        if not msg.has_key("cmd"):
            mpd_print(1, "mpdlistjobs: INVALID msg=:%s:" % (msg))
            sys.exit(-1)
        if msg["cmd"] == "mpdlistjobs_info":
            smjobid = msg["jobid"].split("  ")  # jobnum, mpdid, and alias (if present)
            if len(smjobid) < 3:
                smjobid.append("")
            print_based_on_uname = 0  # default
            print_based_on_jobid = 0  # default
            print_based_on_jobalias = 0  # default
            if not uname or uname == msg["username"]:
                print_based_on_uname = 1
            if not jobid and not jobalias:
                print_based_on_jobid = 1
                print_based_on_jobalias = 1
            else:
                if sjobid and sjobid[0] == smjobid[0] and sjobid[1] == smjobid[1]:
                    print_based_on_jobid = 1
                if jobalias and jobalias == smjobid[2]:
                    print_based_on_jobalias = 1
            if not smjobid[2]:
                smjobid[2] = "          "  # just for printing
            if print_based_on_uname and (print_based_on_jobid or print_based_on_jobalias):
                if sssPrintFormat:
                    print "%s %s %s" % (msg["host"], msg["clipid"], msg["sid"])
                else:
                    print "jobid    = %s@%s" % (smjobid[0], smjobid[1])
                    print "jobalias = %s" % (smjobid[2])
                    print "username = %s" % (msg["username"])
                    print "host     = %s" % (msg["host"])
                    print "pid      = %s" % (msg["clipid"])
                    print "sid      = %s" % (msg["sid"])
                    print "rank     = %s" % (msg["rank"])
                    print "pgm      = %s" % (msg["pgm"])
                    print
        else:  # mpdlistjobs_trailer
            done = 1
    conSock.close()
Ejemplo n.º 12
0
def mpdlistjobs():
    import sys  # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    signal.signal(signal.SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdlistjobs')
    uname = ''
    jobid = ''
    sjobid = ''
    jobalias = ''
    sssPrintFormat = 0
    if len(sys.argv) > 1:
        aidx = 1
        while aidx < len(sys.argv):
            if sys.argv[aidx] == '-h' or sys.argv[aidx] == '--help':
                usage()
            if sys.argv[aidx] == '-u':  # or --user=
                uname = sys.argv[aidx + 1]
                aidx += 2
            elif sys.argv[aidx].startswith('--user'):
                splitArg = sys.argv[aidx].split('=')
                try:
                    uname = splitArg[1]
                except:
                    print 'mpdlistjobs: invalid argument:', sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == '-j':  # or --jobid=
                jobid = sys.argv[aidx + 1]
                aidx += 2
                sjobid = jobid.split('@')  # jobnum and originating host
            elif sys.argv[aidx].startswith('--jobid'):
                splitArg = sys.argv[aidx].split('=')
                try:
                    jobid = splitArg[1]
                    sjobid = jobid.split('@')  # jobnum and originating host
                except:
                    print 'mpdlistjobs: invalid argument:', sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == '-a':  # or --alias=
                jobalias = sys.argv[aidx + 1]
                aidx += 2
            elif sys.argv[aidx].startswith('--alias'):
                splitArg = sys.argv[aidx].split('=')
                try:
                    jobalias = splitArg[1]
                except:
                    print 'mpdlistjobs: invalid argument:', sys.argv[aidx]
                    usage()
                aidx += 1
            elif sys.argv[aidx] == '--sss':
                sssPrintFormat = 1
                aidx += 1
            else:
                print 'unrecognized arg: %s' % sys.argv[aidx]
                sys.exit(-1)

    parmdb = MPDParmDB(
        orderedSources=['cmdline', 'xml', 'env', 'rcfile', 'thispgm'])
    parmsToOverride = {
        'MPD_USE_ROOT_MPD': 0,
        'MPD_SECRETWORD': '',
    }
    for (k, v) in parmsToOverride.items():
        parmdb[('thispgm', k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if (hasattr(os, 'getuid')
            and os.getuid() == 0) or parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = os.path.abspath(os.path.split(
            sys.argv[0])[0])  # normalize
        mpdroot = os.path.join(fullDirName, 'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,
                                   secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {'cmd': 'mpdlistjobs'}
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1, 'no msg recvd from mpd before timeout')
    if msg['cmd'] != 'local_mpdid':  # get full id of local mpd for filters later
        mpd_print(
            1,
            'did not recv local_mpdid msg from local mpd; instead, recvd: %s' %
            msg)
    else:
        if len(sjobid) == 1:
            sjobid.append(msg['id'])
    done = 0
    while not done:
        msg = conSock.recv_dict_msg()
        if not msg.has_key('cmd'):
            mpd_print(1, 'mpdlistjobs: INVALID msg=:%s:' % (msg))
            sys.exit(-1)
        if msg['cmd'] == 'mpdlistjobs_info':
            smjobid = msg['jobid'].split(
                '  ')  # jobnum, mpdid, and alias (if present)
            if len(smjobid) < 3:
                smjobid.append('')
            print_based_on_uname = 0  # default
            print_based_on_jobid = 0  # default
            print_based_on_jobalias = 0  # default
            if not uname or uname == msg['username']:
                print_based_on_uname = 1
            if not jobid and not jobalias:
                print_based_on_jobid = 1
                print_based_on_jobalias = 1
            else:
                if sjobid and sjobid[0] == smjobid[0] and sjobid[1] == smjobid[
                        1]:
                    print_based_on_jobid = 1
                if jobalias and jobalias == smjobid[2]:
                    print_based_on_jobalias = 1
            if not smjobid[2]:
                smjobid[2] = '          '  # just for printing
            if print_based_on_uname and (print_based_on_jobid
                                         or print_based_on_jobalias):
                if sssPrintFormat:
                    print "%s %s %s" % (msg['host'], msg['clipid'], msg['sid'])
                else:
                    print 'jobid    = %s@%s' % (smjobid[0], smjobid[1])
                    print 'jobalias = %s' % (smjobid[2])
                    print 'username = %s' % (msg['username'])
                    print 'host     = %s' % (msg['host'])
                    print 'pid      = %s' % (msg['clipid'])
                    print 'sid      = %s' % (msg['sid'])
                    print 'rank     = %s' % (msg['rank'])
                    print 'pgm      = %s' % (msg['pgm'])
                    print
        else:  # mpdlistjobs_trailer
            done = 1
    conSock.close()
Ejemplo n.º 13
0
def mpdsigjob():
    import sys  # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(argv) < 3 or argv[1] == '-h' or argv[1] == '--help':
        usage()
    signal(SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdsigjob')
    sigtype = argv[1]
    if sigtype.startswith('-'):
        sigtype = sigtype[1:]
    if sigtype.startswith('SIG'):
        sigtype = sigtype[3:]
    import signal as tmpsig  # just to get valid SIG's
    if sigtype.isdigit():
        if int(sigtype) > tmpsig.NSIG:
            print 'invalid signum: %s' % (sigtype)
            exit(-1)
    else:
        if not tmpsig.__dict__.has_key('SIG' + sigtype):
            print 'invalid sig type: %s' % (sigtype)
            exit(-1)
    jobalias = ''
    jobnum = ''
    mpdid = ''
    single_or_group = 'g'
    i = 2
    while i < len(argv):
        if argv[i] == '-a':
            if jobnum:  # should not have both alias and jobid
                print '** cannot specify both jobalias and jobid'
                usage()
            jobalias = argv[i + 1]
            i += 1
            jobnum = '0'
        elif argv[i] == '-j':
            if jobalias:  # should not have both alias and jobid
                print '** cannot specify both jobalias and jobid'
                usage()
            jobid = argv[i + 1]
            i += 1
            sjobid = jobid.split('@')
            jobnum = sjobid[0]
            if len(sjobid) > 1:
                mpdid = sjobid[1]
        elif argv[i] == '-s':
            single_or_group = 's'
        elif argv[i] == '-g':
            single_or_group = 'g'
        else:
            print '** unrecognized arg: %s' % (argv[i])
            usage()
        i += 1

    parmdb = MPDParmDB(
        orderedSources=['cmdline', 'xml', 'env', 'rcfile', 'thispgm'])
    parmsToOverride = {
        'MPD_USE_ROOT_MPD': 0,
        'MPD_SECRETWORD': '',
    }
    for (k, v) in parmsToOverride.items():
        parmdb[('thispgm', k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if getuid() == 0 or parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = path.abspath(path.split(argv[0])[0])  # normalize
        mpdroot = path.join(fullDirName, 'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,
                                   secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {
        'cmd': 'mpdsigjob',
        'sigtype': sigtype,
        'jobnum': jobnum,
        'mpdid': mpdid,
        'jobalias': jobalias,
        's_or_g': single_or_group,
        'username': mpd_get_my_username()
    }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1, 'no msg recvd from mpd before timeout')
    if msg['cmd'] != 'mpdsigjob_ack':
        if msg['cmd'] == 'already_have_a_console':
            mpd_print(
                1,
                'mpd already has a console (e.g. for long ringtest); try later'
            )
        else:
            mpd_print(1, 'unexpected message from mpd: %s' % (msg))
        exit(-1)
    if not msg['handled']:
        print 'job not found'
        exit(-1)
    conSock.close()
Ejemplo n.º 14
0
def mpdsigjob():
    import sys    # to get access to excepthook in next line
    sys.excepthook = mpd_uncaught_except_tb
    if len(argv) < 3  or  argv[1] == '-h'  or  argv[1] == '--help':
        usage()
    signal(SIGINT, sig_handler)
    mpd_set_my_id(myid='mpdsigjob')
    sigtype = argv[1]
    if sigtype.startswith('-'):
        sigtype = sigtype[1:]
    if sigtype.startswith('SIG'):
        sigtype = sigtype[3:]
    import signal as tmpsig  # just to get valid SIG's
    if sigtype.isdigit():
        if int(sigtype) > tmpsig.NSIG:
            print 'invalid signum: %s' % (sigtype)
            exit(-1)
    else:
	if not tmpsig.__dict__.has_key('SIG' + sigtype):
	    print 'invalid sig type: %s' % (sigtype)
	    exit(-1)
    jobalias = ''
    jobnum = ''
    mpdid = ''
    single_or_group = 'g'
    i = 2
    while i < len(argv):
        if argv[i] == '-a':
            if jobnum:      # should not have both alias and jobid
                print '** cannot specify both jobalias and jobid'
                usage()
            jobalias = argv[i+1]
            i += 1
            jobnum = '0'
        elif argv[i] == '-j':
            if jobalias:    # should not have both alias and jobid
                print '** cannot specify both jobalias and jobid'
                usage()
            jobid = argv[i+1]
            i += 1
            sjobid = jobid.split('@')
            jobnum = sjobid[0]
            if len(sjobid) > 1:
                mpdid = sjobid[1]
        elif argv[i] == '-s':
            single_or_group = 's'
        elif argv[i] == '-g':
            single_or_group = 'g'
        else:
            print '** unrecognized arg: %s' % (argv[i])
            usage()
        i += 1

    parmdb = MPDParmDB(orderedSources=['cmdline','xml','env','rcfile','thispgm'])
    parmsToOverride = {
                        'MPD_USE_ROOT_MPD'            :  0,
                        'MPD_SECRETWORD'              :  '',
                      }
    for (k,v) in parmsToOverride.items():
        parmdb[('thispgm',k)] = v
    parmdb.get_parms_from_env(parmsToOverride)
    parmdb.get_parms_from_rcfile(parmsToOverride)
    if getuid() == 0  or  parmdb['MPD_USE_ROOT_MPD']:
        fullDirName = path.abspath(path.split(argv[0])[0])  # normalize
        mpdroot = path.join(fullDirName,'mpdroot')
        conSock = MPDConClientSock(mpdroot=mpdroot,secretword=parmdb['MPD_SECRETWORD'])
    else:
        conSock = MPDConClientSock(secretword=parmdb['MPD_SECRETWORD'])

    msgToSend = {'cmd' : 'mpdsigjob', 'sigtype': sigtype, 'jobnum' : jobnum,
                 'mpdid' : mpdid, 'jobalias' : jobalias, 's_or_g' : single_or_group,
                 'username' : mpd_get_my_username() }
    conSock.send_dict_msg(msgToSend)
    msg = conSock.recv_dict_msg(timeout=5.0)
    if not msg:
        mpd_print(1,'no msg recvd from mpd before timeout')
    if msg['cmd'] != 'mpdsigjob_ack':
        if msg['cmd'] == 'already_have_a_console':
            mpd_print(1,'mpd already has a console (e.g. for long ringtest); try later')
        else:
            mpd_print(1,'unexpected message from mpd: %s' % (msg) )
        exit(-1)
    if not msg['handled']:
        print 'job not found'
        exit(-1)
    conSock.close()