def _zipdir()

in ebcli/core/fileoperations.py [0:0]


def _zipdir(path, zipf, ignore_list=None):
    if ignore_list is None:
        ignore_list = {'.gitignore'}
    ignore_list = {'./' + i for i in ignore_list}
    zipped_roots = []
    for root, dirs, files in os.walk(path):
        if '.elasticbeanstalk' in root:
            io.log_info('  -skipping: {}'.format(root))
            continue
        for d in dirs:
            cur_dir = os.path.join(root, d)
            if os.path.islink(cur_dir):
                # os.walk categorize symlinks-to-directories as dirs
                # and we want to include symlinks in the zip
                if cur_dir in ignore_list:
                    io.log_info(' -skipping: {}'.format(cur_dir))
                else:
                    zipInfo = zipfile.ZipInfo()
                    zipInfo.filename = os.path.join(root, d)

                    # 2716663808L is the "magic code" for symlinks
                    zipInfo.external_attr = 2716663808 if sys.version_info > (3,) else long(2716663808)

                    zipf.writestr(zipInfo, os.readlink(cur_dir))
        for f in files:
            cur_file = os.path.join(root, f)

            if (
                cur_file.endswith('~')
                or cur_file in ignore_list
                or not _validate_file_for_archive(cur_file)
            ):
                # Ignore editor backup files (like file.txt~)
                # Ignore anything in the .ebignore file
                # Ignore files that cannot be archived
                io.log_info('  -skipping: {}'.format(cur_file))
            else:
                if root not in zipped_roots:
                    # Windows requires us to index the folders.
                    io.log_info(' +adding: {}/'.format(root))
                    zipf.write(root)
                    zipped_roots.append(root)
                io.log_info('  +adding: {}'.format(cur_file))
                if os.path.islink(cur_file):
                    zipInfo = zipfile.ZipInfo()
                    zipInfo.filename = os.path.join(root, f)

                    if sys.version_info > (3,):
                        zipInfo.external_attr = 2716663808
                    else:
                        zipInfo.external_attr = long(2716663808)
                    zipf.writestr(zipInfo, os.readlink(cur_file))
                else:
                    zipf.write(cur_file)