CMS 3D CMS Logo

Functions | Variables
FileUtils Namespace Reference

Functions

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

Variables

 historyPath
 

Function Documentation

◆ loadListFromFile()

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

Definition at line 6 of file FileUtils.py.

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: file '%s' does not exist."%(filename))
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 
23 

References edm.print().

◆ save_history()

def FileUtils.save_history (   historyPath = historyPath)

Definition at line 60 of file FileUtils.py.

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 
66 

◆ sectionNofTotal()

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

Definition at line 24 of file FileUtils.py.

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 
42 

Variable Documentation

◆ historyPath

FileUtils.historyPath

Definition at line 57 of file FileUtils.py.

FileUtils.loadListFromFile
def loadListFromFile(filename)
Definition: FileUtils.py:6
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
FileUtils.save_history
def save_history(historyPath=historyPath)
Definition: FileUtils.py:60
FileUtils.sectionNofTotal
def sectionNofTotal(inputList, currentSection, numSections)
Definition: FileUtils.py:24