chiark / gitweb /
systemd-python: Journal this_boot/machine now accepts ID
[elogind.git] / src / python-systemd / journal.py
index 6e82a460b57d81712918d2a7c35700997b0e8db4..60c8111d239a49c17ce92f237cdcfb2a236dda44 100644 (file)
@@ -113,15 +113,26 @@ class Journal(_Journal):
     def add_match(self, *args, **kwargs):
         args = list(args)
         args.extend(_make_line(key, val) for key, val in kwargs.items())
-        super(Journal, self).add_match(*args)
+        for arg in args:
+            super(Journal, self).add_match(arg)
 
-    def get_next(self, *args, **kwargs):
+    def get_next(self, skip=1):
         return self._convert_entry(
-            super(Journal, self).get_next(*args, **kwargs))
+            super(Journal, self).get_next(skip))
 
-    def query_unique(self, key, *args, **kwargs):
+    def query_unique(self, key):
         return set(self._convert_field(key, value)
-            for value in super(Journal, self).query_unique(key, *args, **kwargs))
+            for value in super(Journal, self).query_unique(key))
+
+    def seek_realtime(self, timestamp):
+        if isinstance(timestamp, datetime.datetime):
+            timestamp = float(timestamp.strftime("%s.%f"))
+        return super(Journal, self).seek_realtime(timestamp)
+
+    def seek_monotonic(self, timestamp, bootid=None):
+        if isinstance(timestamp, datetime.timedelta):
+            timestamp = timestamp.totalseconds()
+        return super(Journal, self).seek_monotonic(timestamp, bootid)
 
     def log_level(self, level):
         """Sets maximum log level by setting matches for PRIORITY."""
@@ -131,13 +142,28 @@ class Journal(_Journal):
         else:
             raise ValueError("Log level must be 0 <= level <= 7")
 
-    def this_boot(self):
-        """Add match for _BOOT_ID equal to current boot ID."""
-        self.add_match(_BOOT_ID=_id128.get_boot().hex)
+    def this_boot(self, bootid=None):
+        """Add match for _BOOT_ID equal to current boot ID or the specified boot ID.
+
+        bootid should be either a UUID or a 32 digit hex number.
+        """
+        if bootid is None:
+            bootid = _id128.get_boot().hex
+        else:
+            bootid = getattr(bootid, 'hex', bootid)
+        self.add_match(_BOOT_ID=bootid)
+
+    def this_machine(self, machineid=None):
+        """Add match for _MACHINE_ID equal to the ID of this machine.
+
+        bootid should be either a UUID or a 32 digit hex number.
+        """
+        if machineid is None:
+            machineid = _id128.get_machine().hex
+        else:
+            machineid = getattr(machineid, 'hex', machineid)
+        self.add_match(_MACHINE_ID=machineid)
 
-    def this_machine(self):
-        """Add match for _MACHINE_ID equal to the ID of this machine."""
-        self.add_match(_MACHINE_ID=_id128.get_machine().hex)
 
 def _make_line(field, value):
         if isinstance(value, bytes):