Exemplo n.º 1
0
    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.utils.capturing import Capturing

        # 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"]
            utils.raw_input = lambda _: answers[self.array_counter()]
            self.assertEqual(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"]
            utils.raw_input = lambda _: answers[self.array_counter()]
            self.assertEqual(utils.ask_question("", datetime.datetime, False),
                             parse(answers[2]))

            # Check that None is not allowed as answer
            question = ""
            answer = ""
            utils.raw_input = lambda x: answer if x == question else "y"
            self.assertEqual(utils.ask_question(question, int, True), None)
Exemplo n.º 2
0
    def construct_backup_variables(self, file_backup_folder_abs):
        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[Backup._oldest_object_bk_key] = None
        else:
            backup_variables[Backup._oldest_object_bk_key] = str(
                oldest_object_bk)

        # Setting the backup directory
        backup_variables[Backup._backup_dir_key] = file_backup_folder_abs

        # Setting the days_to_backup
        backup_variables[
            Backup._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[Backup._end_date_of_backup_key] = None
        else:
            backup_variables[
                Backup._end_date_of_backup_key] = str(end_date_of_backup_key)

        # Setting the backup periodicity
        backup_variables[
            Backup._periodicity_key] = utils.ask_question(
            "Please periodicity (in days).", int, False)

        # Setting the backup threshold
        backup_variables[
            Backup._backup_length_threshold_key] = utils.ask_question(
            "Please provide the backup threshold (in hours).", int, False)

        return backup_variables
Exemplo n.º 3
0
    def construct_backup_variables(self, file_backup_folder_abs):
        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 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