def _do_get_stat(self, rethrow=False): try: self.vfsstat = gnomevfs.get_file_info(self.uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FORCE_FAST_MIME_TYPE) if self.vfsstat.type == gnomevfs.FILE_TYPE_SYMBOLIC_LINK: try: self.target_vfsstat = gnomevfs.get_file_info(self.uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FOLLOW_LINKS) except Exception as e: _logger.debug("Failed to get file info for target of '%s'", self.uri, exc_info=True) self.target_vfsstat_error = str(e) except Exception as e: _logger.debug("Failed to get file info for '%s'", self.uri, exc_info=True) self.stat_error = str(e) if rethrow: raise FileStatError(e)
def getSize(self, path): """ @summary: Gets a tuple with size and size description with its units (bytes, Kbytes...) @param path: Path to calculate size. @return: Tuple with size and size description """ # Check if path exist if not os.path.exists(path): __log__.warning("Path does not exist. %s" % path) return (0, "") if (os.path.isdir(path)): return (0, "") try: size = long(os.path.getsize(path)) except: size = 0 sizeDescription = "" if (GNOME): # get mime mime_type = gnomevfs.get_mime_type(path) uri = "file://%s" % urllib.pathname2url(path) fileInfo = gnomevfs.get_file_info(uri) if ((fileInfo.valid_fields & gnomevfs.FILE_INFO_FIELDS_SIZE) != 0): size = fileInfo.size sizeDescription = gnomevfs.format_file_size_for_display(size) else: sizeDescription = self.__getSizeDescription__(size) return (size, sizeDescription)
def finished(self): Pipeline.finished(self) if self.aborted: # remove partial file try: gnomevfs.unlink(self.output_filename) except: pass return # Copy file permissions try: info = gnomevfs.get_file_info(self.sound_file.uri, gnomevfs.FILE_INFO_FIELDS_PERMISSIONS) gnomevfs.set_file_info(self.output_filename, info, gnomevfs.SET_FILE_INFO_PERMISSIONS) except: log('Cannot set permission on \'%s\'' % gnomevfs.format_uri_for_display(self.output_filename)) if self.delete_original and self.processing and not self.error: log('deleting: \'%s\'' % self.sound_file.uri) try: gnomevfs.unlink(self.sound_file.uri) except: log('Cannot remove \'%s\'' % gnomevfs.format_uri_for_display(self.output_filename))
def __init__(self, filename="", displayed_name="", expected_hash="", size=0): if displayed_name: self.displayed_name = displayed_name else: self.displayed_name = os.path.split(filename)[1] self.displayed_name = gnomevfs.unescape_string_for_display( self.displayed_name) self.filename = filename # the Hash loaded from file self.expected_hash = expected_hash # the Hash calculated self.real_hash = "" # the file size self.size = size self.status = HASH_NOT_CHECKED if not size: try: info = gnomevfs.get_file_info(self.filename, gnomevfs.FILE_INFO_FIELDS_SIZE) self.size = info.size except: log(_("Warning: cannot get size of file '%s'") % filename) self.size = 0
def unlink(self, uri): """Deletes the specified URI. @param uri: The URI to delete. @type uri: a gnomevfs.URI """ # Be sure the file exists then delete it if gnomevfs.exists(uri): file_info = gnomevfs.get_file_info(uri) # Double check the user wants to delete the file response = dialogs.choice_ok_cancel(fmt0001 % str(uri), True) if response == gtk.RESPONSE_OK: try: if files.is_dir(file_info): self.__remove_directory(uri) else: gnomevfs.unlink(uri) except Exception, e: dialogs.error(fmt0002 % e) self.refresh()
def vfs_walk(uri): """similar to os.path.walk, but with gnomevfs. uri -- the base folder uri. return a list of uri. """ if str(uri)[-1] != '/': uri = uri.append_string("/") info = gnomevfs.get_file_info(uri, gnomevfs.FILE_INFO_GET_MIME_TYPE) filelist = [] try: dirlist = gnomevfs.open_directory(uri) except: pass print "skipping:", uri return filelist for file_info in dirlist: if file_info.name[0] == ".": continue if file_info.type == 2: filelist.extend( vfs_walk( uri.resolve_relative(file_info.name) )) if file_info.type == 1: filelist.append( str(uri.append_string(file_info.name)) ) return filelist
def _get_file_info(self): self._open_file() # get_file_info works more reliably on remote vfs shares # than self.vfsFileHandle.get_file_info(). if self.fileInfo == None: if self.exists(): self.fileInfo = gnomevfs.get_file_info(self._URI, gnomevfs.FILE_INFO_DEFAULT)
def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files): for uri in selected_files: if gnomevfs.get_file_info(uri,gnomevfs.FILE_INFO_GET_MIME_TYPE|gnomevfs.FILE_INFO_FORCE_FAST_MIME_TYPE).mime_type=='text/x-patch': cmd = "patch -p1 --directory='%s' --input='%s' --quiet" % (inactive_cwd, urllib.unquote(uri.path)) os.system(cmd) return True
def set_repository(self, uri=None, force=False): """Sets the repository to be viewed. @param uri: The URI to set the repository to. @type uri: a gnomevfs.URI @param force: Should the repository be forced to refresh. @type force: a boolean @raise ValueError: If the URI passed does not exist, or if the URI does not point to a directory. """ # Set the URI to the user's home directory if no URI was passed if uri is None: uri = self.get_settings().get_repository() # Error if the file passed does not exist or is not a directory if not gnomevfs.exists(uri): raise ValueError, err0001 directory = gnomevfs.get_file_info(uri) if not files.is_dir(directory): raise ValueError, err0001 # Do nothing if the repository passed is the current repository and # the set was not forced if not force and str(uri) == str(self.get_repository()): return # Record what the default repository is in the settings self.get_settings().set_repository(uri) self.__tree_view.set_repository(uri)
def __stat(self, file): self.cwd = gnomevfs.URI(os.getcwd()) if str(self.cwd)[-1] != '/': self.cwd = self.cwd.append_string('/') file_uri = self.cwd.resolve_relative(file) try: file_info = gnomevfs.get_file_info(file_uri, gnomevfs.FILE_INFO_GET_MIME_TYPE) except: class file_info: name = file file_type = "" file_size = 0 mime = "" # print 'Name: ', file_info.name file_type = '(none)' try: file_type = ('unknown', 'regular', 'directory', 'fifo', 'socket', 'chardev', 'blockdev', 'symlink')[file_info.type] except: pass # print 'Type: ', file_type file_size = '(unknown)' try: file_size = file_info.size except: file_size = 0 # print 'Size: ', file_size mime_type = '(none)' try: mime_type = file_info.mime_type except: pass #print 'Mime type: ', mime_type return file_uri, file_info.name, file_type, file_size, mime_type, file_info.mtime
def set_destination_filename(self, name): # if it exists and its a directory then transfer into that dir # with the new filename if gnomevfs.exists(self._dest): info = gnomevfs.get_file_info(self._dest, gnomevfs.FILE_INFO_DEFAULT) if info.type == gnomevfs.FILE_TYPE_DIRECTORY: # append the new filename self._dest = self._dest.append_file_name(name)
def less(self, file): file = self.cwd.resolve_relative(file) file_info = gnomevfs.get_file_info(file) fp = gnomevfs.open(file, gnomevfs.OPEN_READ) less = os.popen('less -m -F -', 'w') buffer = fp.read(file_info.size) less.write(buffer) less.close()
def cd(self, dir): new_cwd = self.cwd.resolve_relative(dir) if str(new_cwd)[-1] != '/': new_cwd = new_cwd.append_string('/') if gnomevfs.get_file_info(new_cwd).type != \ gnomevfs.FILE_TYPE_DIRECTORY: raise gnomevfs.error('%s is not a directory' % dir) self.cwd = new_cwd
def display(self, desc, event): uri = desc.get_uri() if not gnomevfs.exists(uri): return file_info = gnomevfs.get_file_info(uri) is_dir = files.is_dir(file_info) icon_manager = Icons(self) if is_dir: pixbuf = icon_manager.retrieve_icon(u'stock_folder', gtk.STOCK_DIRECTORY) self.__appendMenuItem(label=menu0001, pixbuf=pixbuf, callback=lambda a: self.__set_repository(uri)) pixbuf = None else: self.__appendMenuItem(stock=gtk.STOCK_OPEN, callback=lambda a: self.__open_file(uri)) if is_dir: self.__appendSeperator() pixbuf = icon_manager.retrieve_icon(gtk.STOCK_NEW, gtk.STOCK_NEW) self.__appendMenuItem(label=menu0003, pixbuf=pixbuf, callback=lambda a: self.__create_file_in(uri)) self.__appendMenuItem(label=menu0010, pixbuf=pixbuf, callback=lambda a: self.__create_folder_in(uri)) self.__appendSeperator() pixbuf = None if gnomevfs.exists(uri) and uri.is_local: pixbuf = None if icon_manager.theme.has_icon(u'gnome-terminal'): pixbuf = icon_manager.theme.load_icon(u'gnome-terminal', 16, gtk.ICON_LOOKUP_USE_BUILTIN) self.__appendMenuItem(label=menu0011, pixbuf=pixbuf, callback=lambda a: self.__open_terminal(uri)) pixbuf = icon_manager.retrieve_icon(u'stock_open', gtk.STOCK_OPEN) self.__appendMenuItem(label=u'Browse...', pixbuf=pixbuf, callback=lambda a: self.__open_file_browser(uri)) self.__appendSeperator() self.__appendMenuItem(stock=gtk.STOCK_CUT, sensitive=False) self.__appendMenuItem(stock=gtk.STOCK_COPY, sensitive=False) if is_dir: self.__appendMenuItem(stock=gtk.STOCK_PASTE, sensitive=False) self.__appendSeperator() self.__appendMenuItem(menu0008, sensitive=False) self.__appendSeperator() self.__appendMenuItem(stock=gtk.STOCK_DELETE, callback=lambda a: self.__unlink(uri)) pixbuf = None if icon_manager.theme.has_icon(u'gconf-editor'): pixbuf = icon_manager.theme.load_icon(u'gconf-editor', 16, gtk.ICON_LOOKUP_USE_BUILTIN) self.__appendSeperator() self.__appendMenuItem(label=menu0002, pixbuf=pixbuf, callback=lambda a: self.__display_settings()) pixbuf = None icon_manager = None self.popup(None, None, None, event.button, event.time)
def get_repository(self): uri = self.get_string('repository', HOME_URI) file_info = gnomevfs.get_file_info(uri) try: if files.is_dir(file_info): file_uri = gnomevfs.URI(uri) except: file_uri = files.get_user_home_uri() return file_uri
def __do_update_async(self, url, cb): results = (None, None) uri = gnomevfs.URI(url) try: vfsstat = gnomevfs.get_file_info(uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FOLLOW_LINKS) except gnomevfs.NotFoundError, e: _logger.debug("No file info for target of '%s'", url) gobject.idle_add(cb, results) return
def add_file(self, filename, displayed_name="", hash=""): info = gnomevfs.get_file_info(filename, gnomevfs.FILE_INFO_FIELDS_SIZE) if info.type == gnomevfs.FILE_TYPE_REGULAR: self.files.append(File(filename, displayed_name, hash)) elif info.type == gnomevfs.FILE_TYPE_DIRECTORY: self.add_folder(filename) else: log("error when tring to add: '%s'" % filename)
def get_size_in_bytes(self): # gst.QUERY_SIZE doesn't work reliably until we have ran the # pipeline for a while. Thus we look at the size in a different # way. uri = self.get_input_uri() try: info = gnomevfs.get_file_info(uri) return info.size except gnomevfs.NotFoundError: return 0
def add_file(self, filename, displayed_name=None, hash=None): info = gnomevfs.get_file_info(filename, gnomevfs.FILE_INFO_FIELDS_SIZE) if info.type == gnomevfs.FILE_TYPE_REGULAR: self.files.append(File(filename, displayed_name, hash)) elif info.type == gnomevfs.FILE_TYPE_DIRECTORY: self.add_folder(filename) else: log("error when trying to add: '%s'" % filename)
def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files): for uri in selected_files: if gnomevfs.get_file_info( uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FORCE_FAST_MIME_TYPE ).mime_type == 'text/x-patch': cmd = "patch -p1 --directory='%s' --input='%s' --quiet" % ( inactive_cwd, urllib.unquote(uri.path)) os.system(cmd) return True
def edit_file_name(self, widget, path, new_text): current_dir = self.flist.get_current_dir() #root_iter = self.treestore.get_iter_first() file_iter = self.treestore.get_iter_from_string(path) tuple_path = self.treestore.get_path(file_iter) old_file_name = self.treestore.get_value(file_iter, 1) file_dir = current_dir # for i in tuple_path[1:-1]: # root_iter = self.treestore.iter_nth_child(root_iter, i) # file_dir += '/' + self.treestore.get_value(root_iter, 1) for i in range(1, len(tuple_path)): dir_iter = self.treestore.get_iter(tuple_path[0:i]) file_dir = os.path.join(file_dir, self.treestore.get_value(dir_iter, 1)) if new_text != old_file_name: old_file_uri = os.path.join(file_dir, old_file_name) new_file_uri = os.path.join(file_dir, new_text) if gnomevfs.exists(new_file_uri): secondary_text = _("A file with the same name already exists. Please use a different name.") main_text = _("<b>File already exists.</b>") error = ErrorDialog(main_text, secondary_text) error_return = error.run() if error_return == gtk.RESPONSE_DELETE_EVENT: error.destroy() return elif error_return == 1: error.destroy() return old_file_info = gnomevfs.get_file_info(old_file_uri) old_file_info.name = new_text gnomevfs.set_file_info(old_file_uri, old_file_info, gnomevfs.SET_FILE_INFO_NAME) self.treestore.set_value(file_iter, 1, new_text) self.refresh() # Search for the row of the renamed file and select it def search_new_file(model, path, iter, new_text): file_name = model.get_value(iter, 1) if file_name == new_text: selection = self.treeview.get_selection() selection.select_iter(iter) return True self.treestore.foreach(search_new_file, new_text)
def __init__(self, path, name=None): import gnomevfs if not os.path.exists(path): self.path = '/' else: self.path = os.path.abspath(path) if name is None: fileInfo = gnomevfs.get_file_info(self.path) name = fileInfo.name self.filename = name self.iconNames = ['gnome-fs-directory'] self._cachedFiles = None
def _do_get_stat(self, rethrow=False): try: self.vfsstat = gnomevfs.get_file_info( self.uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FORCE_FAST_MIME_TYPE) if self.vfsstat.type == gnomevfs.FILE_TYPE_SYMBOLIC_LINK: try: self.target_vfsstat = gnomevfs.get_file_info( self.uri, gnomevfs.FILE_INFO_GET_MIME_TYPE | gnomevfs.FILE_INFO_FOLLOW_LINKS) except Exception, e: _logger.debug("Failed to get file info for target of '%s'", self.uri, exc_info=True) self.target_vfsstat_error = str(e) except Exception, e: _logger.debug("Failed to get file info for '%s'", self.uri, exc_info=True) self.stat_error = str(e) if rethrow: raise FileStatError(e)
def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files): parent_dir = string.split(active_cwd, os.sep)[-1] if parent_dir == '': parent_dir = 'root' f_md5sum = file(inactive_cwd + os.sep + parent_dir + '.md5sum', 'w') for uri in selected_files: if gnomevfs.get_file_info(uri).type == gnomevfs.FILE_TYPE_REGULAR: f = file(active_cwd + os.sep + uri.short_name, 'rb') file_content = f.read() f.close() md5sum = hashlib.md5(file_content).hexdigest() f_md5sum.write('%s %s\n' % (md5sum, uri.short_name)) f_md5sum.close() return True
def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files): parent_dir = string.split(active_cwd, os.sep)[-1] if parent_dir=='': parent_dir = 'root' f_md5sum = file(inactive_cwd+os.sep+parent_dir+'.md5sum', 'w') for uri in selected_files: if gnomevfs.get_file_info(uri).type==gnomevfs.FILE_TYPE_REGULAR: f = file(active_cwd+os.sep+uri.short_name, 'rb') file_content = f.read() f.close() md5sum = hashlib.md5(file_content).hexdigest() f_md5sum.write('%s %s\n' % (md5sum, uri.short_name)) f_md5sum.close() return True
def main(main_wnd_xid, active_cwd, inactive_cwd, selected_files): parent_dir = string.split(active_cwd, os.sep)[-1] if parent_dir == "": parent_dir = "root" f_sha1sum = file(inactive_cwd + os.sep + parent_dir + ".sha1sum", "w") for uri in selected_files: if gnomevfs.get_file_info(uri).type == gnomevfs.FILE_TYPE_REGULAR: f = file(active_cwd + os.sep + uri.short_name, "rb") file_content = f.read() f.close() sha1sum = hashlib.sha1(file_content).hexdigest() f_sha1sum.write("%s %s\n" % (sha1sum, uri.short_name)) f_sha1sum.close() return True
def drag_data_received(self, widget, context, x, y, selection, mime_id, time): if mime_id >= 0 and mime_id < len(self.drop_mime_types): mime_type = self.drop_mime_types[mime_id] if mime_type == "text/uri-list": for uri in selection.data.split("\n"): uri = uri.strip() if uri: info = gnomevfs.get_file_info(uri, gnomevfs.FILE_INFO_DEFAULT) if info.type == gnomevfs.FILE_TYPE_DIRECTORY: self.add_folder(uri) else: self.add_file(SoundFile(uri)) context.finish(True, False, time)
def __init__(self, path): gobject.GObject.__init__(self) if os.path.isabs(path): self.path = "file://" + path else: self.path = path try: self.type = gnomevfs.get_file_info(path).type except gnomevfs.Error: self.type = gnomevfs.MONITOR_FILE self.monitor = None self.pending_timeouts = {}
def __init__(self, path, name=None): import gnomevfs if not os.path.exists(path): self.path = '/' if not os.path.isdir(path): raise NotDirectoryError() else: self.path = os.path.abspath(path) if name is None: fileInfo = gnomevfs.get_file_info(self.path) name = fileInfo.name self.filename = name self.iconNames = ['gnome-fs-directory'] self._cachedFiles = None
def get_file_pixbuf(self, url, tam=48): mime = gnomevfs.get_mime_type(url) try: info = gnomevfs.get_file_info(url) icon_type, result = gnome.ui.icon_lookup(self.iconTheme, self.thumbFactory, url, "", self.icon_flags, mime, info) except: print "Error loading icon" icon_type = None try: pixbuf = self.iconTheme.load_icon(icon_type, tam, 0) except: return None return pixbuf
def get_file_pixbuf(self, url, tam=48): try: mime = gnomevfs.get_mime_type(url) info = gnomevfs.get_file_info(url) icon_type, result = gnome.ui.icon_lookup(self.iconTheme, self.thumbFactory, url, "", self.icon_flags, mime, info) except: print "Error loading icon" icon_type = None try: pixbuf = self.iconTheme.load_icon(icon_type, tam, 0) except: return None return pixbuf
def finished(self): Pipeline.finished(self) # Copy file permissions try: info = gnomevfs.get_file_info(self.sound_file.uri, gnomevfs.FILE_INFO_FIELDS_PERMISSIONS) gnomevfs.set_file_info(self.output_filename, info, gnomevfs.SET_FILE_INFO_PERMISSIONS) except: log("Cannot set permission on '%s'" % gnomevfs.format_uri_for_display(self.output_filename)) if self.delete_original and self.processing and not self.error: log("deleting: '%s'" % self.sound_file.uri) try: gnomevfs.unlink(self.sound_file.uri) except: log("Cannot remove '%s'" % gnomevfs.format_uri_for_display(self.output_filename))
def get_repository(self): """Gets the default repository from GConf.""" path = os.path.join(self.base, u'repository') val = self.client.get(path) if val is not None: try: uri = gnomevfs.URI(val.get_string()) file_info = gnomevfs.get_file_info(uri) if files.is_dir(file_info): return uri except: pass return self.set_repository()
def double_click(self, widget, path, view_column): """ Show the files of a expanded folder. @param widget: Reference to the TreeView @type widget: A TreeView object. @param path: The path for the expanded folder. @type path: A tuple. @param view_column: The column in the activated row. @type view_column: A TreeViewColumn object. """ # tree_iter = self.treestore.get_iter(path) # folder_name = self.treestore.get_value(tree_iter,1) #Setting directory subfolder_dir = self.flist.get_current_dir() #if subfolder_dir == "/": # subfolder_dir = "" #Get directory from path for i in range(1, len(path)+1): subfolder = self.treestore.get_iter(path[:i]) #subfolder_dir += "/" + self.treestore.get_value(subfolder, 1) subfolder_dir = os.path.join(subfolder_dir, self.treestore.get_value(subfolder, 1)) #if subfolder_dir == "": # subfolder_dir = "/" # subfolder_name = self.__get_current_directory(subfolder_dir) file_clicked = gnomevfs.get_file_info(subfolder_dir) if file_clicked.type == gnomevfs.FILE_TYPE_DIRECTORY: self.history_back.append(self.flist.get_current_dir()) self.history_forward = [] self.button_back.set_sensitive(True) self.button_forward.set_sensitive(False) self.flist.set_current_dir(subfolder_dir) self.treestore.clear() self.__put_files(None) elif file_clicked.type == gnomevfs.FILE_TYPE_REGULAR: self.document_manager.open_tab(subfolder_dir)
def set_repository(self, uri=None, force=False): """Sets the repository to be viewed.""" # Set the URI to the user's home directory if no URI was passed if uri is None: uri = self.get_settings().get_repository() # Error if the file passed does not exist or is not a directory if not gnomevfs.exists(uri): raise ValueError, err0001 directory = gnomevfs.get_file_info(uri) if not files.is_dir(directory): raise ValueError, err0001 # Do nothing if the repository passed is the current repository and # the set was not forced if not force and str(uri) == str(self.get_repository()): return # Record what the default repository is in the settings self.get_settings().set_repository(uri) self.__tree_view.set_repository(uri)
def __get_file_info(self): try: if self.__uri.startswith("file:///"): return # TODO: self.__document.init_authentication_manager() FILE_INFO_ACCESS_RIGHTS = 1 << 4 fileinfo = get_file_info(self.__uri, FILE_INFO_DEFAULT | FILE_INFO_GET_MIME_TYPE | FILE_INFO_FORCE_SLOW_MIME_TYPE | FILE_INFO_FOLLOW_LINKS | FILE_INFO_ACCESS_RIGHTS) if not fileinfo: raise FileInfoError except AccessDeniedError: raise AccessDeniedError except NotFoundError: raise NotFoundError except: raise FileInfoError return
def finished(self): Pipeline.finished(self) # Copy file permissions try: info = gnomevfs.get_file_info( self.sound_file.uri, gnomevfs.FILE_INFO_FIELDS_PERMISSIONS) gnomevfs.set_file_info(self.output_filename, info, gnomevfs.SET_FILE_INFO_PERMISSIONS) except: log('Cannot set permission on \'%s\'' % gnomevfs.format_uri_for_display(self.output_filename)) if self.delete_original and self.processing and not self.error: log('deleting: \'%s\'' % self.sound_file.uri) try: vfs_unlink(self.sound_file.uri) except: log('Cannot remove \'%s\'' % gnomevfs.format_uri_for_display(self.output_filename))
def __init__(self, filename="", displayed_name="", expected_hash="", size=0): if displayed_name: self.displayed_name=displayed_name else: self.displayed_name=filename self.filename=filename # the Hash loaded from file self.expected_hash=expected_hash # the Hash calculated self.real_hash="" # the file size self.size=size self.status=HASH_NOT_CHECKED if not size: try: info = gnomevfs.get_file_info(self.filename, gnomevfs.FILE_INFO_FIELDS_SIZE) self.size = info.size except: log(_("Warning: cannot get size of file '%s'") % filename) self.size = 0;
def __stat(self, file): self.cwd = gnomevfs.URI(os.getcwd()) if str(self.cwd)[-1] != '/': self.cwd = self.cwd.append_string('/') file_uri = self.cwd.resolve_relative(file) try: file_info = gnomevfs.get_file_info( file_uri, gnomevfs.FILE_INFO_GET_MIME_TYPE) except: class file_info: name = file file_type = "" file_size = 0 mime = "" # print 'Name: ', file_info.name file_type = '(none)' try: file_type = ('unknown', 'regular', 'directory', 'fifo', 'socket', 'chardev', 'blockdev', 'symlink')[file_info.type] except: pass # print 'Type: ', file_type file_size = '(unknown)' try: file_size = file_info.size except: file_size = 0 # print 'Size: ', file_size mime_type = '(none)' try: mime_type = file_info.mime_type except: pass #print 'Mime type: ', mime_type return file_uri, file_info.name, file_type, file_size, mime_type
def load_tree(self, target): """ Loads the tree information from the target backup directory """ self.treestore.clear() # Checking if the target directory is local or remote local = True try: if gnomevfs.URI(target).is_local: target = gnomevfs.get_local_path_from_uri(target) else: local = False except: pass self.local = local self.target = target # Checking if it is a readable directory if local: if not (os.path.exists(target) and os.path.isdir(target) and os.access(target, os.R_OK | os.X_OK)): self.treestore.append( None, ["Error: backups directory does not exist!"]) self.target = False else: if not (gnomevfs.exists(target) and gnomevfs.get_file_info(target).type == 2): self.treestore.append( None, ["Error: backups directory does not exist!"]) self.target = False # Get list of backup directories r = re.compile( r"^(\d{4})-(\d{2})-(\d{2})_(\d{2})[\:\.](\d{2})[\:\.](\d{2})\.\d+\..*?\.(.+)$" ) listing = [] if local and self.target: listing = os.listdir(target) listing = filter(r.search, listing) elif self.target: try: d = gnomevfs.open_directory(target) listing = [] for f in d: if f.type == 2 and f.name != "." and f.name != ".." and r.search( f.name): listing.append(f.name) except: pass # Check if these directories are complete and remove from the list those that are not for adir in listing[:]: if not gnomevfs.exists(self.target + "/" + adir + "/ver"): listing.remove(adir) continue else: if str( gnomevfs.read_entire_file(self.target + "/" + adir + "/ver"))[:3] != "1.4": listing.remove(adir) continue listing.sort() listing.reverse() self.vtree = {} if listing == []: self.treestore.append( None, ["Error: no backups found in the target directory"]) self.target = False else: for base in listing: if str(gnomevfs.read_entire_file(target + "/" + base + "/ver"))[:3] == "1.4": self.vtree[base] = str( gnomevfs.read_entire_file(target + "/" + base + "/flist")).split("\000") else: self.vtree[base] = str( gnomevfs.read_entire_file(target + "/" + base + "/flist")).split("\n") self.blist.clear() for base in listing: self.blist.append([base]) self.good = False self.on_selection_change() if self.target: self.treestore.append(None, [ "Select any of the available backups to see list of files that can be restored." ])