Ubuntu Pastebin

Paste from sergiusens at Tue, 3 May 2016 21:17:02 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import apt
import glob
import os.path
import tempfile


def _get_local_sources_list():
    sources_list = glob.glob('/etc/apt/sources.list.d/*.list')
    sources_list.append('/etc/apt/sources.list')

    sources = ''
    for source in sources_list:
        with open(source) as f:
            sources += f.read()

    return sources


rootdir = tempfile.mkdtemp()
sources = _get_local_sources_list()

os.makedirs(os.path.join(rootdir, 'etc', 'apt'), exist_ok=True)
srcfile = os.path.join(rootdir, 'etc', 'apt', 'sources.list')
with open(srcfile, 'w') as f:
    f.write(sources)

# Do not install recommends
apt.apt_pkg.config.set('Apt::Install-Recommends', 'False')

for key in 'Dir::Etc::Trusted', 'Dir::Etc::TrustedParts':
    apt.apt_pkg.config.set(key, apt.apt_pkg.config.find_file(key))

apt_cache = apt.Cache(rootdir=rootdir, memonly=True)

apt.apt_pkg.config.clear("APT::Update::Post-Invoke-Success")
progress = apt.progress.text.AcquireProgress()
apt_cache.update(sources_list=srcfile, fetch_progress=progress)
apt_cache.open()

apt_cache['wget'].mark_install()

downloaddir = tempfile.mkdtemp()
apt.apt_pkg.config.set("Dir::Cache::Archives", downloaddir)
apt_cache.fetch_archives(progress=progress)
Download as text