CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions
cmssw_das_client Namespace Reference

Functions

def convert_time
 
def extract_value
 
def get_data
 
def get_value
 
def size_format
 

Function Documentation

def cmssw_das_client.convert_time (   val)

Definition at line 9 of file cmssw_das_client.py.

Referenced by extract_value().

9 
10 def convert_time(val):
11  "Convert given timestamp into human readable format"
12  if isinstance(val, int) or isinstance(val, float):
13  return time.strftime('%d/%b/%Y_%H:%M:%S_GMT', time.gmtime(val))
14  return val
def cmssw_das_client.extract_value (   row,
  key,
  base = 10 
)
Generator which extracts row[key] value

Definition at line 36 of file cmssw_das_client.py.

References convert_time(), and size_format().

Referenced by get_value().

36 
37 def extract_value(row, key, base=10):
38  """Generator which extracts row[key] value"""
39  if isinstance(row, dict) and key in row:
40  if key == 'creation_time':
41  row = convert_time(row[key])
42  elif key == 'size':
43  row = size_format(row[key], base)
44  else:
45  row = row[key]
46  yield row
47  if isinstance(row, list) or isinstance(row, GeneratorType):
48  for item in row:
49  for vvv in extract_value(item, key, base):
50  yield vvv
def cmssw_das_client.get_data (   query,
  limit = None,
  threshold = None,
  idx = None,
  host = None,
  cmd = None 
)

Definition at line 70 of file cmssw_das_client.py.

References submitPVValidationJobs.split().

Referenced by shallowTree_test_template.add_rawRelVals(), and tkal_create_file_lists.das_client().

70 
71 def get_data(query, limit=None, threshold=None, idx=None, host=None, cmd=None):
72  cmd_opts = "--format=json"
73  if threshold is not None: cmd_opts += " --threshold=%s" % threshold
74  if limit is not None: cmd_opts += " --limit=%s" % limit
75  if idx is not None: cmd_opts += " --idx=%s" % idx
76  if host is not None: cmd_opts += " --host=%s" % host
77  if not cmd:
78  cmd = "das_client"
79  for path in os.getenv('PATH').split(':'):
80  if os.path.isfile(os.path.join(path, 'dasgoclient')):
81  cmd = "dasgoclient"
82  break
83 
84  p = subprocess.Popen("%s %s --query '%s'" % (cmd, cmd_opts, query),shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
85  stdout, stderr = p.communicate()
86  if not p.returncode: return loads(stdout)
87  return {'status' : 'error', 'reason' : stdout}
def cmssw_das_client.get_value (   data,
  filters,
  base = 10 
)
Filter data from a row for given list of filters

Definition at line 51 of file cmssw_das_client.py.

References extract_value().

51 
52 def get_value(data, filters, base=10):
53  """Filter data from a row for given list of filters"""
54  for ftr in filters:
55  if ftr.find('>') != -1 or ftr.find('<') != -1 or ftr.find('=') != -1:
56  continue
57  row = dict(data)
58  values = []
59  keys = ftr.split('.')
60  for key in keys:
61  val = [v for v in extract_value(row, key, base)]
62  if key == keys[-1]: # we collect all values at last key
63  values += [dumps(i) for i in val]
64  else:
65  row = val
66  if len(values) == 1:
67  yield values[0]
68  else:
69  yield values
def cmssw_das_client.size_format (   uinput,
  ibase = 0 
)
Format file size utility, it converts file size into KB, MB, GB, TB, PB units

Definition at line 15 of file cmssw_das_client.py.

Referenced by extract_value().

15 
16 def size_format(uinput, ibase=0):
17  """
18  Format file size utility, it converts file size into KB, MB, GB, TB, PB units
19  """
20  if not ibase:
21  return uinput
22  try:
23  num = float(uinput)
24  except Exception as _exc:
25  return uinput
26  if ibase == 2.: # power of 2
27  base = 1024.
28  xlist = ['', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
29  else: # default base is 10
30  base = 1000.
31  xlist = ['', 'KB', 'MB', 'GB', 'TB', 'PB']
32  for xxx in xlist:
33  if num < base:
34  return "%3.1f%s" % (num, xxx)
35  num /= base