]> git.alsa-project.org Git - alsa.git/commitdiff
hda-analyzer: update run.py to python3
authorJaroslav Kysela <perex@perex.cz>
Thu, 6 Apr 2023 07:19:03 +0000 (09:19 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 6 Apr 2023 07:19:03 +0000 (09:19 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
hda-analyzer/run.py

index 0456bf2d4fb93f499824a58270f65225f7fa62bc..42f4f2653f83a34934290cf8f7f40ca9b0762f85 100755 (executable)
@@ -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)