lib_sysv.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import os
  2. import re
  3. from checkpackagelib.base import _CheckFunction
  4. from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
  5. from checkpackagelib.lib import EmptyLastLine # noqa: F401
  6. from checkpackagelib.lib import NewlineAtEof # noqa: F401
  7. from checkpackagelib.lib import TrailingSpace # noqa: F401
  8. import checkpackagelib.tool
  9. class Indent(_CheckFunction):
  10. INDENTED_WITH_SPACES = re.compile(r"^[\t]* ")
  11. def check_line(self, lineno, text):
  12. if self.INDENTED_WITH_SPACES.search(text.rstrip()):
  13. return ["{}:{}: should be indented with tabs ({}#adding-packages-start-script)"
  14. .format(self.filename, lineno, self.url_to_manual),
  15. text]
  16. class NotExecutable(checkpackagelib.tool.NotExecutable):
  17. def hint(self):
  18. return ", just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"
  19. class Variables(_CheckFunction):
  20. DAEMON_VAR = re.compile(r"^DAEMON=[\"']{0,1}([^\"']*)[\"']{0,1}")
  21. PIDFILE_PATTERN = re.compile(r"/var/run/(\$DAEMON|\$\{DAEMON\}).pid")
  22. PIDFILE_VAR = re.compile(r"^PIDFILE=[\"']{0,1}([^\"']*)[\"']{0,1}")
  23. def before(self):
  24. self.name = None
  25. def check_line(self, lineno, text):
  26. name_found = self.DAEMON_VAR.search(text.rstrip())
  27. if name_found:
  28. if self.name:
  29. return ["{}:{}: DAEMON variable redefined ({}#adding-packages-start-script)"
  30. .format(self.filename, lineno, self.url_to_manual),
  31. text]
  32. self.name = name_found.group(1)
  33. if '/' in self.name:
  34. self.name = os.path.basename(self.name) # to be used in after() to check the expected filename
  35. return ["{}:{}: Do not include path in DAEMON ({}#adding-packages-start-script)"
  36. .format(self.filename, lineno, self.url_to_manual),
  37. text,
  38. 'DAEMON="{}"'.format(self.name)]
  39. return
  40. pidfile_found = self.PIDFILE_VAR.search(text.rstrip())
  41. if pidfile_found:
  42. pidfile = pidfile_found.group(1)
  43. if not self.PIDFILE_PATTERN.match(pidfile):
  44. return ["{}:{}: Incorrect PIDFILE value ({}#adding-packages-start-script)"
  45. .format(self.filename, lineno, self.url_to_manual),
  46. text,
  47. 'PIDFILE="/var/run/$DAEMON.pid"']
  48. def after(self):
  49. if self.name is None:
  50. return ["{}:0: DAEMON variable not defined ({}#adding-packages-start-script)"
  51. .format(self.filename, self.url_to_manual)]
  52. expected_filename = re.compile(r"S\d\d{}$".format(self.name))
  53. if not expected_filename.match(os.path.basename(self.filename)):
  54. return ["{}:0: filename should be S<number><number><daemon name> ({}#adding-packages-start-script)"
  55. .format(self.filename, self.url_to_manual),
  56. "expecting S<number><number>{}".format(self.name)]