
import os

# class of static methods

class UtilitiesSimTk: # {

   # -------------------------------------------------------------------------------------------------

   # @staticmethod
   def parseFileName( fileName ):
      """Give full path filename, return path, base file name and file suffix
      """
   
      path, pythonFileName = os.path.split( fileName )
      (basename, suffix)   = pythonFileName.split( '.' )
      return [ path, basename, suffix ]

   parseFileName = staticmethod( parseFileName )

   # -------------------------------------------------------------------------------------------------

   def getTabbedString( leftString, rightString, tab=25, tabChar = ' ' ):
      """LeftString + TabSpace + RightString"""
      fullString = leftString
      for ii in range( len( leftString ), tab ):
         fullString += tabChar;
      fullString += rightString
      return fullString
   getTabbedString = staticmethod( getTabbedString )

   # -------------------------------------------------------------------------------------------------

   def getFilesInDirectory( directoryName, regExIncludeFilter=None, regExExcludeFilter=None ):

      """Get list of files in directory and filter if regExFilters are supplied;
         one or both may be supplied; if directoryName is not a bona fide directory
         return an empty list
      """

      if not os.path.isdir( directoryName ):
         return [];

      fileList = os.listdir( directoryName )

      # apply include filter

      if regExIncludeFilter is not None:
         returnFileList = []
         for file in fileList:
            if regExIncludeFilter.match( file ):
               returnFileList.append( file )
         fileList = returnFileList

      # apply exclude filter

      if regExExcludeFilter is not None:
         returnFileList = []
         for file in fileList:
            if not regExExcludeFilter.match( file ):
               returnFileList.append( file )
         fileList = returnFileList

      return fileList 

   getFilesInDirectory = staticmethod( getFilesInDirectory )

   # -------------------------------------------------------------------------------------------------

   def removeSuffix( name, suffixDelimiter = '.' ):

      """Remove suffix from a name"""

      parts = name.split( suffixDelimiter )
      return parts[0]
   removeSuffix = staticmethod( removeSuffix )

   # -------------------------------------------------------------------------------------------------

# } end of class UtilitiesSimTk
