~launchpad-results/launchpad-results/trunk

« back to all changes in this revision

Viewing changes to lib/lpresults/tracker/management/commands/syncdb.py

  • Committer: Marc Tardif
  • Date: 2012-04-03 02:21:47 UTC
  • Revision ID: marc.tardif@canonical.com-20120403022147-70m3lz8xe4cq192y
Fixed Makefile for syncdb target.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
import transaction
11
11
 
 
12
from getpass import getuser
12
13
from optparse import make_option
13
14
 
14
15
from subprocess import (
49
50
        Open a connection as the postgres user and execute query,
50
51
        returning the result for further processing.
51
52
        """
52
 
        popen = Popen([
53
 
            "sudo", "-u", dbadmin, "-s", "/usr/bin/psql",
54
 
            "--tuples-only", "--no-align", "--field-separator=','"],
55
 
            stdin=PIPE, stdout=PIPE)
 
53
        args = [
 
54
            "/usr/bin/psql", "--tuples-only", "--no-align",
 
55
            "--field-separator=','"]
 
56
 
 
57
        if getuser() != dbadmin:
 
58
            args[:0] = ["sudo", "-u", dbadmin, "-s"]
 
59
 
 
60
        popen = Popen(args, stdin=PIPE, stdout=PIPE)
56
61
        output, errors = popen.communicate(query)
57
62
        return output.strip()
58
63