@ -366,6 +366,9 @@ class processProgress(process):
self . cacheresult = " \n " . join ( self . cacheresult )
self . cacheresult = " \n " . join ( self . cacheresult )
def countFiles ( dirpath , onefilesystem = True ) :
def countFiles ( dirpath , onefilesystem = True ) :
"""
Count files in specified dirpath
"""
num = 1
num = 1
for dirpath , dirnames , filenames in os . walk ( dirpath ) :
for dirpath , dirnames , filenames in os . walk ( dirpath ) :
num + = len ( set ( dirnames ) | set ( filenames ) )
num + = len ( set ( dirnames ) | set ( filenames ) )
@ -376,6 +379,10 @@ def countFiles(dirpath,onefilesystem=True):
dirnames . remove ( dirname )
dirnames . remove ( dirname )
return num
return num
def getFilesCount ( directory ) :
""" Alias for compatibility """
return countFiles ( directory , onefilesystem = False )
def runOsCommand ( cmd , in_str = None , env_dict = None ) :
def runOsCommand ( cmd , in_str = None , env_dict = None ) :
""" Run system command
""" Run system command
@ -445,15 +452,22 @@ def getRunCommands():
def isMount ( pathname ) :
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 '
mtabFile = ' /etc/mtab '
if not os . access ( mtabFile , os . R_OK ) :
if not os . access ( mtabFile , os . R_OK ) :
return " "
return " "
return filter ( lambda x : x != absPath ,
return filter ( lambda x : x != find Path,
reduce ( lambda x , y : y ,
reduce ( lambda x , y : y ,
filter ( lambda x : absPath in x ,
ifilter ( lambda x : any ( p in x for p in findPath ) ,
map ( lambda x : [ x [ 0 ] , x [ 1 ] ] ,
i map( lambda x : [ x [ 0 ] , x [ 1 ] ] ,
map( lambda x : x . split ( " " ) ,
i map( lambda x : x . split ( " " ) ,
open ( mtabFile ) ) ) ) , [ " " ] ) ) [ 0 ]
open ( mtabFile ) ) ) ) , [ " " ] ) ) [ 0 ]
def commonPath ( * paths ) :
def commonPath ( * paths ) :
@ -505,13 +519,6 @@ def checkDigestFile(digestfile):
digest . hexdigest ( ) . upper ( ) == hashdata . upper ( ) ) )
digest . hexdigest ( ) . upper ( ) == hashdata . upper ( ) ) )
return result
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 ) :
def listDirectory ( directory , fullPath = False , onlyDir = False ) :
""" Get files from directory, if it exists """
""" Get files from directory, if it exists """
if not path . exists ( directory ) :
if not path . exists ( directory ) :
@ -664,7 +671,8 @@ class SingletonParam(type):
def __call__ ( cls , * args , * * kw ) :
def __call__ ( cls , * args , * * kw ) :
keyarg = args [ 0 ] if args else " "
keyarg = args [ 0 ] if args else " "
if not keyarg in cls . instance :
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 ]
return cls . instance [ keyarg ]
import device
import device
@ -696,8 +704,9 @@ class FStab(object):
) . get ( ' DEVNAME ' , data [ 0 ] )
) . get ( ' DEVNAME ' , data [ 0 ] )
data [ 1 ] = data [ 1 ] if data [ 2 ] != " swap " else " swap "
data [ 1 ] = data [ 1 ] if data [ 2 ] != " swap " else " swap "
self . rotateCache = zip ( * self . cache )
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 """
""" Get data from fstab """
if not eq is None :
if not eq is None :
filterfunc = lambda x : x [ where ] == eq
filterfunc = lambda x : x [ where ] == eq