67 68NAME=Column(_('Name'),str,hide=True) 69URI=Column(_('URI'),str,hide=True) 70TOOLTIP=Column(_('Description'),str,hide=True) 71ITEM_VIEW=Column(_('Item'),str,props={'ypad':6,'yalign':0},resizable=True,markup=True) 72SELF_SIZE=Column(_('Self Size'),int,hide=True) 73TOTAL_SIZE=Column(_('Total Size'),int,hide=True) 74PRETTY_SIZE=Column(_('Size'),str,props={'xalign':1.0}) 75ITEM_OBJECT=Column(_('Object'),object,hide=True) 76 77ACTION_REMOVE=object()# just make a unique value
91 92SECTION_INTERFACES=Section( 93_("Feeds"), 94_("Feeds in the cache")) 95SECTION_UNOWNED_IMPLEMENTATIONS=Section( 96_("Unowned implementations and temporary files"), 97_("These probably aren't needed any longer. You can delete them.")) 98SECTION_INVALID_INTERFACES=Section( 99_("Invalid feeds (unreadable)"),100_("These feeds exist in the cache but cannot be read. You should probably delete them."))101102importcgi
107108name=d.get('name',None)109desc=d.get('desc',None)110uri=d.get('uri',None)111112setcol(NAME,name)113setcol(URI,uri)114ifnameanduri:115setcol(ITEM_VIEW,'<span font-size="larger" weight="bold">%s</span>\n'116'<span color="#666666">%s</span>'%tuple(map(cgi.escape,(name,uri))))117else:118setcol(ITEM_VIEW,cgi.escape(nameordesc))119120size=d.get('size',0)121setcol(SELF_SIZE,size)122setcol(TOTAL_SIZE,0)# must be set to prevent type error123setcol(TOOLTIP,d.get('tooltip',None))124setcol(ITEM_OBJECT,d.get('object',None))125returnvals126127menu=None
151"Present a blocking warning message with OK/Cancel buttons, and return True if OK was pressed"152dialog=gtk.MessageDialog(parent=parent,buttons=gtk.BUTTONS_OK_CANCEL,type=gtk.MESSAGE_WARNING)153dialog.set_property('text',message)154response=[]155def_response(dialog,resp):156ifresp==gtk.RESPONSE_OK:157response.append(True)
170"Get the size for a directory tree. Get the size from the .manifest if possible."171man=os.path.join(path,'.manifest')172ifos.path.exists(man):173size=os.path.getsize(man)174withopen(man,'rt')asstream:175forlineinstream:176ifline[:1]in"XF":177size+=int(line.split(' ',4)[3])178else:179size=0180forroot,dirs,filesinos.walk(path):181fornameinfiles:182size+=os.path.getsize(os.path.join(root,name))183returnsize
239deletable=self.deletable_children()240undeletable=list(filter(lambdachild:notchild.may_delete,self.in_cache))241# the only undeletable items we expect to encounter are LocalImplementations242unexpected_undeletable=list(filter(lambdachild:notisinstance(child,LocalImplementation),undeletable))243assertnotunexpected_undeletable,"unexpected undeletable items!: %r"%(unexpected_undeletable,)244[child.delete()forchildindeletable]
336try:337manifest.verify(self.impl_path)338exceptBadDigestasex:339box=gtk.MessageDialog(None,0,340gtk.MESSAGE_WARNING,gtk.BUTTONS_OK,str(ex))341ifex.detail:342swin=gtk.ScrolledWindow()343buffer=gtk.TextBuffer()344mono=buffer.create_tag('mono',family='Monospace')345buffer.insert_with_tags(buffer.get_start_iter(),ex.detail,mono)346text=gtk.TextView(buffer)347text.set_editable(False)348text.set_cursor_visible(False)349swin.add(text)350swin.set_shadow_type(gtk.SHADOW_IN)351swin.set_border_width(4)352box.vbox.pack_start(swin)353swin.show_all()354box.set_resizable(True)355else:356box=gtk.MessageDialog(None,0,357gtk.MESSAGE_INFO,gtk.BUTTONS_OK,358_('Contents match digest; nothing has been changed.'))359box.run()360box.destroy()
516errors=[]517518model=self.model519paths=get_selected_paths(self.tree_view)520paths.reverse()521forpathinpaths:522item=model[path][ITEM_OBJECT.idx]523assertitem.delete524try:525item.delete()526exceptOSErrorasex:527errors.append(str(ex))528else:529model.remove(model.get_iter(path))530self._update_sizes()531532iferrors:533gtkutils.show_message_box(self.window,_("Failed to delete:\n%s")%'\n'.join(errors))
536"""Display the window and scan the caches to populate it."""537self.window.show()538self.window.get_window().set_cursor(gtkutils.get_busy_pointer())539gtk.gdk.flush()540# (async so that the busy pointer works on GTK 3)541@tasks.async542defpopulate():543populate=self._populate_model()544yieldpopulate545try:546tasks.check(populate)547except:548importlogging549logging.warn("fail",exc_info=True)550raise551# (we delay until here because inserting with the view set is very slow)552self.tree_view.set_model(self.view_model)553self.set_initial_expansion()
557model=self.model558try:559i=model.get_iter_root()560whilei:561# expand only "Feeds"562ifmodel[i][ITEM_OBJECT.idx]isSECTION_INTERFACES:563self.tree_view.expand_row(model.get_path(i),False)564i=model.iter_next(i)565finally:566self.window.get_window().set_cursor(None)
570# Find cached implementations571572unowned={}# Impl ID -> Store573duplicates=[]# TODO574575forsinself.iface_cache.stores.stores:576ifos.path.isdir(s.dir):577foridinos.listdir(s.dir):578ifidinunowned:579duplicates.append(id)580unowned[id]=s581582ok_feeds=[]583error_feeds=[]584585# Look through cached feeds for implementation owners586all_interfaces=self.iface_cache.list_all_interfaces()587all_feeds={}588foruriinall_interfaces:589try:590iface=self.iface_cache.get_interface(uri)591exceptExceptionasex:592error_feeds.append((uri,str(ex),0))593else:594all_feeds.update(self.iface_cache.get_feeds(iface))595596forurl,feedinall_feeds.items():597ifnotfeed:continue598yield599feed_size=0600try:601ifurl!=feed.url:602# (e.g. for .new feeds)603raiseException('Incorrect URL for feed (%s vs %s)'%(url,feed.url))604605ifos.path.isabs(url):606cached_feed=url607feed_type=LocalFeed608else:609feed_type=RemoteFeed610cached_feed=basedir.load_first_cache(namespaces.config_site,611'interfaces',model.escape(url))612user_overrides=basedir.load_first_config(namespaces.config_site,613namespaces.config_prog,614'interfaces',model._pretty_escape(url))615616feed_size=size_if_exists(cached_feed)+size_if_exists(user_overrides)617exceptExceptionasex:618error_feeds.append((url,str(ex),feed_size))619else:620cached_feed=feed_type(feed,feed_size)621forimplinfeed.implementations.values():622ifimpl.local_path:623cached_feed.in_cache.append(LocalImplementation(impl))624fordigestinimpl.digests:625ifdigestinunowned:626cached_dir=unowned[digest].dir627impl_path=os.path.join(cached_dir,digest)628impl_size=get_size(impl_path)629cached_feed.in_cache.append(KnownImplementation(cached_feed,cached_dir,impl,impl_size,digest))630delunowned[digest]631cached_feed.in_cache.sort()632ok_feeds.append(cached_feed)633634iferror_feeds:635iter=SECTION_INVALID_INTERFACES.append_to(self.raw_model)636foruri,ex,sizeinerror_feeds:637item=InvalidFeed(uri,ex,size)638item.append_to(self.raw_model,iter)639640unowned_sizes=[]641local_dir=os.path.join(basedir.xdg_cache_home,'0install.net','implementations')642foridinunowned:643ifunowned[id].dir==local_dir:644impl=UnusedImplementation(local_dir,id)645unowned_sizes.append((impl.size,impl))646ifunowned_sizes:647iter=SECTION_UNOWNED_IMPLEMENTATIONS.append_to(self.raw_model)648forsize,iteminunowned_sizes:649item.append_to(self.raw_model,iter)650651ifok_feeds:652iter=SECTION_INTERFACES.append_to(self.raw_model)653foriteminok_feeds:654yield655item.append_to(self.raw_model,iter)656self._update_sizes()
659"""Set TOTAL_SIZE and PRETTY_SIZE to the total size, including all children."""660m=self.raw_model661defupdate(itr):662total=m[itr][SELF_SIZE.idx]663total+=sum(map(update,all_children(m,itr)))664m[itr][PRETTY_SIZE.idx]=support.pretty_size(total)iftotalelse'-'665m[itr][TOTAL_SIZE.idx]=total666returntotal
687return_filter688689defnot_(func):690returnlambda*a:notfunc(*a)691692defis_local_feed(model,iter):693returnisinstance(model[iter][ITEM_OBJECT.idx],LocalFeed)694695defhas_implementations(model,iter):696returnmodel.iter_has_child(iter)697698return[699('All',lambda*a:True),700('Feeds with implementations',filter_only([ValidFeed],has_implementations)),701('Feeds without implementations',filter_only([ValidFeed],not_(has_implementations))),702('Local Feeds',filter_only([ValidFeed],is_local_feed)),703('Remote Feeds',filter_only([ValidFeed],not_(is_local_feed))),704]705FILTER_OPTIONS=init_filters()706707708cache_help=help_box.HelpBox(_("Cache Explorer Help"),709(_('Overview'),'\n'+710_("""When you run a program using Zero Install, it downloads the program's 'feed' file, \711which gives information about which versions of the program are available. This feed \712file is stored in the cache to save downloading it next time you run the program.713714When you have chosen which version (implementation) of the program you want to \715run, Zero Install downloads that version and stores it in the cache too. Zero Install lets \716you have many different versions of each program on your computer at once. This is useful, \717since it lets you use an old version if needed, and different programs may need to use \718different versions of libraries in some cases.719720The cache viewer shows you all the feeds and implementations in your cache. \721This is useful to find versions you don't need anymore, so that you can delete them and \722free up some disk space.""")),723724(_('Invalid feeds'),'\n'+725_("""The cache viewer gets a list of all feeds in your cache. However, some may not \726be valid; they are shown in the 'Invalid feeds' section. It should be fine to \727delete these. An invalid feed may be caused by a local feed that no longer \728exists or by a failed attempt to download a feed (the name ends in '.new').""")),729730(_('Unowned implementations and temporary files'),'\n'+731_("""The cache viewer searches through all the feeds to find out which implementations \732they use. If no feed uses an implementation, it is shown in the 'Unowned implementations' \733section.734735Unowned implementations can result from old versions of a program no longer being listed \736in the feed file. Temporary files are created when unpacking an implementation after \737downloading it. If the archive is corrupted, the unpacked files may be left there. Unless \738you are currently unpacking new programs, it should be fine to delete everything in this \739section.""")),740741(_('Feeds'),'\n'+742_("""All remaining feeds are listed in this section. You may wish to delete old versions of \743certain programs. Deleting a program which you may later want to run will require it to be downloaded \744again. Deleting a version of a program which is currently running may cause it to crash, so be careful!""")))745