# Path: packtools/file_utils.py
# def is_folder(source):
# def is_zipfile(source):
# def xml_files_list(path):
# def files_list(path):
# def read_file(path, encoding="utf-8", mode="r"):
# def read_from_zipfile(zip_path, filename):
# def xml_files_list_from_zipfile(zip_path):
# def files_list_from_zipfile(zip_path):
# def write_file(path, source, mode="w"):
# def create_zip_file(files, zip_name, zip_folder=None):
# def delete_folder(path):
# def create_temp_file(filename, content=None, mode='w'):
# def copy_file(source, target):
# def size(file_path):
# def get_prefix_by_xml_filename(xml_filename):
# def get_file_role(file_path, prefix, pdf_langs):
# def extract_issn_from_zip_uri(zip_uri):
# def is_valid_file(file_path, check_mimetype=False):
# def get_mimetype(file_path):
# def get_filename(file_path):
# 
# Path: packtools/sps/sps_maker.py
# FILE_PATHS_REQUIRED_KEYS = ['xml', 'assets', 'renditions']
# def get_names_and_packages(path):
# def make_package_from_paths(paths, zip_folder=None):
# def make_package_from_uris(xml_uri, renditions_uris_and_names=[], zip_folder=None):
# def _get_xml_sps_from_uri(xml_uri):
# def _get_xml_sps_from_path(xml_path):
# def _get_assets_uris_and_names(xml_sps):
# def _get_xml_uri_and_name(xml_sps, xml_uri=None):
# def _get_zip_filename(xml_sps, output_filename=None):
# def _zip_files_from_uris_and_names(zip_name, uris_and_names, zip_folder=None):
# def _remove_invalid_uris(uris_and_names):
# def _zip_files_from_paths(zip_name, xml_sps, paths, zip_folder=None):
# def _check_keys_and_files(paths: dict):
# def _get_canonical_files_paths(xml_sps, paths):


import argparse
import logging
from packtools import file_utils
from packtools.sps import sps_maker

def _get_rendition_dict(rendition_uri_or_path):
    return {
        'uri': rendition_uri_or_path,
        'name': file_utils.get_filename(rendition_uri_or_path),
    }


def main():
    parser = argparse.ArgumentParser(description="Article package maker CLI utility")
    parser.add_argument('--output_dir', default='.', help='Output directory where the package will be generated')
    parser.add_argument("--loglevel", default="WARNING")

    subparsers = parser.add_subparsers(title='Commands', dest='command')

    uris_parser = subparsers.add_parser('uris', help='Make package from URIs')
    uris_parser.add_argument('--xml', help='XML URI', required=True)
    uris_parser.add_argument('--renditions', default=[], nargs='+', help='Renditions URI')

    paths_parser = subparsers.add_parser('paths', help='Make package from files paths')
    paths_parser.add_argument('--xml', help='XML file path', required=True)
    paths_parser.add_argument('--renditions', default=[], nargs='+', help='Renditions file path')
    paths_parser.add_argument('--assets', default=[], nargs='+', help='Assets file path')

    args = parser.parse_args()

    logging.basicConfig(level=getattr(logging, args.loglevel.upper()))

    if args.command == 'uris':
        uris_dict = generate_uris_dict(args.xml, args.renditions)

# Path: packtools/file_utils.py
# def is_folder(source):
# def is_zipfile(source):
# def xml_files_list(path):
# def files_list(path):
# def read_file(path, encoding="utf-8", mode="r"):
# def read_from_zipfile(zip_path, filename):
# def xml_files_list_from_zipfile(zip_path):
# def files_list_from_zipfile(zip_path):
# def write_file(path, source, mode="w"):
# def create_zip_file(files, zip_name, zip_folder=None):
# def delete_folder(path):
# def create_temp_file(filename, content=None, mode='w'):
# def copy_file(source, target):
# def size(file_path):
# def get_prefix_by_xml_filename(xml_filename):
# def get_file_role(file_path, prefix, pdf_langs):
# def extract_issn_from_zip_uri(zip_uri):
# def is_valid_file(file_path, check_mimetype=False):
# def get_mimetype(file_path):
# def get_filename(file_path):
# 
# Path: packtools/sps/sps_maker.py
# FILE_PATHS_REQUIRED_KEYS = ['xml', 'assets', 'renditions']
# def get_names_and_packages(path):
# def make_package_from_paths(paths, zip_folder=None):
# def make_package_from_uris(xml_uri, renditions_uris_and_names=[], zip_folder=None):
# def _get_xml_sps_from_uri(xml_uri):
# def _get_xml_sps_from_path(xml_path):
# def _get_assets_uris_and_names(xml_sps):
# def _get_xml_uri_and_name(xml_sps, xml_uri=None):
# def _get_zip_filename(xml_sps, output_filename=None):
# def _zip_files_from_uris_and_names(zip_name, uris_and_names, zip_folder=None):
# def _remove_invalid_uris(uris_and_names):
# def _zip_files_from_paths(zip_name, xml_sps, paths, zip_folder=None):
# def _check_keys_and_files(paths: dict):
# def _get_canonical_files_paths(xml_sps, paths):


# Path: packtools/package_maker.py
import argparse
import logging
from packtools import file_utils
from packtools.sps import sps_maker


def _get_rendition_dict(rendition_uri_or_path):
    return {
        'uri': rendition_uri_or_path,
        'name': file_utils.get_filename(rendition_uri_or_path),
    }


def main():
    parser = argparse.ArgumentParser(description="Article package maker CLI utility")
    parser.add_argument('--output_dir', default='.', help='Output directory where the package will be generated')
    parser.add_argument("--loglevel", default="WARNING")

    subparsers = parser.add_subparsers(title='Commands', dest='command')

    uris_parser = subparsers.add_parser('uris', help='Make package from URIs')
    uris_parser.add_argument('--xml', help='XML URI', required=True)
    uris_parser.add_argument('--renditions', default=[], nargs='+', help='Renditions URI')

    paths_parser = subparsers.add_parser('paths', help='Make package from files paths')
    paths_parser.add_argument('--xml', help='XML file path', required=True)
    paths_parser.add_argument('--renditions', default=[], nargs='+', help='Renditions file path')
    paths_parser.add_argument('--assets', default=[], nargs='+', help='Assets file path')

    args = parser.parse_args()

    logging.basicConfig(level=getattr(logging, args.loglevel.upper()))

    if args.command == 'uris':
        uris_dict = generate_uris_dict(args.xml, args.renditions)

        sps_maker.make_package_from_uris(