2
# Copyright (C) 2012 Canonical
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.
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
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
4
21
Expunge httplib2 caches
14
class ExpungeCache(object):
16
def __init__(self, dirs, args):
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
25
print "Would delete: %s" % f
27
logging.debug("Deleting: %s" % f)
31
logging.warn("When expunging the cache, could not unlink "
32
"file '%s' (%s)'" % (f, e))
35
# go over the directories
38
for root, dirs, files in os.walk(d):
40
fullpath = os.path.join(root, f)
41
header = open(fullpath).readline().strip()
42
if not header.startswith("status:"):
44
"Skipping files with unknown header: '%s'" % f)
46
if self.keep_only_http200 and header != "status: 200":
49
mtime = os.path.getmtime(fullpath)
50
logging.debug("mtime of '%s': '%s" % (f, mtime))
51
if (mtime + self.keep_time) < now:
29
from softwarecenter.expunge import ExpungeCache
54
32
if __name__ == "__main__":
55
33
parser = argparse.ArgumentParser(
88
cleaner = ExpungeCache(args.directories, args)
66
cleaner = ExpungeCache(args.directories,
68
args.by_unsuccessful_http_states,