Error while installing debian packages programmitically

Post your Debian questions here.

Error while installing debian packages programmitically

Postby payman » August 12th, 2018, 1:19 pm

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 :

Code: Select all
 #!/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 :



I don't know what is wrong with my script?
payman
 
Posts: 4
Joined: August 12th, 2018, 1:01 pm

Re: Error while installing debian packages programmitically

Postby golinux » August 12th, 2018, 2:00 pm

Why not just use gdebi to install? Does it not like your packages?
May the FORK be with you!
User avatar
golinux
 
Posts: 1117
Joined: July 23rd, 2011, 4:45 pm
Location: not a 'buntard!

Re: Error while installing debian packages programmitically

Postby payman » August 12th, 2018, 2:07 pm

golinux wrote:Why not just use gdebi to install? Does it not like your packages?


Because I need to write a very light customized and simple package manager for an embedded device.
payman
 
Posts: 4
Joined: August 12th, 2018, 1:01 pm

Re: Error while installing debian packages programmitically

Postby CwF » August 13th, 2018, 2:29 pm

...I think you need to scanpackages and create the packages.gz file that details what apt finds at that address? Maybe you did that, didn't mention it, or if other debs in that directory at your http address work with apt....
CwF
 
Posts: 18
Joined: May 19th, 2016, 4:47 pm

Re: Error while installing debian packages programmitically

Postby payman » August 14th, 2018, 5:26 am

CwF wrote:...I think you need to scanpackages and create the packages.gz file that details what apt finds at that address? Maybe you did that, didn't mention it, or if other debs in that directory at your http address work with apt....


Yes, I've created Packages.gz file and as I mentioned, using command line (apt-get install) the packages will be installed successfully, it is installation from script that causes the error.
payman
 
Posts: 4
Joined: August 12th, 2018, 1:01 pm


Return to General Questions

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests

cron

x