Ejemplo n.º 1
0
    def delete(self, args):
        """Remove a given key for a given subject.

        Arguments:
            subject     -- Name of the subject this entry applies to
            bitness     -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit)
            key         -- Key to delete
        """
        checks.chk_arg_count(args, 3)
        subject, bitness, key = args
        subject = checks.chk_subject(subject)
        bitness = checks.chk_bitness(bitness)
        key = checks.chk_grubkey(key)
        self.cursor.execute('''
                SELECT subject_id FROM subject
                WHERE subject_name=? AND is_64bit=?''',
                (subject, bitness))
        row = self.cursor.fetchone()
        if row == None:
            raise ValueError('No such test subject.')
        subjectid = row[0]
        self.cursor.execute('''
                SELECT completion_id FROM completion
                WHERE subject_id=? AND key=?''',
                (subjectid, key))
        result = self.cursor.fetchall()
        if result != None:
            self.cursor.execute('''
                    DELETE FROM completion
                    WHERE subject_id=? AND key=?''',
                    (subjectid, key))
            self.connection.commit()
Ejemplo n.º 2
0
    def add(self, args):
        """Add a completion for given subject.

        Arguments:
            subject     -- Name of the test subject this entry applies to
            bitness     -- Bitness of the test subject (0 = 32-bit, 1 = 64-bit)
            key         -- String that is present in the template
            value       -- Substitution for key
        """
        checks.chk_arg_count(args, 4)
        subject, bitness, key, value = args
        subject = checks.chk_subject(subject)
        bitness = checks.chk_bitness(bitness)
        key = checks.chk_grubkey(key)
        value = checks.grubvalues[key](value)
        self.cursor.execute('''
                SELECT subject_id FROM subject
                WHERE subject_name=? AND is_64bit=?''',
                (subject, bitness))
        row = self.cursor.fetchone()
        if row == None:
            raise ValueError('No such test subject.')
        subjectid = row[0]
        self.cursor.execute('''
                SELECT key, value FROM completion
                WHERE subject_id=? AND key=?''', (subjectid, key))
        if self.cursor.fetchone() != None:
            self.cursor.execute('''
                    UPDATE completion SET value=?
                    WHERE subject_id=? AND key=?''',
                    (value, subjectid, key))
            sys.stderr.write(
                    ('Key "%s" already existed for subject "%s".\n' +
                    'The key got updated with the new value.\n') %
                    (key, subject))
        else:
            self.cursor.execute('''
                    INSERT INTO completion(subject_id, key, value)
                    VALUES (?,?,?)''',
                    (subjectid, key, value))
        self.connection.commit()