Esempio n. 1
0
def generate_analytics_id():
  getstatusoutput("mkdir -p  ~/.config/alibuild")
  err, output = getstatusoutput("uuidgen >  ~/.config/alibuild/analytics-uuid")
  # If an error is found while generating the unique user ID, we disable
  # the analytics on the machine.
  if err:
    debug("Could not generate unique ID for user. Disabling analytics")
    getstatusoutput("touch ~/.config/alibuild/disable-analytics")
    return False
  return True
Esempio n. 2
0
def systemInfo():
    _, out = getstatusoutput("env")
    debug("Environment:\n%s", out)
    _, out = getstatusoutput("uname -a")
    debug("uname -a: %s", out)
    _, out = getstatusoutput("mount")
    debug("Mounts:\n%s", out)
    _, out = getstatusoutput("df")
    debug("Disk free:\n%s", out)
    for f in ["/etc/lsb-release", "/etc/redhat-release", "/etc/os-release"]:
        err, out = getstatusoutput("cat " + f)
        if not err:
            debug("%s:\n%s", f, out)
Esempio n. 3
0
def git(args, directory=".", check=True):
  debug("Executing git %s (in directory %s)", " ".join(args), directory)
  # We can't use git --git-dir=%s/.git or git -C %s here as the former requires
  # that the directory we're inspecting to be the root of a git directory, not
  # just contained in one (and that breaks CI tests), and the latter isn't
  # supported by the git version we have on slc6.
  # Silence cd as shell configuration can cause the new directory to be echoed.
  err, output = getstatusoutput("""\
  set -e +x
  cd {directory} >/dev/null 2>&1
  exec git {args}
  """.format(directory=quote(directory),
             args=" ".join(map(quote, args))))
  if check and err != 0:
    raise RuntimeError("Error {} from git {}: {}".format(err, " ".join(args), output))
  return output if check else (err, output)
Esempio n. 4
0
 def __call__(self):
     m = re.search(r'^dist:(.*)@([^@]+)$', self.url)
     fn, gh = m.groups()
     err, d = getstatusoutput(
         format("GIT_DIR=%(dist)s/.git git show %(gh)s:%(fn)s.sh",
                dist=self.configDir,
                gh=gh,
                fn=fn.lower()))
     if err:
         raise RuntimeError(
             format(
                 "Cannot read recipe %(fn)s from reference %(gh)s.\n" +
                 "Make sure you run first (this will not alter your recipes):\n"
                 +
                 "  cd %(dist)s && git remote update -p && git fetch --tags",
                 dist=self.configDir,
                 gh=gh,
                 fn=fn))
     return d
Esempio n. 5
0
def __partialCloneFilter():
  err, out = getstatusoutput("LANG=C git clone --filter=blob:none 2>&1 | grep 'unknown option'")
  return err and "--filter=blob:none" or ""
Esempio n. 6
0
def disable_analytics():
  getstatusoutput("mkdir -p ~/.config/alibuild && touch ~/.config/alibuild/disable-analytics")
  return False
Esempio n. 7
0
def doDoctor(args, parser):
    if not exists(args.configDir):
        parser.error("Wrong path to alidist specified: %s" % args.configDir)

    prunePaths(abspath(args.workDir))

    if exists(expanduser("~/.rootlogon.C")):
        warning(
            "You have a ~/.rootlogon.C notice that this might"
            " interfere with your environment in hidden ways.\n"
            "Please review it an make sure you are not force loading any library"
            " which might interphere with the rest of the setup.")
    # Decide if we can use homebrew. If not, we replace it with "true" so
    # that we do not get spurious messages on linux
    homebrew_replacement = ""
    err, output = getstatusoutput("type c++")
    if err:
        warning(
            "Unable to find system compiler.\n"
            "%s\n"
            "Please follow prerequisites:\n"
            "* On Centos compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-centos7.html\n"
            "* On Fedora compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-fedora.html\n"
            "* On Ubuntu compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-ubuntu.html\n"
            "* On macOS: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-macos.html\n",
            output)
    err, output = getstatusoutput("type git")
    if err:
        error(
            "Unable to find git.\n"
            "%s\n"
            "Please follow prerequisites:\n"
            "* On Centos compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-centos7.html\n"
            "* On Fedora compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-fedora.html\n"
            "* On Ubuntu compatible systems: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-ubuntu.html\n"
            "* On macOS: https://alice-doc.github.io/alice-analysis-tutorial/building/prereq-macos.html\n",
            output)
    # Decide if we can use homebrew. If not, we replace it with "true" so
    # that we do not get spurious messages on linux
    homebrew_replacement = ""
    err, output = getstatusoutput("which brew")
    if err:
        homebrew_replacement = "brew() { true; }; "

    dockerImage = args.dockerImage if "dockerImage" in args else ""
    if args.docker and not dockerImage:
        dockerImage = "alisw/%s-builder" % args.architecture.split("_")[0]

    logger.setLevel(logging.BANNER)
    if args.debug:
        logger.setLevel(logging.DEBUG)

    specs = {}
    packages = []
    exitcode = 0
    for p in args.packages:
        path = "%s/%s.sh" % (args.configDir, p.lower())
        if not exists(path):
            error("Cannot find recipe %s for package %s.", path, p)
            exitcode = 1
            continue
        packages.append(p)
    systemInfo()

    specs = {}
    defaultsReader = lambda: readDefaults(args.configDir, args.defaults, parser
                                          .error, args.architecture)
    (err, overrides, taps) = parseDefaults(args.disable, defaultsReader, info)
    if err:
        error("%s", err)
        sys.exit(1)

    def performValidateDefaults(spec):
        (ok, msg, valid) = validateDefaults(spec, args.defaults)
        if not ok:
            error("%s", msg)
        return (ok, msg, valid)

    with DockerRunner(dockerImage,
                      ["--network=host"]) as getstatusoutput_docker:
        fromSystem, own, failed, validDefaults = \
          getPackageList(packages                = packages,
                         specs                   = specs,
                         configDir               = args.configDir,
                         preferSystem            = args.preferSystem,
                         noSystem                = args.noSystem,
                         architecture            = args.architecture,
                         disable                 = args.disable,
                         defaults                = args.defaults,
                         performPreferCheck      = lambda pkg, cmd: checkPreferSystem(pkg, cmd, homebrew_replacement, getstatusoutput_docker),
                         performRequirementCheck = lambda pkg, cmd: checkRequirements(pkg, cmd, homebrew_replacement, getstatusoutput_docker),
                         performValidateDefaults = performValidateDefaults,
                         overrides               = overrides,
                         taps                    = taps,
                         log                     = info)

    alwaysBuilt = set(x for x in specs) - fromSystem - own - failed
    if alwaysBuilt:
        banner(
            "The following packages will be built by aliBuild because\n"
            " usage of a system version of it is not allowed or supported, by policy:\n\n- %s",
            " \n- ".join(alwaysBuilt))
    if fromSystem:
        banner(
            "The following packages will be picked up from the system:\n\n- %s\n\n"
            "If this is not you want, you have to uninstall / unload them.",
            "\n- ".join(fromSystem))
    if own:
        banner(
            "The following packages will be built by aliBuild because they couldn't be picked up from the system:\n\n"
            "- %s\n\n"
            "This is not a real issue, but it might take longer the first time you invoke aliBuild.\n"
            "Look at the error messages above to get hints on what packages you need to install separately.",
            "\n- ".join(own))
    if failed:
        banner(
            "The following packages are system dependencies and could not be found:\n\n- %s\n\n"
            "Look at the error messages above to get hints on what packages you need to install separately.",
            "\n- ".join(failed))
        exitcode = 1
    if validDefaults and args.defaults not in validDefaults:
        banner(
            "The list of packages cannot be built with the defaults you have specified.\n"
            "List of valid defaults:\n\n- %s\n\n"
            "Use the `--defaults' switch to specify one of them.",
            "\n- ".join(validDefaults))
        exitcode = 2
    if validDefaults is None:
        banner(
            "No valid defaults combination was found for the given list of packages, check your recipes!"
        )
        exitcode = 3
    if exitcode:
        error(
            "There were errors: build cannot be performed if they are not resolved. Check the messages above."
        )
    sys.exit(exitcode)