def construct_backup_variables(file_backup_folder_abs): """Construct backup variables.""" backup_variables = {} # Setting the oldest backup timestamp oldest_object_bk = utils.ask_question( 'Please provide the oldest backup timestamp ' '(e.g. 2014-07-18 13:54:53.688484+00:00): ', datetime.datetime, True) if oldest_object_bk is None: backup_variables[AbstractBackup.OLDEST_OBJECT_BK_KEY] = None else: backup_variables[AbstractBackup.OLDEST_OBJECT_BK_KEY] = str( oldest_object_bk) # Setting the backup directory backup_variables[ AbstractBackup.BACKUP_DIR_KEY] = file_backup_folder_abs # Setting the days_to_backup backup_variables[ AbstractBackup.DAYS_TO_BACKUP_KEY] = utils.ask_question( 'Please provide the number of days to backup: ', int, True) # Setting the end date end_date_of_backup_key = utils.ask_question( 'Please provide the end date of the backup (e.g. 2014-07-18 13:54:53.688484+00:00): ', datetime.datetime, True) if end_date_of_backup_key is None: backup_variables[AbstractBackup.END_DATE_OF_BACKUP_KEY] = None else: backup_variables[AbstractBackup.END_DATE_OF_BACKUP_KEY] = str( end_date_of_backup_key) # Setting the backup periodicity backup_variables[AbstractBackup.PERIODICITY_KEY] = utils.ask_question( 'Please provide the periodicity (in days): ', int, False) # Setting the backup threshold backup_variables[ AbstractBackup.BACKUP_LENGTH_THRESHOLD_KEY] = utils.ask_question( 'Please provide the backup threshold (in hours): ', int, False) return backup_variables
def test_ask_backup_question(self): """ This method checks that the combined use of query_string and query_yes_no by the ask_backup_question is done as expected. """ from aiida.common.utils import Capturing from aiida.manage.backup import backup_utils # Capture the sysout for the following code with Capturing(): # Test that a question that asks for an integer is working # The given answers are in order: # - a non-accepted empty answer # - an answer that can not be parsed based on the given type # - the final expected answer self.seq = -1 answers = ['', '3fd43', '1', 'yes'] backup_utils.input = lambda _: answers[self.array_counter()] self.assertEqual(backup_utils.ask_question('', int, False), int(answers[2])) # Test that a question that asks for a date is working correctly. # The behavior is similar to the above test. self.seq = -1 answers = ['', '3fd43', '2015-07-28 20:48:53.197537+02:00', 'yes'] backup_utils.input = lambda _: answers[self.array_counter()] self.assertEqual( backup_utils.ask_question('', datetime.datetime, False), parse(answers[2])) # Check that None is not allowed as answer question = '' answer = '' backup_utils.input = lambda x: answer if x == question else 'y' self.assertEqual(backup_utils.ask_question(question, int, True), None)