Связывать командные строки с ключами

Питон-скрипт от Адама - это то, что мне нужно. Brilliant. Rygel с gst-launch не работает с одним из моих рендерингов, но этот скрипт работает с обоими. В моем случае я беру аудиопоток ввода из squeezelite (для squeezebox) и отправки в средство визуализации.

Зная немного об этом, мне удалось внести некоторые дополнения в скрипт, который:

i) позволить ему запускаться из сценария оболочки и заканчиваться с помощью SIGTERM / SIGKILL (теперь оператор «except» включает в себя «systemexit»)

ii) позволяет остановить и перезапустить сценарий и повторно использовать один и тот же порт (поскольку это был перезапущенный скрипт, как правило, отказался, заявив, что он не смог открыть порт, если средство визуализации все еще открыло его) - (allow_reuse_address = True)

iii) make версия, которая принимает входные данные из stdin и вытесняет его с помощью sox для вывода в формате wav (на порту 8082)

Итак, моя версия выглядит так:

#!/usr/bin/python

import BaseHTTPServer
import SocketServer
import subprocess

PORT = 8082

MIMETYPE = 'audio/x-wav'
BUFFER = 65536

class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
  def do_HEAD(s):
    print s.client_address, s.path, s.command
    s.send_response(200)
    s.send_header('content-type', MIMETYPE)
    s.end_headers()
  def do_GET(s):
    s.do_HEAD()
    pa = subprocess.Popen('sox -t raw -r 96000 -b 24 -L -e signed -c 2 - -t wav -r 44100 -b 16 -L -e signed -c 2 - ', shell = True, bufsize = BUFFER, stdout = subprocess.PIPE)
    while True:
        data = pa.stdout.read(1024)
        if len(data) == 0: break
        s.wfile.write(data)
    print 'stream closed'

SocketServer.TCPServer.allow_reuse_address = True
httpd = SocketServer.TCPServer(("", PORT), Handler)

print "listening on port", PORT

try:
 httpd.serve_forever()

except (KeyboardInterrupt, SystemExit):
 pass

httpd.server_close()
1
задан 7 August 2013 в 17:30

1 ответ

Для меня в соответствии с http://ubuntuforums.org/archive/index.php/t-1680158.html этот прием работает:

xdotool key --clearmodifiers XF86MonBrightnessDown

И из man xdtool это означает следующее:

CLEARMODIFIERS
   Any command taking the --clearmodifiers flag will attempt to clear any
   active input modifiers during the command and restore them afterwards.

   For example, if you were to run this command:
    xdotool key a

   The result would be 'a' or 'A' depending on whether or not you were
   holding the shift key on your keyboard. Often it is undesirable to have
   any modifiers active, so you can tell xdotool to clear any active
   modifiers.

   The order of operations if you hold shift while running 'xdotool key
   --clearmodifiers a' is this:

   1. Query for all active modifiers (finds shift, in this case)
   2. Try to clear shift by sending 'key up' for the shift key
   3. Runs normal 'xdotool key a'
   4. Restore shift key by sending 'key down' for shift

   The --clearmodifiers flag can currently clear of the following:

   ·   any key in your active keymap that has a modifier associated with
       it.  (See xmodmap(1)'s 'xmodmap -pm' output)

   ·   mouse buttons (1, 2, 3, 4, and 5)

   ·   caps lock
0
ответ дан 24 May 2018 в 19:16

Другие вопросы по тегам:

Похожие вопросы: