Skip to content
8 changes: 8 additions & 0 deletions data/zypp-plugin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@
<solvable match="w" important="true">udev</solvable>
<solvable match="w">*</solvable>
</solvables>

<!-- Set enabled to "true" in order to save zypper commandline arguments in snapshot descriptions.
by default argoments following zypp(zypper) are truncated at 32 chars. change to 0 for unlimited output -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in arguments

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks


<description>
<zypper-extended-description enabled="false">32</zypper-extended-description>
</description>


</snapper-zypp-plugin-conf>
32 changes: 30 additions & 2 deletions scripts/zypp-plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class Config:

def __init__(self):
self.solvables = []
self.zypper_extended_description = []
self.zypper_extended_description.append("false")
self.zypper_extended_description.append("0")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use an array to store two values of different type and meaning. Just use e.g. self.zypper_extended_description_enable = false and self.zypper_extended_description_length = 0.

self.load_file("/etc/snapper/zypp-plugin.conf")


Expand Down Expand Up @@ -90,6 +93,19 @@ def load_dom(self, dom):

except:
pass
try:
for tmp3 in dom.getElementsByTagName("description"):
for tmp4 in tmp3.getElementsByTagName("zypper-extended-description"):
string_size = tmp4.childNodes[0].data

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to int here instead of below.

description_enabled = tmp4.getAttribute("enabled")
if not description_enabled in [ "true", "false" ]:
loggin.error("unknown extended-config enabled attribute %s" % description_enabled)
continue
if description_enabled == "true":
self.zypper_extended_description[0] = "true"
self.zypper_extended_description[1] = string_size
except:
pass



Expand Down Expand Up @@ -145,15 +161,27 @@ def match_solvables(self, names):
if found and important:
return True, True
return found, important

def zypper_arguments(self):
if basename(readlink("/proc/%d/exe" % getppid())) == "zypper":
argument = " " + " ".join(open("/proc/%s/cmdline" % getppid()).read().split('\x00')[1:])
else:
return ""
if config.zypper_extended_description[1] == "0":
return argument
else:
return argument[0:int(config.zypper_extended_description[1])]


def PLUGINBEGIN(self, headers, body):

logging.info("PLUGINBEGIN")

logging.debug("headers: %s" % headers)

self.description = "zypp(%s)" % basename(readlink("/proc/%d/exe" % getppid()))
if config.zypper_extended_description[0] != "true":
self.description = "zypp(%s)" % basename(readlink("/proc/%d/exe" % getppid()))
elif config.zypper_extended_description[0] == "true":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple else is enough here.

self.description = "zypp(%s)%s" % (basename(readlink("/proc/%d/exe" % getppid())), self.zypper_arguments())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basename(readlink(... code is twice here. You could do something like:

self.description = basename(readlink("/proc/%d/exe" % getppid()))
if zypper_extended_description_enabled
    self.description.append(self.zypper_arguments())

self.userdata = self.get_userdata(headers)

self.ack()
Expand Down