Fix get auto values for bool variables.

Set getFilesCount as alias to countFiles
Improve isMount for work with LVM.
Discard count files for variable os_...linux_filesnum, because
it is too long operation. Files num are will count by calculate-builder
before pack.
master3.3
Mike Hiretsky 12 years ago
parent 413397267f
commit 23ed0ce2e7

@ -277,7 +277,7 @@ class Variable:
if value and value.lower() != "auto":
return "on" if self.isTrue(value) else "off"
else:
return value
return ""
if self.type == "bool":
value = "on" if self.isTrue(value) else "off"
if "bool" in self.type and "list" in self.type:

@ -366,6 +366,9 @@ class processProgress(process):
self.cacheresult = "\n".join(self.cacheresult)
def countFiles(dirpath,onefilesystem=True):
"""
Count files in specified dirpath
"""
num = 1
for dirpath,dirnames,filenames in os.walk(dirpath):
num += len(set(dirnames) | set(filenames))
@ -376,6 +379,10 @@ def countFiles(dirpath,onefilesystem=True):
dirnames.remove(dirname)
return num
def getFilesCount(directory):
"""Alias for compatibility"""
return countFiles(directory,onefilesystem=False)
def runOsCommand(cmd,in_str=None, env_dict=None):
"""Run system command
@ -445,15 +452,22 @@ def getRunCommands():
def isMount(pathname):
"""В случае монтирования директории выдает другой примонтированный путь"""
absPath = path.abspath(pathname)
findPath = [path.abspath(pathname)]
if findPath[0].startswith('/dev'):
info = device.getUdevDeviceInfo(name=findPath[0])
if 'DM_VG_NAME' in info and 'DM_LV_NAME' in info:
lvmDeviceName = \
'/dev/mapper/{vg}-{lv}'.format(vg=info['DM_VG_NAME'],
lv=info['DM_LV_NAME'])
findPath.append(lvmDeviceName)
mtabFile = '/etc/mtab'
if not os.access(mtabFile,os.R_OK):
return ""
return filter(lambda x: x!=absPath,
return filter(lambda x: x!=findPath,
reduce(lambda x,y: y,
filter(lambda x: absPath in x,
map(lambda x: [x[0], x[1]],
map(lambda x: x.split(" "),
ifilter(lambda x: any(p in x for p in findPath),
imap(lambda x: [x[0], x[1]],
imap(lambda x: x.split(" "),
open(mtabFile)))), [""]))[0]
def commonPath(*paths):
@ -505,13 +519,6 @@ def checkDigestFile(digestfile):
digest.hexdigest().upper() == hashdata.upper()))
return result
def getFilesCount(directory):
"""Get files count from directory"""
if path.exists(directory):
return len(reduce(lambda x,y:x+y,map(lambda x:x[1]+x[2],
os.walk(directory)),[]))
return 0
def listDirectory(directory,fullPath=False,onlyDir=False):
"""Get files from directory, if it exists"""
if not path.exists(directory):
@ -664,7 +671,8 @@ class SingletonParam(type):
def __call__(cls,*args,**kw):
keyarg = args[0] if args else ""
if not keyarg in cls.instance:
cls.instance[keyarg] = super(SingletonParam, cls).__call__(*args, **kw)
cls.instance[keyarg] = \
super(SingletonParam, cls).__call__(*args, **kw)
return cls.instance[keyarg]
import device
@ -696,8 +704,9 @@ class FStab(object):
).get('DEVNAME',data[0])
data[1] = data[1] if data[2] != "swap" else "swap"
self.rotateCache = zip(*self.cache)
def getBy(self,what=DIR,where=NAME,_in=None,eq=None,noteq=None,allentry=False):
def getBy(self,what=DIR,where=NAME,_in=None,eq=None,
noteq=None,allentry=False):
"""Get data from fstab"""
if not eq is None:
filterfunc = lambda x: x[where] == eq

@ -193,8 +193,11 @@ class VariableOsLinuxFilesnum(Variable,Linux):
systemRoot = "/"
def get(self):
"""Get files count"""
return str(countFiles(self.systemRoot))
"""Get files count. Count files discard because it to long
operation. This value is already count by calculate-builder and
is placed in calculate3.env"""
return str(0)
#return str(countFiles(self.systemRoot))
class LinuxDataVars(SimpleDataVars):
def __init__(self,systemRoot="/"):

Loading…
Cancel
Save