# Path: alibuild_helpers/cmd.py
# 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):
#   def __init__(self, fmtstr):
#   def format(self, record):
#   def __init__(self, begin_msg=""):
#   def __call__(self, txt, *args):
#   def erase(self):
#   def end(self, msg="", error=False):
# def log_banner(self, message, *args, **kws):
# def log_success(self, message, *args, **kws):
# class LogFormatter(logging.Formatter):
# class ProgressPrint:


import os, subprocess, sys
from os.path import exists, expanduser
from os import unlink
from alibuild_helpers.cmd import getstatusoutput
from alibuild_helpers.log import debug, banner
#   analytics. If no, remember the answer and disable it. If yes,
#   generate a uuid with uuidgen and remember it.
def decideAnalytics(hasDisableFile, hasUuid, isTty, questionCallback):
  if hasDisableFile:
    debug("Analytics previously disabled.")
    return False
  if hasUuid:
    debug("User has analytics id. Pushing analytics to Google Analytics.")
    return True
  if not isTty:
    debug("This is not an interactive process and "
          "no indication has been given about analytics. Disabling")
    return False
  return questionCallback()

def report(eventType, **metadata):
  if "ALIBUILD_NO_ANALYTICS" in os.environ:
    return
  opts = {
    "v": "1",
    "tid": os.environ["ALIBUILD_ANALYTICS_ID"],
    "cid": os.environ["ALIBUILD_ANALYTICS_USER_UUID"],
    "aip": "1",
    "an": "aliBuild",
    "av": os.environ["ALIBUILD_VERSION"],
    "t": eventType
  }
  opts.update(metadata)
  architecture = os.environ["ALIBUILD_ARCHITECTURE"]
  ostype = "Macintosh" if architecture.startswith("osx") else "Linux"

# Path: alibuild_helpers/cmd.py
# 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):
#   def __init__(self, fmtstr):
#   def format(self, record):
#   def __init__(self, begin_msg=""):
#   def __call__(self, txt, *args):
#   def erase(self):
#   def end(self, msg="", error=False):
# def log_banner(self, message, *args, **kws):
# def log_success(self, message, *args, **kws):
# class LogFormatter(logging.Formatter):
# class ProgressPrint:


# Path: alibuild_helpers/analytics.py
import os, subprocess, sys
from os.path import exists, expanduser
from os import unlink
from alibuild_helpers.cmd import getstatusoutput
from alibuild_helpers.log import debug, banner

#   analytics. If no, remember the answer and disable it. If yes,
#   generate a uuid with uuidgen and remember it.
def decideAnalytics(hasDisableFile, hasUuid, isTty, questionCallback):
  if hasDisableFile:
    debug("Analytics previously disabled.")
    return False
  if hasUuid:
    debug("User has analytics id. Pushing analytics to Google Analytics.")
    return True
  if not isTty:
    debug("This is not an interactive process and "
          "no indication has been given about analytics. Disabling")
    return False
  return questionCallback()

def report(eventType, **metadata):
  if "ALIBUILD_NO_ANALYTICS" in os.environ:
    return
  opts = {
    "v": "1",
    "tid": os.environ["ALIBUILD_ANALYTICS_ID"],
    "cid": os.environ["ALIBUILD_ANALYTICS_USER_UUID"],
    "aip": "1",
    "an": "aliBuild",
    "av": os.environ["ALIBUILD_VERSION"],
    "t": eventType
  }
  opts.update(metadata)
  architecture = os.environ["ALIBUILD_ARCHITECTURE"]
  ostype = "Macintosh" if architecture.startswith("osx") else "Linux"

  osversion, osprocessor = architecture.split("_", 1)