# 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 detectArch():
#   try:
#     with open("/etc/os-release") as osr:
#       osReleaseLines = osr.readlines()
#     hasOsRelease = True
#   except (IOError,OSError):
#     osReleaseLines = []
#     hasOsRelease = False
#   try:
#     import platform
#     if platform.system() == "Darwin":
#       if platform.machine() == "x86_64":
#         return "osx_x86-64"
#       else:
#         return "osx_arm64"
#   except:
#     pass
#   try:
#     import platform, distro
#     platformTuple = distro.linux_distribution()
#     platformSystem = platform.system()
#     platformProcessor = platform.processor()
#     if not platformProcessor or " " in platformProcessor:
#       platformProcessor = platform.machine()
#     return doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor)
#   except:
#     return doDetectArch(hasOsRelease, osReleaseLines, ["unknown", "", ""], "", "")
# 
# Path: alibuild_helpers/utilities.py
# def normalise_multiple_options(option, sep=","):
#   return [x for x in ",".join(option).split(sep) if x]


import argparse
import multiprocessing
import re
import os
  import commands
  import subprocess as commands
import sys
from alibuild_helpers.utilities import format, detectArch
from alibuild_helpers.utilities import normalise_multiple_options
from os.path import abspath, dirname, basename

    if args.docker and args.architecture.startswith("osx"):
      parser.error("cannot use `-a %s` and --docker" % args.architecture)

    if args.docker and commands.getstatusoutput("which docker")[0]:
      parser.error("cannot use --docker as docker executable is not found")

    # If specified, used the docker image requested, otherwise, if running
    # in docker the docker image is given by the first part of the
    # architecture we want to build for.
    if args.docker and not "dockerImage" in args:
      args.dockerImage = "alisw/%s-builder" % args.architecture.split("_")[0]

    if args.remoteStore.endswith("::rw") and args.writeStore:
      parser.error("cannot specify ::rw and --write-store at the same time")

    if args.remoteStore.endswith("::rw"):
      args.remoteStore = args.remoteStore[0:-4]
      args.writeStore = args.remoteStore

  if args.action in ["build", "init"]:
    if "develPrefix" in args and args.develPrefix == None:
      if "chdir" in args:
        args.develPrefix = basename(abspath(args.chdir))
      else:
        args.develPrefix = basename(dirname(abspath(args.configDir)))
    if "dockerImage" in args:
      args.develPrefix = "%s-%s" % (args.develPrefix, args.architecture) if "develPrefix" in args else args.architecture

  if args.action == "init":

# 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 detectArch():
#   try:
#     with open("/etc/os-release") as osr:
#       osReleaseLines = osr.readlines()
#     hasOsRelease = True
#   except (IOError,OSError):
#     osReleaseLines = []
#     hasOsRelease = False
#   try:
#     import platform
#     if platform.system() == "Darwin":
#       if platform.machine() == "x86_64":
#         return "osx_x86-64"
#       else:
#         return "osx_arm64"
#   except:
#     pass
#   try:
#     import platform, distro
#     platformTuple = distro.linux_distribution()
#     platformSystem = platform.system()
#     platformProcessor = platform.processor()
#     if not platformProcessor or " " in platformProcessor:
#       platformProcessor = platform.machine()
#     return doDetectArch(hasOsRelease, osReleaseLines, platformTuple, platformSystem, platformProcessor)
#   except:
#     return doDetectArch(hasOsRelease, osReleaseLines, ["unknown", "", ""], "", "")
# 
# Path: alibuild_helpers/utilities.py
# def normalise_multiple_options(option, sep=","):
#   return [x for x in ",".join(option).split(sep) if x]


# Path: alibuild_helpers/args.py
import argparse
import multiprocessing
import re
import os
  import commands
  import subprocess as commands
import sys
from alibuild_helpers.utilities import format, detectArch
from alibuild_helpers.utilities import normalise_multiple_options
from os.path import abspath, dirname, basename


    if args.docker and args.architecture.startswith("osx"):
      parser.error("cannot use `-a %s` and --docker" % args.architecture)

    if args.docker and commands.getstatusoutput("which docker")[0]:
      parser.error("cannot use --docker as docker executable is not found")

    # If specified, used the docker image requested, otherwise, if running
    # in docker the docker image is given by the first part of the
    # architecture we want to build for.
    if args.docker and not "dockerImage" in args:
      args.dockerImage = "alisw/%s-builder" % args.architecture.split("_")[0]

    if args.remoteStore.endswith("::rw") and args.writeStore:
      parser.error("cannot specify ::rw and --write-store at the same time")

    if args.remoteStore.endswith("::rw"):
      args.remoteStore = args.remoteStore[0:-4]
      args.writeStore = args.remoteStore

  if args.action in ["build", "init"]:
    if "develPrefix" in args and args.develPrefix == None:
      if "chdir" in args:
        args.develPrefix = basename(abspath(args.chdir))
      else:
        args.develPrefix = basename(dirname(abspath(args.configDir)))
    if "dockerImage" in args:
      args.develPrefix = "%s-%s" % (args.develPrefix, args.architecture) if "develPrefix" in args else args.architecture

  if args.action == "init":

    args.configDir = format(args.configDir, prefix=args.develPrefix+"/")