# Path: elbepack/shellhelper.py
# class CommandError(Exception):
# 
#     def __init__(self, cmd, returncode):
#         super(CommandError, self).__init__(cmd, returncode)
#         self.returncode = returncode
#         self.cmd = cmd
# 
#     def __str__(self):
#         return "Error: %d returned from Command %s" % (
#             self.returncode, self.cmd)
# 
# def do(cmd, allow_fail=False, stdin=None, env_add=None):
#     """do() - Execute cmd in a shell and redirect outputs to logging.
# 
#     Throws a CommandError if cmd failed with allow_Fail=False.
# 
#     --
# 
#     Let's redirect the loggers to current stdout
#     >>> import sys
#     >>> from elbepack.log import open_logging
#     >>> open_logging({"streams":sys.stdout})
# 
#     >>> do("true")
#     [CMD] true
# 
#     >>> do("false", allow_fail=True)
#     [CMD] false
# 
#     >>> do("cat -", stdin=b"ELBE")
#     [CMD] cat -
# 
#     >>> do("cat - && false", stdin=b"ELBE") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
# 
#     >>> do("false") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
#     """
# 
#     new_env = os.environ.copy()
#     if env_add:
#         new_env.update(env_add)
# 
#     if isinstance(stdin, str):
#         stdin = stdin.encode()
# 
#     logging.info(cmd, extra={"context":"[CMD] "})
# 
#     r, w = os.pipe()
# 
#     if stdin is None:
#         p = Popen(cmd, shell=True, stdout=w, stderr=STDOUT, env=new_env)
#     else:
#         p = Popen(cmd, shell=True, stdin=PIPE, stdout=w, stderr=STDOUT, env=new_env)
# 
#     async_logging(r, w, soap, log)
#     p.communicate(input=stdin)
# 
#     if p.returncode and not allow_fail:
#         raise CommandError(cmd, p.returncode)


import os
from elbepack.shellhelper import CommandError, do
        self.suffix = suffix

    def pack_file(self, builddir, fname):
        try:
            fpath = os.path.join(builddir, fname)
            do('%s "%s"' % (self.cmd, fpath))
        except CommandError:
            # in case of an error, we just return None
            # which means, that the orig file does not
            # exist anymore
            return None

        return fname + self.suffix


class TarArchiver(Packer):

    def __init__(self, flag, suffix):
        self.flag = flag
        self.suffix = suffix

    def pack_file(self, builddir, fname):
        try:
            fpath = os.path.join(builddir, fname)
            dirname = os.path.dirname(fpath)
            basename = os.path.basename(fpath)
            archname = fpath + self.suffix
            do('tar cv%sf "%s" --sparse -C "%s" "%s"' %
               (self.flag, archname, dirname, basename))
            do('rm -f "%s"' % fpath)

# Path: elbepack/shellhelper.py
# class CommandError(Exception):
# 
#     def __init__(self, cmd, returncode):
#         super(CommandError, self).__init__(cmd, returncode)
#         self.returncode = returncode
#         self.cmd = cmd
# 
#     def __str__(self):
#         return "Error: %d returned from Command %s" % (
#             self.returncode, self.cmd)
# 
# def do(cmd, allow_fail=False, stdin=None, env_add=None):
#     """do() - Execute cmd in a shell and redirect outputs to logging.
# 
#     Throws a CommandError if cmd failed with allow_Fail=False.
# 
#     --
# 
#     Let's redirect the loggers to current stdout
#     >>> import sys
#     >>> from elbepack.log import open_logging
#     >>> open_logging({"streams":sys.stdout})
# 
#     >>> do("true")
#     [CMD] true
# 
#     >>> do("false", allow_fail=True)
#     [CMD] false
# 
#     >>> do("cat -", stdin=b"ELBE")
#     [CMD] cat -
# 
#     >>> do("cat - && false", stdin=b"ELBE") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
# 
#     >>> do("false") # doctest: +ELLIPSIS
#     Traceback (most recent call last):
#     ...
#     elbepack.shellhelper.CommandError: ...
#     """
# 
#     new_env = os.environ.copy()
#     if env_add:
#         new_env.update(env_add)
# 
#     if isinstance(stdin, str):
#         stdin = stdin.encode()
# 
#     logging.info(cmd, extra={"context":"[CMD] "})
# 
#     r, w = os.pipe()
# 
#     if stdin is None:
#         p = Popen(cmd, shell=True, stdout=w, stderr=STDOUT, env=new_env)
#     else:
#         p = Popen(cmd, shell=True, stdin=PIPE, stdout=w, stderr=STDOUT, env=new_env)
# 
#     async_logging(r, w, soap, log)
#     p.communicate(input=stdin)
# 
#     if p.returncode and not allow_fail:
#         raise CommandError(cmd, p.returncode)


# Path: elbepack/packers.py
import os
from elbepack.shellhelper import CommandError, do

        self.suffix = suffix

    def pack_file(self, builddir, fname):
        try:
            fpath = os.path.join(builddir, fname)
            do('%s "%s"' % (self.cmd, fpath))
        except CommandError:
            # in case of an error, we just return None
            # which means, that the orig file does not
            # exist anymore
            return None

        return fname + self.suffix


class TarArchiver(Packer):

    def __init__(self, flag, suffix):
        self.flag = flag
        self.suffix = suffix

    def pack_file(self, builddir, fname):
        try:
            fpath = os.path.join(builddir, fname)
            dirname = os.path.dirname(fpath)
            basename = os.path.basename(fpath)
            archname = fpath + self.suffix
            do('tar cv%sf "%s" --sparse -C "%s" "%s"' %
               (self.flag, archname, dirname, basename))
            do('rm -f "%s"' % fpath)

        except CommandError: