python: reformat using black
Code cannot currently be submitted to this repo because it fails
in the unit-test phase. Attempt to reformat the code using `black`
to hopefully make pycodestyle happier.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I17aa506471ceade224bcab5b2fa0dc8cd7a88c0a
diff --git a/pyflashbmc/bmc_update.py b/pyflashbmc/bmc_update.py
index 98c3ca6..c2046e4 100644
--- a/pyflashbmc/bmc_update.py
+++ b/pyflashbmc/bmc_update.py
@@ -15,14 +15,14 @@
import os
from obmc.dbuslib.bindings import get_dbus, DbusProperties, DbusObjectManager
-DBUS_NAME = 'org.openbmc.control.BmcFlash'
-OBJ_NAME = '/org/openbmc/control/flash/bmc'
-DOWNLOAD_INTF = 'org.openbmc.managers.Download'
+DBUS_NAME = "org.openbmc.control.BmcFlash"
+OBJ_NAME = "/org/openbmc/control/flash/bmc"
+DOWNLOAD_INTF = "org.openbmc.managers.Download"
-BMC_DBUS_NAME = 'xyz.openbmc_project.State.BMC'
-BMC_OBJ_NAME = '/xyz/openbmc_project/state/bmc0'
+BMC_DBUS_NAME = "xyz.openbmc_project.State.BMC"
+BMC_OBJ_NAME = "/xyz/openbmc_project/state/bmc0"
-UPDATE_PATH = '/run/initramfs'
+UPDATE_PATH = "/run/initramfs"
def doExtract(members, files):
@@ -35,29 +35,27 @@
fw_env = "/etc/fw_env.config"
lines = 0
files = []
- envcfg = open(fw_env, 'r')
+ envcfg = open(fw_env, "r")
try:
for line in envcfg.readlines():
# ignore lines that are blank or start with #
- if (line.startswith("#")):
+ if line.startswith("#"):
continue
- if (not len(line.strip())):
+ if not len(line.strip()):
continue
fn = line.partition("\t")[0]
files.append(fn)
lines += 1
finally:
envcfg.close()
- if (lines < 1 or lines > 2 or (lines == 2 and files[0] != files[1])):
- raise Exception("Error parsing %s\n" % fw_env)
+ if lines < 1 or lines > 2 or (lines == 2 and files[0] != files[1]):
+ raise Exception("Error parsing %s\n" % fw_env)
shutil.copyfile(files[0], os.path.join(UPDATE_PATH, "image-u-boot-env"))
class BmcFlashControl(DbusProperties, DbusObjectManager):
def __init__(self, bus, name):
- super(BmcFlashControl, self).__init__(
- conn=bus,
- object_path=name)
+ super(BmcFlashControl, self).__init__(conn=bus, object_path=name)
self.Set(DBUS_NAME, "status", "Idle")
self.Set(DBUS_NAME, "filename", "")
@@ -68,38 +66,38 @@
self.Set(DBUS_NAME, "auto_apply", False)
bus.add_signal_receiver(
- self.download_error_handler, signal_name="DownloadError")
+ self.download_error_handler, signal_name="DownloadError"
+ )
bus.add_signal_receiver(
- self.download_complete_handler, signal_name="DownloadComplete")
+ self.download_complete_handler, signal_name="DownloadComplete"
+ )
self.update_process = None
self.progress_name = None
- @dbus.service.method(
- DBUS_NAME, in_signature='ss', out_signature='')
+ @dbus.service.method(DBUS_NAME, in_signature="ss", out_signature="")
def updateViaTftp(self, ip, filename):
self.Set(DBUS_NAME, "status", "Downloading")
self.TftpDownload(ip, filename)
- @dbus.service.method(
- DBUS_NAME, in_signature='s', out_signature='')
+ @dbus.service.method(DBUS_NAME, in_signature="s", out_signature="")
def update(self, filename):
self.Set(DBUS_NAME, "filename", filename)
self.download_complete_handler(filename, filename)
- @dbus.service.signal(DOWNLOAD_INTF, signature='ss')
+ @dbus.service.signal(DOWNLOAD_INTF, signature="ss")
def TftpDownload(self, ip, filename):
self.Set(DBUS_NAME, "filename", filename)
pass
# Signal handler
def download_error_handler(self, filename):
- if (filename == self.Get(DBUS_NAME, "filename")):
+ if filename == self.Get(DBUS_NAME, "filename"):
self.Set(DBUS_NAME, "status", "Download Error")
def download_complete_handler(self, outfile, filename):
# do update
- if (filename != self.Get(DBUS_NAME, "filename")):
+ if filename != self.Get(DBUS_NAME, "filename"):
return
print("Download complete. Updating...")
@@ -127,7 +125,8 @@
for f in list(copy_files.keys()):
if f not in files:
raise Exception(
- "ERROR: File not found in update archive: "+f)
+ "ERROR: File not found in update archive: " + f
+ )
except Exception as e:
print(str(e))
@@ -142,11 +141,11 @@
if self.Get(DBUS_NAME, "clear_persistent_files"):
print("Removing persistent files")
try:
- os.unlink(UPDATE_PATH+"/whitelist")
+ os.unlink(UPDATE_PATH + "/whitelist")
except OSError as e:
- if (e.errno == errno.EISDIR):
+ if e.errno == errno.EISDIR:
pass
- elif (e.errno == errno.ENOENT):
+ elif e.errno == errno.ENOENT:
pass
else:
raise
@@ -157,7 +156,7 @@
for file in os.listdir(wldir):
os.unlink(os.path.join(wldir, file))
except OSError as e:
- if (e.errno == errno.EISDIR):
+ if e.errno == errno.EISDIR:
pass
else:
raise
@@ -175,37 +174,46 @@
def Verify(self):
self.Set(DBUS_NAME, "status", "Checking Image")
try:
- subprocess.check_call([
- "/run/initramfs/update",
- "--no-flash",
- "--no-save-files",
- "--no-restore-files",
- "--no-clean-saved-files"])
+ subprocess.check_call(
+ [
+ "/run/initramfs/update",
+ "--no-flash",
+ "--no-save-files",
+ "--no-restore-files",
+ "--no-clean-saved-files",
+ ]
+ )
self.Set(DBUS_NAME, "status", "Image ready to apply.")
- if (self.Get(DBUS_NAME, "auto_apply")):
+ if self.Get(DBUS_NAME, "auto_apply"):
self.Apply()
except Exception:
self.Set(DBUS_NAME, "auto_apply", False)
try:
- subprocess.check_output([
- "/run/initramfs/update",
- "--no-flash",
- "--ignore-mount",
- "--no-save-files",
- "--no-restore-files",
- "--no-clean-saved-files"],
- stderr=subprocess.STDOUT)
+ subprocess.check_output(
+ [
+ "/run/initramfs/update",
+ "--no-flash",
+ "--ignore-mount",
+ "--no-save-files",
+ "--no-restore-files",
+ "--no-clean-saved-files",
+ ],
+ stderr=subprocess.STDOUT,
+ )
self.Set(
- DBUS_NAME, "status",
- "Deferred for mounted filesystem. reboot BMC to apply.")
+ DBUS_NAME,
+ "status",
+ "Deferred for mounted filesystem. reboot BMC to apply.",
+ )
except subprocess.CalledProcessError as e:
- self.Set(
- DBUS_NAME, "status", "Verify error: %s" % e.output)
+ self.Set(DBUS_NAME, "status", "Verify error: %s" % e.output)
except OSError as e:
self.Set(
- DBUS_NAME, "status",
- "Verify error: problem calling update: %s" % e.strerror)
+ DBUS_NAME,
+ "status",
+ "Verify error: problem calling update: %s" % e.strerror,
+ )
def Cleanup(self):
if self.progress_name:
@@ -219,8 +227,7 @@
self.update_process = None
self.Set(DBUS_NAME, "status", "Idle")
- @dbus.service.method(
- DBUS_NAME, in_signature='', out_signature='')
+ @dbus.service.method(DBUS_NAME, in_signature="", out_signature="")
def Abort(self):
if self.update_process:
try:
@@ -228,29 +235,28 @@
except Exception:
pass
for file in os.listdir(UPDATE_PATH):
- if file.startswith('image-'):
+ if file.startswith("image-"):
os.unlink(os.path.join(UPDATE_PATH, file))
self.Cleanup()
- @dbus.service.method(
- DBUS_NAME, in_signature='', out_signature='s')
+ @dbus.service.method(DBUS_NAME, in_signature="", out_signature="s")
def GetUpdateProgress(self):
msg = ""
if self.update_process and self.update_process.returncode is None:
self.update_process.poll()
- if (self.update_process is None):
+ if self.update_process is None:
pass
- elif (self.update_process.returncode > 0):
+ elif self.update_process.returncode > 0:
self.Set(DBUS_NAME, "status", "Apply failed")
- elif (self.update_process.returncode is None):
+ elif self.update_process.returncode is None:
pass
- else: # (self.update_process.returncode == 0)
+ else: # (self.update_process.returncode == 0)
files = ""
for file in os.listdir(UPDATE_PATH):
- if file.startswith('image-'):
+ if file.startswith("image-"):
files = files + file
if files == "":
msg = "Apply Complete. Reboot to take effect."
@@ -261,32 +267,33 @@
msg = self.Get(DBUS_NAME, "status") + "\n"
if self.progress_name:
try:
- prog = open(self.progress_name, 'r')
+ prog = open(self.progress_name, "r")
for line in prog:
# strip off initial sets of xxx\r here
# ignore crlf at the end
# cr will be -1 if no '\r' is found
cr = line.rfind("\r", 0, -2)
- msg = msg + line[cr + 1:]
+ msg = msg + line[(cr + 1):]
except OSError as e:
- if (e.error == EEXIST):
+ if e.error == EEXIST:
pass
raise
return msg
- @dbus.service.method(
- DBUS_NAME, in_signature='', out_signature='')
+ @dbus.service.method(DBUS_NAME, in_signature="", out_signature="")
def Apply(self):
progress = None
self.Set(DBUS_NAME, "status", "Writing images to flash")
try:
progress = tempfile.NamedTemporaryFile(
- delete=False, prefix="progress.")
+ delete=False, prefix="progress."
+ )
self.progress_name = progress.name
- self.update_process = subprocess.Popen([
- "/run/initramfs/update"],
+ self.update_process = subprocess.Popen(
+ ["/run/initramfs/update"],
stdout=progress.file,
- stderr=subprocess.STDOUT)
+ stderr=subprocess.STDOUT,
+ )
except Exception as e:
try:
progress.close()
@@ -301,29 +308,36 @@
except Exception:
pass
- @dbus.service.method(
- DBUS_NAME, in_signature='', out_signature='')
+ @dbus.service.method(DBUS_NAME, in_signature="", out_signature="")
def PrepareForUpdate(self):
- subprocess.call([
- "fw_setenv",
- "openbmconce",
- "copy-files-to-ram copy-base-filesystem-to-ram"])
+ subprocess.call(
+ [
+ "fw_setenv",
+ "openbmconce",
+ "copy-files-to-ram copy-base-filesystem-to-ram",
+ ]
+ )
# Set the variable twice so that it is written to both environments of
# the u-boot redundant environment variables since initramfs can only
# read one of the environments.
- subprocess.call([
- "fw_setenv",
- "openbmconce",
- "copy-files-to-ram copy-base-filesystem-to-ram"])
+ subprocess.call(
+ [
+ "fw_setenv",
+ "openbmconce",
+ "copy-files-to-ram copy-base-filesystem-to-ram",
+ ]
+ )
self.Set(DBUS_NAME, "status", "Switch to update mode in progress")
o = bus.get_object(BMC_DBUS_NAME, BMC_OBJ_NAME)
intf = dbus.Interface(o, "org.freedesktop.DBus.Properties")
- intf.Set(BMC_DBUS_NAME,
- "RequestedBMCTransition",
- "xyz.openbmc_project.State.BMC.Transition.Reboot")
+ intf.Set(
+ BMC_DBUS_NAME,
+ "RequestedBMCTransition",
+ "xyz.openbmc_project.State.BMC.Transition.Reboot",
+ )
-if __name__ == '__main__':
+if __name__ == "__main__":
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = get_dbus()
diff --git a/pyflashbmc/setup.py b/pyflashbmc/setup.py
index ed86cbb..9aeaf71 100644
--- a/pyflashbmc/setup.py
+++ b/pyflashbmc/setup.py
@@ -1,6 +1,7 @@
from distutils.core import setup
-setup(name='pyflashbmc',
- version='1.0',
- scripts=['bmc_update.py'],
- )
+setup(
+ name="pyflashbmc",
+ version="1.0",
+ scripts=["bmc_update.py"],
+)