PLUTO
pluto_files_IO.PlutoFiles Class Reference
Inheritance diagram for pluto_files_IO.PlutoFiles:
Collaboration diagram for pluto_files_IO.PlutoFiles:

Public Member Functions

def __init__ (self, fname)
 
def OpenFile (self)
 
def List2File (self, contents)
 
def File2List (self)
 
def LocateString (self, string)
 
def DeleteLines (self, lbeg, lend)
 
def InsertLine (self, string, lbeg)
 
def ReplaceLine (self, NewLine, OldLineIndex)
 
def ReplaceWord
 
def ReadLines (self, beg, end)
 
def UpdateListFromFile (self, scrhlist, updatelist)
 
def ReplaceObsoletes (self)
 

Public Attributes

 fname
 
 f
 
 fc
 

Detailed Description

Definition at line 4 of file pluto_files_IO.py.

Constructor & Destructor Documentation

def pluto_files_IO.PlutoFiles.__init__ (   self,
  fname 
)

Definition at line 5 of file pluto_files_IO.py.

5  def __init__(self, fname):
6  self.fname = fname
7 
def __init__(self, fname)

Member Function Documentation

def pluto_files_IO.PlutoFiles.DeleteLines (   self,
  lbeg,
  lend 
)

Definition at line 48 of file pluto_files_IO.py.

48  def DeleteLines(self, lbeg, lend):
49  scrh = self.File2List()
50  del scrh[lbeg:lend+1]
51  self.List2File(scrh)
52 
def List2File(self, contents)
def DeleteLines(self, lbeg, lend)

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.File2List (   self)

Definition at line 22 of file pluto_files_IO.py.

22  def File2List(self):
23  NewList = []
24  self.OpenFile()
25  for line in self.f.readlines():
26  NewList.append(line)
27  return NewList
28 

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.InsertLine (   self,
  string,
  lbeg 
)

Definition at line 53 of file pluto_files_IO.py.

53  def InsertLine(self, string, lbeg):
54  scrh = self.File2List()
55  scrh.insert(lbeg, string) #Inserts String at position lbeg.
56  self.List2File(scrh)
57 
def List2File(self, contents)
def InsertLine(self, string, lbeg)

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.List2File (   self,
  contents 
)

Definition at line 14 of file pluto_files_IO.py.

14  def List2File(self, contents):
15  self.fc = open(self.fname, 'w')
16  # contents is a List.
17  for item in contents:
18  self.fc.write("%s"%item)
19 
20  self.fc.close()
21 
def List2File(self, contents)

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.LocateString (   self,
  string 
)

Definition at line 29 of file pluto_files_IO.py.

29  def LocateString(self,string):
30  strlist = []
31  scrh = self.File2List()
32  for item in scrh:
33  if len(string.split()) == 1 and string.split()[0] == string: # Look for 1 word
34  if string in item.split():
35  strlist.append([scrh.index(item), item])
36 
37  # Look for the whole string... Careful with \n matches thats why 1 word match is better
38  elif len(string.split()) > 1:
39  if string == item:
40  strlist.append([scrh.index(item), item])
41 
42  else:
43  print "Invalid String in LocateString"
44  sys.exit()
45 
46  return strlist
47 
def LocateString(self, string)

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.OpenFile (   self)

Definition at line 8 of file pluto_files_IO.py.

8  def OpenFile(self):
9  try:
10  self.f = open(self.fname, 'r')
11  except IOError:
12  print "File : %s not found"%self.fname
13 

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.ReadLines (   self,
  beg,
  end 
)

Definition at line 80 of file pluto_files_IO.py.

80  def ReadLines(self, beg, end):
81  scrh = self.File2List()
82  return scrh[beg:end+1]
83 
def ReadLines(self, beg, end)

Here is the call graph for this function:

def pluto_files_IO.PlutoFiles.ReplaceLine (   self,
  NewLine,
  OldLineIndex 
)

Definition at line 58 of file pluto_files_IO.py.

58  def ReplaceLine(self, NewLine, OldLineIndex):
59  scrh = self.File2List()
60  scrh[OldLineIndex] = NewLine
61  self.List2File(scrh)
62 
def ReplaceLine(self, NewLine, OldLineIndex)
def List2File(self, contents)

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.ReplaceObsoletes (   self)

Definition at line 94 of file pluto_files_IO.py.

94  def ReplaceObsoletes(self):
95  oldwords = ['INCLUDE_ROTATION', 'INCLUDE_BODY_FORCE', 'INCLUDE_COOLING', 'INCLUDE_BACKGROUND_FIELD',
96  'TIME_EVOLUTION', 'RAYMOND', 'NEQ', 'CT_VEC_POT_INIT', 'USE_VECTOR_POTENTIAL',
97  'SAVE_VEC_POT']
98  newwords = ['ROTATING_FRAME', 'BODY_FORCE', 'COOLING','BACKGROUND_FIELD', 'TIME_STEPPING', 'SNEq',
99  'MINEq', 'USE_VECTOR_POTENTIAL', 'ASSIGN_VECTOR_POTENTIAL', 'UPDATE_VECTOR_POTENTIAL']
100 
101  for i in range(len(oldwords)):
102  self.ReplaceWord(oldwords[i],newwords[i])
103 

Here is the call graph for this function:

def pluto_files_IO.PlutoFiles.ReplaceWord (   self,
  oldword,
  newword,
  DelOld = False 
)

Definition at line 63 of file pluto_files_IO.py.

63  def ReplaceWord(self, oldword, newword, DelOld = False):
64  scrh = self.LocateString(oldword)
65  try:
66  scrh[0]
67  except IndexError:
68  #print 'Word %s not found in file %s'%(oldword, self.fname)
69  pass
70  else:
71  l = scrh[0][1].split(' ')
72  l[l.index(oldword)] = newword
73  newline = ' '.join(l)
74  if DelOld:
75  self.DeleteLines(scrh[0][0], scrh[0][0])
76  self.InsertLine(newword, scrh[0][0])
77  else:
78  self.ReplaceLine(newline,scrh[0][0])
79 
def LocateString(self, string)
def ReplaceLine(self, NewLine, OldLineIndex)
def InsertLine(self, string, lbeg)
def DeleteLines(self, lbeg, lend)

Here is the call graph for this function:

Here is the caller graph for this function:

def pluto_files_IO.PlutoFiles.UpdateListFromFile (   self,
  scrhlist,
  updatelist 
)

Definition at line 84 of file pluto_files_IO.py.

84  def UpdateListFromFile(self, scrhlist, updatelist):
85  self.OpenFile()
86  for line in self.f.readlines():
87  for e in scrhlist:
88  if e in line.split():
89  updatelist[scrhlist.index(e)] = line.split()[-1]
90  else:
91  continue
92 
93 
def UpdateListFromFile(self, scrhlist, updatelist)

Here is the call graph for this function:

Member Data Documentation

pluto_files_IO.PlutoFiles.f

Definition at line 10 of file pluto_files_IO.py.

pluto_files_IO.PlutoFiles.fc

Definition at line 15 of file pluto_files_IO.py.

pluto_files_IO.PlutoFiles.fname

Definition at line 6 of file pluto_files_IO.py.


The documentation for this class was generated from the following file: