# 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/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/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
# 
# def star():
#   return re.sub("build.*$", "", basename(sys.argv[0]).lower())
# 
# def resolve_store_path(architecture, spec_hash):
#   """Return the path where a tarball with the given hash is to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, "store", spec_hash[:2], spec_hash))
# 
# def resolve_links_path(architecture, package):
#   """Return the path where symlinks for the given package are to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, package))


import glob
import os
import os.path
import re
import sys
import time
import requests
      import boto3
from requests.exceptions import RequestException
from alibuild_helpers.cmd import execute
from alibuild_helpers.log import debug, warning, error, dieOnError
from alibuild_helpers.utilities import format, star, resolve_store_path, resolve_links_path
    from botocore.exceptions import ClientError
    from botocore.exceptions import ClientError
        if not has_sep:
          debug("Ignoring malformed line in manifest: %r", line)
          continue
        if not target.startswith(b"../../"):
          target = b"../../" + target
        target = os.fsdecode(target)
        link_path = os.path.join(self.workdir, links_path, os.fsdecode(link_name))
        dieOnError(execute("ln -sf {} {}".format(target, link_path)),
                  "Unable to create symlink {} -> {}".format(link_name, target))
        n_symlinks += 1
      debug("Got %d entries in manifest", n_symlinks)

    # Create remote symlinks that aren't in the manifest yet.
    debug("Looking for symlinks not in manifest")
    for link_key in self._s3_listdir(links_path):
      link_path = os.path.join(self.workdir, link_key)
      if os.path.islink(link_path):
        continue
      debug("Fetching leftover symlink %s", link_key)
      resp = self.s3.get_object(Bucket=self.remoteStore, Key=link_key)
      target = os.fsdecode(resp["Body"].read()).rstrip("\n")
      if not target.startswith("../../"):
        target = "../../" + target
      dieOnError(execute("ln -sf {} {}".format(target, link_path)),
                 "Unable to create symlink {} -> {}".format(link_key, target))

  def syncToRemote(self, p, spec):
    if not self.writeStore:
      return
    tarballNameWithRev = ("{package}-{version}-{revision}.{architecture}.tar.gz"

# 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/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/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
# 
# def star():
#   return re.sub("build.*$", "", basename(sys.argv[0]).lower())
# 
# def resolve_store_path(architecture, spec_hash):
#   """Return the path where a tarball with the given hash is to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, "store", spec_hash[:2], spec_hash))
# 
# def resolve_links_path(architecture, package):
#   """Return the path where symlinks for the given package are to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, package))


# Path: alibuild_helpers/sync.py
import glob
import os
import os.path
import re
import sys
import time
import requests
      import boto3
from requests.exceptions import RequestException
from alibuild_helpers.cmd import execute
from alibuild_helpers.log import debug, warning, error, dieOnError
from alibuild_helpers.utilities import format, star, resolve_store_path, resolve_links_path
    from botocore.exceptions import ClientError
    from botocore.exceptions import ClientError

        if not has_sep:
          debug("Ignoring malformed line in manifest: %r", line)
          continue
        if not target.startswith(b"../../"):
          target = b"../../" + target
        target = os.fsdecode(target)
        link_path = os.path.join(self.workdir, links_path, os.fsdecode(link_name))
        dieOnError(execute("ln -sf {} {}".format(target, link_path)),
                  "Unable to create symlink {} -> {}".format(link_name, target))
        n_symlinks += 1
      debug("Got %d entries in manifest", n_symlinks)

    # Create remote symlinks that aren't in the manifest yet.
    debug("Looking for symlinks not in manifest")
    for link_key in self._s3_listdir(links_path):
      link_path = os.path.join(self.workdir, link_key)
      if os.path.islink(link_path):
        continue
      debug("Fetching leftover symlink %s", link_key)
      resp = self.s3.get_object(Bucket=self.remoteStore, Key=link_key)
      target = os.fsdecode(resp["Body"].read()).rstrip("\n")
      if not target.startswith("../../"):
        target = "../../" + target
      dieOnError(execute("ln -sf {} {}".format(target, link_path)),
                 "Unable to create symlink {} -> {}".format(link_key, target))

  def syncToRemote(self, p, spec):
    if not self.writeStore:
      return
    tarballNameWithRev = ("{package}-{version}-{revision}.{architecture}.tar.gz"

                          .format(architecture=self.architecture, **spec))