# Path: cavedb/generate_docs.py
# def write_global_bulletin_files():
#     outputter = cavedb.docgen_all.create_global_docgen_classes()
# 
#     outputter.open(None)
# 
#     outputter.indexed_terms([])
# 
#     # No GIS section. Only write that on the bulletin.
# 
#     outputter.begin_regions([])
# 
#     for bulletin in cavedb.models.Bulletin.objects.all():
#         for region in cavedb.models.BulletinRegion.objects.filter(bulletin__id=bulletin.id):
#             write_region(region, outputter)
# 
#     outputter.end_regions()
# 
#     outputter.close()
# 
#     write_build_scripts(cavedb.utils.GLOBAL_BULLETIN_ID, outputter)
# 
# Path: cavedb/generate_docs.py
# def write_bulletin_files(bulletin):
#     outputter = cavedb.docgen_all.create_bulletin_docgen_classes(bulletin)
# 
#     all_regions_gis_hash = get_all_regions_gis_hash(bulletin.id)
# 
#     outputter.open(all_regions_gis_hash)
# 
#     outputter.indexed_terms(get_indexed_terms(bulletin))
# 
#     write_gis_sections(bulletin.id, outputter)
# 
#     chapters = get_chapters_and_sections(bulletin.id)
# 
#     outputter.begin_regions(chapters)
# 
#     for region in cavedb.models.BulletinRegion.objects.filter(bulletin__id=bulletin.id):
#         write_region(region, outputter)
# 
#     outputter.end_regions()
# 
#     outputter.close()
# 
#     write_build_scripts(bulletin.id, outputter)
# 
# Path: cavedb/generate_docs.py
# def run_buildscript(bulletin_id):
#     build_script_file = cavedb.utils.get_build_script(bulletin_id)
# 
#     basedir = '%s/bulletins/bulletin_%s' % (settings.MEDIA_ROOT, bulletin_id)
#     os.chdir(basedir)
#     os.system('%s' % (build_script_file))


import sys
import django
import cavedb.utils
from cavedb.generate_docs import write_global_bulletin_files
from cavedb.generate_docs import write_bulletin_files
from cavedb.generate_docs import run_buildscript
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0


django.setup()

# pylint: disable=wrong-import-position


def do_build_bulletin(bulletin_id):
    if bulletin_id == cavedb.utils.GLOBAL_BULLETIN_ID:
        write_global_bulletin_files()
    else:
        bulletin = cavedb.models.Bulletin.objects.get(pk=bulletin_id)
        if bulletin is None:
            print('Bulletin %s not found' % (bulletin_id))
            sys.exit(1)

        write_bulletin_files(bulletin)

    run_buildscript(bulletin_id)


if __name__ == '__main__':

# Path: cavedb/generate_docs.py
# def write_global_bulletin_files():
#     outputter = cavedb.docgen_all.create_global_docgen_classes()
# 
#     outputter.open(None)
# 
#     outputter.indexed_terms([])
# 
#     # No GIS section. Only write that on the bulletin.
# 
#     outputter.begin_regions([])
# 
#     for bulletin in cavedb.models.Bulletin.objects.all():
#         for region in cavedb.models.BulletinRegion.objects.filter(bulletin__id=bulletin.id):
#             write_region(region, outputter)
# 
#     outputter.end_regions()
# 
#     outputter.close()
# 
#     write_build_scripts(cavedb.utils.GLOBAL_BULLETIN_ID, outputter)
# 
# Path: cavedb/generate_docs.py
# def write_bulletin_files(bulletin):
#     outputter = cavedb.docgen_all.create_bulletin_docgen_classes(bulletin)
# 
#     all_regions_gis_hash = get_all_regions_gis_hash(bulletin.id)
# 
#     outputter.open(all_regions_gis_hash)
# 
#     outputter.indexed_terms(get_indexed_terms(bulletin))
# 
#     write_gis_sections(bulletin.id, outputter)
# 
#     chapters = get_chapters_and_sections(bulletin.id)
# 
#     outputter.begin_regions(chapters)
# 
#     for region in cavedb.models.BulletinRegion.objects.filter(bulletin__id=bulletin.id):
#         write_region(region, outputter)
# 
#     outputter.end_regions()
# 
#     outputter.close()
# 
#     write_build_scripts(bulletin.id, outputter)
# 
# Path: cavedb/generate_docs.py
# def run_buildscript(bulletin_id):
#     build_script_file = cavedb.utils.get_build_script(bulletin_id)
# 
#     basedir = '%s/bulletins/bulletin_%s' % (settings.MEDIA_ROOT, bulletin_id)
#     os.chdir(basedir)
#     os.system('%s' % (build_script_file))


# Path: cavedb/scripts/generate_single_bulletin.py
import sys
import django
import cavedb.utils
from cavedb.generate_docs import write_global_bulletin_files
from cavedb.generate_docs import write_bulletin_files
from cavedb.generate_docs import run_buildscript

#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0


django.setup()

# pylint: disable=wrong-import-position


def do_build_bulletin(bulletin_id):
    if bulletin_id == cavedb.utils.GLOBAL_BULLETIN_ID:
        write_global_bulletin_files()
    else:
        bulletin = cavedb.models.Bulletin.objects.get(pk=bulletin_id)
        if bulletin is None:
            print('Bulletin %s not found' % (bulletin_id))
            sys.exit(1)

        write_bulletin_files(bulletin)

    run_buildscript(bulletin_id)


if __name__ == '__main__':

    if len(sys.argv) != 2: