rs_general.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 """
3 @file rs_general.py
4 """
5 
6 import os
7 import subprocess
8 import time
9 import string
10 import signal
11 import commands
12 import fileinput
13 from PIL import Image
14 
15 # Find the latest rosout log file
16 BASE_LOG_DIR = (os.path.expanduser('~/.ros/log/'))
17 LOG_FOLDER = os.listdir(BASE_LOG_DIR)
18 LOG_FOLDER.sort(key=lambda fn: os.path.getmtime(BASE_LOG_DIR+fn)
19  if os.path.isdir(BASE_LOG_DIR+fn) else 0)
20 LOGFILE = BASE_LOG_DIR+LOG_FOLDER[-1] + '/rosout.log'
21 
22 
24  """parse args to get camera type
25  @fn parse_camera_type
26  @param args: all the arguments
27  @return camera_type
28  """
29  argc = len(args)
30  if argc == 0:
31  return None
32 
33  for i in range(0, argc):
34  if args[i] == 'camera_type' and i+1 < argc:
35  return args[i+1]
36 
37 
39  """parse args to get all the camera parameters and paired values
40  the args transferred from .test file, should remove 4 elements
41  in args: start 1 - script name;
42  last 3 - '--gtest_output', '--name', '_log';
43  @fn parse_camera_type
44  @param args: all the arguments
45  @return param_dict: dictionary of camera params
46  """
47  param_dict = {}
48  argc = len(args) - 4
49  if argc == 0:
50  return None
51 
52  params = args[1:-3]
53  for i in range(0, argc, 2):
54  if i+1 < argc:
55  param_dict.setdefault(params[i], params[i+1])
56 
57  return param_dict
58 
59 
60 def is_log_contains_keyword(log_file, keyword):
61  """check if the keyword contains in log"""
62  if (not os.path.exists(os.path.expanduser(log_file)) or
63  keyword is None or
64  keyword == ''):
65  return False
66  file = open(os.path.expanduser(log_file))
67  for line in file:
68  if line.find(keyword) != -1:
69  file.close()
70  return True
71  file.close()
72  return False
73 
74 
75 def shell_cmd_timeout(cmd, timeout=0):
76  """Execute shell command till timeout"""
77  cmd_proc = subprocess.Popen(cmd, stderr=subprocess.STDOUT,
78  stdout=subprocess.PIPE, shell=True,
79  preexec_fn=os.setsid)
80  pid = cmd_proc.pid
81  pgid = os.getpgid(pid)
82  if not cmd_proc:
83  return -1, ''
84  t_timeout, tick = timeout, 2
85  while True:
86  time.sleep(tick)
87  ret = cmd_proc.poll()
88  if ret is not None:
89  break
90  if t_timeout > 0:
91  t_timeout -= tick
92  if t_timeout <= 0:
93  os.killpg(pgid, signal.SIGTERM)
94  ret = -99999
95  break
96  return
def shell_cmd_timeout(cmd, timeout=0)
Definition: rs_general.py:75
def parse_camera_type(args)
Definition: rs_general.py:23
def is_log_contains_keyword(log_file, keyword)
Definition: rs_general.py:60
def get_camera_params_and_values(args)
Definition: rs_general.py:38


realsense_camera
Author(s): Rajvi Jingar , Reagan Lopez , Matt Hansen , Mark Horn
autogenerated on Mon Jun 10 2019 14:40:37