Changeset 2748

Show
Ignore:
Timestamp:
01/31/18 02:45:59 (6 years ago)
Author:
jwoithe
Message:

[PATCH 12/13] ffado-diag: tolerate python3 or missing external tools.

From Nicolas Boulenguez.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/support/tools/ffado-diag.in

    r2746 r2748  
    2323# 
    2424 
     25from __future__ import print_function 
    2526import sys 
    2627 
     
    108109        with open( "$PYTHONDIR/static_info.txt", "r" ) as f: 
    109110            for line in f: 
    110                 line = line[:-1] 
    111                 if line is not "\n" and line.startswith("  "): 
    112                     print (line) 
     111                if line.startswith("  "): 
     112                    print (line, end='') 
    113113    except: 
    114114        print ("Failed to read $PYTHONDIR/static_info.txt.") 
     
    117117 
    118118    print (" uname -a...") 
    119     print ("   " + run_command (('uname', '-a'))) 
     119    print ("   " + run_command_string (('uname', '-a'))) 
    120120 
    121121    print (" Hardware...") 
     
    124124    list_host_controllers() 
    125125    print ("   CPU info:") 
    126     if get_command_path('lscpu'): 
    127         print (run_command(('lscpu',))) 
    128     else: 
     126    try: 
     127        lscpu_path = run_command (('which', 'lscpu')).rstrip () 
     128        print (run_command_string ((lscpu_path,))) 
     129    except subprocess.CalledProcessError: 
    129130        with open ('/proc/cpuinfo') as f: 
    130131            for l in f: 
    131                 print (l.rstrip ()
     132                print (l, end=''
    132133 
    133134    print (" Configuration...") 
  • trunk/libffado/support/tools/ffado_diag_helpers.py

    r2746 r2748  
    1919# 
    2020 
     21from __future__ import print_function 
    2122import glob 
    2223import sys 
    2324import os 
     25import errno 
    2426import logging 
    2527import subprocess 
     
    112114        return False 
    113115 
    114 def run_command(cmd): 
    115     try: 
    116         outtext = subprocess.check_output (cmd).decode () 
    117     except: 
    118         return "" 
     116# Raise an exception for any problem. 
     117def run_command (cmd): 
     118    outtext = subprocess.check_output (cmd) 
     119    outtext = outtext.decode ('utf8') 
    119120    log.debug("%s outputs: %s" % (str (cmd), outtext)) 
    120121    return outtext 
    121122 
     123# Wrapper intercepting common exceptions and returning a string nevertheless. 
     124def run_command_string (cmd): 
     125    try: 
     126        return run_command (cmd) 
     127    except OSError, ( errorcode, emsg ): 
     128        if (errorcode == errno.ENOENT): 
     129            msg = "Not found" 
     130        else: 
     131            msg = "Failed to execute %s" % str (cmd) 
     132            log.warning (msg) 
     133        return msg 
     134    # Other errors are raised. 
     135    except subprocess.CalledProcessError: 
     136        msg = "Command %s returned a non-zero exit status" % str (cmd) 
     137        log.warning (msg) 
     138        return msg 
     139 
    122140# package versions 
    123141def get_package_version(name): 
    124     cmd = ('pkg-config', '--modversion', name) 
    125     return run_command(cmd) 
     142    return run_command_string (('pkg-config', '--modversion', name)) 
    126143 
    127144def get_package_flags(name): 
    128     cmd = ('pkg-config', '--cflags', '--libs', name) 
    129     return run_command(cmd) 
    130  
    131 def get_command_path(name): 
    132     cmd = ('which', name) 
    133     return run_command(cmd) 
     145    return run_command_string (('pkg-config', '--cflags', '--libs', name)) 
    134146 
    135147def get_version_first_line(cmd): 
    136     ver = run_command(cmd).split("\n"
    137     if len(ver) == 0: 
    138         ver = ["None"] 
    139     if "sh: " in ver[0]: 
    140         ver = ["Not found"] 
    141     return ver[0
     148    outtext = run_command_string (cmd
     149    i = outtext.find ("\n") 
     150    if i == -1: 
     151        return outtext 
     152    else: 
     153        return outtext [:i
    142154 
    143155def list_host_controllers(): 
    144     lspci_cmd = get_command_path("lspci") 
    145     if lspci_cmd == "": 
     156    try: 
     157        lspci_cmd = run_command (('which', 'lspci')).rstrip () 
     158    except subprocess.CalledProcessError: 
    146159        lspci_cmd = "/sbin/lspci" 
    147160    outtext = run_command ((lspci_cmd,)) 
     
    154167 
    155168def get_juju_permissions(): 
    156     return run_command(('ls', '-lh') + tuple(glob.glob ('/dev/fw*'))) 
     169    return run_command_string (['ls', '-lh'] + glob.glob ('/dev/fw*')) 
    157170 
    158171def get_user_ids(): 
    159     return run_command(('id',)); 
     172    return run_command_string (('id',)); 
    160173 
    161174def usage (): 
     
    183196    print("   PyQt5 (by pyuic5) . %s" % get_version_first_line(('pyuic5', '--version'))) 
    184197    print("   jackd ............. %s" % get_version_first_line(('jackd', '--version'))) 
    185     print("     path ............ %s" % get_command_path('jackd')
     198    print("     path ............ %s" % run_command_string (('which', 'jackd')), end=''
    186199    print("     flags ........... %s" % get_package_flags("jack")) 
    187200    print("   libraw1394 ........ %s" % get_package_version("libraw1394")) 
  • trunk/libffado/support/tools/listirqinfo.py

    r2743 r2748  
    5555    def load(self): 
    5656        # get PID info 
    57         outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')).decode (
     57        outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')).decode ('utf8'
    5858        rawstr = r"""([0-9]+) +\[IRQ-([0-9]+)\] +([A-Z]{2}) +([-0-9]+)""" 
    5959        compile_obj = re.compile(rawstr) 
     
    7272                IRQs[irq.number] = irq 
    7373 
    74         outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')).decode (
     74        outtext = subprocess.check_output (('ps', '-eLo', 'pid,cmd,class,rtprio')).decode ('utf8'
    7575        rawstr = r"""([0-9]+) +\[softirq-(.*)\] +([A-Z]+) +([-0-9]+)""" 
    7676        compile_obj = re.compile(rawstr)