From b9bf5fd166caa9cf7fd26993a670aef59fdeddf5 Mon Sep 17 00:00:00 2001 From: Wilmer Uruchi Ticona Date: Thu, 29 Apr 2021 13:03:04 +0200 Subject: [PATCH 1/2] Implementing #688. Added update database experiment version on updateversion command. --- autosubmit/autosubmit.py | 29 +++++++++++- autosubmit/database/db_common.py | 46 +++++++++++++++++++ docs/source/usage.rst | 4 ++ .../configuration/update_description.rst | 20 ++++++++ 4 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 docs/source/usage/configuration/update_description.rst diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 480bff54c..81c26e175 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 efe5aef7c..dd00ed255 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 741cf8635..6a4d1707e 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/update_description.rst b/docs/source/usage/configuration/update_description.rst new file mode 100644 index 000000000..22996238e --- /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 -- GitLab From 91f7522c781c31361a4d2b198044a3a031c8097f Mon Sep 17 00:00:00 2001 From: Wilmer Uruchi Ticona Date: Thu, 29 Apr 2021 13:10:20 +0200 Subject: [PATCH 2/2] Added documentation to #688 --- docs/source/usage.rst | 8 ++++---- docs/source/usage/configuration/index.rst | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 6a4d1707e..3b64c9b85 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -26,10 +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`) +-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 887dd60a3..692f0a9fb 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 -- GitLab