~ubuntu-branches/ubuntu/precise/software-center/precise

« back to all changes in this revision

Viewing changes to utils/expunge-cache.py

  • Committer: Package Import Robot
  • Author(s): Michael Vogt, Michael Vogt, Gary Lasker
  • Date: 2012-03-30 18:00:50 UTC
  • Revision ID: package-import@ubuntu.com-20120330180050-vuoqiczj131r9tgh
Tags: 5.1.14
[ Michael Vogt ]
* lp:~mvo/software-center/lp962580:
  - add locking to the expunge helper process to fix bugs that are triggered
    if multiple expunge cache processes are run (LP: #962580)
* lp:~mvo/software-center/cache-refresh-glitch:
  - ensure that we get a full refresh if a pkg was not available before
    show_app is called
* lp:~mvo/software-center/lp940482:
  - fix crash if the debfile does not return proper utf8 for the
    description (LP: #940482)
* lp:~mvo/software-center/lp966514:
  - properly handle network disconnect conditions with the Ubuntu
    SSO dialog (LP: #966514)
* lp:~mvo/software-center/lp966879:
  - fix for crashes in the installed view treeview (LP: #966879,
    LP: #950899)
* lp:~mvo/software-center/lp846204:
  - fix ValueError crashes in get_iter due to invalid tree paths
    (LP: #846204)
* lp:~mvo/software-center/lp964433:
  - disconnect the model from the view before calling set_from_matches
    (LP: #964433)
* lp:~mvo/software-center/treeview-keep-state-on-db-cache-change:
 - restore the state of the installed view treeview when the
   the db or cache changes, such as on an app install or remove
* lp:~mvo/software-center/946393:
 - fix installing multiple apps when in a custom list view (LP: #946393)
* lp:~mvo/software-center/lp969050:
 - disconnect the view when the model is cleared to avoid a furry of
   cursor_changed signals as the rows get removed (LP: #969050)

[ Gary Lasker ]
* lp:~gary-lasker/software-center/installed-pane-refresh:
  - avoid rebuilding the treeview in the installedpane if its not
    required (LP: #828887)
* lp:~gary-lasker/software-center/fix-crash-lp967036:
  - Small branch to fix a crash due to a UnicodeDecodeError when accessing 
    the short description for H/W requirements (LP: #967036)
* lp:~gary-lasker/software-center/fix-crash-lp935930:
  - fix a crash due to a UnicodeDecodeError (LP: #935930)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
 
2
# Copyright (C) 2012 Canonical
 
3
#
 
4
# Authors:
 
5
#  Michael Vogt
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify it under
 
8
# the terms of the GNU General Public License as published by the Free Software
 
9
# Foundation; version 3.
 
10
#
 
11
# This program is distributed in the hope that it will be useful, but WITHOUT
 
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
14
# details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License along with
 
17
# this program; if not, write to the Free Software Foundation, Inc.,
 
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2
19
 
3
20
"""
4
21
Expunge httplib2 caches
7
24
import argparse
8
25
import logging
9
26
import os
10
 
import time
11
27
import sys
12
28
 
13
 
 
14
 
class ExpungeCache(object):
15
 
 
16
 
    def __init__(self, dirs, args):
17
 
        self.dirs = dirs
18
 
        # days to keep data in the cache (0 == disabled)
19
 
        self.keep_time = 60 * 60 * 24 * args.by_days
20
 
        self.keep_only_http200 = args.by_unsuccessful_http_states
21
 
        self.dry_run = args.dry_run
22
 
 
23
 
    def _rm(self, f):
24
 
        if self.dry_run:
25
 
            print "Would delete: %s" % f
26
 
        else:
27
 
            logging.debug("Deleting: %s" % f)
28
 
            try:
29
 
                os.unlink(f)
30
 
            except OSError as e:
31
 
                logging.warn("When expunging the cache, could not unlink "
32
 
                             "file '%s' (%s)'" % (f, e))
33
 
 
34
 
    def clean(self):
35
 
        # go over the directories
36
 
        now = time.time()
37
 
        for d in self.dirs:
38
 
            for root, dirs, files in os.walk(d):
39
 
                for f in files:
40
 
                    fullpath = os.path.join(root, f)
41
 
                    header = open(fullpath).readline().strip()
42
 
                    if not header.startswith("status:"):
43
 
                        logging.debug(
44
 
                            "Skipping files with unknown header: '%s'" % f)
45
 
                        continue
46
 
                    if self.keep_only_http200 and header != "status: 200":
47
 
                        self._rm(fullpath)
48
 
                    if self.keep_time:
49
 
                        mtime = os.path.getmtime(fullpath)
50
 
                        logging.debug("mtime of '%s': '%s" % (f, mtime))
51
 
                        if (mtime + self.keep_time) < now:
52
 
                            self._rm(fullpath)
 
29
from softwarecenter.expunge import ExpungeCache
 
30
 
53
31
 
54
32
if __name__ == "__main__":
55
33
    parser = argparse.ArgumentParser(
85
63
    os.nice(19)
86
64
 
87
65
    # do it
88
 
    cleaner = ExpungeCache(args.directories, args)
 
66
    cleaner = ExpungeCache(args.directories, 
 
67
                           args.by_days, 
 
68
                           args.by_unsuccessful_http_states,
 
69
                           args.dry_run)
89
70
    cleaner.clean()