From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SddSi-0008W4-5w for garchives@archives.gentoo.org; Sun, 10 Jun 2012 08:25:28 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3AC4FE0028; Sun, 10 Jun 2012 08:25:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E4B57E0028 for ; Sun, 10 Jun 2012 08:25:20 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4CE151B408A for ; Sun, 10 Jun 2012 08:25:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 4BE58E542E for ; Sun, 10 Jun 2012 08:25:18 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1339316699.2b47483b406a40974f7e2ce4df4163dd08e657d2.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/cache/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/cache/sqlite.py X-VCS-Directories: pym/portage/cache/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 2b47483b406a40974f7e2ce4df4163dd08e657d2 X-VCS-Branch: master Date: Sun, 10 Jun 2012 08:25:18 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 7a1e518e-c006-41f3-8d6f-83ff67e0f39d X-Archives-Hash: d1701a3f4af053a90ef5ac5eebf7b6c0 commit: 2b47483b406a40974f7e2ce4df4163dd08e657d2 Author: Zac Medico gentoo org> AuthorDate: Sun Jun 10 08:24:59 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Jun 10 08:24:59 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D2b47483b cache/sqlite.py: dynamically add columns to table --- pym/portage/cache/sqlite.py | 42 +++++++++++++++++++++++++++++++++++++= +++-- 1 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index fcc62ff..7ca5a03 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -1,6 +1,7 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 +import re import sys from portage.cache import fs_template from portage.cache import cache_errors @@ -117,7 +118,13 @@ class database(fs_template.FsBased): for k, v in self._db_table.items(): if self._db_table_exists(v["table_name"]): create_statement =3D self._db_table_get_create(v["table_name"]) - if create_statement !=3D v["create"]: + table_ok, missing_keys =3D self._db_validate_create_statement(create= _statement) + if table_ok: + if missing_keys: + for k in sorted(missing_keys): + cursor.execute("ALTER TABLE %s ADD COLUMN %s TEXT" % + (self._db_table["packages"]["table_name"], k)) + else: writemsg(_("sqlite: dropping old table: %s\n") % v["table_name"]) cursor.execute("DROP TABLE %s" % v["table_name"]) cursor.execute(v["create"]) @@ -138,6 +145,37 @@ class database(fs_template.FsBased): self._db_escape_string(table_name)) return cursor.fetchall()[0][0] =20 + def _db_validate_create_statement(self, statement): + missing_keys =3D None + if statement =3D=3D self._db_table["packages"]["create"]: + return True, missing_keys + + m =3D re.match(r'^\s*CREATE\s*TABLE\s*%s\s*\(\s*%s\s*INTEGER\s*PRIMARY= \s*KEY\s*AUTOINCREMENT\s*,(.*)\)\s*$' % + (self._db_table["packages"]["table_name"], + self._db_table["packages"]["package_id"]), + statement) + if m is None: + return False, missing_keys + + unique_constraints =3D set([self._db_table["packages"]["package_key"]]= ) + missing_keys =3D set(self._allowed_keys) + unique_re =3D re.compile(r'^UNIQUE\s*\(\s*(\w*)\s*\)\s*$') + column_re =3D re.compile(r'^\s*(\w*)\s*TEXT\s*$') + for x in m.group(1).split(","): + m =3D unique_re.match(x) + if m is not None: + unique_constraints.discard(m.group(1)) + continue + m =3D column_re.match(x) + if m is not None: + missing_keys.discard(m.group(1)) + continue + + if unique_constraints: + return False, missing_keys + + return True, missing_keys + def _db_init_cache_size(self, cache_bytes): cursor =3D self._db_cursor cursor.execute("PRAGMA page_size")