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

« back to all changes in this revision

Viewing changes to ubuntuone/platform/__init__.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
# -*- encoding: utf-8 -*-
 
2
#
 
3
# Copyright 2009-2011 Canonical Ltd.
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
#
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
# PURPOSE.  See the GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along
 
15
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
"""Platform specific bindings."""
 
18
 
 
19
import os
1
20
import sys
2
21
 
 
22
from ubuntu_sso.xdg_base_directory import xdg_home
 
23
 
3
24
# very hackish way to avoid "import *" to satisfy pyflakes
4
25
# and to avoid import ubuntuone.platform.X as source (it wont work)
5
26
 
11
32
    source = linux
12
33
 
13
34
from ubuntuone.platform import credentials
14
 
 
15
 
target = sys.modules[__name__]
16
 
for k in dir(source):
17
 
    setattr(target, k, getattr(source, k))
 
35
from ubuntuone.platform import tools
 
36
 
 
37
 
 
38
def expand_user(path):
 
39
    """Fix Python expanduser for weird chars in windows."""
 
40
    # Receives bytes, returns unicode
 
41
    assert isinstance(path, str)
 
42
    try:
 
43
        path.decode('utf-8')
 
44
    except UnicodeDecodeError:
 
45
        raise AssertionError('The path %r must be encoded in utf-8' % path)
 
46
    tilde = '~'
 
47
    if not path.startswith(tilde) or \
 
48
    (len(path) > 1 and path[1:2] != os.path.sep):
 
49
        return path
 
50
    result = path.replace('~', xdg_home, 1)
 
51
 
 
52
    assert isinstance(result, str)
 
53
    try:
 
54
        result.decode('utf-8')
 
55
    except UnicodeDecodeError:
 
56
        raise AssertionError('The path %r must be encoded in utf-8' % result)
 
57
    return result
 
58
 
 
59
 
 
60
platform = source.platform
 
61
access = source.access
 
62
allow_writes = source.allow_writes
 
63
can_write = source.can_write
 
64
get_path_list = source.get_path_list
 
65
is_link = source.is_link
 
66
is_root = source.is_root
 
67
listdir = source.listdir
 
68
make_dir = source.make_dir
 
69
make_link = source.make_link
 
70
move_to_trash = source.move_to_trash
 
71
native_rename = source.native_rename
 
72
normpath = source.normpath
 
73
open_file = source.open_file
 
74
path_exists = source.path_exists
 
75
read_link = source.read_link
 
76
recursive_move = source.recursive_move
 
77
remove_dir = source.remove_dir
 
78
remove_file = source.remove_file
 
79
remove_link = source.remove_link
 
80
remove_tree = source.remove_tree
 
81
rename = source.rename
 
82
set_application_name = source.set_application_name
 
83
set_dir_readonly = source.set_dir_readonly
 
84
set_dir_readwrite = source.set_dir_readwrite
 
85
set_file_readonly = source.set_file_readonly
 
86
set_file_readwrite = source.set_file_readwrite
 
87
set_no_rights = source.set_no_rights
 
88
stat_path = source.stat_path
 
89
walk = source.walk
 
90
 
 
91
# From Logger
 
92
setup_filesystem_logging = source.setup_filesystem_logging
 
93
get_filesystem_logger = source.get_filesystem_logger
 
94
 
 
95
# From File System Notifications
 
96
FilesystemMonitor = source.FilesystemMonitor
 
97
_GeneralINotifyProcessor = source._GeneralINotifyProcessor
 
98
 
 
99
# IPC
 
100
ExternalInterface = source.ExternalInterface
 
101
is_already_running = source.is_already_running