# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):


import logging
import os.path
import warnings
from taxtastic import refpkg
    stats_group.add_argument("--frequency-type", choices=('empirical', 'model'),
                             help="""Residue frequency type from the model. Required
                        for PhyML Amino Acid alignments.""")


def action(args):
    """Updates a Refpkg with new files.

    *args* should be an argparse object with fields refpkg (giving the
    path to the refpkg to operate on) and changes (a series of strings
    of the form 'key=file' giving the key to update in the refpkg and
    the file to store under that key)."
    """
    log.info('loading reference package')

    pairs = [p.split('=', 1) for p in args.changes]
    if args.metadata:
        rp = refpkg.Refpkg(args.refpkg, create=False)
        rp.start_transaction()
        for key, value in pairs:
            rp.update_metadata(key, value)
        rp.commit_transaction('Updated metadata: ' +
                              ', '.join(['%s=%s' % (a, b)
                                         for a, b in pairs]))
    else:
        for key, filename in pairs:
            if not(os.path.exists(filename)):
                print("No such file: %s" % filename)
                exit(1)


# Path: taxtastic/refpkg.py
# FORMAT_VERSION = '1.1'
# class DerivedFileNotUpdatedWarning(UserWarning):
# class NoAncestor(Exception):
# class Refpkg(object):
# def is_string(val):
# def md5file(fobj):
# def scratch_file(unlink=True, **kwargs):
# def manifest_template():
# def transaction(f, self, *args, **kwargs):
#     def __init__(self, path, create=None):
#     def _install_zipfile_handlers(self):
#         def zipopen(name, *mode):
#         def file_path(name):
#     def file_path(self, name):
#     def open(self, name, *mode):
#     def open_manifest(self, *mode):
#     def open_resource(self, resource, *mode):
#     def resource_name(self, resource):
#     def resource_md5(self, resource):
#     def calculate_resource_md5(self, resource):
#     def resource_path(self, resource):
#     def _set_defaults(self):
#     def _sync_to_disk(self):
#     def _sync_from_disk(self):
#     def _add_file(self, key, path):
#     def _delete_file(self, path):
#     def metadata(self, key):
#     def file_keys(self):
#     def metadata_keys(self):
#     def _log(self, msg):
#     def log(self):
#     def is_invalid(self):
#     def _check_refpkg(self):
#     def update_metadata(self, key, value):
#     def update_file(self, key, new_path):
#     def reroot(self, rppr=None, pretend=False):
#     def update_phylo_model(self, stats_type, stats_file, frequency_type=None):
#     def rollback(self):
#     def rollforward(self):
#     def strip(self):
#     def start_transaction(self):
#     def commit_transaction(self, log=None):
#     def is_ill_formed(self):
#     def load_db(self):
#     def most_recent_common_ancestor(self, *ts):
#     def _large_mrca(self, ts):
#     def _small_mrca(self, ts):
#     def file_abspath(self, resource):
#     def file_name(self, resource):
#     def file_md5(self, resource):


# Path: taxtastic/subcommands/update.py
import logging
import os.path
import warnings
from taxtastic import refpkg

    stats_group.add_argument("--frequency-type", choices=('empirical', 'model'),
                             help="""Residue frequency type from the model. Required
                        for PhyML Amino Acid alignments.""")


def action(args):
    """Updates a Refpkg with new files.

    *args* should be an argparse object with fields refpkg (giving the
    path to the refpkg to operate on) and changes (a series of strings
    of the form 'key=file' giving the key to update in the refpkg and
    the file to store under that key)."
    """
    log.info('loading reference package')

    pairs = [p.split('=', 1) for p in args.changes]
    if args.metadata:
        rp = refpkg.Refpkg(args.refpkg, create=False)
        rp.start_transaction()
        for key, value in pairs:
            rp.update_metadata(key, value)
        rp.commit_transaction('Updated metadata: ' +
                              ', '.join(['%s=%s' % (a, b)
                                         for a, b in pairs]))
    else:
        for key, filename in pairs:
            if not(os.path.exists(filename)):
                print("No such file: %s" % filename)
                exit(1)


        rp = refpkg.Refpkg(args.refpkg, create=False)