irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

lib.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import base64
3 import collections
4 import contextlib
5 import copy
6 import errno
7 import getpass
8 import grp
9 import hashlib
10 import itertools
11 import json
12 import logging
13 import mmap
14 import os
15 import platform
16 import pprint
17 import psutil
18 import pwd
19 import re
20 import shlex
21 import shutil
22 import socket
23 import subprocess
24 import sys
25 import tempfile
26 import time
27 
28 from . import six
29 
30 from .exceptions import IrodsError, IrodsWarning
31 from . import paths
32 
33 # get the fully qualified domain name
34 #(no, really, getfqdn() is insufficient)
36  return socket.getaddrinfo(
37  socket.gethostname(), 0, 0, 0, 0, socket.AI_CANONNAME)[0][3]
38 
40  if not isinstance(args, str) and isinstance(args, six.text_type):
41  args = args.encode('ascii')
42  return shlex.split(args)
43 
44 def execute_command_nonblocking(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, use_unsafe_shell=False, **kwargs):
45  l = logging.getLogger(__name__)
46  if not use_unsafe_shell and isinstance(args, six.string_types):
47  args = safe_shlex_split_for_2_6(args)
48  kwargs['stdout'] = stdout
49  kwargs['stderr'] = stderr
50  kwargs['shell'] = use_unsafe_shell
51  if 'env' in kwargs:
52  kwargs_without_env = copy.copy(kwargs)
53  kwargs_without_env['env'] = 'HIDDEN'
54  else :
55  kwargs_without_env = kwargs
56  l.debug('Calling %s with options:\n%s', args, pprint.pformat(kwargs_without_env))
57  try :
58  return subprocess.Popen(args, **kwargs)
59  except OSError as e:
60  six.reraise(IrodsError,
61  IrodsError('\n'.join([
62  'Call to open process with {0} failed:'.format(
63  args),
64  indent(
65  'Could not find the requested executable \'{0}\'; '
66  'please ensure \'{0}\' is installed and in the path.'.format(
67  args[0]))])),
68  sys.exc_info()[2])
69 
70 def execute_command_timeout(args, timeout=10, **kwargs):
71  p = execute_command_nonblocking(args, **kwargs)
72  start_time = time.time()
73  while time.time() < start_time + timeout:
74  if p.poll() is not None:
75  out, err = communicate_and_log(p, args)
76  check_command_return(args, out, err, p.returncode, **kwargs)
77  break
78  time.sleep(0.3)
79  else:
80  try:
81  if p.poll() is None:
82  p.kill()
83  except OSError:
84  pass
85  raise IrodsError(
86  'The call {0} did not complete within'
87  ' {1} seconds.'.format(args, timeout))
88 
89 def execute_command_permissive(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=None, **kwargs):
90  if input is not None:
91  if 'stdin' in kwargs and kwargs['stdin'] != subprocess.PIPE:
92  raise IrodsError('\'input\' option is mutually exclusive with a \'stdin\' '
93  'option that is not equal to \'subprocess.PIPE\'.')
94  kwargs['stdin'] = subprocess.PIPE
95  p = execute_command_nonblocking(args, stdout=stdout, stderr=stderr, **kwargs)
96 
97  out, err = communicate_and_log(p, args, input)
98  return (out, err, p.returncode)
99 
100 def check_command_return(args, out, err, returncode, **kwargs):
101  if returncode is not None and returncode != 0:
102  if 'env' in kwargs:
103  kwargs_without_env = copy.copy(kwargs)
104  kwargs_without_env['env'] = 'HIDDEN'
105  else :
106  kwargs_without_env = kwargs
107  raise IrodsError('\n'.join([
108  'Call to open process with {0} returned an error:'.format(
109  args),
110  indent(
111  'Options passed to Popen:',
112  indent(*['{0}: {1}'.format(k, v) for k, v in kwargs_without_env.items()]),
113  'Return code: {0}'.format(returncode),
114  'Standard output:',
115  indent(out),
116  'Error output:',
117  indent(err))]))
118 
119 def communicate_and_log(p, args, input=None):
120  l = logging.getLogger(__name__)
121  out, err = [t.decode('utf_8') for t in p.communicate(input=(input.encode('ascii') if input is not None else None))]
122  message = ['Command %s returned with code %s.' % (args, p.returncode)]
123  if input:
124  message.append('stdin:\n%s' % indent(input))
125  if out:
126  message.append('stdout:\n%s' % indent(out))
127  if err:
128  message.append('stderr:\n%s' % indent(err))
129  l.debug('\n'.join(message))
130  return (out, err)
131 
132 def execute_command(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs):
133  out, err, returncode = execute_command_permissive(args, stdout=stdout, stderr=stderr, **kwargs)
134  check_command_return(args, out, err, returncode, **kwargs)
135 
136  return (out, err)
137 
138 def indent(*text, **kwargs):
139  if 'indentation' in kwargs:
140  indentation = kwargs['indentation']
141  else:
142  indentation=' '
143  return '\n'.join([
144  ''.join([indentation, '\n{0}'.format(indentation).join(lines.splitlines())])
145  for lines in text])
146 
147 def get_pids_executing_binary_file(binary_file_path):
148  def get_exe(process):
149  if psutil.version_info >= (2,0):
150  return process.exe()
151  return process.exe
152  abspath = os.path.abspath(binary_file_path)
153  pids = []
154  for p in psutil.process_iter():
155  try:
156  if abspath == get_exe(p):
157  pids.append(p.pid)
158  except (psutil.NoSuchProcess, psutil.AccessDenied):
159  pass
160  return pids
161 
162 def kill_pid(pid):
163  p = psutil.Process(pid)
164  p.suspend()
165  p.terminate()
166  p.kill()
167 
168 def find_shared_object(so_name, regex=False, additional_directories=[]):
169  paths = []
170  if regex:
171  so_regex = re.compile(so_name)
172 
173  if 'LD_PRELOAD' in os.environ:
174  for path in os.environ['LD_PRELOAD'].split(':'):
175  if path not in paths and os.path.exists(path) and (
176  (regex and so_regex.match(os.path.basename(path))) or
177  (not regex and os.path.basename(path) == so_name)):
178  paths.append(path)
179 
180  if 'LD_LIBRARY_PATH' in os.environ:
181  for directory in os.environ['LD_LIBRARY_PATH'].split(':'):
182  if regex and os.path.exists(directory):
183  for name in os.listdir(directory):
184  if so_regex.match(name) and os.path.join(directory, name) not in paths:
185  paths.append(os.path.join(directory, name))
186  elif os.path.exists(os.path.join(directory, so_name)) and os.path.join(directory, so_name) not in paths:
187  paths.append(os.path.join(directory, so_name))
188 
189  env = os.environ.copy()
190  env['PATH'] = ':'.join([env['PATH'], '/sbin'])
191  out, _ = execute_command(['ldconfig', '-vNX'], env=env)
192  for directory in [d.rstrip(':') for d in out.splitlines() if d and d[0] == '/']:
193  if regex and os.path.exists(directory):
194  for name in os.listdir(directory):
195  if so_regex.match(name) and os.path.join(directory, name) not in paths:
196  paths.append(os.path.join(directory, name))
197  elif os.path.exists(os.path.join(directory, so_name)) and os.path.join(directory, so_name) not in paths:
198  paths.append(os.path.join(directory, so_name))
199 
200  for (directory, _, names) in itertools.chain(*[os.walk(d) for d in itertools.chain(additional_directories, ['/usr/lib/'])]):
201  if regex:
202  for name in names:
203  if so_regex.match(os.path.basename(name)) and os.path.join(directory, name) not in paths:
204  paths.append(os.path.join(directory, name))
205  elif os.path.exists(os.path.join(directory, so_name)) and os.path.join(directory, so_name) not in paths:
206  paths.append(os.path.join(directory, so_name))
207 
208  return paths
209 
210 def file_digest(filename, hash_type, encoding='hex'):
211  block_size = pow(2, 20)
212  hasher = hashlib.new(hash_type)
213  with open(filename, 'rb') as f:
214  while True:
215  data = f.read(block_size)
216  if not data:
217  break
218  hasher.update(data)
219  if encoding == 'hex':
220  return hasher.hexdigest()
221  if encoding == 'base64':
222  return base64.b64encode(hasher.digest()).decode()
223  if encoding is None or encoding == 'none':
224  return hasher.digest()
225  raise IrodsError('Unknown encoding %s for digest' % (encoding))
226 
227 
229  possible_shm_locations = ['/var/run/shm', '/dev/shm']
230  for l in possible_shm_locations:
231  try:
232  files = os.listdir(l)
233  for f in files:
234  if 'irods' in f.lower():
235  return os.path.join(l, f)
236  except OSError:
237  pass
238  return False
239 
241  rv = []
242  for i in l:
243  if not isinstance(i, str) and isinstance(i, six.text_type):
244  i = i.encode('ascii')
245  elif isinstance(i, list):
246  i = json_object_hook_list(i)
247  rv.append(i)
248  return rv
249 
251  rv = {}
252  for k, v in d.items():
253  if not isinstance(k, str) and isinstance(k, six.text_type):
254  k = k.encode('ascii')
255  if not isinstance(v, str) and isinstance(v, six.text_type):
256  v = v.encode('ascii')
257  elif isinstance(v, list):
258  v = json_object_hook_list(v)
259  rv[k] = v
260  return rv
261 
262 def open_and_load_json(filename):
263  with open(filename, 'rt') as f:
264  return json.load(f, object_hook=json_object_hook_dict)
265 
266 def update_json_file_from_dict(filename, update_dict):
267  env = open_and_load_json(filename)
268  env.update(update_dict)
269  with open(filename, 'wt') as f:
270  json.dump(env, f, indent=4)
271 
272 def create_directory_of_small_files(directory_name_suffix, file_count):
273  if not os.path.exists(directory_name_suffix):
274  os.mkdir(directory_name_suffix)
275  for i in range(file_count):
276  with open('{0}/{1}'.format(directory_name_suffix, i), 'wt') as f:
277  print("iglkg3fqfhwpwpo-" + "A" * i, file=f, end='')
278 
279 def create_local_testfile(filename):
280  filepath = os.path.abspath(filename)
281  with open(filepath, 'wt') as f:
282  print('TESTFILE -- [' + filepath + ']', file=f, end='')
283  return filepath
284 
285 def touch(fname, times=None):
286  with open(fname, 'at'):
287  os.utime(fname, times)
288 
289 def cat(fname, string):
290  with open(fname, 'at') as f:
291  print(string, file=f, end='')
292 
293 def make_file(f_name, f_size, contents='zero', block_size_in_bytes=1000):
294  if contents not in ['arbitrary', 'random', 'zero']:
295  raise AssertionError
296  if contents == 'arbitrary' or f_size == 0:
297  execute_command(['truncate', '-s', str(f_size), f_name])
298  return
299 
300  source = {'zero': '/dev/zero',
301  'random': '/dev/urandom'}[contents]
302 
303  count = f_size / block_size_in_bytes
304  if count > 0:
305  execute_command(['dd', 'if='+source, 'of='+f_name, 'count='+str(count), 'bs='+str(block_size_in_bytes)])
306  leftover_size = f_size % block_size_in_bytes
307  if leftover_size > 0:
308  execute_command(['dd', 'if='+source, 'of='+f_name, 'count=1', 'bs='+str(leftover_size), 'oflag=append', 'conv=notrunc'])
309  else:
310  execute_command(['dd', 'if='+source, 'of='+f_name, 'count=1', 'bs='+str(f_size)])
311 
312 
313 def make_dir_p(directory):
314  try:
315  os.makedirs(directory)
316  except OSError as e:
317  if e.errno == errno.EEXIST and os.path.isdir(directory):
318  pass
319  else:
320  raise
321 
322 def make_large_local_tmp_dir(dir_name, file_count, file_size):
323  os.makedirs(dir_name)
324  for i in range(file_count):
325  make_file(os.path.join(dir_name, "junk" + str(i).zfill(4)),
326  file_size)
327  local_files = os.listdir(dir_name)
328  if len(local_files) != file_count:
329  raise AssertionError("dd loop did not make all " + str(file_count) + " files")
330  return local_files
331 
332 def make_deep_local_tmp_dir(root_name, depth=10, files_per_level=50, file_size=100):
333  # output
334  directories = {}
335 
336  current_dir_name = root_name
337  for d in range(depth):
338  # make subdir and files
339  files = make_large_local_tmp_dir(current_dir_name, files_per_level, file_size)
340 
341  # add to output
342  directories[current_dir_name] = files
343 
344  # next level down
345  current_dir_name = os.path.join(current_dir_name, 'sub'+str(d))
346 
347  return directories
348 
349 def files_in_dir(path):
350  for file in os.listdir(path):
351  if os.path.isfile(os.path.join(path, file)):
352  yield file
353 
354 def get_user_env(user):
355  out, _ = execute_command(['su', '-', user, '-c',
356  'python -c "from __future__ import print_function; import os; import json; print(json.dumps(dict(os.environ)))"'])
357  return json.loads(out)
358 
359 def switch_user(user, group=None):
360  user_env = get_user_env(user)
361 
362  pw_record = pwd.getpwnam(user)
363  os.environ['HOME'] = pw_record.pw_dir
364  os.environ['LOGNAME'] = pw_record.pw_name
365  os.environ['USER'] = pw_record.pw_name
366  os.setgid(pw_record.pw_gid if group is None else grp.getgrnam(group).gr_gid)
367  os.setuid(pw_record.pw_uid)
368 
369 @contextlib.contextmanager
370 def file_backed_up(filename):
371  with tempfile.NamedTemporaryFile(prefix=os.path.basename(filename)) as f:
372  shutil.copyfile(filename, f.name)
373  try:
374  yield filename
375  finally:
376  shutil.copyfile(f.name, filename)
377 
378 @contextlib.contextmanager
379 def directory_deleter(dirname):
380  try:
381  yield dirname
382  finally:
383  shutil.rmtree(dirname)
384 
386  try:
387  import jsonschema
388  return True
389  except ImportError:
390  return False
391 
392 def prepend_string_to_file(string, filename):
393  with open(filename, 'r') as f:
394  contents = f.read()
395  with open(filename, 'wt') as f:
396  print(string, file=f, end='')
397  print(contents, file=f, end='')
398 
399 def make_environment_dict(username, hostname, zone_name, use_ssl=True):
400  irods_home = os.path.join('/', zone_name, 'home', username)
401 
402  environment = {
403  'irods_host': hostname,
404  'irods_port': 1247,
405  'irods_default_resource': 'demoResc',
406  'irods_home': irods_home,
407  'irods_cwd': irods_home,
408  'irods_user_name': username,
409  'irods_zone_name': zone_name,
410  'irods_client_server_negotiation': 'request_server_negotiation',
411  'irods_client_server_policy': 'CS_NEG_REFUSE',
412  'irods_encryption_key_size': 32,
413  'irods_encryption_salt_size': 8,
414  'irods_encryption_num_hash_rounds': 16,
415  'irods_encryption_algorithm': 'AES-256-CBC',
416  'irods_default_hash_scheme': 'SHA256',
417  'irods_maximum_size_for_single_buffer_in_megabytes': 32,
418  'irods_default_number_of_transfer_threads': 4,
419  'irods_maximum_number_of_transfer_threads': 64,
420  'irods_transfer_buffer_size_for_parallel_transfer_in_megabytes': 4,
421  'irods_connection_pool_refresh_time_in_seconds': 300
422 
423  }
424  if use_ssl:
425  environment.update({
426  'irods_client_server_policy': 'CS_NEG_REQUIRE',
427  'irods_ssl_verify_server': 'cert',
428  'irods_ssl_ca_certificate_file': '/etc/irods/server.crt',
429  })
430  return environment
431 
433  return platform.linux_distribution()[0]
434 
436  return platform.linux_distribution()[1].split('.')[0]
437 
439  if isinstance(ils_out, six.string_types):
440  ils_out = ils_out.strip().split()
441  for item in ils_out:
442  # strip collections
443  if not item.startswith('C- /'):
444  yield item
445 
447  return os.stat(path).st_size
448 
449 def write_to_log(log_path, message):
450  with open(log_path, 'at') as f:
451  print(message, file=f, end='')
452 
453 def count_occurrences_of_regexp_in_log(log_path, pattern, start_index=0):
454  occurrences = []
455  target = None
456  if isinstance(pattern,(tuple,list)):
457  pattern = [pattern[0].encode('ascii')] + list(pattern[1:])
458  elif isinstance(pattern,re._pattern_type):
459  target = pattern
460  else:
461  pattern = [pattern.encode('ascii')] # assume string-like
462  if target is None: target=re.compile(*pattern)
463  with open(log_path) as f:
464  m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
465  occurrences.extend(j for j in target.finditer(m[start_index:]))
466  m.close()
467  return occurrences
468 
469 def count_occurrences_of_string_in_log(log_path, string, start_index=0):
470  with open(log_path) as f:
471  m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
472  n = 0
473  target = string.encode('ascii')
474  i = m.find(target, start_index)
475  while i != -1:
476  n += 1
477  i = m.find(target, i + 1)
478  m.close()
479  return n
480 
481 def version_string_to_tuple(version_string):
482  return tuple(map(int, version_string.split('.')))
483 
485  _, err, ret = execute_command_permissive([
486  os.path.join( paths.server_bin_directory(), 'hostname_resolves_to_local_address'),
487  hostname])
488  if ret == 0:
489  return True
490  elif ret == 1:
491  return False
492  raise IrodsError('Error encountered in hostname_resolves_to_local_address for hostname [{0}]:\n{1}'.format(hostname, err))
493 
494 def get_header(message):
495  lines = [l.strip() for l in message.splitlines()]
496  length = 0
497  for line in lines:
498  length = max(length, len(line))
499  edge = '+' + '-' * (length + 2) + '+'
500  format_string = '{0:<' + str(length) + '}'
501  header_lines = ['', edge]
502  for line in lines:
503  header_lines.append('| ' + format_string.format(line) + ' |')
504  header_lines.append(edge)
505  header_lines.append('')
506  return '\n'.join(header_lines)
507 
508 def nested_update(d, u):
509  for k, v in u.items():
510  d[k] = nested_update(d.get(k, {}), v) if isinstance(v, collections.Mapping) else u[k]
511  return d
512 
513 def prompt(*args, **kwargs):
514  echo = kwargs.get('echo', True)
515  end = kwargs.get('end', ': ')
516  input_filter = kwargs.get('input_filter', lambda x: x)
517 
518  l = logging.getLogger(__name__)
519  message = ''.join([args[0] % tuple(args[1:]), end])
520  while True:
521  l.debug(message)
522  if echo:
523  print(message, end='')
524  sys.stdout.flush()
525  user_input = sys.stdin.readline().rstrip('\n')
526  l.debug('User input: %s', user_input)
527  else:
528  if sys.stdin.isatty():
529  user_input = getpass.getpass(message)
530  else:
531  print('Warning: Cannot control echo output on the terminal (stdin is not a tty). Input may be echoed.', file=sys.stderr)
532  user_input = sys.stdin.readline().rstrip('\n')
533  if not sys.stdin.isatty():
534  print('\n', end='')
535  try :
536  return input_filter(user_input)
537  except InputFilterError as e:
538  l.debug('Error encountered in user input:', exc_info=sys.exc_info())
539  l.warning(e.args[0] if len(e.args) else "User input error.")
540 
541 def default_prompt(*args, **kwargs):
542  l = logging.getLogger(__name__)
543  default = kwargs.pop('default', [])
544  input_filter = kwargs.pop('input_filter', lambda x: x)
545 
546  while True:
547  if default:
548  if len(default) == 1:
549  message = ''.join([
550  args[0] % tuple(args[1:]),
551  ' [%s]' % (default[0])])
552  user_input = prompt(message, **kwargs)
553  if not user_input:
554  user_input = default[0]
555  else:
556  message = ''.join([
557  args[0] % tuple(args[1:]), ':\n',
558  '\n'.join(['%d. %s' % (i + 1, default[i]) for i in range(0, len(default))]),
559  '\nPlease select a number or choose 0 to enter a new value'])
560  user_input = default_prompt(message, default=[1], **kwargs)
561  try:
562  i = int(user_input) - 1
563  except (TypeError, ValueError):
564  i = -1
565  if i in range(0, len(default)):
566  user_input = default[i]
567  else:
568  user_input = prompt('New value', **kwargs)
569  else:
570  user_input = prompt(*args, **kwargs)
571  try :
572  return input_filter(user_input)
573  except InputFilterError as e:
574  l.debug('Error encountered in user input:', exc_info=sys.exc_info())
575  l.warning(e.args[0] if len(e.args) else "User input error.")
576 
577 def int_filter(field='Input'):
578  def f(x):
579  try:
580  return int(x)
581  except ValueError as e:
582  irods.six.reraise(InputFilterError, InputFilterError('%s must be an integer.' % (field)), sys.exc_info()[2])
583  return f
584 
585 def set_filter(set_, field='Input'):
586  def f(x):
587  if x in set_:
588  return x
589  raise InputFilterError('%s must be chosen from %s' % (field, list(set_)))
590  return f
591 
592 def character_count_filter(minimum=None, maximum=None, field='Input'):
593  def f(x):
594  if (minimum is None or len(x) >= minimum) and (maximum is None or len(x) <= maximum):
595  return x
596  if minimum is not None and minimum < 0:
597  new_minimum = 0
598  else:
599  new_minimum = minimum
600  if new_minimum is not None and maximum is not None:
601  if new_minimum == maximum:
602  raise InputFilterError('%s must be exactly %s character%s in length.' % (field, maximum, '' if maximum == 1 else 's'))
603  if new_minimum < maximum:
604  raise InputFilterError('%s must be between %s and %s characters in length.' % (field, new_minimum, maximum))
605  raise IrodsError('Minimum character count %s must not be greater than maximum character count %s.' % (new_minimum, maximum))
606  if new_minimum is not None:
607  raise InputFilterError('%s must be at least %s character%s in length.' % (field, new_minimum, '' if new_minimum == 1 else 's'))
608  raise InputFilterError('%s may be at most %s character%s in length.' % (field, maximum, '' if maximum == 1 else 's'))
609  return f
610 
611 class InputFilterError(Exception):
612  pass
613 
614 class callback_on_change_dict(dict):
615  def __init__(self, *args, **kwargs):
616  if args:
617  self.callback = args[0]
618  args = args[1:]
619  else:
620  self.callback = lambda: None
621  super(callback_on_change_dict, self).__init__(*args, **kwargs)
622 
623  def __setitem__(self, *args, **kwargs):
624  super(callback_on_change_dict, self).__setitem__(*args, **kwargs)
625  self.callback()
626 
627  def __delitem__(self, *args, **kwargs):
628  super(callback_on_change_dict, self).__delitem__(*args, **kwargs)
629  self.callback()
630 
631  def update(self, *args, **kwargs):
632  super(callback_on_change_dict, self).update(*args, **kwargs)
633  self.callback()
634 
635  def clear(self, *args, **kwargs):
636  super(callback_on_change_dict, self).clear(*args, **kwargs)
637  self.callback()
638 
639  def pop(self, *args, **kwargs):
640  super(callback_on_change_dict, self).pop(*args, **kwargs)
641  self.callback()
642 
643  def popitem(self, *args, **kwargs):
644  super(callback_on_change_dict, self).popitem(*args, **kwargs)
645  self.callback()
646 
647  def setdefault(self, *args, **kwargs):
648  super(callback_on_change_dict, self).setdefault(*args, **kwargs)
649  self.callback()
650 
651 def delayAssert(a, interval=1, maxrep=100):
652  for _ in range(maxrep):
653  time.sleep(interval) # wait for test to fire
654  if a():
655  break
656  if not a():
657  raise AssertionError
658 
659 def log_message_occurrences_equals_count(msg, count=1, server_log_path=None, start_index=0):
660  if server_log_path is None:
661  server_log_path=paths.server_log_path()
662  return count == count_occurrences_of_string_in_log(server_log_path, msg, start_index)
663 
664 def log_message_occurrences_greater_than_count(msg, count=1, server_log_path=None, start_index=0):
665  if server_log_path is None:
666  server_log_path=paths.server_log_path()
667  return count_occurrences_of_string_in_log(server_log_path, msg, start_index) > count
668 
669 def log_message_occurrences_fewer_than_count(msg, count=1, server_log_path=None, start_index=0):
670  if server_log_path is None:
671  server_log_path=paths.server_log_path()
672  return count_occurrences_of_string_in_log(server_log_path, msg, start_index) < count
673 
674 def log_message_occurrences_is_one_of_list_of_counts(msg, expected_value_list=None, server_log_path=None, start_index=0):
675  if server_log_path is None:
676  server_log_path=paths.server_log_path()
677  return count_occurrences_of_string_in_log(server_log_path, msg, start_index) in expected_value_list
irods.lib.count_occurrences_of_string_in_log
def count_occurrences_of_string_in_log(log_path, string, start_index=0)
Definition: lib.py:469
irods.lib.create_local_testfile
def create_local_testfile(filename)
Definition: lib.py:279
irods.lib.directory_deleter
def directory_deleter(dirname)
Definition: lib.py:379
irods.lib.get_hostname
def get_hostname()
Definition: lib.py:35
irods.lib.cat
def cat(fname, string)
Definition: lib.py:289
irods.lib.character_count_filter
def character_count_filter(minimum=None, maximum=None, field='Input')
Definition: lib.py:592
irods.lib.hostname_resolves_to_local_address
def hostname_resolves_to_local_address(hostname)
Definition: lib.py:484
irods.lib.int_filter
def int_filter(field='Input')
Definition: lib.py:577
irods.lib.execute_command_permissive
def execute_command_permissive(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, input=None, **kwargs)
Definition: lib.py:89
irods.lib.callback_on_change_dict.popitem
def popitem(self, *args, **kwargs)
Definition: lib.py:643
irods.lib.prepend_string_to_file
def prepend_string_to_file(string, filename)
Definition: lib.py:392
irods.lib.make_file
def make_file(f_name, f_size, contents='zero', block_size_in_bytes=1000)
Definition: lib.py:293
irods.lib.touch
def touch(fname, times=None)
Definition: lib.py:285
irods.lib.log_message_occurrences_equals_count
def log_message_occurrences_equals_count(msg, count=1, server_log_path=None, start_index=0)
Definition: lib.py:659
irods.lib.kill_pid
def kill_pid(pid)
Definition: lib.py:162
irods.lib.delayAssert
def delayAssert(a, interval=1, maxrep=100)
Definition: lib.py:651
irods.lib.execute_command_timeout
def execute_command_timeout(args, timeout=10, **kwargs)
Definition: lib.py:70
irods.pyparsing.range
range
Definition: pyparsing.py:111
irods.lib.file_backed_up
def file_backed_up(filename)
Definition: lib.py:370
irods.lib.communicate_and_log
def communicate_and_log(p, args, input=None)
Definition: lib.py:119
irods.lib.execute_command_nonblocking
def execute_command_nonblocking(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, use_unsafe_shell=False, **kwargs)
Definition: lib.py:44
irods.lib.log_message_occurrences_greater_than_count
def log_message_occurrences_greater_than_count(msg, count=1, server_log_path=None, start_index=0)
Definition: lib.py:664
irods.lib.json_object_hook_dict
def json_object_hook_dict(d)
Definition: lib.py:250
irods.lib.make_dir_p
def make_dir_p(directory)
Definition: lib.py:313
irods.lib.log_message_occurrences_fewer_than_count
def log_message_occurrences_fewer_than_count(msg, count=1, server_log_path=None, start_index=0)
Definition: lib.py:669
irods.lib.count_occurrences_of_regexp_in_log
def count_occurrences_of_regexp_in_log(log_path, pattern, start_index=0)
Definition: lib.py:453
irods.lib.open_and_load_json
def open_and_load_json(filename)
Definition: lib.py:262
irods.lib.callback_on_change_dict.__setitem__
def __setitem__(self, *args, **kwargs)
Definition: lib.py:623
irods.lib.find_shared_object
def find_shared_object(so_name, regex=False, additional_directories=[])
Definition: lib.py:168
irods.lib.prompt
def prompt(*args, **kwargs)
Definition: lib.py:513
irods.lib.write_to_log
def write_to_log(log_path, message)
Definition: lib.py:449
irods.lib.switch_user
def switch_user(user, group=None)
Definition: lib.py:359
irods.six.reraise
def reraise(tp, value, tb=None)
Definition: six.py:667
irods.lib.is_jsonschema_installed
def is_jsonschema_installed()
Definition: lib.py:385
irods.lib.callback_on_change_dict.__delitem__
def __delitem__(self, *args, **kwargs)
Definition: lib.py:627
irods.lib.update_json_file_from_dict
def update_json_file_from_dict(filename, update_dict)
Definition: lib.py:266
irods.lib.json_object_hook_list
def json_object_hook_list(l)
Definition: lib.py:240
irods.lib.callback_on_change_dict.__init__
def __init__(self, *args, **kwargs)
Definition: lib.py:615
irods.lib.default_prompt
def default_prompt(*args, **kwargs)
Definition: lib.py:541
irods.lib.execute_command
def execute_command(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
Definition: lib.py:132
irods.lib.files_in_dir
def files_in_dir(path)
Definition: lib.py:349
irods.lib.callback_on_change_dict.callback
callback
Definition: lib.py:617
int
typedef int((*funcPtr)())
irods.password_obfuscation.decode
def decode(s, uid=None)
Definition: password_obfuscation.py:43
irods.lib.get_os_distribution_version_major
def get_os_distribution_version_major()
Definition: lib.py:435
irods.lib.indent
def indent(*text, **kwargs)
Definition: lib.py:138
irods.lib.log_message_occurrences_is_one_of_list_of_counts
def log_message_occurrences_is_one_of_list_of_counts(msg, expected_value_list=None, server_log_path=None, start_index=0)
Definition: lib.py:674
irods.lib.InputFilterError
Definition: lib.py:611
irods::join
std::string join(std::vector< std::string > &strs, const std::string &separator)
Definition: irods_serialization.cpp:169
irods.lib.callback_on_change_dict.pop
def pop(self, *args, **kwargs)
Definition: lib.py:639
irods.lib.get_pids_executing_binary_file
def get_pids_executing_binary_file(binary_file_path)
Definition: lib.py:147
irods.lib.callback_on_change_dict.setdefault
def setdefault(self, *args, **kwargs)
Definition: lib.py:647
irods.lib.get_file_size_by_path
def get_file_size_by_path(path)
Definition: lib.py:446
irods.lib.make_deep_local_tmp_dir
def make_deep_local_tmp_dir(root_name, depth=10, files_per_level=50, file_size=100)
Definition: lib.py:332
irods.lib.get_os_distribution
def get_os_distribution()
Definition: lib.py:432
irods.lib.file_digest
def file_digest(filename, hash_type, encoding='hex')
Definition: lib.py:210
irods.lib.get_object_names_from_entries
def get_object_names_from_entries(ils_out)
Definition: lib.py:438
irods.lib.nested_update
def nested_update(d, u)
Definition: lib.py:508
irods.lib.get_user_env
def get_user_env(user)
Definition: lib.py:354
irods.lib.check_command_return
def check_command_return(args, out, err, returncode, **kwargs)
Definition: lib.py:100
irods.exceptions.IrodsError
Definition: exceptions.py:1
irods.password_obfuscation.encode
def encode(s, uid=None, mtime=None)
Definition: password_obfuscation.py:88
irods.lib.make_environment_dict
def make_environment_dict(username, hostname, zone_name, use_ssl=True)
Definition: lib.py:399
irods.lib.get_header
def get_header(message)
Definition: lib.py:494
irods.lib.callback_on_change_dict.update
def update(self, *args, **kwargs)
Definition: lib.py:631
irods.lib.create_directory_of_small_files
def create_directory_of_small_files(directory_name_suffix, file_count)
Definition: lib.py:272
list
Definition: irods_list.h:13
irods.lib.set_filter
def set_filter(set_, field='Input')
Definition: lib.py:585
irods.lib.safe_shlex_split_for_2_6
def safe_shlex_split_for_2_6(args)
Definition: lib.py:39
irods.lib.callback_on_change_dict.clear
def clear(self, *args, **kwargs)
Definition: lib.py:635
irods.lib.make_large_local_tmp_dir
def make_large_local_tmp_dir(dir_name, file_count, file_size)
Definition: lib.py:322
irods.lib.version_string_to_tuple
def version_string_to_tuple(version_string)
Definition: lib.py:481
irods.lib.re_shm_exists
def re_shm_exists()
Definition: lib.py:228