-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest-rpmbuild-regression.py
87 lines (77 loc) · 2.46 KB
/
test-rpmbuild-regression.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright (C) 2012 Red Hat, Inc.
# Authors: Jan Kaluza <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import os
import sys
import errno
from subprocess import Popen, PIPE
import mimetypes
import difflib
from pyfile import *
import re
mimetypes.init()
detected = []
undetected = []
def test_attr(attr):
global detected
global undetected
regex = None
path = None
f = open(attr)
for line in f.readlines():
if len(line.split()) != 0 and line.split()[0].endswith("_magic"):
regex = line[line.find("_magic") + 6:].strip()
regex = regex.replace("(", "\\(")
regex = regex.replace(")", "\\)")
regex = regex.replace("|", "\\|")
regex = regex.replace("?", "\\?")
l = line.split()[0]
if l.find("perl") != -1:
path = "./db/pl"
elif l.find("python") != -1:
path = "./db/py"
elif l.find("elf") != -1:
path = "./db/elf"
elif l.find("mono") != -1:
path = "./db/mono"
break
f.close()
if regex and path:
for f in os.listdir(path):
if f.endswith("json"):
continue
full_path = os.path.join(path, f)
output = get_simple_metadata(full_path)['output']
#print regex, [output]
p1 = Popen(["echo", "-n", output[:-1]], stdout=PIPE)
p2 = Popen(["grep", regex], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close()
output = p2.communicate()[0]
if len(output) == 0 and not full_path in detected:
if not full_path in undetected:
undetected.append(full_path)
elif not full_path in detected:
if full_path in undetected:
undetected.remove(full_path)
detected.append(full_path)
# run this only if started as script from command line
if __name__ == '__main__':
for attr in os.listdir("./rpm-fileattrs"):
test_attr(os.path.join("./rpm-fileattrs", attr))
print "Undetected:", undetected
#metadata = get_simple_metadata(sys.argv[1])
#print metadata