CMS 3D CMS Logo

Functions
FileUtils Namespace Reference

Functions

def loadListFromFile (filename)
 
def save_history (historyPath=historyPath)
 
def sectionNofTotal (inputList, currentSection, numSections)
 

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.

5 def loadListFromFile (filename):
6  """Loads a list of strings from file. Will append to given list
7  if asked."""
8  retval = []
9  filename = os.path.expanduser (filename)
10  if not os.path.exists (filename):
11  print "Error: file '%s' does not exist."%(filename)
12  raise RuntimeError("Bad filename")
13  source = open (filename, 'r')
14  for line in source.readlines():
15  line = re.sub (r'#.+$', '', line) # remove comment characters
16  line = line.strip()
17  if len (line):
18  retval.append (line)
19  source.close()
20  return retval
21 
22 
def loadListFromFile(filename)
Definition: FileUtils.py:5
def FileUtils.save_history (   historyPath = historyPath)

Definition at line 59 of file FileUtils.py.

59  def save_history(historyPath=historyPath):
60  import readline
61  readline.write_history_file(historyPath)
62  if os.path.exists(historyPath):
63  readline.read_history_file(historyPath)
64 
65 
def save_history(historyPath=historyPath)
Definition: FileUtils.py:59
def FileUtils.sectionNofTotal (   inputList,
  currentSection,
  numSections 
)
Returns the appropriate sublist given the current section
(1..numSections)

Definition at line 23 of file FileUtils.py.

23 def sectionNofTotal (inputList, currentSection, numSections):
24  """Returns the appropriate sublist given the current section
25  (1..numSections)"""
26  currentSection -= 1 # internally, we want 0..N-1, not 1..N
27  size = len (inputList)
28  perSection = size // numSections
29  extra = size % numSections
30  start = perSection * currentSection
31  num = perSection
32  if currentSection < extra:
33  # the early sections get an extra item
34  start += currentSection
35  num += 1
36  else:
37  start += extra
38  stop = start + num
39  return inputList[ start:stop ]
40 
41 
def sectionNofTotal(inputList, currentSection, numSections)
Definition: FileUtils.py:23