Commit fb865642 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added 'findInvalidFileAndDirNames()' method + use os.stat(path).st_size to calculate file/dir size.

parent 432164b1
Loading
Loading
Loading
Loading
+21 −9
Original line number Original line Diff line number Diff line
@@ -10,8 +10,6 @@ import re
import shutil
import shutil
import sys
import sys


from exceptions import IllegalCharacterException



class SystemUtils(object):
class SystemUtils(object):
    
    
@@ -56,21 +54,35 @@ class SystemUtils(object):
        else:
        else:
            return False
            return False
        
        
    def findInvalidFileAndDirNames(self, path):
        """
        Scans 'path' recursively to search for file/dir names with
        invalid characters.
        """
        invalidList = []
        for folder, subfolders, files in os.walk(path, topdown = True):
            cwd = os.path.basename(folder)
            folderAbsPath = os.path.dirname(folder) + '/' + cwd
            if self.findIllegalCharacters(cwd):
                invalidList.append([folderAbsPath])
            for f in files:
                fileAbsPath = folderAbsPath + '/' + f
                if self.findIllegalCharacters(f):
                    invalidList.append([fileAbsPath])
        return invalidList

    def scanRecursive(self, path):
    def scanRecursive(self, path):
        """Performs a recursive scan of dirs and files."""
        dirList = []
        dirList = []
        fileList = []
        fileList = []
        for folder, subfolders, files in os.walk(path, topdown = True):
        for folder, subfolders, files in os.walk(path, topdown = True):
            cwd = os.path.basename(folder)
            cwd = os.path.basename(folder)
            if folder != path:
            if folder != path:
                folderAbsPath = os.path.dirname(folder) + '/' + cwd
                folderAbsPath = os.path.dirname(folder) + '/' + cwd
                if self.findIllegalCharacters(cwd):
                    raise(IllegalCharacterException(folderAbsPath))
                dirList.append(folderAbsPath)
                dirList.append(folderAbsPath)
                i = 0
                i = 0
                for f in files:
                for f in files:
                    fileAbsPath = folderAbsPath + '/' + f
                    fileAbsPath = folderAbsPath + '/' + f
                    if self.findIllegalCharacters(f):
                        raise(IllegalCharacterException(fileAbsPath))
                    files[i] = fileAbsPath
                    files[i] = fileAbsPath
                    i += 1
                    i += 1
                fileList.append(files)
                fileList.append(files)
@@ -105,18 +117,18 @@ class SystemUtils(object):
        """
        """
        size = 0
        size = 0
        if os.path.isfile(path) and not os.path.islink(path):
        if os.path.isfile(path) and not os.path.islink(path):
            size = os.path.getsize(path)    
            size = os.stat(path).st_size
        elif os.path.isdir(path) and not os.path.islink(path):            
        elif os.path.isdir(path) and not os.path.islink(path):            
            for folder, subfolders, files in os.walk(path, topdown = True):
            for folder, subfolders, files in os.walk(path, topdown = True):
                cwd = os.path.basename(folder)
                cwd = os.path.basename(folder)
                parent = os.path.dirname(folder)
                parent = os.path.dirname(folder)
                base = parent + '/' + cwd
                base = parent + '/' + cwd
                if not os.path.islink(folder):
                if not os.path.islink(folder):
                    size += os.path.getsize(folder)
                    size += os.stat(folder).st_size
                    for f in files:
                    for f in files:
                        file = base + '/' + f
                        file = base + '/' + f
                        if not os.path.islink(file):
                        if not os.path.islink(file):
                            size += os.path.getsize(file)
                            size += os.stat(file).st_size
        return size
        return size


    def getFileSystemSize(self, path):
    def getFileSystemSize(self, path):