util.py
Go to the documentation of this file.
1 import collections
2 import os
3 import re
4 import stat
5 
6 import rospkg
7 
8 import yaml
9 
10 CONFIG_PATH = os.path.expanduser('~/.ros/roscompile.yaml')
11 CONFIG = None
12 PKG_PATH = rospkg.RosPack().get_path('roscompile')
13 
14 roscompile_functions = collections.OrderedDict()
15 
16 
17 def roscompile(f):
18  roscompile_functions[f.__name__] = f
19  return f
20 
21 
22 def get_ignore_data_helper(basename, add_newline=True):
23  fn = os.path.join(PKG_PATH, 'data', basename + '.ignore')
24  lines = []
25  for s in open(fn):
26  if s == '\n':
27  continue
28  if add_newline:
29  lines.append(s)
30  else:
31  lines.append(s[:-1])
32  return lines
33 
34 
35 def get_ignore_data(name, variables=None, add_newline=True):
36  ignore_lines = get_ignore_data_helper(name, add_newline)
37  if not variables:
38  return ignore_lines
39  for pattern in get_ignore_data_helper(name + '_patterns', add_newline):
40  ignore_lines.append(pattern % variables)
41  return ignore_lines
42 
43 
45  existing_permissions = stat.S_IMODE(os.lstat(fn).st_mode)
46  os.chmod(fn, existing_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
47 
48 
49 def get_config():
50  global CONFIG
51  if CONFIG is None:
52  if os.path.exists(CONFIG_PATH):
53  CONFIG = yaml.safe_load(open(CONFIG_PATH))
54  else:
55  CONFIG = {}
56  return CONFIG
57 
58 
60  # https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
61  s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
62  return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
63 
64 
66  return ''.join([x.title() for x in name.split('_')])
def get_ignore_data(name, variables=None, add_newline=True)
Definition: util.py:35
def convert_to_underscore_notation(name)
Definition: util.py:59
def convert_to_caps_notation(name)
Definition: util.py:65
def make_executable(fn)
Definition: util.py:44
def get_ignore_data_helper(basename, add_newline=True)
Definition: util.py:22
def roscompile(f)
Definition: util.py:17
def get_config()
Definition: util.py:49


roscompile
Author(s):
autogenerated on Wed Mar 3 2021 03:56:01