utils Namespace Reference

Functions

def writefile (fname, fill)
 
def killfiles (lst)
 
def reverse (retto)
 
def openPipe (command)
 
def hierher_openPipe (command)
 
def runShellCommand (command)
 
def getURLName (url)
 
def downloader (uri, cmd)
 
def ynask (quest)
 
def fixpaths (inpath)
 

Function Documentation

◆ downloader()

def utils.downloader (   uri,
  cmd 
)
 downloads the content of an URL 
150 def downloader(uri,cmd):
151  """ downloads the content of an URL """
152 
153  name = getURLName(uri)
154  try:
155  if(cmd == 'urllib2'):
156  import urllib.request, urllib.error, urllib.parse
157  url = urllib.request.urlopen(uri)
158  f = open(name,'w')
159  for line in url.readlines():
160  f.write(line)
161  url.close()
162  f.close()
163  elif(cmd == 'wget'):
164  comm = 'wget '+uri
165  (output, error, retz) = runShellCommand(comm)
166  else:
167  raise
168  except:
169  print(" ")
170  print("=================================================================================")
171  print("Cannot download"+name)
172  print("Make sure the network is reachable.")
173  print("Packages may be downloaded with wget though a proxy; in order to")
174  print("enable this feature it is enough the set the http_proxy environment")
175  print("variable (read the wget man pages for more details).")
176  print("If you still have troubles, you can manually download "+name+" from this URL:")
177  print(uri)
178  print("into the current directory:")
179  print(os.getcwd())
180 
181 
182 
if(UPLO(*uplo)==INVALID) info
Definition: level3_impl.h:428
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet print(const Packet &a)
Definition: GenericPacketMath.h:1166
def downloader(uri, cmd)
Definition: utils.py:150
def runShellCommand(command)
Definition: utils.py:87
def getURLName(url)
Definition: utils.py:137

References getURLName(), if(), Eigen::internal.print(), and runShellCommand().

Referenced by scalapack.Scalapack.down_install(), blacs.Blacs.down_install_blacs(), blas.Blas.down_install_blas(), and lapack.Lapack.down_install_lapack().

◆ fixpaths()

def utils.fixpaths (   inpath)
195 def fixpaths(inpath):
196 
197  lst = inpath.split(" ")
198 
199  outpath = ""
200 
201  if(len(lst) == 1):
202  outpath = os.path.abspath(inpath)
203  return outpath
204  else:
205  for i in lst:
206  if re.search("^-L",i):
207  p = "-L"+os.path.abspath(i[2:])
208  else:
209  p = i
210 
211  outpath = outpath+p+" "
212 
213  return outpath
def fixpaths(inpath)
Definition: utils.py:195

References if().

Referenced by framework.Frame.parse_args().

◆ getURLName()

def utils.getURLName (   url)
137 def getURLName(url):
138  directory=os.curdir
139 
140  name="%s%s%s" % (
141  directory,
142  os.sep,
143  url.split("/")[-1]
144  )
145 
146  return name
147 
148 
149 

Referenced by scalapack.Scalapack.down_install(), blacs.Blacs.down_install_blacs(), blas.Blas.down_install_blas(), lapack.Lapack.down_install_lapack(), and downloader().

◆ hierher_openPipe()

def utils.hierher_openPipe (   command)
52 def hierher_openPipe(command):
53 
54  import subprocess
55  #import popen2
56 
57  pipe = None
58 
59  #if hasattr(popen2, 'Popen3'):
60  # pipe = popen2.Popen3(command, 1)
61  # input = pipe.tochild
62  # output = pipe.fromchild
63  # err = pipe.childerr
64  # to here
65  #else:
66 
67  # new from https://docs.python.org/2/library/subprocess.html#subprocess-replacements
68  p = subprocess.Popen(command, shell=True,
69  stdin=subprocess.PIPE,
70  stdout=subprocess.PIPE,
71  stderr=subprocess.PIPE,
72  close_fds=True)
73  pipe = p
74  (input,
75  output,
76  err) = (p.stdin, p.stdout, p.stderr)
77 
78  # orig:
79  # import os
80  # (input, output, err) = os.popen3(command)
81 
82 
83  return (input, output, err, pipe)
84 
85 
86 
def hierher_openPipe(command)
Definition: utils.py:52

◆ killfiles()

def utils.killfiles (   lst)
 deletes a list of files 
23 def killfiles(lst):
24  """ deletes a list of files """
25  for i in lst:
26  if(os.path.isfile(i)):
27  os.remove(i)
28 
29 
def killfiles(lst)
Definition: utils.py:23

References if().

Referenced by blacs.Blacs.check_blacs(), blas.Blas.check_blas(), lapack.Lapack.check_lapack(), framework.Frame.check_linking(), framework.Frame.check_mpicc(), framework.Frame.check_mpif77(), framework.Frame.set_mangling(), and blacs.Blacs.set_transcomm().

◆ openPipe()

def utils.openPipe (   command)
40 def openPipe(command):
41 
42  import subprocess
43 
44  pipe = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE,
45  stdout=subprocess.PIPE, stderr=subprocess.PIPE,
46  text=True, close_fds=True)
47  (input, output, err) = (pipe.stdin, pipe.stdout, pipe.stderr)
48  return (input, output, err, pipe)
49 
50 
51 # old version; now completely bypassed by function above
def openPipe(command)
Definition: utils.py:40

Referenced by runShellCommand().

◆ reverse()

def utils.reverse (   retto)
 reverses a string 
30 def reverse(retto):
31  """ reverses a string """
32  verso = list(retto) # string -> list of chars
33  verso.reverse() # inplace reverse the list
34  verso = ''.join(verso)
35  return verso
36 
37 # Puneet's replacement for the original openPipe function (still
38 # included below in half-edited stated for reference; prefixed by
39 # "hierher_"
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:17

◆ runShellCommand()

def utils.runShellCommand (   command)
 runs a shell command 
87 def runShellCommand(command):
88  """ runs a shell command """
89 
90  import select
91 
92  ret = None
93  out = ''
94  err = ''
95  (input, output, error, pipe) = openPipe(command)
96  input.close()
97  outputClosed = 0
98  errorClosed = 0
99  lst = [output, error]
100  while 1:
101  ready = select.select(lst, [], [])
102  if len(ready[0]):
103  if error in ready[0]:
104  msg = error.readline()
105  if msg:
106  err += str(msg)
107  else:
108  errorClosed = 1
109  lst.remove(error)
110  if output in ready[0]:
111  msg = output.readline()
112  if msg:
113  out += str(msg)
114  else:
115  outputClosed = 1
116  lst.remove(output)
117  if outputClosed and errorClosed:
118  break
119  output.close()
120  error.close()
121  if pipe:
122  ret = pipe.wait()
123 
124  if not isinstance(out,str):
125  out=out.decode("utf-8")
126 
127  if not isinstance(err,str):
128  err=err.decode("utf-8")
129 
130  if not isinstance(ret,str):
131  ret=ret # .decode("utf-8")
132 
133  return (out, err, ret)
134 
135 
136 
str
Definition: compute_granudrum_aor.py:141

References openPipe(), and compute_granudrum_aor.str.

Referenced by framework.Frame.cc_is_gnu(), framework.Frame.cc_is_intel(), framework.Frame.cc_is_pgi(), blacs.Blacs.check_blacs(), blas.Blas.check_blas(), lapack.Lapack.check_lapack(), framework.Frame.check_linking(), framework.Frame.check_mpicc(), framework.Frame.check_mpif77(), framework.Frame.cleanup(), scalapack.Scalapack.down_install(), blacs.Blacs.down_install_blacs(), blas.Blas.down_install_blas(), lapack.Lapack.down_install_lapack(), downloader(), framework.Frame.fc_is_gnu(), framework.Frame.fc_is_intel(), framework.Frame.fc_is_pgi(), framework.Frame.set_download(), lapack.Lapack.set_etime(), framework.Frame.set_mangling(), and blacs.Blacs.set_transcomm().

◆ writefile()

def utils.writefile (   fname,
  fill 
)

◆ ynask()

def utils.ynask (   quest)
 asks a binary question 
183 def ynask(quest):
184  """ asks a binary question """
185  print(quest)
186  ans = ''
187  while(ans != 'y' and ans != 'n'):
188  ans = input("[y/n] :")
189  if (ans != 'y' and ans != 'n'):
190  print("Please answer \"y\" for yes or \"n\" for no")
191 
192  return ans
193 
194 
def ynask(quest)
Definition: utils.py:183

References Eigen::internal.print().