# 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/cmd.py
# def execute(command, printer=debug):
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   popen = Popen(command, shell=is_string(command), stdout=PIPE,
#                 universal_newlines=True, **kwargs)
#   lines_iterator = iter(popen.stdout.readline, "")
#   for line in lines_iterator:
#     if not line: break
#     printer("%s", line.strip("\n"))
#   out = popen.communicate()[0].strip("\n")
#   if out:
#     printer(out)
#   return popen.returncode
# 
# Path: alibuild_helpers/git.py
# def __partialCloneFilter():
# 
# Path: alibuild_helpers/utilities.py
# def format(s, **kwds):
#   if sys.version_info[0] >= 3:
#     if isinstance(s, bytes):
#       try:
#         s = s.decode("utf-8")  # to get newlines as such and not as escaped \n
#       except:
#         s = s.decode("latin-1")  # Workaround issue with some special characters of latin-1 which are not understood by unicode
#     else:
#       s = str(s)
#   elif isinstance(s, str):
#     s = unicode(s, "utf-8")  # utf-8 is a safe assumption
#   elif not isinstance(s, unicode):
#     s = unicode(str(s))
#   return s % kwds


from alibuild_helpers.log import dieOnError, debug
from alibuild_helpers.cmd import execute
from alibuild_helpers.git import partialCloneFilter
from os.path import dirname, abspath
from alibuild_helpers.utilities import format
  from collections import OrderedDict
  from ordereddict import OrderedDict
import os
import os.path as path
import tempfile
  """
  Update source reference area, if possible.
  If the area is already there and cannot be written, assume it maintained
  by someone else.

  If the area can be created, clone a bare repository with the sources.

  Returns the reference repository's local path if available, otherwise None.
  Throws a fatal error in case repository cannot be updated even if it appears
  to be writeable.

  @referenceSources : a string containing the path to the sources to be updated
  @p                : the name of the package to be updated
  @spec             : the spec of the package to be updated (an OrderedDict)
  @fetch            : whether to fetch updates: if False, only clone if not found
  """
  assert(type(spec) == OrderedDict)
  if not "source" in spec:
    return

  debug("Updating references.")
  referenceRepo = os.path.join(abspath(referenceSources), p.lower())

  try:
    os.makedirs(abspath(referenceSources))
  except:
    pass

  if not is_writeable(referenceSources):
    if path.exists(referenceRepo):

# 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/cmd.py
# def execute(command, printer=debug):
#   kwargs = {} if sys.version_info.major < 3 else {"encoding": "utf-8"}
#   popen = Popen(command, shell=is_string(command), stdout=PIPE,
#                 universal_newlines=True, **kwargs)
#   lines_iterator = iter(popen.stdout.readline, "")
#   for line in lines_iterator:
#     if not line: break
#     printer("%s", line.strip("\n"))
#   out = popen.communicate()[0].strip("\n")
#   if out:
#     printer(out)
#   return popen.returncode
# 
# Path: alibuild_helpers/git.py
# def __partialCloneFilter():
# 
# Path: alibuild_helpers/utilities.py
# def format(s, **kwds):
#   if sys.version_info[0] >= 3:
#     if isinstance(s, bytes):
#       try:
#         s = s.decode("utf-8")  # to get newlines as such and not as escaped \n
#       except:
#         s = s.decode("latin-1")  # Workaround issue with some special characters of latin-1 which are not understood by unicode
#     else:
#       s = str(s)
#   elif isinstance(s, str):
#     s = unicode(s, "utf-8")  # utf-8 is a safe assumption
#   elif not isinstance(s, unicode):
#     s = unicode(str(s))
#   return s % kwds


# Path: alibuild_helpers/workarea.py
from alibuild_helpers.log import dieOnError, debug
from alibuild_helpers.cmd import execute
from alibuild_helpers.git import partialCloneFilter
from os.path import dirname, abspath
from alibuild_helpers.utilities import format
  from collections import OrderedDict
  from ordereddict import OrderedDict
import os
import os.path as path
import tempfile

  """
  Update source reference area, if possible.
  If the area is already there and cannot be written, assume it maintained
  by someone else.

  If the area can be created, clone a bare repository with the sources.

  Returns the reference repository's local path if available, otherwise None.
  Throws a fatal error in case repository cannot be updated even if it appears
  to be writeable.

  @referenceSources : a string containing the path to the sources to be updated
  @p                : the name of the package to be updated
  @spec             : the spec of the package to be updated (an OrderedDict)
  @fetch            : whether to fetch updates: if False, only clone if not found
  """
  assert(type(spec) == OrderedDict)
  if not "source" in spec:
    return

  debug("Updating references.")
  referenceRepo = os.path.join(abspath(referenceSources), p.lower())

  try:
    os.makedirs(abspath(referenceSources))
  except:
    pass

  if not is_writeable(referenceSources):
    if path.exists(referenceRepo):

      debug("Using %s as reference for %s", referenceRepo, p)