# Path: py2app/util.py
# def makedirs(path):
#     path = fsencoding(path)
#     if not os.path.exists(path):
#         os.makedirs(path)
# 
# def mergecopy(src, dest):
#     return macholib.util.mergecopy(src, dest)
# 
# def mergetree(src, dst, condition=None, copyfn=mergecopy):
#     """Recursively merge a directory tree using mergecopy()."""
#     return macholib.util.mergetree(src, dst, condition=condition, copyfn=copyfn)
# 
# def skipscm(ofn):
#     ofn = fsencoding(ofn)
#     fn = os.path.basename(ofn)
#     if fn in SCMDIRS:
#         return False
#     return True
# 
# def make_exec(path):
#     mask = os.umask(0)
#     os.umask(mask)
#     os.chmod(path, os.stat(path).st_mode | (0111 & ~mask))


import os
import plistlib
import shutil
import py2app.bundletemplate
    import sys
from pkg_resources import resource_filename
from py2app.util import makedirs, mergecopy, mergetree, skipscm, make_exec


def create_pluginbundle(destdir, name, extension='.plugin', module=py2app.bundletemplate,
        platform='MacOS', copy=mergecopy, mergetree=mergetree,
        condition=skipscm, plist={}):
    kw = module.plist_template.infoPlistDict(
        plist.get('CFBundleExecutable', name), plist)
    plugin = os.path.join(destdir, kw['CFBundleName'] + extension)
    contents = os.path.join(plugin, 'Contents')
    resources = os.path.join(contents, 'Resources')
    platdir = os.path.join(contents, platform)
    dirs = [contents, resources, platdir]
    plist = plistlib.Plist()
    plist.update(kw)
    plistPath = os.path.join(contents, 'Info.plist')
    if os.path.exists(plistPath):
        if plist != plistlib.Plist.fromFile(plistPath):
            for d in dirs:

# Path: py2app/util.py
# def makedirs(path):
#     path = fsencoding(path)
#     if not os.path.exists(path):
#         os.makedirs(path)
# 
# def mergecopy(src, dest):
#     return macholib.util.mergecopy(src, dest)
# 
# def mergetree(src, dst, condition=None, copyfn=mergecopy):
#     """Recursively merge a directory tree using mergecopy()."""
#     return macholib.util.mergetree(src, dst, condition=condition, copyfn=copyfn)
# 
# def skipscm(ofn):
#     ofn = fsencoding(ofn)
#     fn = os.path.basename(ofn)
#     if fn in SCMDIRS:
#         return False
#     return True
# 
# def make_exec(path):
#     mask = os.umask(0)
#     os.umask(mask)
#     os.chmod(path, os.stat(path).st_mode | (0111 & ~mask))


# Path: py2app/create_pluginbundle.py
import os
import plistlib
import shutil
import py2app.bundletemplate
    import sys
from pkg_resources import resource_filename
from py2app.util import makedirs, mergecopy, mergetree, skipscm, make_exec



def create_pluginbundle(destdir, name, extension='.plugin', module=py2app.bundletemplate,
        platform='MacOS', copy=mergecopy, mergetree=mergetree,
        condition=skipscm, plist={}):
    kw = module.plist_template.infoPlistDict(
        plist.get('CFBundleExecutable', name), plist)
    plugin = os.path.join(destdir, kw['CFBundleName'] + extension)
    contents = os.path.join(plugin, 'Contents')
    resources = os.path.join(contents, 'Resources')
    platdir = os.path.join(contents, platform)
    dirs = [contents, resources, platdir]
    plist = plistlib.Plist()
    plist.update(kw)
    plistPath = os.path.join(contents, 'Info.plist')
    if os.path.exists(plistPath):
        if plist != plistlib.Plist.fromFile(plistPath):
            for d in dirs:

                shutil.rmtree(d, ignore_errors=True)