From f112789a5871b4bee3726acbad49f7be8d5c298f Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Sat, 9 Feb 2008 19:22:35 +0100 Subject: [PATCH] =?UTF-8?q?Outil=20pour=20g=C3=A9n=C3=A9rer=20la=20liste?= =?UTF-8?q?=20des=20paquets=20avec=20leurs=20versions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit darcs-hash:20080209182235-af139-ada04c70e8aabe4ac033c456e0a56222d0d400d4.gz --- bcfg2/create-versions-index.py | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 bcfg2/create-versions-index.py diff --git a/bcfg2/create-versions-index.py b/bcfg2/create-versions-index.py new file mode 100755 index 00000000..9554e150 --- /dev/null +++ b/bcfg2/create-versions-index.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# create-versions-index.py +# ------------------------ +# +# Copyright (C) 2008 Jeremie Dimino +# +# This file 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 file 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 Street #330, Boston, MA 02111-1307, USA. + +'''Outil pour générer la liste des paquets avec leurs version pour le +plugin Rules de bcfg2.''' + +__all__ = ["gen_rules"] + +import apt, commands +from xml.dom.minidom import Document + +def gen_rules(cache): + '''Création des règles''' + doc = Document() + root = doc.createElement("Rule") + root.setAttribute("priority", "20") + group = doc.createElement("Group") + group.setAttribute("name", commands.getoutput("uname -m")) + + for pkg in cache: + if pkg.candidateVersion: + pkginfo = doc.createElement("Package") + pkginfo.setAttribute("name", pkg.name) + pkginfo.setAttribute("version", pkg.candidateVersion) + group.appendChild(pkginfo) + + root.appendChild(group) + + return root + +if __name__ == "__main__": + import sys, os, time + + print >>sys.stderr, "Chargement du cache..." + cache = apt.Cache() + print >>sys.stderr, "Génération du document XML..." + print ("" % + (time.ctime(), os.path.basename(sys.argv[0]))) + sys.stdout.write(gen_rules(cache).toprettyxml())