-
Notifications
You must be signed in to change notification settings - Fork 0
/
AptRepository.py
67 lines (51 loc) · 2.11 KB
/
AptRepository.py
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
import re
import subprocess
from mx.Tools import verscmp
class AptRepository:
path = None
def __init__( self, path ):
self.path = path
def Include( self, distribution, changesfile, component=None ):
print "### Including %s" % changesfile
c = subprocess.Popen(
["reprepro"] +
["--waitforlock", "12"] +
(["--component", component] if component else []) +
["--basedir", self.path] +
["include", distribution , changesfile]
)
c.wait()
if c.returncode:
raise "Process exit with code: %s" % c.returncode
def Exists( self, distribution, architecture, sourcename, version, component=None ):
arch_filter = "Architecture (==%s)," % architecture if architecture else ""
# for packages that were part
pkg_filter = [
"(%s Source (==%s))" % (arch_filter,sourcename),
"(%s !Source,Package(==%s))" % (arch_filter,sourcename)
]
pkg_filter = "|".join(pkg_filter)
print pkg_filter
c = subprocess.Popen(
["reprepro"] +
["--waitforlock", "12"] +
["--basedir", self.path] +
(["--architecture", architecture] if architecture else []) +
(["--component", component ] if component else []) +
["listfilter", distribution , pkg_filter ],
stdout=subprocess.PIPE)
output = c.communicate()[0]
if c.returncode:
raise "Process exit with code: %s" % c.returncode
for match in _regex_parse_list.finditer(output):
if verscmp(match.group("version"), version) >= 0:
print version
return True
return False
_regex_parse_list = re.compile(
"^" +
"(?P<distribution> [-+.a-z0-9]+ ) \| " +
"(?P<section> [-+.a-z0-9]+ ) \| " +
"(?P<architecture> [-+.a-z0-9]+ ): \s+ " +
"(?P<package> [-+.a-z0-9]+ ) \s+" +
"(?P<version> [-+.a-z0-9]+ )$", re.X | re.M | re.I )