chiark / gitweb /
systemd-python: use .hex instead of .get_hex()
[elogind.git] / src / python-systemd / journal.py
index 7d42525ab2d6da77f7c8fa87ae4651752e9fea43..dd1f2299735673107eb090de0b0aa32ee870a830 100644 (file)
@@ -31,9 +31,10 @@ if _sys.version_info >= (3,3):
     from collections import ChainMap as _ChainMap
 from syslog import (LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR,
                     LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG)
-from ._journal import sendv, stream_fd
+from ._journal import __version__, sendv, stream_fd
 from ._reader import (_Reader, NOP, APPEND, INVALIDATE,
-                      LOCAL_ONLY, RUNTIME_ONLY, SYSTEM_ONLY,
+                      LOCAL_ONLY, RUNTIME_ONLY,
+                      SYSTEM, SYSTEM_ONLY, CURRENT_USER,
                       _get_catalog)
 from . import id128 as _id128
 
@@ -55,6 +56,9 @@ def _convert_realtime(t):
 def _convert_timestamp(s):
     return _datetime.datetime.fromtimestamp(int(s) / 1000000)
 
+def _convert_trivial(x):
+    return x
+
 if _sys.version_info >= (3,):
     def _convert_uuid(s):
         return _uuid.UUID(s.decode())
@@ -87,6 +91,7 @@ DEFAULT_CONVERTERS = {
     '__REALTIME_TIMESTAMP': _convert_realtime,
     '_SOURCE_MONOTONIC_TIMESTAMP': _convert_source_monotonic,
     '__MONOTONIC_TIMESTAMP': _convert_monotonic,
+    '__CURSOR': _convert_trivial,
     'COREDUMP': bytes,
     'COREDUMP_PID': int,
     'COREDUMP_UID': int,
@@ -119,7 +124,7 @@ class Reader(_Reader):
     See systemd.journal-fields(7) for more info on typical fields
     found in the journal.
     """
-    def __init__(self, flags=0, path=None, converters=None):
+    def __init__(self, flags=0, path=None, files=None, converters=None):
         """Create an instance of Reader, which allows filtering and
         return of journal entries.
 
@@ -145,7 +150,7 @@ class Reader(_Reader):
         Reader implements the context manager protocol: the journal
         will be closed when exiting the block.
         """
-        super(Reader, self).__init__(flags, path)
+        super(Reader, self).__init__(flags, path, files)
         if _sys.version_info >= (3,3):
             self.converters = _ChainMap()
             if converters is not None:
@@ -187,18 +192,18 @@ class Reader(_Reader):
         """
         return self
 
-    if _sys.version_info >= (3,):
-        def __next__(self):
-            """Part of iterator protocol.
-            Returns self.get_next().
-            """
-            return self.get_next()
-    else:
-        def next(self):
-            """Part of iterator protocol.
-            Returns self.get_next().
-            """
-            return self.get_next()
+    def __next__(self):
+        """Part of iterator protocol.
+        Returns self.get_next() or raises StopIteration.
+        """
+        ans = self.get_next()
+        if ans:
+            return ans
+        else:
+            raise StopIteration()
+
+    if _sys.version_info < (3,):
+        next = __next__
 
     def add_match(self, *args, **kwargs):
         """Add one or more matches to the filter journal log entries.
@@ -240,7 +245,7 @@ class Reader(_Reader):
         Entries will be processed with converters specified during
         Reader creation.
 
-        Equivilent to get_next(-skip).
+        Equivalent to get_next(-skip).
         """
         return self.get_next(-skip)
 
@@ -288,7 +293,7 @@ class Reader(_Reader):
             monotonic = monotonic.totalseconds()
         monotonic = int(monotonic * 1000000)
         if isinstance(bootid, _uuid.UUID):
-            bootid = bootid.get_hex()
+            bootid = bootid.hex
         return super(Reader, self).seek_monotonic(monotonic, bootid)
 
     def log_level(self, level):
@@ -309,7 +314,7 @@ class Reader(_Reader):
         Equivalent to add_match(MESSAGE_ID=`messageid`).
         """
         if isinstance(messageid, _uuid.UUID):
-            messageid = messageid.get_hex()
+            messageid = messageid.hex
         self.add_match(MESSAGE_ID=messageid)
 
     def this_boot(self, bootid=None):
@@ -341,12 +346,14 @@ class Reader(_Reader):
 
 def get_catalog(mid):
     if isinstance(mid, _uuid.UUID):
-        mid = mid.get_hex()
+        mid = mid.hex
     return _get_catalog(mid)
 
 def _make_line(field, value):
         if isinstance(value, bytes):
                 return field.encode('utf-8') + b'=' + value
+        elif isinstance(value, int):
+                return field + '=' + str(value)
         else:
                 return field + '=' + value