def walk(model, it, last): while it: yield model[it] for x in walk(model, model.iter_children(it), last): yield x if last == None or model.get_path(it) != model.get_path(last): it = model.iter_next(it) else: it = None
def walk(model, it): while it: yield it for x in walk(model, model.iter_children(it)): yield x it = model.iter_next(it)
def local_archive_changed(chooser): model.clear() path = chooser.get_filename() widgets.get_widget('subdirectory_frame').set_sensitive(False) self.destroy_tmp() if not path: return if mime_type.get_active() == 0: type = None else: type = mime_type.get_active_text() archive_url = widgets.get_widget('archive_url') url = archive_url.get_text() if not url: url = 'http://SITE/' + os.path.basename(path) archive_url.set_text(url) start_offset = 0 if not type: if url.endswith('.package'): type = 'Autopackage' else: type = unpack.type_from_url(url) if type == 'Autopackage': # Autopackage isn't a real type. Examine the .package file # and find out what it really is. start_offset, type = autopackage_get_details(path) self.tmpdir = tempfile.mkdtemp('-0publish-gui') try: # Must be readable to helper process running as 'zeroinst'... old_umask = os.umask(0022) try: unpack_dir = os.path.join(self.tmpdir, 'unpacked') os.mkdir(unpack_dir) dialog.window.set_cursor(watch) gtk.gdk.flush() try: unpack.unpack_archive(url, file(path), unpack_dir, type = type, start_offset = start_offset) manifest.fixup_permissions(unpack_dir) finally: dialog.window.set_cursor(None) finally: os.umask(old_umask) except: chooser.unselect_filename(path) self.destroy_tmp() raise iter = model.append(None, ['Everything']) items = os.listdir(unpack_dir) for f in items: model.append(iter, [f]) tree.expand_all() # Choose a sensible default iter = model.get_iter_root() if len(items) == 1 and \ os.path.isdir(os.path.join(unpack_dir, items[0])) and \ items[0] not in ('usr', 'opt', 'bin', 'etc', 'sbin', 'doc', 'var'): iter = model.iter_children(iter) selection.select_iter(iter) self.mime_type = type self.start_offset = start_offset widgets.get_widget('subdirectory_frame').set_sensitive(True)
def all_children(model, iter): "make a python generator out of the children of `iter`" iter = model.iter_children(iter) while iter: yield iter iter = model.iter_next(iter)