Commits

htgoebel committed 5a12247

Implementing filetrigger as a pure compilation script, since the RPM
database must not be manipulated by a filetrigger.

Comments (0)

Files changed (1)

python-compile.script

-#!/usr/bin/python
-# -*- mode: python ; coding: utf-8 -*-
+#!/bin/bash
+# -*- coding: utf-8 -*-
 
 # Copyright 2011 Hartmut Goebel <h.goebel@goebel-consult.de>
 
-# http://www.ukuug.org/events/linux2004/programme/paper-PNasrat-1/rpm-python-slides/frames.html
-# http://www.mail-archive.com/mageia-dev@mageia.org/msg02043.html
-# https://qa.mandriva.com/show_bug.cgi?id=50484
-# http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-rpm-programming-python.html
+unset PYTHONDONTWRITEBYTECODE
 
-import sys
-import rpm
+declare -a filenames
+while read FILENAME; do
+    if [ "${FILENAME#-}" != "$FILENAME" ] ; then
+	echo removing "${FILENAME#-}"
+	rm -f "${FILENAME#-}"[co] 2>/dev/null
+    else
+	filenames[${#filenames}]="${FILENAME#+}"
+    fi
+done
 
-def read_from_triggerlist():
-    for l in sys.stdin.readlines():
-        # action, filename
-        yield l[0], l[1:].rstrip('\n')
+# compile non-optimized
+for fn in "${filenames[@]}" ; do
+    echo "$fn"
+done | xargs python -S -m py_compile
 
-def collect_headers(ts, filenames):
-    for fn in filenames:
-        for h in ts.dbMatch('basenames', fn):
-            yield h
+# compile optimized
+for fn in "${filenames[@]}" ; do
+    echo "$fn"
+done | xargs python -S -O -m py_compile
 
-def list_packages(ts):
-    # :test:
-    for h in ts.dbMatch():
-        print "%s-%s-%s" % (h['name'], h['version'], h['release'])
-        print h['filenames']
-
-# md5list, filelist, linklist, filesizes, mtimes, uids, gids, redvs, modes
-
-def main():
-    transaction = rpm.TransactionSet()
-    list_packages(transaction)
-    for action, filename in read_from_triggerlist():
-        print '-->', action, repr(filename)
-        for h in collect_headers(transaction, [filename]):
-            print "%s-%s-%s" % (h['name'], h['version'], h['release'])
-
-if __name__ == '__main__':
-    dbPath = None
-    if sys.argv[1] == '--test':
-        dbPath = sys.argv[2]
-        print "setting dbpath", dbPath
-        rpm.addMacro("_dbpath", dbPath)
-    main()
-    if dbPath:
-        rpm.delMacro("_dbpath")
-
-raise SystemExit()
-
-
-mi.pattern(rpm.RPMTAG_ARCH, rpm.RPMMIRE_DEFAULT, "i386")
-for idx in mi:
-    instance = mi.instance()
-    ts.addErase(instance)
-
-for h in mi:
-    name=h['filenames']
-    fileflags=h['fileflags']
-    md5sums=h['filemd5s']
-    total=len(names)
-
-for i in xrange(total):
-    if (fileflags[i] & rpm.RPMFILE_CONFIG):
-        if isModified(names[i], md5sums[i]):
-            configs.append(names[i])
-
-
-def isModified(fileName, fileMD5):
-    m = md5.new()
-    f = open(fileName,"r")
-    data = f.read()
-    f.close()
-    m.update(data)
-    if fileMD5 != m.hexdigest():
-        return 1
-    else:
-        return 0
+for fn in "${filenames[@]}" ; do
+    chmod --reference="$fn" "$fn"[co]
+    chown --reference="$fn" "$fn"[co]
+done