Exemple #1
0
 def __init__(self, progress=None, rootdir=None, memonly=False):
     self._cache = None
     self._depcache = None
     self._records = None
     self._list = None
     self._callbacks = {}
     self._weakref = weakref.WeakValueDictionary()
     self._set = set()
     if memonly:
         # force apt to build its caches in memory
         apt_pkg.config.set("Dir::Cache::pkgcache", "")
     if rootdir:
         if os.path.exists(rootdir+"/etc/apt/apt.conf"):
             apt_pkg.read_config_file(apt_pkg.config,
                                    rootdir + "/etc/apt/apt.conf")
         if os.path.isdir(rootdir+"/etc/apt/apt.conf.d"):
             apt_pkg.read_config_dir(apt_pkg.config,
                                   rootdir + "/etc/apt/apt.conf.d")
         apt_pkg.config.set("Dir", rootdir)
         apt_pkg.config.set("Dir::State::status",
                            rootdir + "/var/lib/dpkg/status")
         # create required dirs/files when run with special rootdir
         # automatically
         self._check_and_create_required_dirs(rootdir)
         # Call InitSystem so the change to Dir::State::Status is actually
         # recognized (LP: #320665)
         apt_pkg.init_system()
     self.open(progress)
Exemple #2
0
 def test_configuration(self):
     with open(self.file_unicode, 'w') as config:
         config.write("Hello { World 1; };")
     apt_pkg.read_config_file(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, self.dir_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, b"/etc/apt/apt.conf.d")
 def test_configuration(self):
     with open(self.file_unicode, 'w') as config:
         config.write("Hello { World 1; };")
     apt_pkg.read_config_file(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_bytes)
     apt_pkg.read_config_file_isc(apt_pkg.config, self.file_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, self.dir_unicode)
     apt_pkg.read_config_dir(apt_pkg.config, b"/etc/apt/apt.conf.d")
Exemple #4
0
    def __init__(self, progress=None, rootdir=None, memonly=False):
        # type: (Optional[OpProgress], Optional[str], bool) -> None
        self._cache = cast(apt_pkg.Cache, None)  # type: apt_pkg.Cache
        self._depcache = cast(apt_pkg.DepCache, None)  # type: apt_pkg.DepCache
        self._records = cast(apt_pkg.PackageRecords,
                             None)  # type: apt_pkg.PackageRecords # noqa
        self._list = cast(apt_pkg.SourceList, None)  # type: apt_pkg.SourceList
        self._callbacks = {
        }  # type: Dict[str, List[Union[Callable[..., None],str]]] # noqa
        self._callbacks2 = {
        }  # type: Dict[str, List[Tuple[Callable[..., Any], Tuple[Any, ...], Dict[Any,Any]]]] # noqa
        self._weakref = weakref.WeakValueDictionary(
        )  # type: weakref.WeakValueDictionary[str, apt.Package] # noqa
        self._weakversions = weakref.WeakSet(
        )  # type: weakref.WeakSet[Version] # noqa
        self._changes_count = -1
        self._sorted_set = None  # type: Optional[List[str]]

        self.connect("cache_post_open", "_inc_changes_count")
        self.connect("cache_post_change", "_inc_changes_count")
        if memonly:
            # force apt to build its caches in memory
            apt_pkg.config.set("Dir::Cache::pkgcache", "")
        if rootdir:
            rootdir = os.path.abspath(rootdir)
            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                apt_pkg.read_config_file(apt_pkg.config,
                                         rootdir + "/etc/apt/apt.conf")
            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                apt_pkg.read_config_dir(apt_pkg.config,
                                        rootdir + "/etc/apt/apt.conf.d")
            apt_pkg.config.set("Dir", rootdir)
            apt_pkg.config.set("Dir::State::status",
                               rootdir + "/var/lib/dpkg/status")
            # also set dpkg to the rootdir path so that its called for the
            # --print-foreign-architectures call
            apt_pkg.config.set("Dir::bin::dpkg",
                               os.path.join(rootdir, "usr", "bin", "dpkg"))
            # create required dirs/files when run with special rootdir
            # automatically
            self._check_and_create_required_dirs(rootdir)
            # Call InitSystem so the change to Dir::State::Status is actually
            # recognized (LP: #320665)
            apt_pkg.init_system()

        # Prepare a lock object (context manager for archive lock)
        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
        self._archive_lock = _WrappedLock(archive_dir)

        self.open(progress)
Exemple #5
0
    def __init__(self, progress=None, rootdir=None, memonly=False):
        # type: (OpProgress, str, bool) -> None
        self._cache = cast(apt_pkg.Cache, None)  # type: apt_pkg.Cache
        self._depcache = cast(apt_pkg.DepCache, None)  # type: apt_pkg.DepCache
        self._records = cast(apt_pkg.PackageRecords, None)  # type: apt_pkg.PackageRecords # nopep8
        self._list = cast(apt_pkg.SourceList, None)  # type: apt_pkg.SourceList
        self._callbacks = {}  # type: Dict[str, List[Union[Callable[..., None],str]]] # nopep8
        self._callbacks2 = {}  # type: Dict[str, List[Tuple[Callable[..., Any], Tuple[Any, ...], Dict[Any,Any]]]] # nopep8
        self._weakref = weakref.WeakValueDictionary()  # type: weakref.WeakValueDictionary[str, apt.Package] # nopep8
        self._weakversions = weakref.WeakSet()  # type: weakref.WeakSet[Version] # nopep8
        self._changes_count = -1
        self._sorted_set = None  # type: Optional[List[str]]

        self.connect("cache_post_open", "_inc_changes_count")
        self.connect("cache_post_change", "_inc_changes_count")
        if memonly:
            # force apt to build its caches in memory
            apt_pkg.config.set("Dir::Cache::pkgcache", "")
        if rootdir:
            rootdir = os.path.abspath(rootdir)
            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                apt_pkg.read_config_file(apt_pkg.config,
                                         rootdir + "/etc/apt/apt.conf")
            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                apt_pkg.read_config_dir(apt_pkg.config,
                                        rootdir + "/etc/apt/apt.conf.d")
            apt_pkg.config.set("Dir", rootdir)
            apt_pkg.config.set("Dir::State::status",
                               rootdir + "/var/lib/dpkg/status")
            # also set dpkg to the rootdir path so that its called for the
            # --print-foreign-architectures call
            apt_pkg.config.set("Dir::bin::dpkg",
                               os.path.join(rootdir, "usr", "bin", "dpkg"))
            # create required dirs/files when run with special rootdir
            # automatically
            self._check_and_create_required_dirs(rootdir)
            # Call InitSystem so the change to Dir::State::Status is actually
            # recognized (LP: #320665)
            apt_pkg.init_system()

        # Prepare a lock object (context manager for archive lock)
        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
        self._archive_lock = _WrappedLock(archive_dir)

        self.open(progress)
Exemple #6
0
    def __init__(self, progress=None, rootdir=None, memonly=False):
        self._cache = None
        self._depcache = None
        self._records = None
        self._list = None
        self._callbacks = {}
        self._weakref = weakref.WeakValueDictionary()
        self._set = set()
        self._fullnameset = set()
        self._changes_count = -1
        self._sorted_set = None

        self.connect("cache_post_open", self._inc_changes_count)
        self.connect("cache_post_change", self._inc_changes_count)
        if memonly:
            # force apt to build its caches in memory
            apt_pkg.config.set("Dir::Cache::pkgcache", "")
        if rootdir:
            rootdir = os.path.abspath(rootdir)
            # clear old config first (Bug#728274)
            apt_pkg.config.clear("APT")
            apt_pkg.config.set("Dir", rootdir)
            apt_pkg.init_config()
            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                apt_pkg.read_config_file(apt_pkg.config,
                                         rootdir + "/etc/apt/apt.conf")
            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                apt_pkg.read_config_dir(apt_pkg.config,
                                        rootdir + "/etc/apt/apt.conf.d")
            apt_pkg.config.set("Dir::State::status",
                               rootdir + "/var/lib/dpkg/status")
            # also set dpkg to the rootdir path so that its called for the
            # --print-foreign-architectures call
            apt_pkg.config.set("Dir::bin::dpkg",
                               os.path.join(rootdir, "usr", "bin", "dpkg"))
            # create required dirs/files when run with special rootdir
            # automatically
            self._check_and_create_required_dirs(rootdir)
            # Call InitSystem so the change to Dir::State::Status is actually
            # recognized (LP: #320665)
            apt_pkg.init_system()
        self.open(progress)
Exemple #7
0
    def __init__(self, progress=None, rootdir=None, memonly=False):
        self._cache = None
        self._depcache = None
        self._records = None
        self._list = None
        self._callbacks = {}
        self._weakref = weakref.WeakValueDictionary()
        self._set = set()
        self._fullnameset = set()
        self._changes_count = -1
        self._sorted_set = None

        self.connect("cache_post_open", self._inc_changes_count)
        self.connect("cache_post_change", self._inc_changes_count)
        if memonly:
            # force apt to build its caches in memory
            apt_pkg.config.set("Dir::Cache::pkgcache", "")
        if rootdir:
            rootdir = os.path.abspath(rootdir)
            # clear old config first (Bug#728274)
            apt_pkg.config.clear("APT")
            apt_pkg.config.set("Dir", rootdir)
            apt_pkg.init_config()
            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                apt_pkg.read_config_file(apt_pkg.config,
                                         rootdir + "/etc/apt/apt.conf")
            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                apt_pkg.read_config_dir(apt_pkg.config,
                                        rootdir + "/etc/apt/apt.conf.d")
            apt_pkg.config.set("Dir::State::status",
                               rootdir + "/var/lib/dpkg/status")
            # also set dpkg to the rootdir path so that its called for the
            # --print-foreign-architectures call
            apt_pkg.config.set("Dir::bin::dpkg",
                               os.path.join(rootdir, "usr", "bin", "dpkg"))
            # create required dirs/files when run with special rootdir
            # automatically
            self._check_and_create_required_dirs(rootdir)
            # Call InitSystem so the change to Dir::State::Status is actually
            # recognized (LP: #320665)
            apt_pkg.init_system()
        self.open(progress)
    def get_updatesApt(self, input_data):
        import apt_pkg
        action = input_data['action']
        upgrade_list = []
        skipped_list = []
        upgrade_count = 0
        skipped_count = 0

        apt_pkg.init()

        if os.path.exists("/etc/apt/apt.conf"):
            apt_pkg.read_config_file(apt_pkg.config,
                                     "/etc/apt/apt.conf")
        if os.path.isdir("/etc/apt/apt.conf.d"):
            apt_pkg.read_config_dir(apt_pkg.config,
                                    "/etc/apt/apt.conf.d")
        apt_pkg.init_system()

        cache = apt_pkg.GetCache(None)

        depcache = apt_pkg.GetDepCache(cache)
        depcache.ReadPinFile()
        depcache.Init(None)

        for i in cache.packages:
            if i.current_state is apt_pkg.CURSTATE_INSTALLED:
                if depcache.is_upgradable(i):
                    if depcache.marked_keep(i):
                        skipped_list.append(i.name)
                        skipped_count += 1
                    else:
                        upgrade_list.append(i.name)
                        upgrade_count += 1
        return(retval(0, "Package Update List", {
            "consequences": [
                'attrs.AvailablePackages := %s' % cache.PackageCount,
                'attrs.UpgradablePackageCount := %s' % upgrade_count,
                'attrs.SkippedPackageCount := %s' % skipped_count,
                'attrs.UpgradablePackages := %s' % json.dumps(upgrade_list),
                'attrs.SkippedPackageList := %s' % json.dumps(skipped_list)]}))
Exemple #9
0
    def __init__(self, progress=None, rootdir=None, memonly=False):
        # type: (OpProgress, str, bool) -> None
        self._cache = None  # type: apt_pkg.Cache
        self._depcache = None  # type: apt_pkg.DepCache
        self._records = None  # type: apt_pkg.PackageRecords
        self._list = None  # type: apt_pkg.SourceList
        self._callbacks = {}  # type: Dict[str, List[Callable[..., None]]]
        self._callbacks2 = {
        }  # type: Dict[str, List[Tuple[Callable[..., None], List[Any], Dict[Any,Any]]]]
        self._weakref = weakref.WeakValueDictionary()  # type: ignore
        self._changes_count = -1
        self._sorted_set = None  # type: List[str]

        self.connect("cache_post_open", "_inc_changes_count")
        self.connect("cache_post_change", "_inc_changes_count")
        if memonly:
            # force apt to build its caches in memory
            apt_pkg.config.set("Dir::Cache::pkgcache", "")
        if rootdir:
            rootdir = os.path.abspath(rootdir)
            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                apt_pkg.read_config_file(apt_pkg.config,
                                         rootdir + "/etc/apt/apt.conf")
            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                apt_pkg.read_config_dir(apt_pkg.config,
                                        rootdir + "/etc/apt/apt.conf.d")
            apt_pkg.config.set("Dir", rootdir)
            apt_pkg.config.set("Dir::State::status",
                               rootdir + "/var/lib/dpkg/status")
            # also set dpkg to the rootdir path so that its called for the
            # --print-foreign-architectures call
            apt_pkg.config.set("Dir::bin::dpkg",
                               os.path.join(rootdir, "usr", "bin", "dpkg"))
            # create required dirs/files when run with special rootdir
            # automatically
            self._check_and_create_required_dirs(rootdir)
            # Call InitSystem so the change to Dir::State::Status is actually
            # recognized (LP: #320665)
            apt_pkg.init_system()
        self.open(progress)