~mvo/aptdaemon/allow-unauthenticated

« back to all changes in this revision

Viewing changes to aptdaemon/core.py

  • Committer: sebi at glatzor
  • Date: 2009-08-27 10:03:50 UTC
  • mfrom: (220.2.5 merge-repo)
  • Revision ID: sebi@glatzor.de-20090827100350-a0ni2pqxa3kwtoep
Merge AddRepository feature from Michael Vogt. Thanks a lot!

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
import dbus.mainloop.glib
52
52
import dbus.glib
53
53
from softwareproperties.AptAuth import AptAuth
 
54
from aptsources.sourceslist import SourcesList
 
55
import apt_pkg
54
56
 
55
57
import errors
56
58
from enums import *
1011
1013
        deferred.add_callback(lambda trans: trans.tid)
1012
1014
        return deferred
1013
1015
 
 
1016
    def _add_repository(self, type, uri, dist, comps, comment, sourcesfile):
 
1017
        """Helper for the add-repository function"""
 
1018
        old_umask = os.umask(0022)
 
1019
        sources = SourcesList()
 
1020
        entry = sources.add(type, uri, dist, comps, comment, file=sourcesfile)
 
1021
        if entry.invalid:
 
1022
            raise errors.RepositoryInvalidError()
 
1023
        sources.save()
 
1024
        os.umask(old_umask)
 
1025
 
 
1026
    @dbus_deferred_method(APTDAEMON_DBUS_INTERFACE,
 
1027
                          in_signature="sssasss", out_signature="",
 
1028
                          sender_keyword="sender")
 
1029
    def AddRepository(self, type, uri, dist, comps, comment, sourcesfile,
 
1030
                      sender):
 
1031
        """Add given repository to the sources list.
 
1032
 
 
1033
        Keyword arguments:
 
1034
        type -- the type of the entry (deb, deb-src)
 
1035
        uri -- the main repository uri (e.g. http://archive.ubuntu.com/ubuntu)
 
1036
        dist -- the distribution to use (e.g. karmic, "/")
 
1037
        comps -- a (possible empty) list of components (main, restricted)
 
1038
        comment -- an (optional) comment
 
1039
        sourcesfile -- an (optinal) filename in sources.list.d 
 
1040
        sender -- the unique D-Bus name of the sender (provided by D-Bus)
 
1041
        """
 
1042
        log_trans.info("AddRepository() was called: type='%s' uri='%s' "
 
1043
                       "dist='%s' comps='%s' comment='%s' sourcefile='%s'" \
 
1044
                       % (type, uri, dist, comps, comment, sourcesfile))
 
1045
        if sourcesfile:
 
1046
            if not sourcesfile.endswith(".list"):
 
1047
                sourcesfile += ".list"
 
1048
            d = apt_pkg.Config.FindDir("Dir::Etc::sourceparts")
 
1049
            sourcesfile = os.path.join(d, os.path.basename(sourcesfile))
 
1050
        else:
 
1051
            sourcesfile = None
 
1052
        action = policykit1.PK_ACTION_CHANGE_REPOSITORY
 
1053
        deferred = policykit1.check_authorization_by_name(sender, action)
 
1054
        deferred.add_callback(lambda x: self._add_repository(type, uri, dist,
 
1055
                                                             comps, comment,
 
1056
                                                             sourcesfile))
 
1057
        return deferred
 
1058
 
1014
1059
    @dbus_deferred_method(APTDAEMON_DBUS_INTERFACE,
1015
1060
                          in_signature="", out_signature="as",
1016
1061
                          sender_keyword="sender")