pygame / config / libconfig.py

import subprocess
from config import msys, helpers
try:
    msys_obj = msys.Msys (require_mingw=False)
except:
    msys_obj = None

def run_command (cmd):
    try:
        retcode, output = 0, None
        if msys.is_msys():
            retcode, output = msys_obj.run_shell_command (cmd)
        else:
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            output = p.communicate()[0]
            retcode = p.returncode
        if helpers.getversion()[0] >= 3:
            output = str (output, "utf-8")
        return retcode, output
    except OSError:
        return -1, None

def exec_config(libconfig, flags):
    cmd = [libconfig, flags]
    return run_command (cmd)[1].split ()

def get_incdirs(libconfig):
    flags = exec_config (libconfig, "--cflags")
    newflags = []
    for f in flags:
        if f.startswith ('-I'):
            newflags.append (f[2:])
    return newflags

def get_cflags(libconfig):
    flags = exec_config (libconfig, "--cflags")
    newflags = []
    for f in flags:
        if f.startswith ('-I'):
            continue
        newflags.append (f)
    return newflags

def get_libdirs(libconfig):
    flags = exec_config (libconfig, "--libs")
    newflags = []
    for f in flags:
        if f.startswith ('-L'):
            newflags.append (f[2:])
    return newflags

def get_libs(libconfig):
    flags = exec_config (libconfig, "--libs")
    newflags = []
    for f in flags:
        if f.startswith ('-l'):
            newflags.append (f[2:])
    return newflags

def get_lflags(libconfig):
    flags = exec_config (libconfig, "--libs")
    newflags = []
    for f in flags:
        if f.startswith ('-l') or f.startswith ('-L'):
            continue
        newflags.append (f)
    return newflags

def get_version(libconfig):
    return exec_config(libconfig, "--version")

def has_libconfig(libconfig):
    cmd = [libconfig, "--version"]
    return run_command (cmd)[0] == 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.