/usr/lib/python2.7/dist-packages/loofah/sources.py is in python-loofah 0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | from loofah.utils import tmpfile
from loofah.core import get_sources_uri, db, _get_context
from contextlib import contextmanager
import urllib2
import json
import gzip
@contextmanager
def download_sources():
with tmpfile() as fd:
f = urllib2.urlopen(get_sources_uri())
open(fd, 'w').write(f.read())
yield (fd, _get_context())
@contextmanager
def process_sources():
with download_sources() as info:
fd, suite = info
with tmpfile() as newfd:
f = gzip.open(fd, 'r')
try:
yield (f, suite)
finally:
pass
f.close()
def digest_sources():
sent = None
with process_sources() as info:
fd, suite = info
sent = Sources(suite)
ret = {}
key = None
for line in fd.readlines():
if line.strip() == "":
package = PackageEntry(ret)
sent.add_entry(package)
ret = {}
continue
if line[0] == " ":
if ret[key] != "":
ret[key] += "\n"
ret[key] += line.strip()
else:
line = line.strip()
key, val = line.split(":", 1)
key = key.strip()
ret[key] = val.strip()
return sent
class PackageEntry(dict):
def __init__(self, entry, mangle=True):
if mangle:
entry = self._mangle(entry)
for key in entry:
self[key] = entry[key]
def _mangle(self, entry):
for key in ['Build-Depends', 'Build-Depends-Indep']:
if key in entry:
entry[key] = [
x.split()[0].strip() for x in entry[key].split(",")
]
if 'Uploaders' in entry:
entry['Uploaders'] = [
x.strip() for x in entry['Uploaders'].split(",")
]
if 'Package-List' in entry:
entry['Package-List'] = [
{
"name": y[0],
"type": y[1],
"section": y[2],
"priority": y[3]
} for y in [
x.split() for x in entry['Package-List'].split("\n")
]
]
for key in ["Files", "Checksums-Sha256", "Checksums-Sha1"]:
entry[key] = [
{
"hash": y[0],
"size": y[1],
"file": y[2]
} for y in [x.split() for x in entry[key].split("\n")]
]
return entry
class Sources(dict):
def __init__(self, info):
self.info = info
self.base = "{protocol}{base}".format(**info)
self.suite = info['suite']
self.dist = info['distro']
self.version = info['version']
def add_entry(self, package):
key = package['Package']
self[key] = package
# print "I: New package: %s" % (key)
def get_table(self):
base, suite, dist, version = (
self.base, self.suite, self.dist, self.version
)
table = getattr(getattr(getattr(db, dist), version), suite)
return table
def load(self):
table = self.get_table()
for package in table.find():
self.add_entry(PackageEntry(package))
def save(self):
base, suite, dist, version = (
self.base, self.suite, self.dist, self.version
)
foo = "{dist}/{ver}/{sui}".format(
dist=dist,
ver=version,
sui=suite
)
table = self.get_table()
obj = self.info
obj['_id'] = foo
db.meta.update({"_id": foo}, obj, True, safe=True)
print("Dropping old data")
table.drop()
print("Table dropped, reloading")
for package in self:
obj = self[package]
obj['_id'] = obj['Package']
table.update({"_id": obj['_id']}, obj, True, safe=True)
print("Updated.")
def query(self, query):
table = self.get_table()
for package in table.find(query, timeout=False):
yield package
|