-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_aptcache_usage' into 'master'
Create class AptCache - This class uses the apt.Cache, but verify if the package exists on xapian See merge request !36
- Loading branch information
Showing
10 changed files
with
57 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
|
||
import apt | ||
import xapian | ||
|
||
|
||
class AptCache: | ||
|
||
DEFAULT_AXI_PATH = "/var/lib/apt-xapian-index/index" | ||
|
||
def __init__(self): | ||
self.axi = xapian.Database(AptCache.DEFAULT_AXI_PATH) | ||
|
||
self.cache = apt.Cache() | ||
|
||
def __getitem__(self, pkg_name): | ||
return self.get(pkg_name) | ||
|
||
def __contains__(self, pkg_name): | ||
return self.xapian_has_pkg(pkg_name) and pkg_name in self.cache | ||
|
||
def get(self, pkg_name): | ||
if self.xapian_has_pkg(pkg_name): | ||
return self.cache[pkg_name] | ||
|
||
raise KeyError("The cache has no package named '{}'".format(pkg_name)) | ||
|
||
def xapian_has_pkg(self, pkg_name): | ||
term = 'XP' + pkg_name | ||
return self.axi.get_termfreq(term) > 0L |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters