def main():
    parser = argparse.ArgumentParser(description='Merges the contents of two SDKs')
    first_group = parser.add_mutually_exclusive_group(required=True)
    first_group.add_argument('--first-archive', help='Path to the first SDK - as an archive', default='')
    first_group.add_argument('--first-directory', help='Path to the first SDK - as a directory', default='')
    second_group = parser.add_mutually_exclusive_group(required=True)
    second_group.add_argument('--second-archive', help='Path to the second SDK - as an archive', default='')
    second_group.add_argument('--second-directory', help='Path to the second SDK - as a directory', default='')
    output_group = parser.add_mutually_exclusive_group(required=True)
    output_group.add_argument('--output-archive', help='Path to the merged SDK - as an archive', default='')
    output_group.add_argument('--output-directory', help='Path to the merged SDK - as a directory', default='')
    args = parser.parse_args()
    has_errors = False
    with _open_archive(args.first_archive, args.first_directory) as first_dir, _open_archive(args.second_archive, args.second_directory) as second_dir, _open_output(args.output_archive, args.output_directory) as out_dir:
        first_elements = set([Part(p) for p in _get_manifest(first_dir)['parts']])
        second_elements = set([Part(p) for p in _get_manifest(second_dir)['parts']])
        common_elements = (first_elements & second_elements)
        for element in sorted((first_elements - common_elements)):
            _copy_element(element.meta, first_dir, out_dir)
        for element in (second_elements - common_elements):
            _copy_element(element.meta, second_dir, out_dir)
        for raw_element in sorted(common_elements):
            element = raw_element.meta
            first_meta = _get_meta(element, first_dir)
            second_meta = _get_meta(element, second_dir)
            (first_common, first_arch) = _get_files(first_meta)
            (second_common, second_arch) = _get_files(second_meta)
            if (not _copy_identical_files(first_common, first_dir, second_common, second_dir, out_dir)):
                print(('Error: different common files for %s' % element))
                has_errors = True
                continue
            all_arches = (set(first_arch.keys()) | set(second_arch.keys()))
            for arch in all_arches:
                if ((arch in first_arch) and (arch in second_arch)):
                    if (not _copy_identical_files(first_arch[arch], first_dir, second_arch[arch], second_dir, out_dir)):
                        print(('Error: different %s files for %s' % (arch, element)))
                        has_errors = True
                        continue
                elif (arch in first_arch):
                    _copy_files(first_arch[arch], first_dir, out_dir)
                elif (arch in second_arch):
                    _copy_files(second_arch[arch], second_dir, out_dir)
            if (not _write_meta(element, first_dir, second_dir, out_dir)):
                print(('Error: unable to merge meta for %s' % element))
                has_errors = True
        if (not _write_manifest(first_dir, second_dir, out_dir)):
            print('Error: could not write manifest file')
            has_errors = True
    return (1 if has_errors else 0)
def main():
    parser = argparse.ArgumentParser(description='Merges the contents of two SDKs')
    first_group = parser.add_mutually_exclusive_group(required=True)
    first_group.add_argument('--first-archive', help='Path to the first SDK - as an archive', default=)
    first_group.add_argument('--first-directory', help='Path to the first SDK - as a directory', default=)
    second_group = parser.add_mutually_exclusive_group(required=True)
    second_group.add_argument('--second-archive', help='Path to the second SDK - as an archive', default=)
    second_group.add_argument('--second-directory', help='Path to the second SDK - as a directory', default=)
    output_group = parser.add_mutually_exclusive_group(required=True)
    output_group.add_argument('--output-archive', help='Path to the merged SDK - as an archive', default=)
    output_group.add_argument('--output-directory', help='Path to the merged SDK - as a directory', default=)
    args = parser.parse_args()
    has_errors = False
    with _open_archive(args.first_archive, args.first_directory) as first_dir, _open_archive(args.second_archive, args.second_directory) as second_dir, _open_output(args.output_archive, args.output_directory) as out_dir:
        first_elements = set([Part(p) for p in _get_manifest(first_dir)['parts']])
        second_elements = set([Part(p) for p in _get_manifest(second_dir)['parts']])
        common_elements = (first_elements & second_elements)
        for element in sorted((first_elements - common_elements)):
            _copy_element(element.meta, first_dir, out_dir)
        for element in (second_elements - common_elements):
            _copy_element(element.meta, second_dir, out_dir)
        for raw_element in sorted(common_elements):
            element = raw_element.meta
            first_meta = _get_meta(element, first_dir)
            second_meta = _get_meta(element, second_dir)
            (first_common, first_arch) = _get_files(first_meta)
            (second_common, second_arch) = _get_files(second_meta)
            if (not _copy_identical_files(first_common, first_dir, second_common, second_dir, out_dir)):
                print(('Error: different common files for %s' % element))
                has_errors = True
                continue
            all_arches = (set(first_arch.keys()) | set(second_arch.keys()))
            for arch in all_arches:
                if ((arch in first_arch) and (arch in second_arch)):
                    if (not _copy_identical_files(first_arch[arch], first_dir, second_arch[arch], second_dir, out_dir)):
                        print(('Error: different %s files for %s' % (arch, element)))
                        has_errors = True
                        continue
                elif (arch in first_arch):
                    _copy_files(first_arch[arch], first_dir, out_dir)
                elif (arch in second_arch):
                    _copy_files(second_arch[arch], second_dir, out_dir)
            if (not _write_meta(element, first_dir, second_dir, out_dir)):
                print(('Error: unable to merge meta for %s' % element))
                has_errors = True
        if (not _write_manifest(first_dir, second_dir, out_dir)):
            print('Error: could not write manifest file')
            has_errors = True
    return (1 if has_errors else 0)