Merge lp:~oheoh/command-not-found/command-not-found into lp:command-not-found

Proposed by Raphael Kienhöfer on 2020-04-27
Status: Needs review
Proposed branch: lp:~oheoh/command-not-found/command-not-found
Merge into: lp:command-not-found
Diff against target: 46 lines (+16/-1)
2 files modified
CommandNotFound/db/creator.py (+15/-1)
debian/control (+1/-0)
To merge this branch: bzr merge lp:~oheoh/command-not-found/command-not-found
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team 2020-04-27 Pending
Review via email: mp+383023@code.launchpad.net

Commit message

db creator: Add handling for lz4-compressed command lists from apt

Description of the change

Measures were put in place for command-not-found to not need python3-lz4 (universe) to be installed to work, it only is required if one wants to process lz4-compressed apt command lists.

Testing:
- enable apt index compression:
   /etc/apt/apt.conf.d/02compress-indexes:
    Acquire::GzipIndexes "true";
    Acquire::CompressionTypes::Order { "xz"; "gz"; };
    Acquire::Languages { "none"; };
- delete cnf DBs if they already exist
   rm /var/lib/command-not-found/*
- run apt update
- command lists in ls /var/lib/apt/lists/*Commands-* now are lz4-compressed
- command-not-found still works as intended

To post a comment you must log in.

Unmerged revisions

279. By Raphael Kienhöfer on 2020-04-27

db creator: Add handling for lz4-compressed command lists from apt

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CommandNotFound/db/creator.py'
2--- CommandNotFound/db/creator.py 2018-03-20 11:31:18 +0000
3+++ CommandNotFound/db/creator.py 2020-04-27 20:57:40 +0000
4@@ -6,8 +6,15 @@
5 import os
6 import sqlite3
7 import sys
8+import tempfile
9 import time
10
11+try:
12+ import lz4.frame
13+ lz4_supported = True
14+except ModuleNotFoundError:
15+ lz4_supported = False
16+
17 import apt_pkg
18 apt_pkg.init()
19
20@@ -123,7 +130,14 @@
21 return meta
22 def _fill_commands(self, con):
23 for f in self.files:
24- with open(f) as fp:
25+ if f.endswith(".lz4"):
26+ if not lz4_supported: continue
27+ fp = tempfile.TemporaryFile()
28+ with open(f, "rb") as c:
29+ fp.write(lz4.frame.decompress(c.read()))
30+ fp.seek(0, 0)
31+ else: fp = open(f)
32+ with fp:
33 self._parse_single_commands_file(con, fp)
34 self.stats["total_time"] = time.time() - self.stats["total_time"]
35 logging.info("processed %i packages in %.2fs" % (
36
37=== modified file 'debian/control'
38--- debian/control 2018-04-13 15:06:55 +0000
39+++ debian/control 2020-04-27 20:57:40 +0000
40@@ -40,5 +40,6 @@
41 python3-gdbm,
42 ${misc:Depends},
43 ${python3:Depends}
44+Recommends: python3-lz4
45 Description: Python 3 bindings for command-not-found.
46 This package will install the Python 3 library for command_not_found tool.

Subscribers

People subscribed via source and target branches