#!/usr/bin/python
# Copyright 2010 Canonical Ltd.
#
# This file is part of desktopcouch.
#
# desktopcouch is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# desktopcouch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with desktopcouch.  If not, see <http://www.gnu.org/licenses/>.
#
# Authors: Chad Miller <chad.miller@canonical.com>

"""Return on stdout the port that the personal couchdb is listening on.
As always, success returns a zero exit code, and an exception in Python
returns an exit code of one.  On error, stderr should have information 
useful for debugging."""

import desktopcouch
import sys
import os

devnull = open(os.devnull, "w")
saved_stdout = sys.stdout
try:
    # Don't let any of our output interfere
    sys.stdout = devnull
    port = desktopcouch.find_port()
finally:
    sys.stdout = saved_stdout
    devnull.close()

print port

