All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
python.mkdir Namespace Reference

Functions

def main
 
def help
 
def mkdir
 
def existdir
 

Variables

tuple Ifdh = ifdh.ifdh()
 
tuple rc = main(sys.argv)
 

Function Documentation

def python.mkdir.existdir (   dir,
  verbose 
)

Definition at line 161 of file mkdir.py.

162 def existdir(dir, verbose):
163 
164  # Remove trailing '/' character(s), if any (except if or until entire path is '/').
165 
166  while len(dir) > 1 and dir[-1] == '/':
167  dir = dir[:-1]
168 
169  # If at this point, the directory path has been reduced to just '/', return True.
170 
171  if dir == '/':
172  return True
173 
174  # Check contents of parent directory (if any).
175  # If ifdh ls for the parent directory fails, return false.
176  # Note that ifdh may print out various alarming but harmless
177  # message at this point.
178 
179  parent = os.path.dirname(dir)
180  base = os.path.basename(dir)
181  contents = []
182  try:
183  contents = Ifdh.ls(parent, 1)
184  except:
185  contents = []
186 
187  # Loop over parent directory contents.
188  # Only compare the base part of the path, since the mountpoint may differ.
189 
190  for content in contents:
191 
192  # Is this a directory (ifdh signals by adding '/' at end)?
193 
194  if len(content) > 1 and content[-1] == '/':
195 
196  # Does base match?
197 
198  if os.path.basename(content[:-1]) == base:
199  return True
200 
201  # If we fall out of the loopp, that means we didn't find this directory
202  # in the parent directory.
203 
204  return False
205 
206 # Command line.
def existdir
Definition: mkdir.py:161
def python.mkdir.help ( )

Definition at line 79 of file mkdir.py.

79 
80 def help():
81  filename = sys.argv[0]
82  file = open(filename, 'r')
83 
84  doprint=0
85 
86  for line in file.readlines():
87  if line[2:10] == 'mkdir.py':
88  doprint = 1
89  elif line[0:6] == '######' and doprint:
90  doprint = 0
91  if doprint:
92  if len(line) > 2:
93  print(line[2:], end=' ')
94  else:
95  print()
96  return
97 
98 
99 # This function safely creates the specified directory and parent directories
100 # if they don't exist. It is not an error if the specified directory already
101 # exists.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def help
Definition: mkdir.py:79
open(RACETRACK) or die("Could not open file $RACETRACK for writing")
def python.mkdir.main (   argv)

Definition at line 46 of file mkdir.py.

46 
47 def main(argv):
48 
49  verbose = 0
50  dir = ''
51 
52  # Parse arguments.
53 
54  args = argv[1:]
55  if len(args) == 0:
56  help()
57  return 0
58  while len(args) > 0:
59  if args[0] == '-h' or args[0] == '--help' :
60  help()
61  return 0
62  elif args[0] == '-v':
63  verbose = 1
64  del args[0]
65  elif args[0][0] == '-':
66  print('Unknown option %s' % args[0])
67  return 1
68  else:
69  if dir != '':
70  print('Too many arguments.')
71  return 1
72  dir = args[0]
73  del args[0]
74 
75  mkdir(dir, verbose)
76  return
77 
78 # Help function.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def help
Definition: mkdir.py:79
def mkdir
Definition: mkdir.py:102
def main
Definition: mkdir.py:46
def python.mkdir.mkdir (   dir,
  verbose 
)

Definition at line 102 of file mkdir.py.

103 def mkdir(dir, verbose):
104 
105  # Remove trailing '/' character(s), if any (except if or until entire path is '/').
106 
107  while len(dir) > 1 and dir[-1] == '/':
108  dir = dir[:-1]
109 
110  # If at this point, the directory path has been reduced to just '/', quit.
111 
112  if dir == '/':
113  if verbose:
114  print('mkdir asked to make directory \'/\'.')
115  return
116 
117  # Test whether target directory already exists.
118 
119  exists = existdir(dir, verbose)
120  if exists:
121 
122  # If target directory already exists, just return.
123 
124  if verbose:
125  print('Directory %s already exists.' % dir)
126  return
127 
128  else:
129 
130  # Target directoroy doesn't exist.
131 
132  if verbose:
133  print('Directory %s doesn\'t exist.' % dir)
134 
135  # Make sure that the parent directory exists by calling this function recursively.
136 
137  parent = os.path.dirname(dir)
138  mkdir(parent, verbose)
139 
140  # Make the directory.
141  # Catch errors and exit with error status in that case.
142 
143  ok = False
144  try:
145  if verbose:
146  print('Making directory %s' % dir)
147  Ifdh.mkdir(dir)
148  ok = True
149  except:
150  print('Caught exception from Ifdh.mkdir for directory %s.' % dir)
151  ok = False
152  if not ok:
153  sys.exit(1)
154 
155  # Done (success).
156 
157  return
158 
159 
160 # This function tests whether the specified directory exists.
do one_file $F done echo for F in find $TOP name CMakeLists txt print
def mkdir
Definition: mkdir.py:102
def existdir
Definition: mkdir.py:161

Variable Documentation

tuple python.mkdir.Ifdh = ifdh.ifdh()

Definition at line 42 of file mkdir.py.

tuple python.mkdir.rc = main(sys.argv)

Definition at line 208 of file mkdir.py.