~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise

« back to all changes in this revision

Viewing changes to ubuntuone/syncdaemon/config.py

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2011-12-21 15:46:25 UTC
  • mfrom: (1.1.56)
  • Revision ID: package-import@ubuntu.com-20111221154625-ujvunri4frsecj2k
Tags: 2.99.0-0ubuntu1
* New upstream release.
  - Verify timestamp to avoid invalid auth failures (LP: #692597)
  - Files in new UDFs not uploaded due to filtering (LP: #869920)
* debian/patches:
  - Remove upstreamed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# ubuntuone.syncdaemon.config - SyncDaemon config utilities
2
2
#
3
 
# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
4
 
#
5
 
# Copyright 2009 Canonical Ltd.
 
3
# Copyright 2009-2011 Canonical Ltd.
6
4
#
7
5
# This program is free software: you can redistribute it and/or modify it
8
6
# under the terms of the GNU General Public License version 3, as published
25
23
 
26
24
from ConfigParser import NoOptionError, NoSectionError
27
25
from optparse import OptionParser
28
 
from ubuntuone.platform import path_exists, rename
29
26
from ubuntu_sso.xdg_base_directory import (
30
27
    load_config_paths,
 
28
    native_path,
31
29
    save_config_path,
32
30
    xdg_data_home,
33
31
    xdg_cache_home,
34
32
)
35
33
 
 
34
from ubuntuone.platform import expand_user
 
35
 
36
36
# the try/except is to work with older versions of configglue (that
37
37
# had everything that is now configglue.inischema.* as configglue.*).
38
38
# The naming shenanigans are to work around pyflakes being completely
70
70
logger = logging.getLogger('ubuntuone.SyncDaemon.config')
71
71
 
72
72
# get (and possibly create if don't exists) the user config file
73
 
_user_config_path = os.path.join(save_config_path('ubuntuone'), CONFIG_FILE)
 
73
_user_config_path = os.path.join(native_path(save_config_path('ubuntuone')),
 
74
                                 CONFIG_FILE)
74
75
 
75
76
# module private config instance.
76
77
# this object is the shared config
85
86
    Return the path using user home + value.
86
87
 
87
88
    """
88
 
    result = os.path.expanduser(path_from_unix(value))
 
89
    path = path_from_unix(value)
 
90
    result = expand_user(path)
89
91
    assert isinstance(result, str)
90
92
    return result
91
93
 
151
153
    """
152
154
    config_files = []
153
155
    for xdg_config_dir in load_config_paths('ubuntuone'):
 
156
        xdg_config_dir = native_path(xdg_config_dir)
154
157
        config_file = os.path.join(xdg_config_dir, CONFIG_FILE)
155
 
        if path_exists(config_file):
 
158
        if os.path.exists(config_file):
156
159
            config_files.append(config_file)
157
160
 
158
161
        config_logs = os.path.join(xdg_config_dir, CONFIG_LOGS)
159
 
        if path_exists(config_logs):
 
162
        if os.path.exists(config_logs):
160
163
            config_files.append(config_logs)
161
164
 
162
165
    # reverse the list as load_config_paths returns the user dir first
164
167
    # if we are running from a branch, get the config files from it too
165
168
    config_file = os.path.join(os.path.dirname(__file__), os.path.pardir,
166
169
                               os.path.pardir, 'data', CONFIG_FILE)
167
 
    if path_exists(config_file):
 
170
    if os.path.exists(config_file):
168
171
        config_files.append(config_file)
169
172
 
170
173
    config_logs = os.path.join('data', CONFIG_LOGS)
171
 
    if path_exists(config_logs):
 
174
    if os.path.exists(config_logs):
172
175
        config_files.append(config_logs)
173
176
 
174
177
    return config_files
287
290
 
288
291
    def save(self):
289
292
        """Save the config object to disk"""
 
293
        # We should not use standard functions from os_helper here,
 
294
        # because the configglue superclasses do not use them.
 
295
        # Instead, all paths used in this module should be "native",
 
296
        # that is: utf-8 str on linux, or (unicode or mbcs str) on windows
 
297
        from ubuntuone.platform import native_rename
 
298
 
290
299
        # cleanup empty sections
291
300
        for section in [MAIN, THROTTLING, NOTIFICATIONS]:
292
301
            if self.has_section(section) and not self.options(section):
293
302
                self.remove_section(section)
294
303
        with open(self.config_file + '.new', 'w') as fp:
295
304
            self.write(fp)
296
 
        if path_exists(self.config_file):
297
 
            rename(self.config_file, self.config_file + '.old')
298
 
        rename(self.config_file + '.new', self.config_file)
 
305
        if os.path.exists(self.config_file):
 
306
            native_rename(self.config_file, self.config_file + '.old')
 
307
        native_rename(self.config_file + '.new', self.config_file)
299
308
 
300
309
    def get_parsed(self, section, option):
301
310
        """get that fallbacks to our custom defaults"""
419
428
        return self.get_parsed(NOTIFICATIONS, 'show_all_notifications')
420
429
 
421
430
 
422
 
 
423
431
def configglue(fileobj, *filenames, **kwargs):
424
432
    """Populate an OptionParser with options and defaults taken from a
425
433
    series of files.
426
434
 
427
435
    @param fileobj: An INI file, as a file-like object.
428
436
    @param filenames: An optional series of filenames to merge.
429
 
    @param kwargs: options passed on to the OptionParser constructor except for:
 
437
    @param kwargs: options passed on to the OptionParser constructor except for
430
438
    @param args: parse these args (defaults to sys.argv[1:])
431
439
    """
432
440
    cp = SyncDaemonConfigParser()
474
482
    config = get_user_config(config_files=config_files)
475
483
    config.override_options(overridden)
476
484
    return op, options, args
477