File: check_pbuilderrc.py

package info (click to toggle)
cmake-format 0.6.13-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,436 kB
  • sloc: python: 16,990; makefile: 14
file content (59 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Check ~/.pbuilderrc for some common advisable configurations
"""

import io
import os
import logging
import re

logger = logging.getLogger(__name__)


def get_extra_packages(content):
  extra_packages = []
  for line in content.split("\n"):
    line = line.strip()
    prefix = "EXTRAPACKAGES="
    if line.startswith(prefix):
      extra_packages.extend(line[len(prefix):].split(","))
  return extra_packages


def get_ldpreloads(content):
  preloads = []
  for line in content.split("\n"):
    line = line.strip()
    prefix = "export LD_PRELOAD="
    if line.startswith(prefix):
      value = line[len(prefix):].strip('"')
      value = re.sub(r"\$\{[^\}]*\}", "", value)
      preloads.extend(value.split(":"))
  return preloads


def main():
  filepath = os.path.expanduser("~/.pbuilderrc")
  if not os.path.exists(filepath):
    logger.warning(
        "No ~/.pbuilderrc in current build environment. It is highly"
        " recommended to include a ~/.pbuilderrc.")
    return

  with io.open(filepath, "r", encoding="utf-8") as infile:
    content = infile.read()

  extra_packages = get_extra_packages(content)
  if "eatmydata" not in extra_packages:
    logger.warning(".pbuilderrc missing EXTRAPACKAGES=eatmydata")

  ld_preloads = get_ldpreloads(content)
  if "libeatmydata.so" not in ld_preloads:
    logger.warning(
        '.pbuilderrc missing '
        '`export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}libeatmydata.so"`\n'
        'Contains: %s', ", ".join(ld_preloads))


if __name__ == "__main__":
  main()