
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> Make this file PEP 8 clean Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- Makefile.am | 1 + src/kimchi/disks.py | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Makefile.am b/Makefile.am index b79919c..e57d3b6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ EXTRA_DIST = \ PEP8_WHITELIST = \ src/kimchi/asynctask.py \ src/kimchi/config.py.in \ + src/kimchi/disks.py \ src/kimchi/server.py \ plugins/__init__.py \ plugins/sample/__init__.py \ diff --git a/src/kimchi/disks.py b/src/kimchi/disks.py index 93d5dbc..874f669 100644 --- a/src/kimchi/disks.py +++ b/src/kimchi/disks.py @@ -18,26 +18,26 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -import collections -import os import re import subprocess -import sys from kimchi.exception import OperationFailed + def get_partitions_paths(): try: """ Returns all available partitions path of the host """ - blkid = subprocess.Popen(["blkid", "-o", "device" ], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + blkid = subprocess.Popen( + ["blkid", "-o", "device"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) dev_paths = blkid.communicate()[0].rstrip("\n").split("\n") except: raise OperationFailed("Unable to retrieve partitions' full path.") return dev_paths + def get_partition_path(name, dev_paths): """ Returns device path given a partition name """ dev_path = None @@ -49,11 +49,13 @@ def get_partition_path(name, dev_paths): if dev_path: return dev_path + def get_partitions_names(): try: """ Returns all the names of available partitions """ - lsblk = subprocess.Popen(["lsblk", "-Pbo","NAME,TYPE" ], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + lsblk = subprocess.Popen( + ["lsblk", "-Pbo", "NAME,TYPE"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = lsblk.communicate()[0] lines_output = output.rstrip("\n").split("\n") # Will be used later to double check the partition @@ -67,11 +69,12 @@ def get_partitions_names(): expression = r"%s=\".*?\"" % key match = re.search(expression, line) field = match.group() - k, v = field.split('=',1) + k, v = field.split('=', 1) d[k.lower()] = v[1:-1] - if d['type'] not in ['part','lvm']: + if d['type'] not in ['part', 'lvm']: continue - # split()[0] to avoid the second part of the name, after the whiteline + # split()[0] to avoid the second part of the name, + # after the whiteline name = d['name'].split()[0] # There are special cases where lsblk reports # a partition that does not exist in blkid and fdisk (Extended @@ -84,18 +87,18 @@ def get_partitions_names(): except: raise OperationFailed("Unable to retrieve partitions' full path.") + def get_partition_details(name): try: # Find device path - dev_path = get_partition_path(name, - get_partitions_paths()) + dev_path = get_partition_path(name, get_partitions_paths()) # Couldn't find dev_path. if not dev_path: return # Executing lsblk to get partition/disk info - lsblk = subprocess.Popen(["lsblk", "-Pbo", - "TYPE,FSTYPE,SIZE,MOUNTPOINT", dev_path ], - stdout=subprocess.PIPE,stderr=subprocess.PIPE) + lsblk = subprocess.Popen( + ["lsblk", "-Pbo", "TYPE,FSTYPE,SIZE,MOUNTPOINT", dev_path], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) # single line output output = lsblk.communicate()[0].rstrip("\n") # output is on format key="value", where key = NAME, TYPE, FSTYPE, @@ -106,7 +109,7 @@ def get_partition_details(name): expression = r"%s=\".*?\"" % key match = re.search(expression, output) field = match.group() - k, v = field.split('=',1) + k, v = field.split('=', 1) d[k.lower()] = v[1:-1] if d['mountpoint']: # Sometimes the mountpoint comes with [SWAP] or other -- 1.7.10.4 -- project-kimchi mailing list <project-kimchi@googlegroups.com> https://groups.google.com/forum/#!forum/project-kimchi --- You received this message because you are subscribed to the Google Groups "project-kimchi" group. To unsubscribe from this group and stop receiving emails from it, send an email to project-kimchi+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.