# Path: antbs/utils/utility_functions.py
# def remove(src):
#     if not isinstance(src, str):
#         raise ValueError('src must be of type(str), type({0}) given.'.format(type(src)))
# 
#     if os.path.islink(src):
#         method_to_call = os.unlink
# 
#     elif os.path.isdir(src):
#         method_to_call = shutil.rmtree
# 
#     else:
#         method_to_call = os.remove
# 
#     try:
#         method_to_call(src)
#     except Exception as err:
#         logging.exception(err)


import os
import subprocess
import logging
from . import remove
# by works containing it is required.
#
# You should have received a copy of the GNU General Public License
# along with AntBS; If not, see <http://www.gnu.org/licenses/>.

""" Sign packages with gpg """



logger = logging.getLogger('antbs')
GPG_BIN = '/usr/bin/gpg'
SIG_EXT = '.sig'
PKG_EXT = '.pkg.tar.xz'


def batch_sign(paths, db, bnum='', uid='', passphrase='', is_iso=False):
    if not isinstance(paths, set):
        logger.error('paths must be a set')
        return False

    for path in paths:
        logger.info('[SIGN PKG] Creating detached signature for %s' % path)
        db.publish(
            'live:build_output:{0}'.format(bnum),
            'Creating detached signature for %s' % path
        )

        sigpath = path + SIG_EXT

        try:

# Path: antbs/utils/utility_functions.py
# def remove(src):
#     if not isinstance(src, str):
#         raise ValueError('src must be of type(str), type({0}) given.'.format(type(src)))
# 
#     if os.path.islink(src):
#         method_to_call = os.unlink
# 
#     elif os.path.isdir(src):
#         method_to_call = shutil.rmtree
# 
#     else:
#         method_to_call = os.remove
# 
#     try:
#         method_to_call(src)
#     except Exception as err:
#         logging.exception(err)


# Path: antbs/utils/sign_pkgs.py
import os
import subprocess
import logging
from . import remove

# by works containing it is required.
#
# You should have received a copy of the GNU General Public License
# along with AntBS; If not, see <http://www.gnu.org/licenses/>.

""" Sign packages with gpg """



logger = logging.getLogger('antbs')
GPG_BIN = '/usr/bin/gpg'
SIG_EXT = '.sig'
PKG_EXT = '.pkg.tar.xz'


def batch_sign(paths, db, bnum='', uid='', passphrase='', is_iso=False):
    if not isinstance(paths, set):
        logger.error('paths must be a set')
        return False

    for path in paths:
        logger.info('[SIGN PKG] Creating detached signature for %s' % path)
        db.publish(
            'live:build_output:{0}'.format(bnum),
            'Creating detached signature for %s' % path
        )

        sigpath = path + SIG_EXT

        try:

            os.remove(sigpath)