# Path: pisi/util.py
# def run_logged(cmd):
#     """Run command and get the return value."""
#     ctx.ui.info(_('Running ') + cmd, verbose=True)
#     if ctx.stdout:
#         stdout = ctx.stdout
#     else:
#         if ctx.get_option('debug'):
#             stdout = None
#         else:
#             stdout = subprocess.PIPE
#     if ctx.stderr:
#         stderr = ctx.stderr
#     else:
#         if ctx.get_option('debug'):
#             stderr = None
#         else:
#             stderr = subprocess.STDOUT
# 
#     p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
#     out, err = p.communicate()
#     ctx.ui.debug(_('return value for "%s" is %s') % (cmd, p.returncode))
# 
#     return p.returncode
# 
# Path: pisi/util.py
# def join_path(a, *p):
#     """Join two or more pathname components.
#     Python os.path.join cannot handle '/' at the start of latter components.
#     """
#     path = a
#     for b in p:
#         b = b.lstrip('/')
#         if path == '' or path.endswith('/'):
#             path +=  b
#         else:
#             path += '/' + b
#     return path


import os
import glob
import shutil
import string
import pwd
import grp
import gettext
import pisi.context as ctx
import pisi.actionsapi
import pisi.actionsapi.get
from pisi.actionsapi import error
from pisi.util import run_logged
from pisi.util import join_path
        error(_("ActionsAPI [copy]: No file matched pattern \"%s\".") % source)

    for filePath in sourceGlob:
        if isFile(filePath) and not isLink(filePath):
            try:
                shutil.copy(filePath, destination)
            except IOError:
                error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination))
        elif isLink(filePath) and sym:
            if isDirectory(destination):
                os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath)))
            else:
                if isFile(destination):
                    os.remove(destination)
                os.symlink(os.readlink(filePath), destination)
        elif isLink(filePath) and not sym:
            if isDirectory(filePath):
                copytree(filePath, destination)
            else:
                shutil.copy(filePath, destination)
        elif isDirectory(filePath):
            copytree(filePath, destination, sym)
        else:
            error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)

def copytree(source, destination, sym = True):
    '''recursively copy an entire directory tree rooted at source'''
    if isDirectory(source):
        if os.path.exists(destination):
            if isDirectory(destination):

# Path: pisi/util.py
# def run_logged(cmd):
#     """Run command and get the return value."""
#     ctx.ui.info(_('Running ') + cmd, verbose=True)
#     if ctx.stdout:
#         stdout = ctx.stdout
#     else:
#         if ctx.get_option('debug'):
#             stdout = None
#         else:
#             stdout = subprocess.PIPE
#     if ctx.stderr:
#         stderr = ctx.stderr
#     else:
#         if ctx.get_option('debug'):
#             stderr = None
#         else:
#             stderr = subprocess.STDOUT
# 
#     p = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
#     out, err = p.communicate()
#     ctx.ui.debug(_('return value for "%s" is %s') % (cmd, p.returncode))
# 
#     return p.returncode
# 
# Path: pisi/util.py
# def join_path(a, *p):
#     """Join two or more pathname components.
#     Python os.path.join cannot handle '/' at the start of latter components.
#     """
#     path = a
#     for b in p:
#         b = b.lstrip('/')
#         if path == '' or path.endswith('/'):
#             path +=  b
#         else:
#             path += '/' + b
#     return path


# Path: pisi/actionsapi/shelltools.py
import os
import glob
import shutil
import string
import pwd
import grp
import gettext
import pisi.context as ctx
import pisi.actionsapi
import pisi.actionsapi.get
from pisi.actionsapi import error
from pisi.util import run_logged
from pisi.util import join_path

        error(_("ActionsAPI [copy]: No file matched pattern \"%s\".") % source)

    for filePath in sourceGlob:
        if isFile(filePath) and not isLink(filePath):
            try:
                shutil.copy(filePath, destination)
            except IOError:
                error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination))
        elif isLink(filePath) and sym:
            if isDirectory(destination):
                os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath)))
            else:
                if isFile(destination):
                    os.remove(destination)
                os.symlink(os.readlink(filePath), destination)
        elif isLink(filePath) and not sym:
            if isDirectory(filePath):
                copytree(filePath, destination)
            else:
                shutil.copy(filePath, destination)
        elif isDirectory(filePath):
            copytree(filePath, destination, sym)
        else:
            error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)

def copytree(source, destination, sym = True):
    '''recursively copy an entire directory tree rooted at source'''
    if isDirectory(source):
        if os.path.exists(destination):
            if isDirectory(destination):

                copytree(source, join_path(destination, os.path.basename(source.strip('/'))))