[jhbuild/wip/sysdeps: 1/4] systeminstall: New utility



commit 8fa16bb0023d2b19493f57ad8b1ab9936bfbc863
Author: Colin Walters <walters verbum org>
Date:   Thu Jun 23 16:43:51 2011 -0400

    systeminstall: New utility
    
    This takes pkg-config identifiers and uses a system-specific method
    to install them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=564373

 jhbuild/utils/Makefile.am      |    1 +
 jhbuild/utils/systeminstall.py |  100 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/jhbuild/utils/Makefile.am b/jhbuild/utils/Makefile.am
index b6d63bf..1193ce1 100644
--- a/jhbuild/utils/Makefile.am
+++ b/jhbuild/utils/Makefile.am
@@ -7,6 +7,7 @@ app_PYTHON = \
 	notify.py \
 	packagedb.py \
 	sxml.py \
+	systeminstall.py \
 	trayicon.py \
 	unpack.py
 
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
new file mode 100644
index 0000000..e58e074
--- /dev/null
+++ b/jhbuild/utils/systeminstall.py
@@ -0,0 +1,100 @@
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2011  Colin Walters <walters verbum org>
+#
+#   systeminstall.py - Use system-specific means to acquire dependencies
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import os
+import sys 
+import logging
+import subprocess
+
+import cmds
+
+_classes = []
+
+class SystemInstall(object):
+    def __init__(self):
+        pass
+
+    def install(self, pkgconfig_ids):
+        """Takes a list of pkg-config identifiers and uses a system-specific method to install them."""
+        raise NotImplementedError()
+
+    @classmethod
+    def find_best(cls):
+        for possible_cls in _classes:
+            if possible_cls.detect():
+                return possible_cls()
+
+class YumSystemInstall(SystemInstall):
+    def __init__(self):
+        SystemInstall.__init__(self)
+
+    def install(self, pkgconfig_ids):
+        # Explicitly qualify so we don't get the one in jhbuild root
+        args = ['/usr/bin/pkexec', 'yum', 'install']
+        pkgconfig_provides = map(lambda x: 'pkgconfig(' + x[:-3] + ')', pkgconfig_ids)
+        args.extend(pkgconfig_provides)
+        subprocess.check_call(args, close_fds=True)
+
+    @classmethod
+    def detect(cls):
+        return cmds.has_command('yum')
+
+_classes.append(YumSystemInstall)
+
+# NOTE: This class is unfinished
+class PkconSystemInstall(SystemInstall):
+    def __init__(self):
+        SystemInstall.__init__(self)
+
+    def _get_package_for(self, pkgid):
+        assert pkgid.endswith('.pc')
+        pkgid = pkgid[:-3]
+        proc = subprocess.Popen(['pkcon', '-p', 'what-provides', 'pkgconfig(%s)' % (pkgid, ),
+                                 '--filter=arch;newest'], stdout=subprocess.PIPE, close_fds=True)
+        devnull.close()
+        stdout = proc.communicate()[0]
+        if proc.ecode != 0:
+            return None
+        pkg = None
+        for line in StringIO(stdout):
+            if line.startswith('Package:'):
+                pkg = line[line.find(':') + 1:].strip()
+                break
+        return pkg
+
+    def install(self, pkgconfig_ids):
+        required_pkgs = []
+        for pkgid in pkgconfig_ids:
+            if not pkg.endswith('.pc'):
+                logging.warn("Invalid pkg-config id " + pkg)
+                continue
+            providing_pkg = self._get_package_for(pkgid)
+            if providing_pkg is not None:
+                required_pkgs.append(providing_pkg)
+
+    @classmethod
+    def detect(cls):
+        return cmds.has_command('pkcon')
+
+_classes.append(PkconSystemInstall)
+
+if __name__ == '__main__':
+    installer = SystemInstall.find_best()
+    print "Using %r" % (installer, )
+    installer.install(sys.argv[1:])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]