~mvo/aptdaemon/0.3-fix-race-597017

« back to all changes in this revision

Viewing changes to aptdaemon/worker.py

  • Committer: sebi at glatzor
  • Date: 2010-09-04 06:57:05 UTC
  • mfrom: (477.1.1 make-trans)
  • Revision ID: sebi@glatzor.de-20100904065705-1s685x94s0hiwed9
Merge with make-trans branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import apt.cache
32
32
import apt.debfile
33
33
import apt_pkg
 
34
import aptsources
 
35
import aptsources.distro
 
36
from aptsources.sourceslist import SourcesList
34
37
from gettext import gettext as _
35
38
import gobject
36
39
import pkg_resources
146
149
                self.add_vendor_key_from_keyserver(**self.trans.kwargs)
147
150
            elif self.trans.role == ROLE_REMOVE_VENDOR_KEY:
148
151
                self.remove_vendor_key(**self.trans.kwargs)
 
152
            elif self.trans.role == ROLE_ADD_REPOSITORY:
 
153
                self.add_repository(**self.trans.kwargs)
 
154
            elif self.trans.role == ROLE_ENABLE_DISTRO_COMP:
 
155
                self.enable_distro_comp(**self.trans.kwargs)
149
156
            else:
150
157
                self._open_cache()
151
158
            # Process transaction which can handle a broken dep cache
295
302
            resolver.clear(pkg)
296
303
            resolver.protect(pkg)
297
304
 
 
305
    def enable_distro_comp(self, component):
 
306
        """Enable given component in the sources list.
 
307
 
 
308
        Keyword arguments:
 
309
        component -- a component, e.g. main or universe
 
310
        """
 
311
        old_umask = os.umask(0022)
 
312
        try:
 
313
            sourceslist = SourcesList()
 
314
            distro = aptsources.distro.get_distro()
 
315
            distro.get_sources(sourceslist)
 
316
            distro.enable_component(component)
 
317
            sourceslist.save()
 
318
        finally:
 
319
            os.umask(old_umask)
 
320
 
 
321
    def add_repository(self, rtype, uri, dist, comps, comment, sourcesfile):
 
322
        """Add given repository to the sources list.
 
323
 
 
324
        Keyword arguments:
 
325
        rtype -- the type of the entry (deb, deb-src)
 
326
        uri -- the main repository uri (e.g. http://archive.ubuntu.com/ubuntu)
 
327
        dist -- the distribution to use (e.g. karmic, "/")
 
328
        comps -- a (possible empty) list of components (main, restricted)
 
329
        comment -- an (optional) comment
 
330
        sourcesfile -- an (optinal) filename in sources.list.d 
 
331
        """
 
332
        if sourcesfile:
 
333
            if not sourcesfile.endswith(".list"):
 
334
                sourcesfile += ".list"
 
335
            d = apt_pkg.config.find_dir("Dir::Etc::sourceparts")
 
336
            sourcesfile = os.path.join(d, os.path.basename(sourcesfile))
 
337
        else:
 
338
            sourcesfile = None
 
339
        old_umask = os.umask(0022)
 
340
        try:
 
341
            sources = SourcesList()
 
342
            entry = sources.add(rtype, uri, dist, comps, comment,
 
343
                                file=sourcesfile)
 
344
            if entry.invalid:
 
345
                #FIXME: Introduce new error codes
 
346
                raise RepositoryInvalidError()
 
347
        except:
 
348
            raise
 
349
        else:
 
350
            sources.save()
 
351
        finally:
 
352
            os.umask(old_umask)
 
353
 
298
354
    def add_vendor_key_from_keyserver(self, keyid, keyserver):
299
355
        """Add the signing key from the given (keyid, keyserver) to the
300
356
        trusted vendors.