~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to ubuntuone/oauthdesktop/config.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2010-06-23 23:08:15 UTC
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20100623230815-4m3ugh10u9x9xzw5
Tags: upstream-1.3.2
ImportĀ upstreamĀ versionĀ 1.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ubuntuone.oauthdesktop.config - Configuration for OAuthDesktop
2
 
#
3
 
# Author: Stuart Langridge <stuart.langridge@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
6
 
#
7
 
# This program is free software: you can redistribute it and/or modify it
8
 
# under the terms of the GNU General Public License version 3, as published
9
 
# by the Free Software Foundation.
10
 
#
11
 
# This program is distributed in the hope that it will be useful, but
12
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
 
# PURPOSE.  See the GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License along
17
 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
"Find the config file for ubuntuone-oauth-config"
19
 
import os, ConfigParser
20
 
from xdg.BaseDirectory import load_first_config
21
 
 
22
 
def get_config(use_tmpconfig=True):
23
 
    """Return a ConfigParser object from a config file.
24
 
    Config file is looked for in the source tree first and then in the
25
 
    FreeDesktop BaseDirectory folders.
26
 
    """
27
 
    # if tmpconfig exists, then we are running out of the source tree
28
 
    tmpconfig = os.path.realpath(os.path.join(
29
 
            __file__, "../../../data/oauth_urls"
30
 
            ))
31
 
    if os.path.isfile(tmpconfig) and use_tmpconfig:
32
 
        config_file = tmpconfig
33
 
    else:
34
 
        config_file = load_first_config('ubuntuone','oauth_urls')
35
 
 
36
 
    cfp = ConfigParser.ConfigParser()
37
 
    cfp.FILENAME = None
38
 
    if config_file is not None:
39
 
        try:
40
 
            cfp.read(config_file)
41
 
            cfp.FILENAME = config_file
42
 
        except ConfigParser.Error:
43
 
            cfp = ConfigParser.ConfigParser()
44
 
            cfp.FILENAME = None
45
 
    return cfp
46
 
 
47