summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSun Lihong <lihongx.sun@intel.com>2014-04-18 17:04:52 +0800
committeradmin <yuhuan.yang@samsung.com>2016-02-04 17:40:56 +0800
commitc5d97fc06c52df3313f046c0fd71a7351b40025a (patch)
treee77eeedb5a81761d546798d6826bf2a9aebbdba3
parentf5770374e8ead63469836b124c2b52eb6e04c34a (diff)
downloadmic-c5d97fc06c52df3313f046c0fd71a7351b40025a.tar.gz
mic-c5d97fc06c52df3313f046c0fd71a7351b40025a.tar.bz2
mic-c5d97fc06c52df3313f046c0fd71a7351b40025a.zip
Pylint error of partitionedfs.py and proxy.py
C: 44,8:unset_proxy_environ: Operator not preceded by a space ENV=env.upper() ^ C: 44,8:unset_proxy_environ: Invalid name "ENV" (should match [a-z_][a-z0-9_]{2,30}$) C: 77,4:_ip_to_int: Operator not preceded by a space ipint=0 ^ C: 78,4:_ip_to_int: Operator not preceded by a space shift=24 C: 85,4:_int_to_ip: Operator not preceded by a space ipaddr="" ^ C: 86,4:_int_to_ip: Operator not preceded by a space shift=0 ^ C:111,12:_set_noproxy_list: Comma not followed by a space _my_noproxy_list.append({"match":0,"needle":item}) ^^ C:115,12:_set_noproxy_list: Comma not followed by a space _my_noproxy_list.append({"match":1,"needle":item}) ^^ C:127,16:_set_noproxy_list: Invalid name "ip" (should match [a-z_][a-z0-9_]{2,30}$) C:129,16:_set_noproxy_list: Operator not preceded by a space shift=24 ^ C:130,16:_set_noproxy_list: Operator not preceded by a space netmask=0 ^ C:136,12:_set_noproxy_list: Comma not followed by a space _my_noproxy_list.append({"match":2,"needle":ip,"netmask":netmask}) Change-Id: Iaf24729b3231b9f313af333fe58096d234d3e515
-rw-r--r--mic/imager/raw.py2
-rw-r--r--mic/utils/partitionedfs.py72
-rw-r--r--mic/utils/proxy.py27
3 files changed, 54 insertions, 47 deletions
diff --git a/mic/imager/raw.py b/mic/imager/raw.py
index 2c4e068..14b7833 100644
--- a/mic/imager/raw.py
+++ b/mic/imager/raw.py
@@ -79,7 +79,7 @@ class RawImageCreator(BaseImageCreator):
def _get_fstab(self):
s = ""
- for mp in self.__instloop.mountOrder:
+ for mp in self.__instloop.mount_order:
p = None
for p1 in self.__instloop.partitions:
if p1['mountpoint'] == mp:
diff --git a/mic/utils/partitionedfs.py b/mic/utils/partitionedfs.py
index d07bd39..60ff98e 100644
--- a/mic/utils/partitionedfs.py
+++ b/mic/utils/partitionedfs.py
@@ -41,13 +41,13 @@ class PartitionedMount(Mount):
self.partitions = []
self.subvolumes = []
self.mapped = False
- self.mountOrder = []
- self.unmountOrder = []
+ self.mount_order = []
+ self.unmount_order = []
self.parted = find_binary_path("parted")
self.kpartx = find_binary_path("kpartx")
self.mkswap = find_binary_path("mkswap")
self.dmsetup = find_binary_path("dmsetup")
- self.btrfscmd=None
+ self.btrfscmd = None
self.mountcmd = find_binary_path("mount")
self.umountcmd = find_binary_path("umount")
self.skipformat = skipformat
@@ -107,7 +107,7 @@ class PartitionedMount(Mount):
# We need to handle subvolumes for btrfs
if fstype == "btrfs" and fsopts and fsopts.find("subvol=") != -1:
- self.btrfscmd=find_binary_path("btrfs")
+ self.btrfscmd = find_binary_path("btrfs")
subvol = None
opts = fsopts.split(",")
for opt in opts:
@@ -400,8 +400,8 @@ class PartitionedMount(Mount):
continue
msger.debug("Running kpartx on %s" % d['disk'].device )
- rc, kpartxOutput = runner.runtool([self.kpartx, "-l", "-v", d['disk'].device])
- kpartxOutput = kpartxOutput.splitlines()
+ rc, kpartx_output = runner.runtool([self.kpartx, "-l", "-v", d['disk'].device])
+ kpartx_output = kpartx_output.splitlines()
if rc != 0:
raise MountError("Failed to query partition mapping for '%s'" %
@@ -409,12 +409,12 @@ class PartitionedMount(Mount):
# Strip trailing blank and mask verbose output
i = 0
- while i < len(kpartxOutput) and kpartxOutput[i][0:4] != "loop":
+ while i < len(kpartx_output) and kpartx_output[i][0:4] != "loop":
i = i + 1
- kpartxOutput = kpartxOutput[i:]
+ kpartx_output = kpartx_output[i:]
# Make sure kpartx reported the right count of partitions
- if len(kpartxOutput) != d['numpart']:
+ if len(kpartx_output) != d['numpart']:
# If this disk has more than 3 partitions, then in case of MBR
# paritions there is an extended parition. Different versions
# of kpartx behave differently WRT the extended partition -
@@ -423,16 +423,16 @@ class PartitionedMount(Mount):
# table type is "msdos" and the amount of partitions is more
# than 3, we just assume kpartx mapped the extended parition
# and we remove it.
- if len(kpartxOutput) == d['numpart'] + 1 \
- and d['ptable_format'] == 'msdos' and len(kpartxOutput) > 3:
- kpartxOutput.pop(3)
+ if len(kpartx_output) == d['numpart'] + 1 \
+ and d['ptable_format'] == 'msdos' and len(kpartx_output) > 3:
+ kpartx_output.pop(3)
else:
raise MountError("Unexpected number of partitions from " \
"kpartx: %d != %d" % \
- (len(kpartxOutput), d['numpart']))
+ (len(kpartx_output), d['numpart']))
- for i in range(len(kpartxOutput)):
- line = kpartxOutput[i]
+ for i in range(len(kpartx_output)):
+ line = kpartx_output[i]
newdev = line.split()[0]
mapperdev = "/dev/mapper/" + newdev
loopdev = d['disk'].device + newdev[-1]
@@ -500,12 +500,12 @@ class PartitionedMount(Mount):
msger.debug("Calculating mount order")
for p in self.partitions:
if p['mountpoint']:
- self.mountOrder.append(p['mountpoint'])
- self.unmountOrder.append(p['mountpoint'])
+ self.mount_order.append(p['mountpoint'])
+ self.unmount_order.append(p['mountpoint'])
- self.mountOrder.sort()
- self.unmountOrder.sort()
- self.unmountOrder.reverse()
+ self.mount_order.sort()
+ self.unmount_order.sort()
+ self.unmount_order.reverse()
def cleanup(self):
Mount.cleanup(self)
@@ -520,7 +520,7 @@ class PartitionedMount(Mount):
def unmount(self):
self.__unmount_subvolumes()
- for mp in self.unmountOrder:
+ for mp in self.unmount_order:
if mp == 'swap':
continue
p = None
@@ -532,7 +532,8 @@ class PartitionedMount(Mount):
if p['mount'] != None:
try:
# Create subvolume snapshot here
- if p['fstype'] == "btrfs" and p['mountpoint'] == "/" and not self.snapshot_created:
+ if p['fstype'] == "btrfs" and p['mountpoint'] == "/" and \
+ not self.snapshot_created:
self.__create_subvolume_snapshots(p, p["mount"])
p['mount'].cleanup()
except:
@@ -542,14 +543,15 @@ class PartitionedMount(Mount):
# Only for btrfs
def __get_subvolume_id(self, rootpath, subvol):
if not self.btrfscmd:
- self.btrfscmd=find_binary_path("btrfs")
+ self.btrfscmd = find_binary_path("btrfs")
argv = [ self.btrfscmd, "subvolume", "list", rootpath ]
rc, out = runner.runtool(argv)
msger.debug(out)
if rc != 0:
- raise MountError("Failed to get subvolume id from %s', return code: %d." % (rootpath, rc))
+ raise MountError("Failed to get subvolume id from %s',"
+ "return code: %d." % (rootpath, rc))
subvolid = -1
for line in out.splitlines():
@@ -588,7 +590,8 @@ class PartitionedMount(Mount):
opts.remove(opt)
break
fsopts = ",".join(opts)
- subvolume_metadata += "%d\t%s\t%s\t%s\n" % (subvolid, subvol["subvol"], subvol['mountpoint'], fsopts)
+ subvolume_metadata += "%d\t%s\t%s\t%s\n" % (subvolid, subvol["subvol"],
+ subvol['mountpoint'], fsopts)
if subvolume_metadata:
fd = open("%s/.subvolume_metadata" % pdisk.mountdir, "w")
@@ -641,9 +644,11 @@ class PartitionedMount(Mount):
subvolid = self. __get_subvolume_id(pdisk.mountdir, subvol["subvol"])
# Set default subvolume
if subvolid != -1:
- rc = runner.show([ self.btrfscmd, "subvolume", "set-default", "%d" % subvolid, pdisk.mountdir])
+ rc = runner.show([ self.btrfscmd, "subvolume", "set-default", "%d" %
+ subvolid, pdisk.mountdir])
if rc != 0:
- raise MountError("Failed to set default subvolume id: %d', return code: %d." % (subvolid, rc))
+ raise MountError("Failed to set default subvolume id: %d', return code: %d."
+ % (subvolid, rc))
self.__create_subvolume_metadata(p, pdisk)
@@ -738,7 +743,8 @@ class PartitionedMount(Mount):
snapshotpath = subvolpath + "_%s-1" % snapshotts
rc = runner.show([ self.btrfscmd, "subvolume", "snapshot", subvolpath, snapshotpath ])
if rc != 0:
- raise MountError("Failed to create subvolume snapshot '%s' for '%s', return code: %d." % (snapshotpath, subvolpath, rc))
+ raise MountError("Failed to create subvolume snapshot '%s' for '%s', return code:"
+ "%d." % (snapshotpath, subvolpath, rc))
self.snapshot_created = True
@@ -751,7 +757,7 @@ class PartitionedMount(Mount):
self.__map_partitions()
self.__calculate_mountorder()
- for mp in self.mountOrder:
+ for mp in self.mount_order:
p = None
for p1 in self.partitions:
if p1['mountpoint'] == mp:
@@ -777,18 +783,18 @@ class PartitionedMount(Mount):
if p['mountpoint'] == "/":
rmmountdir = True
if p['fstype'] == "vfat" or p['fstype'] == "msdos":
- myDiskMount = VfatDiskMount
+ my_disk_mount = VfatDiskMount
elif p['fstype'] in ("ext2", "ext3", "ext4"):
- myDiskMount = ExtDiskMount
+ my_disk_mount = ExtDiskMount
elif p['fstype'] == "btrfs":
- myDiskMount = BtrfsDiskMount
+ my_disk_mount = BtrfsDiskMount
else:
raise MountError("Fail to support file system " + p['fstype'])
if p['fstype'] == "btrfs" and not p['fsopts']:
p['fsopts'] = "subvolid=0"
- pdisk = myDiskMount(RawDisk(p['size'] * self.sector_size, p['device']),
+ pdisk = my_disk_mount(RawDisk(p['size'] * self.sector_size, p['device']),
self.mountdir + p['mountpoint'],
p['fstype'],
4096,
diff --git a/mic/utils/proxy.py b/mic/utils/proxy.py
index c1fb94f..acb05e4 100644
--- a/mic/utils/proxy.py
+++ b/mic/utils/proxy.py
@@ -41,9 +41,9 @@ def unset_proxy_environ():
if env in os.environ:
del os.environ[env]
- ENV=env.upper()
- if ENV in os.environ:
- del os.environ[ENV]
+ env_upper = env.upper()
+ if env_upper in os.environ:
+ del os.environ[env_upper]
def _set_proxies(proxy = None, no_proxy = None):
"""Return a dictionary of scheme -> proxy server URL mappings.
@@ -74,16 +74,16 @@ def _set_proxies(proxy = None, no_proxy = None):
_my_noproxy = value
def _ip_to_int(ip):
- ipint=0
- shift=24
+ ipint = 0
+ shift = 24
for dec in ip.split("."):
ipint |= int(dec) << shift
shift -= 8
return ipint
def _int_to_ip(val):
- ipaddr=""
- shift=0
+ ipaddr = ""
+ shift = 0
for i in range(4):
dec = val >> shift
dec &= 0xff
@@ -108,11 +108,11 @@ def _set_noproxy_list():
if item[0] != '.' and item.find("/") == -1:
# Need to match it
- _my_noproxy_list.append({"match":0,"needle":item})
+ _my_noproxy_list.append({"match":0, "needle":item})
elif item[0] == '.':
# Need to match at tail
- _my_noproxy_list.append({"match":1,"needle":item})
+ _my_noproxy_list.append({"match":1, "needle":item})
elif item.find("/") > 3:
# IP/MASK, need to match at head
@@ -126,17 +126,18 @@ def _set_noproxy_list():
netmask = ~((1<<(32-netmask)) - 1)
ip &= netmask
else:
- shift=24
- netmask=0
+ shift = 24
+ netmask = 0
for dec in mask.split("."):
netmask |= int(dec) << shift
shift -= 8
ip &= netmask
- _my_noproxy_list.append({"match":2,"needle":ip,"netmask":netmask})
+ _my_noproxy_list.append({"match":2, "needle":ip, "netmask":netmask})
def _isnoproxy(url):
- (scheme, host, path, parm, query, frag) = urlparse.urlparse(url)
+ host = urlparse.urlparse(url)[1]
+ # urlparse.urlparse(url) returns (scheme, host, path, parm, query, frag)
if '@' in host:
user_pass, host = host.split('@', 1)