Skip to content

Commit

Permalink
Fix various PEP8 violations in recent EDD commits.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwlehman committed Nov 19, 2015
1 parent 243f7c6 commit 249350c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 100 deletions.
47 changes: 26 additions & 21 deletions blivet/devicelibs/edd.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# anchoring tab that would go between them...
re_interface_unknown = re.compile(r'^(\S*)\s*unknown: (\S*) (\S*)\s*$')


class EddEntry(object):

""" This object merely collects what the /sys/firmware/edd/* entries can
Expand Down Expand Up @@ -195,7 +196,7 @@ def __init__(self, sysfspath, root=None):
def _fmt(self, line_pad, separator):
s = "%(t)spath: %(sysfspath)s version: %(version)s %(nl)s" \
"%(t)smbr_signature: %(mbr_sig)s sectors: %(sectors)s"
if self.type != None:
if self.type is not None:
s += " %(type)s"
if self.sysfslink is not None:
s += "%(nl)s%(t)ssysfs pci path: %(sysfslink)s"
Expand Down Expand Up @@ -225,8 +226,8 @@ def _fmt(self, line_pad, separator):
s += "%(nl)s%(t)ssas_address: %(sas_address)s sas_lun: %(sas_lun)s"

d = copy.copy(self.__dict__)
d['t']=line_pad
d['nl']=separator
d['t'] = line_pad
d['nl'] = separator

return s % d

Expand Down Expand Up @@ -352,6 +353,7 @@ class EddMatcher(object):
Assuming, heuristic analysis and guessing hapens here.
"""

def __init__(self, edd_entry, root=None):
self.edd = edd_entry
self.root = root
Expand All @@ -361,7 +363,7 @@ def devname_from_ata_pci_dev(self):
retries = []

def match_port(components, ata_port, ata_port_idx, path, link):
fn = util.Path(util.join_paths(components[0:6] \
fn = util.Path(util.join_paths(components[0:6]
+ ['ata_port', ata_port]), root=self.root)
port_no = int(util.get_sysfs_attr(fn, 'port_no'))

Expand All @@ -377,8 +379,8 @@ def match_port(components, ata_port, ata_port_idx, path, link):
if port_no != self.edd.ata_device + 1:
return

fn = components[0:6] + ['link%d' % (ata_port_idx,),]
exp = [r'.*']+fn+[r'dev%d\.(\d+)(\.(\d+)){0,1}$' % (ata_port_idx,)]
fn = components[0:6] + ['link%d' % (ata_port_idx,), ]
exp = [r'.*'] + fn + [r'dev%d\.(\d+)(\.(\d+)){0,1}$' % (ata_port_idx,)]
exp = util.join_paths(exp)
expmatcher = re.compile(exp)

Expand Down Expand Up @@ -455,7 +457,7 @@ def match_port(components, ata_port, ata_port_idx, path, link):
# iterates the sata device number /independently/ of the host
# bridge it claims things are attached to. In that case this
# the scsi target will always have "0" as the ID component.
args = { 'device': self.edd.ata_device }
args = {'device': self.edd.ata_device}
exp = r"target\d+:0:%(device)s/\d+:0:%(device)s:0/block/.*" % args
matcher = re.compile(exp)
match = matcher.match("/".join(components[7:]))
Expand Down Expand Up @@ -512,9 +514,9 @@ def devname_from_virtio_scsi_pci_dev(self):
tmpl = "../devices/pci0000:00/0000:%(pci_dev)s/virtio*/" \
"host*/target*:0:%(dev)d/*:0:%(dev)d:%(lun)d/block/"
args = {
'pci_dev' : self.edd.pci_dev,
'dev' : self.edd.scsi_id,
'lun' : self.edd.scsi_lun,
'pci_dev': self.edd.pci_dev,
'dev': self.edd.scsi_id,
'lun': self.edd.scsi_lun,
}
pattern = util.Path(tmpl % args, self.root + "/sys/block/")
answers = []
Expand All @@ -523,7 +525,7 @@ def devname_from_virtio_scsi_pci_dev(self):
block_entries = os.listdir(mp.ondisk)
for be in block_entries:
link = mp + be
answers.append({'link':link, 'path':be})
answers.append({'link': link, 'path': be})

if len(answers) > 1:
log.error("Found too many VirtIO SCSI devices for EDD device 0x%x: %s",
Expand All @@ -533,7 +535,7 @@ def devname_from_virtio_scsi_pci_dev(self):
self.edd.sysfslink = answers[0]['link']
return answers[0]['path']
else:
log.info("edd: Could not find VirtIO SCSI device for pci dev %s "\
log.info("edd: Could not find VirtIO SCSI device for pci dev %s "
"channel %s scsi id %s lun %s", self.edd.pci_dev,
self.edd.channel, self.edd.scsi_id, self.edd.scsi_lun)

Expand All @@ -542,10 +544,10 @@ def devname_from_scsi_pci_dev(self):
"host%(chan)d/target%(chan)d:0:%(dev)d/" \
"%(chan)d:0:%(dev)d:%(lun)d/block/"
args = {
'pci_dev' : self.edd.pci_dev,
'chan' : self.edd.channel,
'dev' : self.edd.scsi_id,
'lun' : self.edd.scsi_lun,
'pci_dev': self.edd.pci_dev,
'chan': self.edd.channel,
'dev': self.edd.scsi_id,
'lun': self.edd.scsi_lun,
}
pattern = util.Path(tmpl % args, root=self.root + "/sys/block/")
answers = []
Expand All @@ -554,7 +556,7 @@ def devname_from_scsi_pci_dev(self):
block_entries = os.listdir(mp.ondisk)
for be in block_entries:
link = mp + be
answers.append({'link':link, 'path':be})
answers.append({'link': link, 'path': be})

if len(answers) > 1:
log.error("Found too many SCSI devices for EDD device 0x%x: %s",
Expand All @@ -564,7 +566,7 @@ def devname_from_scsi_pci_dev(self):
self.edd.sysfslink = answers[0]['link']
return answers[0]['path']
else:
log.warning("edd: Could not find SCSI device for pci dev %s "\
log.warning("edd: Could not find SCSI device for pci dev %s "
"channel %s scsi id %s lun %s", self.edd.pci_dev,
self.edd.channel, self.edd.scsi_id, self.edd.scsi_lun)
return None
Expand All @@ -578,7 +580,7 @@ def devname_from_virt_pci_dev(self):
block_entries = os.listdir(mp.ondisk)
for be in block_entries:
link = mp + be
answers.append({'link':link, 'path':be})
answers.append({'link': link, 'path': be})

if len(answers) > 1:
log.error("Found too many VirtIO devices for EDD device 0x%x: %s",
Expand All @@ -601,7 +603,7 @@ def devname_from_pci_dev(self):
if name is not None:
return name
name = self.devname_from_virtio_scsi_pci_dev()
if not name is None:
if name is not None:
return name

unsupported = ("ATAPI", "USB", "1394", "I2O", "RAID", "FIBRE", "SAS")
Expand Down Expand Up @@ -629,13 +631,14 @@ def match_via_mbrsigs(self, mbr_dict):
This will obviously fail for a fresh drive/image, but in extreme
cases can also show false positives for randomly matching data.
"""
sysblock=util.Path("/sys/block/", root=self.root)
sysblock = util.Path("/sys/block/", root=self.root)
for (name, mbr_sig) in mbr_dict.items():
if mbr_sig == self.edd.mbr_sig:
self.edd.sysfslink = util.sysfs_readlink(sysblock, link=name)
return name
return None


def collect_edd_data(root=None):
edd_data_dict = {}
globstr = util.Path("/sys/firmware/edd/int13_dev*/", root=root)
Expand All @@ -646,6 +649,7 @@ def collect_edd_data(root=None):
edd_data_dict[biosdev] = EddEntry(path, root=root)
return edd_data_dict


def collect_mbrs(devices, root=None):
""" Read MBR signatures from devices.
Expand Down Expand Up @@ -689,6 +693,7 @@ def collect_mbrs(devices, root=None):
log.info("edd: collected mbr signatures: %s", mbr_dict)
return mbr_dict


def get_edd_dict(devices, root=None):
""" Generates the 'device name' -> 'edd number' mapping.
Expand Down
17 changes: 13 additions & 4 deletions blivet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# this will get set to anaconda's program_log_lock in enable_installer_mode
program_log_lock = Lock()


class Path(str):

""" Path(path, root=None) provides a filesystem path object, which
Expand Down Expand Up @@ -103,12 +104,12 @@ def __getitem__(self, idx):

def __add__(self, other):
if isinstance(other, Path):
if other.root != None and other.root != "/":
if self.root == None:
if other.root is not None and other.root != "/":
if self.root is None:
self._root = other.root
elif other.root != self.root:
raise ValueError("roots <%s> and <%s> don't match." %
(self.root, other.root))
(self.root, other.root))
path = "%s/%s" % (self.path, other.path)
else:
path = "%s/%s" % (self.path, other)
Expand Down Expand Up @@ -153,6 +154,7 @@ def glob(self):
def __hash__(self):
return self._path.__hash__()


def _run_program(argv, root='/', stdin=None, env_prune=None, stderr_to_stdout=False, binary_output=False):
if env_prune is None:
env_prune = []
Expand Down Expand Up @@ -333,6 +335,7 @@ def notify_kernel(path, action="change"):
f.write("%s\n" % action)
f.close()


def normalize_path_slashes(path):
""" Normalize the slashes in a filesystem path.
Does not actually examine the filesystme in any way.
Expand All @@ -341,6 +344,7 @@ def normalize_path_slashes(path):
path = path.replace("//", "/")
return path


def join_paths(*paths):
""" Joins filesystem paths without any consiration of slashes or
whatnot and then normalizes repeated slashes.
Expand All @@ -349,13 +353,14 @@ def join_paths(*paths):
return join_paths(*paths[0])
return normalize_path_slashes('/'.join(paths))


def get_sysfs_attr(path, attr, root=None):
if not attr:
log.debug("get_sysfs_attr() called with attr=None")
return None
if not isinstance(path, Path):
path = Path(path=path, root=root)
elif root != None:
elif root is not None:
path.newroot(root)

attribute = path + attr
Expand All @@ -372,6 +377,7 @@ def get_sysfs_attr(path, attr, root=None):
testdata_log.debug("sysfs attr %s: %s", attribute, sdata)
return data.strip()


def sysfs_readlink(path, link, root=None):
if not link:
log.debug("sysfs_readlink() called with link=None")
Expand All @@ -391,6 +397,7 @@ def sysfs_readlink(path, link, root=None):
testdata_log.debug("new sysfs link: \"%s\" -> \"%s\"", linkpath, output)
return output


def get_sysfs_path_by_name(dev_node, class_name="block"):
""" Return sysfs path for a given device.
Expand Down Expand Up @@ -1019,6 +1026,7 @@ def the_func(*args, **kwargs):

return deprecate_func


def default_namedtuple(name, fields, doc=""):
"""Create a namedtuple class
Expand Down Expand Up @@ -1047,6 +1055,7 @@ def default_namedtuple(name, fields, doc=""):
class TheDefaultNamedTuple(nt):
if doc:
__doc__ = doc

def __new__(cls, *args, **kwargs):
args_list = list(args)
sorted_kwargs = sorted(kwargs.keys(), key=field_names.index)
Expand Down

0 comments on commit 249350c

Please sign in to comment.