~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/db/backends/postgresql/version.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
import re
6
6
 
7
 
VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')
 
7
# This reg-exp is intentionally fairly flexible here.
 
8
# Needs to be able to handle stuff like:
 
9
#   PostgreSQL 8.3.6
 
10
#   EnterpriseDB 8.3
 
11
#   PostgreSQL 8.3 beta4
 
12
#   PostgreSQL 8.4beta1
 
13
VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)\.?(\d+)?')
 
14
 
 
15
def _parse_version(text):
 
16
    "Internal parsing method. Factored out for testing purposes."
 
17
    major, major2, minor = VERSION_RE.search(text).groups()
 
18
    try:
 
19
        return int(major), int(major2), int(minor)
 
20
    except (ValueError, TypeError):
 
21
        return int(major), int(major2), None
8
22
 
9
23
def get_version(cursor):
10
24
    """
11
 
    Returns a tuple representing the major and minor version number of the
12
 
    server. For example, (7, 4) or (8, 3).
 
25
    Returns a tuple representing the major, minor and revision number of the
 
26
    server. For example, (7, 4, 1) or (8, 3, 4). The revision number will be
 
27
    None in the case of initial releases (e.g., 'PostgreSQL 8.3') or in the
 
28
    case of beta and prereleases ('PostgreSQL 8.4beta1').
13
29
    """
14
30
    cursor.execute("SELECT version()")
15
 
    version = cursor.fetchone()[0]
16
 
    major, minor = VERSION_RE.search(version).groups()
17
 
    return int(major), int(minor)
18
 
 
 
31
    return _parse_version(cursor.fetchone()[0])