diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 480bff54ce3d86605c627a780b32cea40673abc3..81c26e175c95eb390cc820512c928f3ac29c9ffa 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -29,7 +29,7 @@ from notifications.mail_notifier import MailNotifier from bscearth.utils.date import date2str from monitor.monitor import Monitor from database.db_common import get_autosubmit_version, check_experiment_exists -from database.db_common import delete_experiment +from database.db_common import delete_experiment, update_experiment_descrip_version from experiment.experiment_common import copy_experiment from experiment.experiment_common import new_experiment from database.db_common import create_db @@ -485,6 +485,12 @@ class Autosubmit: 'pklfix', description='restore the backup of your pkl') subparser.add_argument('expid', help='experiment identifier') + # Update Description + subparser = subparsers.add_parser( + 'updatedescrip', description="Updates the experiment's description.") + subparser.add_argument('expid', help='experiment identifier') + subparser.add_argument('description', help='New description.') + # Test subparser = subparsers.add_parser( 'test', description='test experiment') @@ -627,9 +633,11 @@ class Autosubmit: return Autosubmit.database_fix(args.expid) elif args.command == 'pklfix': return Autosubmit.pkl_fix(args.expid) + elif args.command == 'updatedescrip': + return Autosubmit.update_description(args.expid, args.description) @staticmethod - def _init_logs(args, console_level='INFO', log_level='DEBUG', expid='None'): + def _init_logs(args, console_level='INFO', log_level='DEBUG', expid='None'): Log.set_console_level(console_level) expid_less = ["expid", "testcase", "install", "-v", "readme", "changelog", "configure", "unarchive"] @@ -3352,9 +3360,26 @@ class Autosubmit: Log.info("Changing {0} experiment version from {1} to {2}", expid, as_conf.get_version(), Autosubmit.autosubmit_version) + update_experiment_descrip_version( + expid, version=Autosubmit.autosubmit_version) as_conf.set_version(Autosubmit.autosubmit_version) return True + @staticmethod + def update_description(expid, new_description): + Log.info("Checking if experiment exists...") + check_experiment_exists(expid) + Log.info("Experiment found.") + Log.info("Setting {0} description to '{1}'".format( + expid, new_description)) + result = update_experiment_descrip_version( + expid, description=new_description) + if result: + Log.info("Update completed successfully.") + else: + Log.critical("Update failed.") + return True + @staticmethod def pkl_fix(expid): """ diff --git a/autosubmit/database/db_common.py b/autosubmit/database/db_common.py index efe5aef7c915b567822f04d0b4abb0e8e041d1f2..dd00ed255d27e2cda1bfdcf20604ee1f0d36775b 100644 --- a/autosubmit/database/db_common.py +++ b/autosubmit/database/db_common.py @@ -194,6 +194,52 @@ def check_experiment_exists(name, error_on_inexistence=True): return True +def update_experiment_descrip_version(name, description=None, version=None): + """ + Updates the experiment's description and/or version + + :param name: experiment name (expid) + :rtype name: str + :param description: experiment new description + :rtype description: str + :param version: experiment autosubmit version + :rtype version: str + :return: If description has been update, True; otherwise, False. + :rtype: bool + """ + if not check_db(): + return False + try: + (conn, cursor) = open_conn() + except DbException as e: + raise AutosubmitCritical( + "Could not establish a connection to the database.", 7001, str(e)) + conn.isolation_level = None + + # Changing default unicode + conn.text_factory = str + # Conditional update + if description is not None and version is not None: + cursor.execute('update experiment set description=:description, autosubmit_version=:version where name=:name', { + 'description': description, 'version': version, 'name': name}) + elif description is not None and version is None: + cursor.execute('update experiment set description=:description where name=:name', { + 'description': description, 'name': name}) + elif version is not None and description is None: + cursor.execute('update experiment set autosubmit_version=:version where name=:name', { + 'version': version, 'name': name}) + else: + raise AutosubmitCritical( + "Not enough data to update {}.".format(name), 7005) + row = cursor.rowcount + close_conn(conn, cursor) + if row == 0: + raise AutosubmitCritical( + "Update on experiment {} failed.".format(name), 7005) + return False + return True + + def get_autosubmit_version(expid): """ Get the minimun autosubmit version needed for the experiment diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 741cf863509ed285725cf7083b9a9462b8fd1d96..3b64c9b85181e41d551695d8e32f834649558297 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -26,6 +26,10 @@ Command list -unarchive Restores an archived experiment -migrate_exp Migrates an experiment from one user to another -report extract experiment parameters +-updateversion Updates the Autosubmit version of your experiment with the current version of the module you are using +-dbfix Fixes the database malformed error in the historical database of your experiment +-pklfix Fixed the blank pkl error of your experiment +-updatedescrip Updates the description of your experiment (See: :ref:`updateDescrip`) Tutorials (How to) diff --git a/docs/source/usage/configuration/index.rst b/docs/source/usage/configuration/index.rst index 887dd60a3e728b1d86d5a476511f9325d095a51e..692f0a9fb4b8fb972552842c4e176010ec6566bb 100644 --- a/docs/source/usage/configuration/index.rst +++ b/docs/source/usage/configuration/index.rst @@ -12,4 +12,5 @@ How to configure your experiment refresh create_members check + update_description diff --git a/docs/source/usage/configuration/update_description.rst b/docs/source/usage/configuration/update_description.rst new file mode 100644 index 0000000000000000000000000000000000000000..22996238e8b562611abfde6a07ce180544ff91e5 --- /dev/null +++ b/docs/source/usage/configuration/update_description.rst @@ -0,0 +1,20 @@ +.. _updateDescrip: + +How to update the description of your experiment +================================================ + +Use the command: +:: + + autosubmit updatedescrip EXPID DESCRIPTION + +*EXPID* is the experiment identifier. + +*DESCRIPTION* is the new description of your experiment. + +Autosubmit will validate the provided data and print the results in the command line. + +Example: +:: + + autosubmit a29z "Updated using Autosubmit updatedescrip" \ No newline at end of file