From 583076406fec125594e0be5500d87a7f5a9454e0 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Fri, 15 Mar 2024 00:23:16 +0100 Subject: [PATCH] Apply selected suggestions courtesy of darker(from black) Signed-off-by: Bernhard Kaindl --- XSConsoleData.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/XSConsoleData.py b/XSConsoleData.py index 205f09f..6eb6ad4 100644 --- a/XSConsoleData.py +++ b/XSConsoleData.py @@ -496,13 +496,20 @@ def UpdateFromNTPConf(self): self.data['ntp']['method'] = "" chronyPerm = os.stat("/etc/dhcp/dhclient.d/chrony.sh").st_mode - if chronyPerm & stat.S_IXUSR and chronyPerm & stat.S_IXGRP and chronyPerm & stat.S_IXOTH: + if ( + chronyPerm & stat.S_IXUSR + and chronyPerm & stat.S_IXGRP + and chronyPerm & stat.S_IXOTH + ): self.data['ntp']['method'] = "DHCP" elif self.data['ntp']['servers']: self.data['ntp']['method'] = "Manual" servers = self.data['ntp']['servers'] - if len(servers) == 4 and all("centos.pool.ntp.org" in server for server in self.data['ntp']['servers']): + if len(servers) == 4 and all( + "centos.pool.ntp.org" in server + for server in self.data['ntp']['servers'] + ): self.data['ntp']['method'] = "Default" else: self.data['ntp']['method'] = "Disabled" @@ -547,10 +554,10 @@ def SaveToNTPConf(self): try: with open("/etc/chrony.conf", "w") as confFile: - for other in self.ntp.othercontents([]): - confFile.write(other + "\n") - for server in self.ntp.servers([]): - confFile.write("server " + server + " iburst\n") + for other in self.ntp.othercontents([]): + confFile.write(other + "\n") + for server in self.ntp.servers([]): + confFile.write("server " + server + " iburst\n") finally: self.UpdateFromNTPConf() @@ -585,15 +592,19 @@ def ResetDefaultNTPServers(self): # Double-check authentication Auth.Inst().AssertAuthenticated() - Data.Inst().NTPServersSet(["0.centos.pool.ntp.org", - "1.centos.pool.ntp.org", - "2.centos.pool.ntp.org", - "3.centos.pool.ntp.org"]) + Data.Inst().NTPServersSet( + [ + "0.centos.pool.ntp.org", + "1.centos.pool.ntp.org", + "2.centos.pool.ntp.org", + "3.centos.pool.ntp.org", + ] + ) def GetDHClientInterfaces(self): (status, output) = getstatusoutput("ls /var/lib/xcp/ | grep leases") if status != 0: - return [] + return [] dhclientFiles = output.splitlines() pattern = "dhclient-(.*).leases"