|
|
|
@ -762,3 +762,36 @@ def getFilesCount(directory):
|
|
|
|
|
return len(reduce(lambda x,y:x+y,map(lambda x:x[1]+x[2],
|
|
|
|
|
os.walk(directory)),[]))
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def detectDeviceForPartition(dev):
|
|
|
|
|
"""Detect parent device for partition by /sys/block (sysfs)"""
|
|
|
|
|
reDeviceSplit = re.compile("^(.*/)?(.*?)(\d+)$")
|
|
|
|
|
device = map(lambda x:filter(lambda x:x in dev,
|
|
|
|
|
x[1]),
|
|
|
|
|
os.walk('/sys/block'))
|
|
|
|
|
if device:
|
|
|
|
|
device = device[0]
|
|
|
|
|
parentdevices = \
|
|
|
|
|
filter(lambda x: os.path.split(dev)[-1] in \
|
|
|
|
|
reduce(lambda y,z:y+z[1],
|
|
|
|
|
os.walk(os.path.join('/sys/block',x)),[]), device)
|
|
|
|
|
if parentdevices:
|
|
|
|
|
return parentdevices[0]
|
|
|
|
|
res = reDeviceSplit.search(dev)
|
|
|
|
|
if res:
|
|
|
|
|
return res.groups()[1]
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
def getProgPath(progname):
|
|
|
|
|
"""Get full path of program or False"""
|
|
|
|
|
baseprogname = os.path.basename(progname)
|
|
|
|
|
env = {"LANG":"C"}
|
|
|
|
|
env.update(os.environ.items() + [("PATH",getpathenv())] +\
|
|
|
|
|
env.items())
|
|
|
|
|
res = runOsCommand("which %s"%progname,env_dict=env)
|
|
|
|
|
if res[0] == 0:
|
|
|
|
|
return res[1][0].strip()
|
|
|
|
|
elif os.path.isabs(progname) and os.path.exists(progname):
|
|
|
|
|
return progname
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|