From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B367B45C24 for ; Sun, 26 Mar 2023 21:35:12 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AB59768C604; Mon, 27 Mar 2023 00:35:09 +0300 (EEST) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E80568C513 for ; Mon, 27 Mar 2023 00:35:03 +0300 (EEST) Received: by mail-wr1-f46.google.com with SMTP id m2so6742944wrh.6 for ; Sun, 26 Mar 2023 14:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679866501; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1mTBpKTXP9cm+vx1MjR2pW+jfVXjKnNJ+91i+N5K60c=; b=DQ/Q08uPXwqoHIexJfCOPgYokVhxHGsoLFyjRn/6rrIxyrkIGx18bFDhjXYO+fgXgI 3IzqjclNeSwDU3vGQ3tvS6jXnm/wbDAF93RFRxNTROLGLJCSIWijw713YMgxgINQ3E19 D8Fkw6YaZs9CychSwF1UZa6qQZ7k3WSqafKXLYyI5qYRTFlee8/nDC8RWiXG6V6LWLnE s9ggWi8jOV3CU7UZi1bDgTMFzwxm4p09NPn/j7bhbb5sPZGQ6VN+gA5Mt1pgYCc0vR2f idhhHgJFi35OUVXL7QuyaWnzFv6pX9YrU+R5rRr1gYO032NaHT7B1MxFOH6RefRWE8Ox v7sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679866501; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1mTBpKTXP9cm+vx1MjR2pW+jfVXjKnNJ+91i+N5K60c=; b=QcGITSiRmN+f3hq+3Bj7Tg5Hg+sb1mGjkOQ6i2k3qxYlxv0BZK97nO3e6UtdoFDGxr sBIjZcFbDrLtVJx7gYRMuvL3zsyFuqBaZjaWFUuJKKvnsoqN2viXp0Fn14Vk89ypKT2A vS1L6ORuJ+hsighngGClBRggnUTLms7R/Z+S/hrCVIF3gNDxGJxDbb8uKmen+z2lG9+h ZB2TM4Fwv7qwWeDvF8hdGuc8h8vVEdoZ5Lf3GvWOQS6kLfoo6RI/pl4MziBrFlQtJBws 1yIM9hNidFmvdVc1/eldnS1MS05kpy5vIB9KgV+m3SbOr01peG+g2wkLjrbOHFvwtizF D49w== X-Gm-Message-State: AAQBX9cqvdOa2GF0+Yhu6A7/7Cs2lzEM6g1sPR3BfgYNuHocyUdvVfoP mrIxoYOJ61MiT/LXrj6oN1/H6KVcdhc= X-Google-Smtp-Source: AKy350adgr2ea+a695lPePbWC4LIaCR3Bt/XQhjqNMa/b4xYX6W30dIb7V+ewMLWzO2Fn8ed9fnDVQ== X-Received: by 2002:adf:eb0b:0:b0:2d8:4e4:8cf1 with SMTP id s11-20020adfeb0b000000b002d804e48cf1mr7222268wrn.21.1679866501233; Sun, 26 Mar 2023 14:35:01 -0700 (PDT) Received: from mariano (dynamic-adsl-62-10-98-143.clienti.tiscali.it. [62.10.98.143]) by smtp.gmail.com with ESMTPSA id g9-20020a5d4889000000b002c559843748sm23405434wrq.10.2023.03.26.14.35.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 14:35:00 -0700 (PDT) Received: by mariano (Postfix, from userid 1000) id 921BFBFB73; Sun, 26 Mar 2023 23:34:59 +0200 (CEST) From: Stefano Sabatini To: FFmpeg development discussions and patches Date: Sun, 26 Mar 2023 23:34:59 +0200 Message-Id: <20230326213459.90011-1-stefasab@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] tools/zmqshell: port to python3 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Stefano Sabatini Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Also extend docs, use argparse and logging. --- tools/zmqshell.py | 63 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/tools/zmqshell.py b/tools/zmqshell.py index a7d1126006..8d941636e1 100755 --- a/tools/zmqshell.py +++ b/tools/zmqshell.py @@ -1,6 +1,32 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 + +import argparse +import cmd +import logging +import sys +import zmq + +HELP = ''' +Provide a shell used to send interactive commands to a zmq filter. + +The command assumes there is a running zmq or azmq filter acting as a +ZMQ server. + +You can send a command to it, follwing the syntax: +TARGET COMMAND [COMMAND_ARGS] + +* TARGET is the target filter identifier to send the command to +* COMMAND is the name of the command sent to the filter +* COMMAND_ARGS is the optional specification of command arguments + +See the zmq/azmq filters documentation for more details, and the +zeromq documentation at: +https://zeromq.org/ +''' + +logging.basicConfig(format='zmqshell|%(levelname)s> %(message)s', level=logging.INFO) +log = logging.getLogger() -import sys, zmq, cmd class LavfiCmd(cmd.Cmd): prompt = 'lavfi> ' @@ -14,13 +40,28 @@ class LavfiCmd(cmd.Cmd): def onecmd(self, cmd): if cmd == 'EOF': sys.exit(0) - print 'Sending command:[%s]' % cmd - self.requester.send(cmd) - message = self.requester.recv() - print 'Received reply:[%s]' % message - -try: - bind_address = sys.argv[1] if len(sys.argv) > 1 else "tcp://localhost:5555" - LavfiCmd(bind_address).cmdloop('FFmpeg libavfilter interactive shell') -except KeyboardInterrupt: + log.info(f"Sending command: {cmd}") + self.requester.send_string(cmd) + response = self.requester.recv_string() + log.info(f"Received response: {response}") + + +class Formatter( + argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter +): pass + + +def main(): + parser = argparse.ArgumentParser(description=HELP, formatter_class=Formatter) + parser.add_argument('--bind-address', '-b', default='tcp://localhost:5555', help='specify bind address used to communicate with ZMQ') + + args = parser.parse_args() + try: + LavfiCmd(args.bind_address).cmdloop('FFmpeg libavfilter interactive shell') + except KeyboardInterrupt: + pass + + +if __name__ == '__main__': + main() -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".