I've built some debian packages and put them on my host. I want to install these packages in a python script. So I've written the install function using apt_pkg as follows :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import apt 
import apt_pkg
import sys
class my_pkg_manager:
    def __init__(self):
        apt_pkg.init()
        self.cache = apt_pkg.Cache()
        self.sources = apt_pkg.SourceList()
        self.pkg_records = apt_pkg.PackageRecords(self.cache)
        self.depcache = apt_pkg.DepCache(self.cache)
        self.pkg_manager = apt_pkg.PackageManager(self.depcache)
        self.fetcher = apt_pkg.Acquire()
    def find_my_package(self):
        for pkg in self.cache.packages:
            if len(pkg.version_list)>0:
                package_site = pkg.version_list[0].file_list[0][0].site
                if package_site == 'my_host_address.com':
            if pkg.name == 'my_pkg_name':
            return pkg
        return None
    def install_package(self, pkg):
        self.depcache.mark_install(pkg)
        self.sources.read_main_list()
        self.pkg_manager.get_archives(self.fetcher, self.sources,
                                      self.pkg_records)
        log_file = open('install_log','w')
        res = self.pkg_manager.do_install(log_file.fileno())
        if res == self.pkg_manager.RESULT_COMPLETED:
            print('result completed!')
        elif res == self.pkg_manager.RESULT_INCOMPLETE:
            print('result incomplete!')
        else:
            print('result failed!')
    def run(self):
        my_pkg = self.find_my_package()
        if my_pkg != None:
            self.install_package(my_pkg)
        else:
            print('Can't find package!') 
if __name__ == '__main__':
    my_package_manager =  my_pkg_manager()
    my_package_manager.run()
If I use apt-get install, packages will be installed without any problem, but with this script the following error occurs :
res = self.pkg_manager.do_install(log_file.fileno()) apt_pkg.Error: E:Internal Error, Pathname to install is not absolute 'myPackage_1.0.0_all.deb'
I've placed .deb file and Packages.gz in a directory named 'debian' in my host and added the following line to my sources.list :
deb http://my_host_address.com debian/
I don't know what is wrong with my script?
deb http://my_host_address.com debian/
should be:
deb http://my_host_address.com /debian/
Absolute path needs to start with a slash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With