~speijnik/update-manager/distribution-independent

« back to all changes in this revision

Viewing changes to UpdateManager/Backend/__init__.py

  • Committer: Stephan Peijnik
  • Date: 2009-04-24 16:18:48 UTC
  • Revision ID: debian@sp.or.at-20090424161848-k2g76y5hi722x0pf
Now using zope.interface for the backend interfaces.
Updated documentation, now using autointerface sphinx extension, which has not been included due to unclear licensing yet.
Added basic reload_package_list method to PythonAptBackend class and a corresponding helper class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from gettext import gettext as _
27
27
 
28
 
class PackageUpdateInfo(object):
29
 
    """
30
 
    Unified update information object.
31
 
    This object contains all information needed by the frontend to provide
32
 
    sensible information about updated packages to the user.
33
 
    The UPDATE_CATEGORY_* values are assigned by priority, making security
34
 
    updates the most important ones and backports the least important ones.
35
 
 
36
 
    TODO: the exact priorities are up to discussion.
37
 
    """
38
 
    UPDATE_CATEGORY_SECURITY = 0
39
 
    """ Security updates category. """
40
 
    UPDATE_CATEGORY_RECOMMENDED = 1
41
 
    """ Recommended updates category. """
42
 
    UPDATE_CATEGORY_DEFAULT = 2
43
 
    """ Default/distribution updates category. """
44
 
    UPDATE_CATEGORY_PROPOSED = 3
45
 
    """ Proposed updates category. """
46
 
    UPDATE_CATEGORY_BACKPORT = 4
47
 
    """ Backport updates category. """
48
 
 
49
 
    UPDATE_CATEGORY_MAP = {
50
 
        UPDATE_CATEGORY_SECURITY: _("Important security updates"),
51
 
        UPDATE_CATEGORY_RECOMMENDED: _("Recommended updates"),
52
 
        UPDATE_CATEGORY_DEFAULT: _("Distribution updates"),
53
 
        UPDATE_CATEGORY_PROPOSED: _("Proposed updates"),
54
 
        UPDATE_CATEGORY_BACKPORT: _("Backports"),
55
 
        }
56
 
    """ Identifier to localized name map for categories. See UPDATE_CATEGORY_*
57
 
    for information about available categories."""
58
 
 
59
 
    def __init__(self, package_name, short_description, installed_version,
60
 
                 update_candidate_version, update_category, download_size):
61
 
        """
62
 
        Initialize PackageUpdateInfo object.
63
 
 
64
 
        The update_category parameter is an integer value,
65
 
        see UPDATE_CATEGORY_* for details.
66
 
        """
67
 
        self._package_name = package_name
68
 
        self._short_description = short_description
69
 
        self._installed_version = installed_version
70
 
        self._update_candidate_version = update_candidate_version
71
 
        self._update_category = update_category
72
 
        self._download_size = download_size
73
 
 
74
 
    @property
75
 
    def package_name(self):
76
 
        """
77
 
        The package's name (property).
78
 
        """
79
 
        return self._package_name
80
 
 
81
 
    @property
82
 
    def short_description(self):
83
 
        """
84
 
        The package's short description (property).
85
 
        """
86
 
        return self._short_description
87
 
 
88
 
    @property
89
 
    def installed_version(self):
90
 
        """
91
 
        The currently installed version of the package (property).
92
 
        """
93
 
        return self._installed_version
94
 
 
95
 
    @property
96
 
    def update_candidate_version(self):
97
 
        """
98
 
        The update candidate's version (property).
99
 
        """
100
 
        return self._update_candidate_version
101
 
 
102
 
    @property
103
 
    def update_category(self):
104
 
        """
105
 
        The update's category (see UPDATE_CATEGORY_* for details, property).
106
 
        """
107
 
        return self._update_category
108
 
 
109
 
    @property
110
 
    def update_category_name(self):
111
 
        """
112
 
        The update category's localized name (property).
113
 
        """
114
 
        return PackageUpdateInfo.UPDATE_CATEGORY_MAP[self._update_category]
115
 
 
116
 
    @property
117
 
    def download_size(self):
118
 
        """
119
 
        The download size in bytes (property).
120
 
        """
121
 
        return self._download_size
122
 
 
123
 
class BackendBase(object):
124
 
    """
125
 
    Base class for update-manager backends.
126
 
 
127
 
    This class forms the API available to update-manager's core and *must*
128
 
    be subclassed by all classes implementing this interface. Also, all
129
 
    methods of this base class must be overwritten in the implementation.
130
 
    """
 
28
from zope.interface import Interface
 
29
 
 
30
UPDATE_CATEGORY_SECURITY = 0
 
31
""" Security updates category. """
 
32
UPDATE_CATEGORY_RECOMMENDED = 1
 
33
""" Recommended updates category. """
 
34
UPDATE_CATEGORY_DEFAULT = 2
 
35
""" Default/distribution updates category. """
 
36
UPDATE_CATEGORY_PROPOSED = 3
 
37
""" Proposed updates category. """
 
38
UPDATE_CATEGORY_BACKPORT = 4
 
39
""" Backport updates category. """
 
40
 
 
41
UPDATE_CATEGORY_MAP = {
 
42
    UPDATE_CATEGORY_SECURITY: _("Important security updates"),
 
43
    UPDATE_CATEGORY_RECOMMENDED: _("Recommended updates"),
 
44
    UPDATE_CATEGORY_DEFAULT: _("Distribution updates"),
 
45
    UPDATE_CATEGORY_PROPOSED: _("Proposed updates"),
 
46
    UPDATE_CATEGORY_BACKPORT: _("Backports"),
 
47
    }
 
48
"""
 
49
A mapping of update category identifiers to their (localized)
 
50
names. See UPDATE_CATEGORY_* for details.
 
51
"""
 
52
    
 
53
def update_category_id_to_name(category_id):
 
54
    """ Converts the given update category ID to a localized name. """
 
55
    if not UPDATE_CATEGORY_MAP.has_key(category_id):
 
56
        return UPDATE_CATEGORY_MAP[UPDATE_CATEGORY_DEFAULT]
 
57
    return UPDATE_CATEGORY_MAP[category_id]
 
58
 
 
59
class IPackageUpdateInfo(Interface):
 
60
    """
 
61
    Package update info interface.
 
62
 
 
63
    This interface is intended to provide all information to a package
 
64
    that could be needed by the UI or update-manager itself.
 
65
    """
 
66
    def __init__(self, backend_package_obj, dist_obj):
 
67
        """
 
68
        The constructor accepts a backend-specific package object
 
69
        and an object of the distribution-specific interface.
 
70
 
 
71
        The latter is needed for things like detecting the category a package
 
72
        fits in.
 
73
        """
 
74
 
 
75
    def get_package_name(self):
 
76
        """ Return the package name as a string. """
 
77
 
 
78
    def get_installed_version(self):
 
79
        """ The currently installed version as a string. """
 
80
 
 
81
    def get_candidate_version(self):
 
82
        """ The candidate's version as a string. """
 
83
 
 
84
    def get_update_category(self):
 
85
        """ The update's category as an integer. """
 
86
 
 
87
    def get_download_size(self):
 
88
        """ The download size in bytes as an integer. """
 
89
 
 
90
    def get_summary(self):
 
91
        """
 
92
        The package summary (aka. short description) as a string.
 
93
        """
 
94
 
 
95
    def get_candidate_archive_name(self):
 
96
        """ The candidate's repository archive name. """
 
97
 
 
98
    def get_candidate_origin_name(self):
 
99
        """ The candidate's repository origin name. """
 
100
 
 
101
    def get_candidate_component_name(self):
 
102
        """ The candidate's repository component name. """
 
103
 
 
104
    def candidate_origin_is_trusted(self):
 
105
        """
 
106
        Return boolean indicating whether the repository we found the candidate
 
107
        in is trusted.
 
108
        """
 
109
 
 
110
# Backend special status constants.
 
111
RELOAD_CACHE_STATUS_DONE = -1   
 
112
""" Cache reload status: done. """
 
113
 
 
114
RELOAD_LIST_STATUS_HIT = -1
 
115
""" Package list reload status: hit. """
 
116
RELOAD_LIST_STATUS_FAILED = -2
 
117
""" Package list reload status: failed. """
 
118
RELOAD_LIST_STATUS_FINISHED = -3
 
119
""" Package list reload status: done/finished. """
 
120
RELOAD_LIST_STATUS_QUEUED = -4
 
121
""" Package list reload status: queued. """
 
122
RELOAD_LIST_STATUS_IGNORED = -5
 
123
""" Package list reload status: ignored. """
 
124
                        
 
125
DOWNLOAD_STATUS_BEGIN = -1
 
126
""" Download status: begin/initialization. """
 
127
DOWNLOAD_STATUS_FINISHED = -2
 
128
""" Download status: finished/finalization. """
 
129
DOWNLOAD_STATUS_PACKAGE_BEGIN = -3
 
130
""" Download status: package begin. """
 
131
DOWNLOAD_STATUS_PACKAGE_FINISHED = -4
 
132
""" Download status: package finished. """
 
133
DOWNLOAD_STATUS_PACKAGE_ERROR = -5
 
134
""" Download status: package error. """
 
135
 
 
136
INSTALL_STATUS_BEGIN = -1
 
137
""" Installation status: begin/initialization. """
 
138
INSTALL_STATUS_FINISHED = -2
 
139
""" Installation status: finished/finalization. """
 
140
INSTALL_STATUS_PACKAGE_BEGIN = -3
 
141
""" Installation status: package begin. """
 
142
INSTALL_STATUS_PACKAGE_UNPACK = -4
 
143
""" Installation status: package unpack. """
 
144
INSTALL_STATUS_PACKAGE_SETUP = -5
 
145
""" Installation status: package setup. """
 
146
INSTALL_STATUS_PACKAGE_FINISHED = -6
 
147
""" Installation status: package finished. """
 
148
INSTALL_STATUS_ERROR = -7
 
149
""" Installation status: error. """                
 
150
 
 
151
class IBackend(Interface):
 
152
    """
 
153
    Interface class for update-manager backends.
 
154
 
 
155
    This class forms the public interface to Update Manager backends.
 
156
    """
 
157
 
131
158
    def get_available_updates(self):
132
159
        """
133
160
        Returns a list containing PackageUpdateInfo objects of available
134
161
        updates.
135
162
        """
136
 
        raise NotImplementedError
137
163
 
138
 
    RELOAD_CACHE_STATUS_DONE = -1
139
 
    """ Cache reload status: done. """
140
 
    
141
164
    def reload_cache(self, cache_progress_callback):
142
165
        """
143
166
        Reloads the package cache.
153
176
        If the value passed as percentage is RELOAD_CACHE_STATUS_DONE
154
177
        all operations have succeeded.
155
178
        """
156
 
        raise NotImplementedError        
157
179
 
158
 
    RELOAD_LIST_STATUS_HIT = -1
159
 
    """ Package list reload status: hit. """
160
 
    RELOAD_LIST_STATUS_FAILED = -2
161
 
    """ Package list reload status: failed. """
162
 
    RELOAD_LIST_STATUS_FINISHED = -3
163
 
    """ Package list reload status: done/finished. """
164
180
    def reload_package_list(self, reload_progress_callback):
165
181
        """
166
182
        Reloads the package list (aptitude update/apt-get update).
173
189
        progress of fetching (values 0-100) in percent, or for negative
174
190
        values the reload result (see RELOAD_LIST_STATUS_*).
175
191
        """
176
 
        raise NotImplementedError
177
192
 
178
 
    DOWNLOAD_STATUS_BEGIN = -1
179
 
    """ Download status: begin/initialization. """
180
 
    DOWNLOAD_STATUS_FINISHED = -2
181
 
    """ Download status: finished/finalization. """
182
 
    DOWNLOAD_STATUS_PACKAGE_BEGIN = -3
183
 
    """ Download status: package begin. """
184
 
    DOWNLOAD_STATUS_PACKAGE_FINISHED = -4
185
 
    """ Download status: package finished. """
186
 
    DOWNLOAD_STATUS_PACKAGE_ERROR = -5
187
 
    """ Download status: package error. """
188
193
    def download_updates(self, selected_updates, download_progress_callback):
189
194
        """
190
195
        Downloads the packages specified in selected_updates.
206
211
        DOWNLOAD_STATUS_BEGIN and DOWNLOAD_STATUS_FINISHED are intended to
207
212
        be used by the frontend to update its UI.
208
213
        """
209
 
        raise NotImplementedError
210
214
        
211
 
    INSTALL_STATUS_BEGIN = -1
212
 
    """ Installation status: begin/initialization. """
213
 
    INSTALL_STATUS_FINISHED = -2
214
 
    """ Installation status: finished/finalization. """
215
 
    INSTALL_STATUS_PACKAGE_BEGIN = -3
216
 
    """ Installation status: package begin. """
217
 
    INSTALL_STATUS_PACKAGE_UNPACK = -4
218
 
    """ Installation status: package unpack. """
219
 
    INSTALL_STATUS_PACKAGE_SETUP = -5
220
 
    """ Installation status: package setup. """
221
 
    INSTALL_STATUS_PACKAGE_FINISHED = -6
222
 
    """ Installation status: package finished. """
223
 
    INSTALL_STATUS_ERROR = -7
224
 
    """ Installation status: error. """
225
215
    def install_updates(self, selected_updates, install_progress_callback,
226
216
                        console_fd):
227
217
        """
241
231
        used by the frontend to update its UI.
242
232
        INSTALL_STATUS_ERROR indicates an error during installation.
243
233
        """
244
 
        raise NotImplementedError
245
234
        
246
235
    def acquire_lock(self):
247
236
        """
248
237
        Acquire the package manager lock.
249
238
        """
250
 
        raise NotImplementedError
251
239
 
252
240
    def release_lock(self):
253
241
        """
254
242
        Release the package manager lock.
255
243
        """
256
 
        raise NotImplementedError
257
244
 
258
245
    def is_locked(self, by_us=False):
259
246
        """
263
250
        any process, whilst setting by_us to True indicates we want to
264
251
        know whether we hold the lock ourselves.
265
252
        """
266
 
        raise NotImplementedError