CMS 3D CMS Logo

Functions | Variables

FileUtils Namespace Reference

Functions

def loadListFromFile
def save_history
def sectionNofTotal

Variables

tuple historyPath = os.path.expanduser("~/.pyhistory")

Function Documentation

def FileUtils::loadListFromFile (   filename)
Loads a list of strings from file.  Will append to given list
if asked.

Definition at line 5 of file FileUtils.py.

00006                                :
00007     """Loads a list of strings from file.  Will append to given list
00008     if asked."""
00009     retval = []
00010     filename = os.path.expanduser (filename)
00011     if not os.path.exists (filename):
00012         print "Error: '%s' file does not exist."
00013         raise RuntimeError, "Bad filename"
00014     source = open (filename, 'r')        
00015     for line in source.readlines():
00016         line = re.sub (r'#.+$', '', line) # remove comment characters
00017         line = line.strip()
00018         if len (line):
00019             retval.append (line)
00020     source.close()
00021     return retval
00022 

def FileUtils::save_history (   historyPath = historyPath)

Definition at line 59 of file FileUtils.py.

00060                                              :
00061         import readline
00062         readline.write_history_file(historyPath)
00063         if os.path.exists(historyPath):
00064             readline.read_history_file(historyPath)
00065 

def FileUtils::sectionNofTotal (   inputList,
  currentSection,
  numSections 
)
Returns the appropriate sublist given the current section
(1..numSections)

Definition at line 23 of file FileUtils.py.

00024                                                             :
00025     """Returns the appropriate sublist given the current section
00026     (1..numSections)"""
00027     currentSection -= 1 # internally, we want 0..N-1, not 1..N
00028     size       = len (inputList)
00029     perSection = size // numSections
00030     extra      = size %  numSections
00031     start      = perSection * currentSection
00032     num        = perSection
00033     if currentSection < extra:
00034         # the early sections get an extra item
00035         start += currentSection
00036         num   += 1
00037     else:
00038         start += extra
00039     stop = start + num
00040     return inputList[ start:stop ]
00041 


Variable Documentation

tuple FileUtils::historyPath = os.path.expanduser("~/.pyhistory")

Definition at line 56 of file FileUtils.py.