~abompard/mailman/import21

« back to all changes in this revision

Viewing changes to src/mailman/database/schema/helpers.py

  • Committer: Aurélien Bompard
  • Date: 2014-01-27 10:58:16 UTC
  • mfrom: (7215.2.17 3.0)
  • Revision ID: aurelien@bompard.org-20140127105816-xptlvnpr3ixak5d2
Merge from the main branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2013-2014 by the Free Software Foundation, Inc.
 
2
#
 
3
# This file is part of GNU Mailman.
 
4
#
 
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
 
6
# the terms of the GNU General Public License as published by the Free
 
7
# Software Foundation, either version 3 of the License, or (at your option)
 
8
# any later version.
 
9
#
 
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
 
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
13
# more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License along with
 
16
# GNU Mailman.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
"""Schema migration helpers."""
 
19
 
 
20
from __future__ import absolute_import, print_function, unicode_literals
 
21
 
 
22
__metaclass__ = type
 
23
__all__ = [
 
24
    'make_listid',
 
25
    ]
 
26
 
 
27
 
 
28
 
 
29
def make_listid(fqdn_listname):
 
30
    """Turn a FQDN list name into a List-ID."""
 
31
    list_name, at, mail_host = fqdn_listname.partition('@')
 
32
    if at == '':
 
33
        # If there is no @ sign in the value, assume it already contains the
 
34
        # list-id.
 
35
        return fqdn_listname
 
36
    return '{0}.{1}'.format(list_name, mail_host)
 
37
 
 
38
 
 
39
 
 
40
def pivot(store, table_name):
 
41
    """Pivot a backup table into the real table name."""
 
42
    store.execute('DROP TABLE {}'.format(table_name))
 
43
    store.execute('ALTER TABLE {0}_backup RENAME TO {0}'.format(table_name))