# Path: alibuild_helpers/cmd.py
# def getoutput(command):
#   """Run command, check it succeeded, and return its stdout as a string."""
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   proc = Popen(command, shell=is_string(command), stdout=PIPE, stderr=PIPE,
#                universal_newlines=True, **kwargs)
#   stdout, stderr = proc.communicate()
#   dieOnError(proc.returncode, "Command %s failed with code %d: %s" %
#              (command, proc.returncode, stderr))
#   return stdout
# 
# def getstatusoutput(command):
#   """Run command and return its return code and output (stdout and stderr)."""
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   proc = Popen(command, shell=is_string(command), stdout=PIPE, stderr=STDOUT,
#                universal_newlines=True, **kwargs)
#   merged_output, _ = proc.communicate()
#   # Strip a single trailing newline, if one exists, to match the behaviour of
#   # subprocess.getstatusoutput.
#   if merged_output.endswith("\n"):
#     merged_output = merged_output[:-1]
#   return proc.returncode, merged_output
# 
# Path: alibuild_helpers/log.py
# def dieOnError(err, msg):
#   if err:
#     error("%s", msg)
#     sys.exit(1)


import yaml
import hashlib
import sys
import os
import re
    import platform
    import platform
    import platform, distro
from os.path import exists
from glob import glob
from os.path import basename, join
from datetime import datetime
  from collections import OrderedDict
  from ordereddict import OrderedDict
from alibuild_helpers.cmd import getoutput, getstatusoutput
from alibuild_helpers.log import dieOnError
  err, spec, recipe = (None, None, None)
  try:
    d = reader()
    header,recipe = d.split("---", 1)
    spec = yamlLoad(header)
    validateSpec(spec)
  except RuntimeError as e:
    err = str(e)
  except IOError as e:
    err = str(e)
  except SpecError as e:
    err = "Malformed header for %s\n%s" % (reader.url, str(e))
  except yaml.scanner.ScannerError as e:
    err = "Unable to parse %s\n%s" % (reader.url, str(e))
  except yaml.parser.ParserError as e:
    err = "Unable to parse %s\n%s" % (reader.url, str(e))
  except ValueError as e:
    err = "Unable to parse %s. Header missing." % reader.url
  return err, spec, recipe

# (Almost pure part of the defaults parsing)
# Override defaultsGetter for unit tests.
def parseDefaults(disable, defaultsGetter, log):
  defaultsMeta, defaultsBody = defaultsGetter()
  # Defaults are actually special packages. They can override metadata
  # of any other package and they can disable other packages. For
  # example they could decide to switch from ROOT 5 to ROOT 6 and they
  # could disable alien for O2. For this reason we need to parse their
  # metadata early and extract the override and disable data.
  defaultsDisable = asList(defaultsMeta.get("disable", []))

# Path: alibuild_helpers/cmd.py
# def getoutput(command):
#   """Run command, check it succeeded, and return its stdout as a string."""
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   proc = Popen(command, shell=is_string(command), stdout=PIPE, stderr=PIPE,
#                universal_newlines=True, **kwargs)
#   stdout, stderr = proc.communicate()
#   dieOnError(proc.returncode, "Command %s failed with code %d: %s" %
#              (command, proc.returncode, stderr))
#   return stdout
# 
# def getstatusoutput(command):
#   """Run command and return its return code and output (stdout and stderr)."""
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   proc = Popen(command, shell=is_string(command), stdout=PIPE, stderr=STDOUT,
#                universal_newlines=True, **kwargs)
#   merged_output, _ = proc.communicate()
#   # Strip a single trailing newline, if one exists, to match the behaviour of
#   # subprocess.getstatusoutput.
#   if merged_output.endswith("\n"):
#     merged_output = merged_output[:-1]
#   return proc.returncode, merged_output
# 
# Path: alibuild_helpers/log.py
# def dieOnError(err, msg):
#   if err:
#     error("%s", msg)
#     sys.exit(1)


# Path: alibuild_helpers/utilities.py
import yaml
import hashlib
import sys
import os
import re
    import platform
    import platform
    import platform, distro
from os.path import exists
from glob import glob
from os.path import basename, join
from datetime import datetime
  from collections import OrderedDict
  from ordereddict import OrderedDict
from alibuild_helpers.cmd import getoutput, getstatusoutput
from alibuild_helpers.log import dieOnError

  err, spec, recipe = (None, None, None)
  try:
    d = reader()
    header,recipe = d.split("---", 1)
    spec = yamlLoad(header)
    validateSpec(spec)
  except RuntimeError as e:
    err = str(e)
  except IOError as e:
    err = str(e)
  except SpecError as e:
    err = "Malformed header for %s\n%s" % (reader.url, str(e))
  except yaml.scanner.ScannerError as e:
    err = "Unable to parse %s\n%s" % (reader.url, str(e))
  except yaml.parser.ParserError as e:
    err = "Unable to parse %s\n%s" % (reader.url, str(e))
  except ValueError as e:
    err = "Unable to parse %s. Header missing." % reader.url
  return err, spec, recipe

# (Almost pure part of the defaults parsing)
# Override defaultsGetter for unit tests.
def parseDefaults(disable, defaultsGetter, log):
  defaultsMeta, defaultsBody = defaultsGetter()
  # Defaults are actually special packages. They can override metadata
  # of any other package and they can disable other packages. For
  # example they could decide to switch from ROOT 5 to ROOT 6 and they
  # could disable alien for O2. For this reason we need to parse their
  # metadata early and extract the override and disable data.
  defaultsDisable = asList(defaultsMeta.get("disable", []))

  for x in defaultsDisable: