Package entropy :: Package transceivers :: Package uri_handlers :: Module skel

Source Code for Module entropy.transceivers.uri_handlers.skel

  1  # -*- coding: utf-8 -*- 
  2  """ 
  3   
  4      @author: Fabio Erculiani <lxnay@sabayonlinux.org> 
  5      @contact: lxnay@sabayonlinux.org 
  6      @copyright: Fabio Erculiani 
  7      @license: GPL-2 
  8   
  9      B{Entropy Transceivers class prototypes module}. 
 10   
 11  """ 
 12  from entropy.const import const_isnumber 
 13  from entropy.output import TextInterface 
14 15 -class EntropyUriHandler(object, TextInterface):
16 17 BASE_PLUGIN_API_VERSION = 0 18 19 """ 20 Base class for EntropyTransceiver URI handler interfaces. This provides 21 a common API for implementing custom URI handlers. 22 23 To add your URI handler to EntropyTransceiver, do the following: 24 >>> EntropyTransceiver.add_uri_handler(my_entropy_transceiver_based_instance) 25 "add_uri_handler" is a EntropyTransceiver static method. 26 """
27 - def __init__(self, uri):
28 """ 29 EntropyUriHandler constructor. 30 When constructor is called, instance should perform a connection and 31 permissions check and raise entropy.exceptions.ConnectionError in case 32 of issues. 33 34 @param uri: URI to handle 35 @type uri: string 36 """ 37 object.__init__(self) 38 self._uri = uri 39 self._speed_limit = 0 40 self._verbose = False 41 self._silent = False 42 self._timeout = None
43
44 - def __enter__(self):
45 """ 46 Support for "with" statement, this will trigger UriHandler connection 47 setup. 48 """ 49 raise NotImplementedError()
50
51 - def __exit__(self, exc_type, exc_value, traceback):
52 """ 53 Support for "with" statement, this will trigger UriHandler connection 54 hang up. 55 """ 56 raise NotImplementedError()
57 58 @staticmethod
59 - def approve_uri(uri):
60 """ 61 Approve given URI by returning True or False depending if this 62 class is able to handle it. 63 64 @param uri: URI to handle 65 @type uri: string 66 @return: True, if URI can be handled by this class 67 @rtype: bool 68 """ 69 raise NotImplementedError()
70 71 @staticmethod
72 - def get_uri_name(uri):
73 """ 74 Given a valid URI (meaning that implementation can handle the provided 75 URI), it extracts and returns the URI name (hostname). 76 77 @param uri: URI to handle 78 @type uri: string 79 @return: URI name 80 @rtype: string 81 """ 82 raise NotImplementedError()
83 84 @staticmethod
85 - def hide_sensible_data(uri):
86 """ 87 Given an URI, hide sensible data from string and return it back. 88 89 @param uri: URI to handle 90 @type uri: string 91 @return: URI cleaned 92 @rtype: string 93 """ 94 raise NotImplementedError()
95
96 - def get_uri(self):
97 """ 98 Return copy of previously stored URI. 99 100 @return: stored URI 101 @rtype: string 102 """ 103 return self._uri[:]
104
105 - def set_output_interface(self, output_interface):
106 """ 107 Provide alternative Entropy output interface (must be based on 108 entropy.output.TextInterface) 109 110 @param output_interface: new entropy.output.TextInterface instance to 111 use 112 @type output_interface: entropy.output.TextInterface based instance 113 @raise AttributeError: if argument passed is not correct 114 """ 115 if not isinstance(output_interface, TextInterface): 116 raise AttributeError( 117 "expected a valid TextInterface based instance") 118 self.updateProgress = output_interface.updateProgress 119 self.askQuestion = output_interface.askQuestion
120
121 - def set_speed_limit(self, speed_limit):
122 """ 123 Set download/upload speed limit in kb/sec form. 124 125 @param speed_limit: speed limit in kb/sec form. 126 @type speed_limit: int 127 """ 128 if not const_isnumber(speed_limit): 129 raise AttributeError("not a number") 130 self._speed_limit = speed_limit
131
132 - def set_timeout(self, timeout):
133 """ 134 Set transceiver tx/rx timeout value in seconds. 135 136 @param timeout: timeout in seconds 137 @type timeout: int 138 """ 139 if not const_isnumber(timeout): 140 raise AttributeError("not a number") 141 self._timeout = timeout
142
143 - def set_silent(self, silent):
144 """ 145 Disable transceiver verbosity. 146 147 @param verbosity: verbosity value 148 @type verbosity: bool 149 """ 150 self._silent = silent
151
152 - def set_verbosity(self, verbosity):
153 """ 154 Set transceiver verbosity. 155 156 @param verbosity: verbosity value 157 @type verbosity: bool 158 """ 159 self._verbose = verbosity
160
161 - def download(self, remote_path, save_path):
162 """ 163 Download URI and save it to save_path. 164 165 @param remote_path: remote path to handle 166 @type remote_path: string 167 @param save_path: complete path where to store file from uri. 168 If directory doesn't exist, it will be created with default 169 Entropy permissions. 170 @type save_path: string 171 @return: execution status, True if done 172 @rtype: bool 173 @raise ConnectionError: if problems happen 174 """ 175 raise NotImplementedError()
176
177 - def upload(self, load_path, remote_path):
178 """ 179 Upload URI from load_path location to uri. 180 181 @param load_path: remote path to handle 182 @type load_path: string 183 @param remote_path: remote path to handle ("directory"/"file name" !) 184 @type remote_path: string 185 @return: execution status, True if done 186 @rtype: bool 187 @raise ConnectionError: if problems happen 188 """ 189 raise NotImplementedError()
190
191 - def rename(self, remote_path_old, remote_path_new):
192 """ 193 Rename URI old to URI new. 194 195 @param remote_path_old: remote path to handle 196 @type remote_path_old: string 197 @param remote_path_new: remote path to create 198 @type remote_path_new: string 199 @return: execution status, True if done 200 @rtype: bool 201 @raise ConnectionError: if problems happen 202 """ 203 raise NotImplementedError()
204
205 - def delete(self, remote_path):
206 """ 207 Remove the remote path (must be a file). 208 209 @param remote_path_old: remote path to remove (only file allowed) 210 @type remote_path_old: string 211 @return: True, if operation went successful 212 @rtype: bool 213 @return: execution status, True if done 214 @rtype: bool 215 @raise ConnectionError: if problems happen 216 """ 217 raise NotImplementedError()
218
219 - def get_md5(self, remote_path):
220 """ 221 Return MD5 checksum of file at URI. 222 223 @param remote_path: remote path to handle 224 @type remote_path: string 225 @return: MD5 checksum in hexdigest form 226 @rtype: string or None (if not supported) 227 """ 228 raise NotImplementedError()
229
230 - def list_content(self, remote_path):
231 """ 232 List content of directory referenced at URI. 233 234 @param remote_path: remote path to handle 235 @type remote_path: string 236 @return: content 237 @rtype: list 238 @raise ValueError: if remote_path does not exist 239 """ 240 raise NotImplementedError()
241
242 - def list_content_metadata(self, remote_path):
243 """ 244 List content of directory referenced at URI with metadata in this form: 245 [(name, size, owner, group, permissions<drwxr-xr-x>,), ...] 246 permissions, owner, group, size, name. 247 248 @param remote_path: remote path to handle 249 @type remote_path: string 250 @return: content 251 @rtype: list 252 @raise ValueError: if remote_path does not exist 253 """ 254 raise NotImplementedError()
255
256 - def is_path_available(self, remote_path):
257 """ 258 Given a remote path (which can point to dir or file), determine whether 259 it's available or not. 260 261 @param remote_path: URI to handle 262 @type remote_path: string 263 @return: availability 264 @rtype: bool 265 """ 266 raise NotImplementedError()
267
268 - def is_dir(self, remote_path):
269 """ 270 Given a remote path (which can point to dir or file), determine whether 271 it's a directory. 272 273 @param remote_path: URI to handle 274 @type remote_path: string 275 @return: True, if remote_path is a directory 276 @rtype: bool 277 """ 278 raise NotImplementedError()
279
280 - def is_file(self, remote_path):
281 """ 282 Given a remote path (which can point to dir or file), determine whether 283 it's a file. 284 285 @param remote_path: URI to handle 286 @type remote_path: string 287 @return: True, if remote_path is a file 288 @rtype: bool 289 """ 290 raise NotImplementedError()
291
292 - def makedirs(self, remote_path):
293 """ 294 Given a remote path, recursively create all the missing directories. 295 296 @param remote_path: URI to handle 297 @type remote_path: string 298 """ 299 raise NotImplementedError()
300
301 - def keep_alive(self):
302 """ 303 Send a keep-alive ping to handler. 304 @raise ConnectionError: if problems happen 305 """ 306 raise NotImplementedError()
307
308 - def close(self):
309 """ 310 Called when requesting to close connection completely. 311 """ 312 raise NotImplementedError()
313