]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
man/notify-example: apply "ruff format"
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Feb 2026 16:50:59 +0000 (01:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 May 2026 17:44:46 +0000 (02:44 +0900)
man/notify-selfcontained-example.py

index 6a1e25b99b2ff27c9b9acfde0ac69dbb5b11202a..13021162211460ec6b41e6cf0eadb11f85b9c74c 100755 (executable)
@@ -18,49 +18,56 @@ import time
 reloading = False
 terminating = False
 
+
 def notify(message):
     if not message:
-        raise ValueError("notify() requires a message")
+        raise ValueError('notify() requires a message')
 
-    socket_path = os.environ.get("NOTIFY_SOCKET")
+    socket_path = os.environ.get('NOTIFY_SOCKET')
     if not socket_path:
         return
 
-    if socket_path[0] not in ("/", "@"):
-        raise OSError(errno.EAFNOSUPPORT, "Unsupported socket type")
+    if socket_path[0] not in ('/', '@'):
+        raise OSError(errno.EAFNOSUPPORT, 'Unsupported socket type')
 
     # Handle abstract socket.
-    if socket_path[0] == "@":
-        socket_path = "\0" + socket_path[1:]
+    if socket_path[0] == '@':
+        socket_path = '\0' + socket_path[1:]
 
     with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_CLOEXEC) as sock:
         sock.connect(socket_path)
         sock.sendall(message)
 
+
 def notify_ready():
-    notify(b"READY=1")
+    notify(b'READY=1')
+
 
 def notify_reloading():
     microsecs = time.clock_gettime_ns(time.CLOCK_MONOTONIC) // 1000
-    notify(f"RELOADING=1\nMONOTONIC_USEC={microsecs}".encode())
+    notify(f'RELOADING=1\nMONOTONIC_USEC={microsecs}'.encode())
+
 
 def notify_stopping():
-    notify(b"STOPPING=1")
+    notify(b'STOPPING=1')
+
 
 def reload(signum, frame):
     global reloading
     reloading = True
 
+
 def terminate(signum, frame):
     global terminating
     terminating = True
 
+
 def main():
-    print("Doing initial setup")
+    print('Doing initial setup')
     global reloading, terminating
 
     # Set up signal handlers.
-    print("Setting up signal handlers")
+    print('Setting up signal handlers')
     signal.signal(signal.SIGHUP, reload)
     signal.signal(signal.SIGINT, terminate)
     signal.signal(signal.SIGTERM, terminate)
@@ -68,13 +75,13 @@ def main():
     # Do any other setup work here.
 
     # Once all setup is done, signal readiness.
-    print("Done setting up")
+    print('Done setting up')
     notify_ready()
 
-    print("Starting loop")
+    print('Starting loop')
     while not terminating:
         if reloading:
-            print("Reloading")
+            print('Reloading')
             reloading = False
 
             # Support notifying the manager when reloading configuration.
@@ -86,19 +93,20 @@ def main():
 
             # Do some reconfiguration work here.
 
-            print("Done reloading")
+            print('Done reloading')
             notify_ready()
 
         # Do the real work here ...
 
-        print("Sleeping for five seconds")
+        print('Sleeping for five seconds')
         time.sleep(5)
 
-    print("Terminating")
+    print('Terminating')
     notify_stopping()
 
-if __name__ == "__main__":
+
+if __name__ == '__main__':
     sys.stdout.reconfigure(line_buffering=True)
-    print("Starting app")
+    print('Starting app')
     main()
-    print("Stopped app")
+    print('Stopped app')