a little nicer
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 1 Jan 2019 15:17:43 +0000 (16:17 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 1 Jan 2019 15:17:43 +0000 (16:17 +0100)
logger.py
plugins/privatebridge.py
sliver_lxc.py
tools.py

index 8216cfb..064e98e 100644 (file)
--- a/logger.py
+++ b/logger.py
@@ -110,7 +110,7 @@ class Buffer:
 
     def add(self, c):
         self.buffer += c
-        if c=='\n':
+        if c == '\n':
             self.flush()
 
     def flush(self):
index 8e77524..9489f69 100644 (file)
@@ -1,35 +1,31 @@
-#!/usr/bin/env python3
+"""
+Private Bridge configurator.
+"""
 
-""" Private Bridge configurator.  """
-
-import http.client
-import os
 import select
-import shutil
 import subprocess
 import time
 import tools
 
-from threading import Thread
 import logger
-import tools
 
 priority = 9
 
 class OvsException (Exception) :
-    def __init__ (self, message="no message"):
-        self.message=message
-    def __repr__ (self): return message
+    def __init__(self, message="no message"):
+        self.message = message
+    def __repr__(self):
+        return self.message
 
 def start():
     logger.log('private bridge plugin starting up...')
 
 def log_call_read(command, timeout=logger.default_timeout_minutes*60, poll=1):
-    message=" ".join(command)
+    message = " ".join(command)
     logger.log("log_call: running command %s" % message)
     logger.verbose("log_call: timeout=%r s" % timeout)
     logger.verbose("log_call: poll=%r s" % poll)
-    trigger=time.time()+timeout
+    trigger = time.time()+timeout
     try:
         child = subprocess.Popen(
             command, bufsize=1,
@@ -40,8 +36,9 @@ def log_call_read(command, timeout=logger.default_timeout_minutes*60, poll=1):
         stdout = ""
         while True:
             # see if anything can be read within the poll interval
-            (r, w, x)=select.select([child.stdout], [], [], poll)
-            if r: stdout = stdout + child.stdout.read(1)
+            (r, w, x) = select.select([child.stdout], [], [], poll)
+            if r:
+                stdout = stdout + child.stdout.read(1)
             # is process over ?
             returncode=child.poll()
             # yes
@@ -55,12 +52,14 @@ def log_call_read(command, timeout=logger.default_timeout_minutes*60, poll=1):
                     return (returncode, stdout)
                 # child has failed
                 else:
-                    log("log_call:end command (%s) returned with code %d" %(message, returncode))
+                    log("log_call:end command (%s) returned with code %d"
+                        %(message, returncode))
                     return (returncode, stdout)
             # no : still within timeout ?
             if time.time() >= trigger:
                 child.terminate()
-                logger.log("log_call:end terminating command (%s) - exceeded timeout %d s"%(message, timeout))
+                logger.log("log_call:end terminating command (%s) - exceeded timeout %d s"
+                           %(message, timeout))
                 return (-2, None)
                 break
     except Exception as e:
@@ -109,8 +108,9 @@ def ovs_addport(name, portname, type, remoteip, key):
     if key:
         args = args + ["options:key=" + str(key)]
 
-    (returncode, stdout) = ovs_vsctl(args)
-    if (returncode != 0): raise OvsException("add-port")
+    returncode, stdout = ovs_vsctl(args)
+    if (returncode != 0):
+        raise OvsException("add-port")
 
 def ovs_delport(name, portname):
     (returncode, stdout) = ovs_vsctl(["del-port", name, portname])
@@ -182,7 +182,7 @@ def GetSlivers(data, conf = None, plc = None):
         sliver_name = sliver['name']
 
         # build a dict of attributes, because it's more convenient
-        attributes={}
+        attributes = {}
         for attribute in sliver['attributes']:
             attributes[attribute['tagname']] = attribute['value']
 
index 19216d7..e54c453 100644 (file)
@@ -80,8 +80,8 @@ class Sliver_LXC(Sliver_Libvirt, Initscript):
             .format(self.name)
         command = plain.split()
         logger.log_call(command, timeout=3)
-                
-        
+
+
     @staticmethod
     def create(name, rec=None):
         '''
index 96df451..d8f216e 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -168,7 +168,8 @@ def write_temp_file(do_write, mode=None, uidgid=None):
     return temporary_filename
 
 
-def replace_file_with_string(target, new_contents, chmod=None, remove_if_empty=False):
+def replace_file_with_string(target, new_contents,
+                             chmod=None, remove_if_empty=False):
     """
 Replace a target file with a new contents
 checks for changes: does not do anything if previous state was already right
@@ -179,8 +180,8 @@ writes in a tmp file, which is then renamed (from sliverauth originally)
 returns True if a change occurred, or the file is deleted
     """
     try:
-        with open(target) as f:
-            current = f.read()
+        with open(target) as feed:
+            current = feed.read()
     except:
         current = ""
     if current == new_contents: