From c599ccda7fbdd7e01fd592f6aabf1ad842b0ccd3 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 6 Apr 2023 09:19:03 +0200 Subject: [PATCH] hda-analyzer: update run.py to python3 Signed-off-by: Jaroslav Kysela --- hda-analyzer/run.py | 47 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/hda-analyzer/run.py b/hda-analyzer/run.py index 0456bf2..42f4f26 100755 --- a/hda-analyzer/run.py +++ b/hda-analyzer/run.py @@ -1,44 +1,45 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -URL="http://git.alsa-project.org/?p=alsa.git;a=blob_plain;f=hda-analyzer/" +URL="http://git.alsa-project.org/?p=alsa.git;a=blob_plain;f=hda-analyzer" FILES=["hda_analyzer.py", "hda_guilib.py", "hda_codec.py", "hda_proc.py", "hda_graph.py", "hda_mixer.py"] try: - import gobject - import gtk - import pango + import gi + gi.require_version("Gtk", "3.0") + from gi.repository import GObject + from gi.repository import Gtk + from gi.repository import Pango except: - print "Please, install pygtk2 or python-gtk package" + print("Please, install python3-gobject package") import os import sys -from urllib import splithost -from httplib import HTTP +from urllib.request import urlopen if os.path.exists("/dev/shm"): TMPDIR="/dev/shm" else: TMPDIR="/tmp" TMPDIR += "/hda-analyzer" -print "Using temporary directory: %s" % TMPDIR -print "You may remove this directory when finished or if you like to" -print "download the most recent copy of hda-analyzer tool." +print("Using temporary directory: %s" % TMPDIR) +print("You may remove this directory when finished or if you like to") +print("download the most recent copy of hda-analyzer tool.") if not os.path.exists(TMPDIR): os.mkdir(TMPDIR) for f in FILES: dest = TMPDIR + '/' + f if os.path.exists(dest): - print "File cached " + dest + print("File cached " + dest) continue - print "Downloading file %s" % f - host, selector = splithost(URL[5:]) - h = HTTP(host) - h.putrequest('GET', URL + f) - h.endheaders() - h.getreply() - contents = h.getfile().read(2*1024*1024) - h.close() - open(dest, "w+").write(contents) -print "Downloaded all files, executing %s" % FILES[0] -os.system("python %s" % TMPDIR + '/' + FILES[0] + ' ' + ' '.join(sys.argv[1:])) + print(f"Downloading file {f}") + with urlopen(f"{URL}/{f}") as response: + contents = response.read() + open(dest, "wb+").write(contents) +print(f"Downloaded all files") +args = ' '.join(sys.argv[1:]) +if args: + args = f" {args}" +cmd = f"python3 {TMPDIR}/{FILES[0]}{args}" +print(f"Invoking '{cmd}'") +os.system(cmd) -- 2.47.1