~excitablesnowball/duplicity/s3-onezone-ia

« back to all changes in this revision

Viewing changes to duplicity/backends/giobackend.py

  • Committer: kenneth at loafman
  • Date: 2017-12-20 13:03:42 UTC
  • Revision ID: kenneth@loafman.com-20171220130342-rzlfz5qrf6rp6xui
* Fixes so pylint 1.8.1 does not complain about missing conditional imports.
  - Fix dpbxbackend so that imports require instantiation of the class.
  - Added pylint: disable=import-error to a couple of conditional imports

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# along with duplicity; if not, write to the Free Software Foundation,
19
19
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
20
 
21
 
# pylint: skip-file
22
 
 
23
21
import os
24
22
import subprocess
25
23
import atexit
51
49
       URLs look like schema://user@server/path.
52
50
    """
53
51
    def __init__(self, parsed_url):
54
 
        from gi.repository import Gio  # @UnresolvedImport
55
 
        from gi.repository import GLib  # @UnresolvedImport
 
52
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
 
53
        from gi.repository import GLib  # @UnresolvedImport  # pylint: disable=import-error
56
54
 
57
55
        class DupMountOperation(Gio.MountOperation):
58
56
            """A simple MountOperation that grabs the password from the environment
100
98
                raise
101
99
 
102
100
    def __done_with_mount(self, fileobj, result, loop):
103
 
        from gi.repository import Gio  # @UnresolvedImport
104
 
        from gi.repository import GLib  # @UnresolvedImport
 
101
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
 
102
        from gi.repository import GLib  # @UnresolvedImport  # pylint: disable=import-error
105
103
        try:
106
104
            fileobj.mount_enclosing_volume_finish(result)
107
105
        except GLib.GError as e:
115
113
        pass
116
114
 
117
115
    def __copy_file(self, source, target):
118
 
        from gi.repository import Gio  # @UnresolvedImport
 
116
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
119
117
        # Don't pass NOFOLLOW_SYMLINKS here. Some backends (e.g. google-drive:)
120
118
        # use symlinks internally for all files. In the normal course of
121
119
        # events, we never deal with symlinks anyway, just tarballs.
124
122
                    None, self.__copy_progress, None)
125
123
 
126
124
    def _error_code(self, operation, e):
127
 
        from gi.repository import Gio  # @UnresolvedImport
128
 
        from gi.repository import GLib  # @UnresolvedImport
 
125
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
 
126
        from gi.repository import GLib  # @UnresolvedImport  # pylint: disable=import-error
129
127
        if isinstance(e, GLib.GError):
130
128
            if e.code == Gio.IOErrorEnum.FAILED and operation == 'delete':
131
129
                # Sometimes delete will return a generic failure on a file not
139
137
                return log.ErrorCode.backend_no_space
140
138
 
141
139
    def _put(self, source_path, remote_filename):
142
 
        from gi.repository import Gio  # @UnresolvedImport
 
140
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
143
141
        source_file = Gio.File.new_for_path(source_path.name)
144
142
        target_file = self.remote_file.get_child_for_display_name(remote_filename)
145
143
        self.__copy_file(source_file, target_file)
146
144
 
147
145
    def _get(self, filename, local_path):
148
 
        from gi.repository import Gio  # @UnresolvedImport
 
146
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
149
147
        source_file = self.remote_file.get_child_for_display_name(filename)
150
148
        target_file = Gio.File.new_for_path(local_path.name)
151
149
        self.__copy_file(source_file, target_file)
152
150
 
153
151
    def _list(self):
154
 
        from gi.repository import Gio  # @UnresolvedImport
 
152
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
155
153
        files = []
156
154
        # We grab display name, rather than file name because some backends
157
155
        # (e.g. google-drive:) use filesystem-specific IDs as file names and
171
169
        target_file.delete(None)
172
170
 
173
171
    def _query(self, filename):
174
 
        from gi.repository import Gio  # @UnresolvedImport
 
172
        from gi.repository import Gio  # @UnresolvedImport  # pylint: disable=import-error
175
173
        target_file = self.remote_file.get_child_for_display_name(filename)
176
174
        info = target_file.query_info(Gio.FILE_ATTRIBUTE_STANDARD_SIZE,
177
175
                                      Gio.FileQueryInfoFlags.NONE, None)