#!/opt/anaconda1anaconda2anaconda3/bin/python
# -*- coding: utf-8
"""A script to upgrade the description in an anvi'o db"""

import sys
import argparse

import anvio
import anvio.dbops as dbops
import anvio.terminal as terminal
import anvio.filesnpaths as filesnpaths

from anvio.errors import ConfigError, FilesNPathsError


__author__ = "A. Murat Eren"
__copyright__ = "Copyright 2017, The anvio Project"
__credits__ = []
__license__ = "GPL 3.0"
__version__ = anvio.__version__
__maintainer__ = "A. Murat Eren"
__email__ = "a.murat.eren@gmail.com"


run = terminal.Run()

def main(args):
    dbops.is_pan_or_profile_db(args.pan_or_profile_db)
    filesnpaths.is_file_plain_text(args.description)

    dbops.update_description_in_db(args.pan_or_profile_db, open(args.description).read())


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Update the description in an anvi'o database")

    parser.add_argument(*anvio.A('pan-or-profile-db'), **anvio.K('pan-or-profile-db', {'required': True}))
    parser.add_argument(*anvio.A('description'), **anvio.K('description', {'required': True}))

    args = parser.parse_args()

    try:
        main(args)
    except ConfigError as e:
        print(e)
        sys.exit(-1)
    except FilesNPathsError as e:
        print(e)
        sys.exit(-1)
