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 TRAILING_PATTERN = re.compile(r'^(.*[^\w])\w+\n$')
14 
15 roscompile_functions = collections.OrderedDict()
16 
17 
18 def roscompile(f):
19  roscompile_functions[f.__name__] = f
20  return f
21 
22 
23 def get_ignore_data_helper(basename, add_newline=True):
24  fn = os.path.join(PKG_PATH, 'data', basename + '.ignore')
25  lines = []
26  if not os.path.exists(fn):
27  return lines
28  for s in open(fn):
29  if s == '\n':
30  continue
31  if add_newline:
32  lines.append(s)
33  else:
34  lines.append(s[:-1])
35  return lines
36 
37 
38 def get_ignore_data(name, variables=None, add_newline=True):
39  ignore_lines = get_ignore_data_helper(name, add_newline)
40  if not variables:
41  return ignore_lines
42  for pattern in get_ignore_data_helper(name + '_patterns', add_newline):
43  ignore_lines.append(pattern % variables)
44  return ignore_lines
45 
46 
48  existing_permissions = stat.S_IMODE(os.lstat(fn).st_mode)
49  os.chmod(fn, existing_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
50 
51 
53  existing_permissions = stat.S_IMODE(os.lstat(fn).st_mode)
54  os.chmod(fn, existing_permissions | ~stat.S_IXUSR | ~stat.S_IXGRP | ~stat.S_IXOTH)
55 
56 
57 def get_config():
58  global CONFIG
59  if CONFIG is None:
60  if os.path.exists(CONFIG_PATH):
61  CONFIG = yaml.safe_load(open(CONFIG_PATH))
62  else:
63  CONFIG = {}
64  return CONFIG
65 
66 
68  # https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
69  s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
70  return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
71 
72 
74  return ''.join([x.title() for x in name.split('_')])
roscompile.util.get_config
def get_config()
Definition: util.py:57
roscompile.util.get_ignore_data
def get_ignore_data(name, variables=None, add_newline=True)
Definition: util.py:38
roscompile.util.make_not_executable
def make_not_executable(fn)
Definition: util.py:52
roscompile.util.make_executable
def make_executable(fn)
Definition: util.py:47
roscompile.util.convert_to_underscore_notation
def convert_to_underscore_notation(name)
Definition: util.py:67
roscompile.util.convert_to_caps_notation
def convert_to_caps_notation(name)
Definition: util.py:73
roscompile.util.get_ignore_data_helper
def get_ignore_data_helper(basename, add_newline=True)
Definition: util.py:23
roscompile.util.roscompile
def roscompile(f)
Definition: util.py:18


roscompile
Author(s):
autogenerated on Tue Jun 21 2022 03:01:39