~mvo/software-center/oneconf-lp981536

« back to all changes in this revision

Viewing changes to softwarecenter/db/history_impl/apthistory.py

mergedĀ fromĀ lp:~alexeftimie/software-center/backend-refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
19
 
 
20
from gi.repository import GObject
 
21
 
20
22
import apt_pkg
21
 
import cPickle
22
 
from gi.repository import GObject
 
23
apt_pkg.init_config()
 
24
 
23
25
import gio
24
26
import glob
25
27
import gzip
26
28
import os.path
27
29
import logging
28
30
 
 
31
try:
 
32
    import cPickle as pickle
 
33
except ImportError:
 
34
    import pickle
29
35
 
30
36
LOG = logging.getLogger(__name__)
31
37
 
68
74
        if os.path.exists(p) and use_cache:
69
75
            with ExecutionTime("loading pickle cache"):
70
76
                try:
71
 
                    self._transactions = cPickle.load(open(p))
 
77
                    self._transactions = pickle.load(open(p))
72
78
                    cachetime = os.path.getmtime(p)
73
79
                except:
74
80
                    LOG.exception("failed to load cache")
80
86
            self._scan(history_gz_file)
81
87
        self._scan(self.history_file)
82
88
        if use_cache:
83
 
            cPickle.dump(self._transactions, open(p, "w"))
 
89
            pickle.dump(self._transactions, open(p, "w"))
84
90
        self._history_ready = True
85
91
    
86
92
    def _scan(self, history_file, rescan = False):
87
93
        LOG.debug("_scan: '%s' (%s)" % (history_file, rescan))
88
94
        try:
89
95
            tagfile = apt_pkg.TagFile(open(history_file))
90
 
        except (IOError, SystemError), ioe:
 
96
        except (IOError, SystemError) as ioe:
91
97
            LOG.debug(ioe)
92
98
            return
93
99
        for stanza in tagfile: