Форум сайта python.su
Ребят, написал небольшой скрипт установки dockera и необходимый софт для его работы.
Проблема вот в чем. После добавления репозитория Докера в sources.list пытаюсь выполнить обновление (cache.update()) и проверяю повился ли после добавления репозитория в кэше пакетов докер (cache).
Пакет docker-ce не появился и выполнение скрипта оканчивается следующей ошибкой:
root@jessie:/home/vagrant# python3 /vagrant/py_deploy_isim_test.py
apt-transport-https is installed
ca-certificates is installed
curl is installed
software-properties-common is installed
OK
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apt/cache.py", line 201, in __getitem__
return self._weakref[key]
File "/usr/lib/python3.4/weakref.py", line 125, in __getitem__
o = self.data[key]()
KeyError: 'docker-ce'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/vagrant/py_deploy_isim_test.py", line 15, in <module>
pkg = cache[pkg_name]
File "/usr/lib/python3/dist-packages/apt/cache.py", line 208, in __getitem__
raise KeyError('The cache has no package named %r' % key)
KeyError: "The cache has no package named 'docker-ce'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apt/cache.py", line 201, in __getitem__
return self._weakref[key]
File "/usr/lib/python3.4/weakref.py", line 125, in __getitem__
o = self.data[key]()
KeyError: 'docker-ce'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/vagrant/py_deploy_isim_test.py", line 40, in <module>
pkg = cache[pkg_name]
File "/usr/lib/python3/dist-packages/apt/cache.py", line 208, in __getitem__
raise KeyError('The cache has no package named %r' % key)
KeyError: "The cache has no package named 'docker-ce'"
#!/usr/bin/python3 import requests import subprocess import apt import aptsources.sourceslist pkg_list = ['apt-transport-https','ca-certificates','curl','software-properties-common','docker-ce'] cache = apt.cache.Cache() cache.update() for pkg_name in pkg_list: try: pkg = cache[pkg_name] if pkg.is_installed: print('{0} is installed'.format(pkg_name)) else: pkg.mark_install() # try: cache.commit() except KeyError: if pkg_name == 'docker-ce': key = requests.get('https://download.docker.com/linux/debian/gpg') with open('d_key', 'wb') as d_key: d_key.write(key.content) d_key.close() # find method in apt lib subprocess.call(['apt-key', 'add', 'd_key']) # Add debian backports repository to sourcelist src_list = aptsources.sourceslist.SourcesList() src_list.add(type='deb', uri='http://ftp.debian.org/debian', dist='jessie-backports', orig_comps=['main'], comment="", pos=-1, file='/etc/apt/sources.list') # Add docker repository to sourcelist src_list.add(type='deb', uri='https://download.docker.com/linux/debian', dist='jessie', orig_comps=['stable'], comment="", pos=-1, file='/etc/apt/sources.list') src_list.save() cache.update() pkg = cache[pkg_name] print("INFO: Begin Docker instalation...") # before install apt-https pkg.mark_install() cache.commit()
Отредактировано grandfa8 (Март 30, 2017 16:20:43)
Офлайн
grandfa8Эта строка неправильная, это должен быть комментарий питона.!/usr/bin/python3
Офлайн
py.user.nextСюда криво скопировал, поправил, извиняюсь
Отредактировано grandfa8 (Март 30, 2017 16:21:34)
Офлайн
grandfa8Не надо вызывать close(), with его сам вызывает.with open('d_key', 'wb') as d_key: d_key.write(key.content) d_key.close()
grandfa8Попробуй добавить
Как сделать так чтобы cache.update() увидел обновленный sources.list?
cache.open(None)
cache.update()
Офлайн
py.user.next после последнего
cache.update()
cache.open(None)
Отредактировано grandfa8 (Март 31, 2017 14:40:14)
Офлайн
Всем привет! Дурачился в ipython пытаясь разрешить свою ситуацию в итоге вот такое получилось:
#!/usr/bin/env python3.4 import requests import subprocess import apt import aptsources.sourceslist import time pkg_list = ['ca-certificates', 'curl', 'software-properties-common', 'docker-ce'] cache = apt.cache.Cache() for pkg_name in pkg_list: try: pkg = cache[pkg_name] if pkg.is_installed: print('{0} is installed'.format(pkg_name)) else: pkg.mark_install() cache.commit() except KeyError: if pkg_name == 'docker-ce': key = requests.get('https://download.docker.com/linux/debian/gpg') with open('d_key', 'wb') as d_key: d_key.write(key.content) # find method in apt lib subprocess.call(['apt-key', 'add', 'd_key']) src_list = aptsources.sourceslist.SourcesList() src_list.add(type='deb', uri='http://ftp.debian.org/debian', dist='jessie-backports', orig_comps=['main'], comment="", pos=-1, file='/etc/apt/sources.list') src_list.add(type='deb', uri='https://download.docker.com/linux/debian', dist='jessie', orig_comps=['stable'], comment="", pos=-1, file='/etc/apt/sources.list') src_list.save() cache.update() cache.open(None) cache.update() cache.open(None) pkg = cache[pkg_name] print("INFO: Begin Docker instalation...") # before install apt-https pkg.mark_install() cache.commit()
cache.update() cache.open(None)
Отредактировано grandfa8 (Апрель 2, 2017 14:56:50)
Офлайн