gst-add.py 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#!/usr/bin/python

import warnings
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
import apt
import string
import sys

cache = apt.Cache()

for fname in sys.argv[1:]:
    
    # get the packagename
    content = []
    for line in open(fname):
        content.append(line)
        if line.startswith("X-AppInstall-Package"):
            pkgname = line.split("=")[1].strip()

    # calc the gst elements
    pkg = cache[pkgname]
    if not pkg.candidateRecord:
        continue
    s = str(pkg.candidateRecord)
    encoder=[]
    decoder=[]
    element=[]
    urisource=[]
    version=""
    for line in s.split("\n"):
        # skip lines that are not key/value
        if line == "" or line.startswith(" ") or line.startswith("\t"):
            continue
        line = line.rstrip()
        # split string
        (key, value) = string.split(line, ":", maxsplit=1)
        if key == "Gstreamer-Decoders":
            decoder = value.split(";")
        elif key == "Gstreamer-Elements":
            element = value.split(",")
        elif key == "Gstreamer-Encoders":
            encoder = value.split(";")
        elif key == "Gstreamer-Uri-Sources":
            urisource = value.split(",")
        elif key == "Gstreamer-Version":
            version = value.strip()
    # skip if we don't have a version
    if not version:
        print "WARNING: no g-s-t data for %s" % pkgname
        continue
    # gen output string
    s=""
    for elm in encoder:
        s+="%s:encoder-%s;" % (version, elm.strip())
    for elm in decoder:
        s+="%s:decoder-%s;" % (version, elm.strip())
    for elm in element:
        s+="%s:element-%s;" % (version, elm.strip())
    for elm in urisource:
        s+="%s:urisource-%s;" % (version, elm.strip())
    
    # write it back
    out = open(fname,"w")
    for line in content:
        if line.startswith("X-AppInstall-Codecs"):
            line="X-AppInstall-Codecs=%s\n" % s
        out.write(line)