Viewing file: installablecodecs.py (3.67 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
#!/usr/bin/python # coding=UTF-8 # # Copyright (C) 2008 Tim-Philipp Müller <tim.muller@collabora.co.uk> # Copyright (C) 2008 Canonical Ltd. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # The Totem project hereby grant permission for non-gpl compatible GStreamer # plugins to be used and distributed together with GStreamer and Totem. This # permission are above and beyond the permissions granted by the GPL license # Totem is covered by. # # See license_change file for details.
import gobject gobject.threads_init() import pygst pygst.require ("0.10") import gst
import os
def allPackagesAvailableApt(package_descs, codec_name, apt_cache): toinstall = '' allinstalled = True for pkg_desc in package_descs: (component, pkg_name) = pkg_desc.split('/') if apt_cache.has_key(pkg_name): package = apt_cache[pkg_name] # we only care about installable ones here, not installed, since # the installed ones we can better check via the registry (also # taking into account element factory ranks etc.) gst.log('%s: package %s: installed=%d, downloadable=%d' % (codec_name, pkg_name, package.isInstalled, package.candidateDownloadable)) if not package.isInstalled: allinstalled = False if not package.candidateDownloadable: gst.log('%s: not available (package %s not downloadable)' % (codec_name, pkg_name)) return False elif toinstall.find(pkg_name) < 0: toinstall += pkg_name + ' '
# if all candidat packages are already installed, things should # be checked via the registry and there's nothing to be gained # here, so pretend the codec is not available for installation # in this case if allinstalled: gst.debug('%s: not available (all already installed)' % (codec_name)) return False else: gst.debug('%s: available (install %s)' % (codec_name, toinstall[:-1])) return True
def getInstallableCodecsUbuntu(): import warnings warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning) import apt import gdbm
codecs = []
try: apt_cache = apt.Cache() except: gst.warning('Failed to read APT cache') return []
try: codec_map = gdbm.open('/var/cache/app-install/gai-codec-map.gdbm') for key in codec_map.keys(): if not key.startswith('0.10:decoder-'): continue codec_name = key[13:] if allPackagesAvailableApt(codec_map[key].split(), codec_name, apt_cache): codecs.append(codec_name) except gdbm.error: gst.warning('gdbm error') return []
return codecs
def getInstallableCodecs(): codecs = [] if os.access('/var/cache/app-install/gai-codec-map.gdbm', os.R_OK): codecs = getInstallableCodecsUbuntu() return codecs
if __name__ == "__main__": codecs = getInstallableCodecs() if len(codecs) > 0: for codec in codecs: print "installable: %s" % (codec) else: print 'No codecs known to be installable'
|