~mmcg069/software-center/details-tweaks

1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
1
# Copyright (C) 2010 Canonical
2
#
3
# Authors:
4
#  Michael Vogt
5
#
6
# This program is free software; you can redistribute it and/or modify it under
7
# the terms of the GNU General Public License as published by the Free Software
8
# Foundation; version 3.
9
#
10
# This program is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13
# details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# this program; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
2112.1.2 by Martin Pitt
All files: Do not import the gi.repository.GObject module with static
19
import sys
20
if 'gobject' in sys.modules:
21
    import gobject as GObject
2114 by Michael Vogt
pyflakes fixes
22
    GObject #pyflakes
2112.1.2 by Martin Pitt
All files: Do not import the gi.repository.GObject module with static
23
else:
24
    from gi.repository import GObject
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
25
1809.1.30 by Alex Eftimie
wrap .candidate and .installed into a generic _Version - long awaited change, tests updated and passing
26
class _Version:
27
    @property
28
    def description(self):
29
        pass
30
    @property
31
    def downloadable(self):
32
        pass
33
    @property
34
    def summary(self):
35
        pass
36
    @property
37
    def size(self):
38
        return self.pkginfo.get_size(self.name)
39
    @property
40
    def installed_size(self):
41
        return 0
42
    @property
43
    def version(self):
44
        pass
45
    @property
46
    def origins(self):
47
        return []
48
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
49
class _Package:
50
    def __init__(self, name, pkginfo):
1818 by Michael Vogt
merged from lp:~alexeftimie/software-center/backend-refactor
51
        self.name = name
52
        self.pkginfo = pkginfo
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
53
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
54
    @property
55
    def installed(self):
1809.1.30 by Alex Eftimie
wrap .candidate and .installed into a generic _Version - long awaited change, tests updated and passing
56
        """ returns a _Version object """
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
57
        if not self.pkginfo.is_installed(self.name):
58
            return None
1809.1.5 by Alex Eftimie
experimental PackageInfo Package abstraction - typo and tests
59
        return self.pkginfo.get_installed(self.name)
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
60
    @property
61
    def candidate(self):
1809.1.30 by Alex Eftimie
wrap .candidate and .installed into a generic _Version - long awaited change, tests updated and passing
62
        """ returns a _Version object """
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
63
        return self.pkginfo.get_candidate(self.name)
64
    @property
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
65
    def versions(self):
1809.1.30 by Alex Eftimie
wrap .candidate and .installed into a generic _Version - long awaited change, tests updated and passing
66
        """ a list of available versions (as _Version) to install """
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
67
        return self.pkginfo.get_versions(self.name)
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
68
69
    @property
1809.1.6 by Alex Eftimie
experimental PackageInfo Package abstraction - must provide an is_installed property for packages
70
    def is_installed(self):
71
        return self.pkginfo.is_installed(self.name)
72
    @property
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
73
    def section(self):
74
        return self.pkginfo.get_section(self.name)
75
    @property
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
76
    def website(self):
77
        return self.pkginfo.get_website(self.name)
78
    @property
79
    def installed_files(self):
80
        return self.pkginfo.get_installed_files(self.name)
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
81
1945.1.3 by Michael Vogt
convert all gobject to gi.repository/GObject
82
class PackageInfo(GObject.GObject):
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
83
    """ abstract interface for the packageinfo information """
84
1945.1.3 by Michael Vogt
convert all gobject to gi.repository/GObject
85
    __gsignals__ = {'cache-ready':  (GObject.SIGNAL_RUN_FIRST,
86
                                     GObject.TYPE_NONE,
87
                                     ()),
88
                    'cache-invalid':(GObject.SIGNAL_RUN_FIRST,
89
                                     GObject.TYPE_NONE,
90
                                     ()),
91
                    'cache-broken':(GObject.SIGNAL_RUN_FIRST,
92
                                     GObject.TYPE_NONE,
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
93
                                     ()),
94
                    }
95
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
96
    def __getitem__(self, k):
97
        return _Package(k, self)
98
    def __contains__(self, pkgname):
99
        return False
100
1821 by Michael Vogt
make the version_compare stuff distro specific
101
    @staticmethod
102
    def version_compare(v1, v2):
103
        """ compare two versions """
104
        return cmp(v1, v2)
105
    @staticmethod
106
    def upstream_version_compare(v1, v2):
107
        """ compare two versions, but ignore the distro specific revisions """
108
        return cmp(v1, v2)
109
    @staticmethod
110
    def upstream_version(v):
111
        """ Return the "upstream" version number of the given version """
112
        return v
113
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
114
    def is_installed(self, pkgname):
115
        pass
116
    def is_available(self, pkgname):
117
        pass
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
118
    def get_installed(self, pkgname):
119
        pass
120
    def get_candidate(self, pkgname):
121
        pass
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
122
    def get_versions(self, pkgname):
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
123
        return []
124
1809.1.1 by Alex Eftimie
extended pkinfo to provide methods for section, summary and description
125
    def get_section(self, pkgname):
126
        pass
127
    def get_summary(self, pkgname):
128
        pass
129
    def get_description(self, pkgname):
130
        pass
1809.1.12 by Alex Eftimie
apt.Package -> pkginfo._Package abstraction fixes
131
    def get_website(self, pkgname):
132
        pass
133
    def get_installed_files(self, pkgname):
134
        return []
135
    def get_size(self, pkgname):
136
        return -1
137
    def get_installed_size(self, pkgname):
138
        return -1
1809.1.4 by Alex Eftimie
experimental PackageInfo Package abstraction
139
    def get_origins(self, pkgname):
140
        return []
1864.2.6 by Alex Eftimie
basic package_info PK implementation, most of the tests pass, hurray
141
    def get_addons(self, pkgname, ignore_installed=False):
1864.2.7 by Alex Eftimie
added Version class (to be migrated into backend-refactor). can now be tested from within gui. hacking a cache since calling resolve each time is slow
142
        """ :return: a tuple of pkgnames (recommends, suggests) """
143
        return ([], [])
1809.1.20 by Alex Eftimie
expose get_ _depends, and simulate methods in PackageInfo
144
1809.1.22 by Alex Eftimie
refactored install size calculation, moved from gtk to PackageInfo backend
145
    def get_packages_removed_on_remove(self, pkg):
1809.1.21 by Alex Eftimie
AptCache methods made private
146
        """ Returns a package names list of reverse dependencies
147
        which will be removed if the package is removed."""
1809.1.20 by Alex Eftimie
expose get_ _depends, and simulate methods in PackageInfo
148
        return []
1809.1.22 by Alex Eftimie
refactored install size calculation, moved from gtk to PackageInfo backend
149
150
    def get_packages_removed_on_install(self, pkg):
151
        """ Returns a package names list of dependencies
152
        which will be removed if the package is installed."""
153
        return []
154
155
    def get_total_size_on_install(self, pkgname, addons_install=None,
156
                                addons_remove=None):
157
        """ Returns a tuple (download_size, installed_size)
158
        with disk size in KB calculated for pkgname installation
159
        plus addons change.
160
        """
161
        return (0, 0)
162
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
163
    def open(self):
164
        """ 
165
        (re)open the cache, this sends cache-invalid, cache-ready signals
166
        """
167
        pass
168
    @property
169
    def ready(self):
170
        pass
171
1804.1.1 by Alex Eftimie
refactoring: proper backend factories and base install backend class
172
# singleton
173
pkginfo = None
1773.1.5 by Michael Vogt
move AptCache out of the source and info the pkginfo abstraction
174
def get_pkg_info():
1804.1.1 by Alex Eftimie
refactoring: proper backend factories and base install backend class
175
    global pkginfo
176
    if pkginfo is None:
1864.2.7 by Alex Eftimie
added Version class (to be migrated into backend-refactor). can now be tested from within gui. hacking a cache since calling resolve each time is slow
177
        from softwarecenter.enums import USE_PACKAGEKIT_BACKEND
178
        if not USE_PACKAGEKIT_BACKEND:
179
            from softwarecenter.db.pkginfo_impl.aptcache import AptCache
180
            pkginfo = AptCache()
181
        else:
182
            from softwarecenter.db.pkginfo_impl.packagekit import PackagekitInfo
183
            pkginfo = PackagekitInfo()        
1773.1.3 by Michael Vogt
abstract the package history and start abstracting the cache as well
184
    return pkginfo