CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.

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

Definition at line 59 of file FileUtils.py.

59 
60  def save_history(historyPath=historyPath):
61  import readline
62  readline.write_history_file(historyPath)
63  if os.path.exists(historyPath):
64  readline.read_history_file(historyPath)
65 
def save_history
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 
24 def sectionNofTotal (inputList, currentSection, numSections):
25  """Returns the appropriate sublist given the current section
26  (1..numSections)"""
27  currentSection -= 1 # internally, we want 0..N-1, not 1..N
28  size = len (inputList)
29  perSection = size // numSections
30  extra = size % numSections
31  start = perSection * currentSection
32  num = perSection
33  if currentSection < extra:
34  # the early sections get an extra item
35  start += currentSection
36  num += 1
37  else:
38  start += extra
39  stop = start + num
40  return inputList[ start:stop ]
41 
def sectionNofTotal
Definition: FileUtils.py:23

Variable Documentation

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

Definition at line 56 of file FileUtils.py.