File 0005-btrfs-defrag-plugin-remove-dependency-on-zypp-plugin.patch of Package btrfsmaintenance.19874

From a1fdf5f2502ead429fe6ea6b44a63ad35aae7242 Mon Sep 17 00:00:00 2001
From: Jeff Mahoney <jeffm@suse.com>
Date: Tue, 12 Mar 2019 16:22:08 -0400
Subject: btrfs-defrag-plugin: remove dependency on zypp-plugin-python
References: FATE#326736 jsc#SLE-4130
Notes: The script is included separately since rpm can't use git binary diffs

Requiring zypp-plugin-python means that we need to pull in 150 MB of
python dependencies.  It's present already on many systems but on
JeOS systems, it won't be by default.  We still want to defrag
the RPM database on those systems.

This commit replaces the python script with a shell script that provides
the same functionality and drops the python dependency entirely.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---

 README.md              |    4 +-
 btrfs-defrag-plugin.py |   81 -------------------------------------------------
 2 files changed, 2 insertions(+), 83 deletions(-)

diff --git a/README.md b/README.md
index d59f3d6..2202ebf 100644
--- a/README.md
+++ b/README.md
@@ -188,7 +188,7 @@ do manual installation of files as described below.
 * `sysconfig.btrfsmaintenance` configuration template is put to:
  * `/etc/sysconfig/btrfsmaintenance` on SUSE and RedHat based systems or derivatives
  * `/etc/default/btrfsmaintenance` on Debian and derivatives
-* `/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.py` post-update script for
+* `/usr/lib/zypp/plugins/commit/btrfs-defrag-plugin.sh` post-update script for
   zypper (the package manager), applies to SUSE-based distros for now
 * cron refresh scripts are installed (see bellow)
 
@@ -212,7 +212,7 @@ configuration file in `/etc/sysconfig/btrfsmaintenance` by installing the
 The package database files tend to be updated in a random way and get
 fragmented, which particularly hurts on btrfs. For rpm-based distros this means files
 in `/var/lib/rpm`. The script or plugin simpy runs a defragmentation on the affected files.
-See `btrfs-defrag-plugin.py` for more details.
+See `btrfs-defrag-plugin.sh` for more details.
 
 At the moment the 'zypper' package manager plugin exists. As the package
 managers differ significantly, there's no single plugin/script to do that.
diff --git a/btrfs-defrag-plugin.py b/btrfs-defrag-plugin.py
deleted file mode 100644
index dab9556..0000000
--- a/btrfs-defrag-plugin.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/usr/bin/python
-
-# This plugin defragments rpm files after update.
-#
-# If the filesystem is btrfs, run defrag command in the RPM database
-# folder, set the desired extent size to 32MiB, but this may change in the
-# result depending on the fragmentation of the free space.
-#
-# Why 32MiB:
-# - the worst fragmentation has been observed on Packages
-# - this can grow up to several hundred of megabytes
-# - the file gets updated at random places
-# - although the file will be composed of many extents, it's faster to
-#   merge only the extents that affect some portions of the file, instead
-#   of the whole file; the difference is negligible
-# - due to the free space fragmentation over time, it's hard to find
-#   contiguous space, the bigger the extent is, the worse and the extent
-#   size hint is not reached anyway
-
-import sys
-if sys.version_info[0] >= 3:
-    from builtins import str
-    popen_kwargs = { 'encoding': 'ascii' }
-else:
-    popen_kwargs = { }
-from zypp_plugin import Plugin
-import subprocess
-
-DEBUG=False
-EXTENT_SIZE=32*1024*1024
-LOGFILE='/tmp/btrfs-defrag-plugin.log'
-PATH=subprocess.check_output(["rpm", "--eval", "%_dbpath"], **popen_kwargs).strip()
-
-def dbg(args):
-    if not DEBUG: return
-    f=open(LOGFILE, "a+")
-    f.write(args)
-    f.write("\n")
-    f.close()
-
-def qx(args):
-    out=subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, **popen_kwargs).stdout
-    outstr="".join(out.readlines())
-    out.close()
-    return outstr
-
-def fstype(path):
-    ret=qx('stat -f --format=%T "'+path+'"')
-    return ret.rstrip()
-
-class BtrfsDefragPlugin(Plugin):
-  def PLUGINBEGIN(self, headers, body):
-    self.actions = []
-    self.commit_hook_supported = False
-    dbg('--- Btrfs defrag plugin begin')
-    self.ack()
-
-  def PLUGINEND(self, headers, body):
-    dbg('--- Btrfs defrag plugin end: %s %s\n' % (str(headers), str(body)))
-    dbg('--- fstype(%s) = |%s|' % (PATH, fstype(PATH)))
-    if fstype(PATH) != 'btrfs':
-        self.ack()
-        return
-    if DEBUG:
-        dbg('--- Fragmentation before')
-        dbg(qx('filefrag %s/*' % (PATH)))
-    # defrag options:
-    # - verbose
-    # - recursive
-    # - flush each file before going to the next one
-    # - set the extent target hint
-    ret = qx('btrfs filesystem defragment -v -f -r -t %s "%s"' % \
-            (str(EXTENT_SIZE), PATH))
-    if DEBUG:
-        dbg(ret)
-        dbg('--- Fragmentation after')
-        dbg(qx('filefrag %s/*' % (PATH)))
-    self.ack()
-
-plugin = BtrfsDefragPlugin()
-plugin.main()
openSUSE Build Service is sponsored by