10

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?

payman
  • 300
  • 2
  • 15

1 Answers1

5

deb http://my_host_address.com debian/

should be:

deb http://my_host_address.com /debian/

Absolute path needs to start with a slash.

  • I've tried your solution and it doesn't work for me. – payman Aug 19 '18 at 05:09
  • @payman Sorry about that. Can you look at [this](https://askubuntu.com/questions/458748/is-it-possible-to-add-a-location-folder-on-my-hard-disk-to-sources-list)? It looks like you're editing sources.list wrong or I'm misunderstanding. – Jack Strosahl Aug 20 '18 at 16:24