2
2
# -*- coding: utf-8 -*-
3
3
4
4
"""
5
- Copyright (c) 2014-2015 pocsuite developers (http://sebug.net )
5
+ Copyright (c) 2014-2015 pocsuite developers (http://seebug.org )
6
6
See the file 'docs/COPYING' for copying permission
7
7
"""
8
8
9
+ import re
10
+ from pocsuite .lib .core .data import kb
11
+ from pocsuite .lib .core .data import conf
9
12
from pocsuite .lib .core .data import logger
10
13
from pocsuite .lib .core .enums import CUSTOM_LOGGING
11
14
from pocsuite .lib .core .settings import POC_ATTRS
15
+ from pocsuite .lib .core .settings import POC_REQUIRES_REGEX
12
16
from pocsuite .lib .core .settings import OLD_VERSION_CHARACTER
13
- from pocsuite .lib .core .data import kb
17
+
18
+
19
+ def requiresCheck ():
20
+ if not conf .requires :
21
+ return
22
+
23
+ requires_regex = re .compile (POC_REQUIRES_REGEX )
24
+ install_requires = []
25
+ for _ , poc in kb .pocs .items ():
26
+ try :
27
+ requires = requires_regex .search (poc ).group (1 )
28
+ install_requires += [require [1 :- 1 ] for require in requires .split ("," )]
29
+ except Exception , ex :
30
+ pass
31
+
32
+ infoMsg = "install_requires:\n " + "\n " .join (install_requires )
33
+ logger .log (CUSTOM_LOGGING .SYSINFO , infoMsg )
14
34
15
35
16
36
def pocViolation ():
17
37
violation = False
18
- for pocname , pocInstance in kb .registeredPocs .items ():
38
+ if conf .requiresFreeze :
39
+ install_requires = []
40
+ for pocName , pocInstance in kb .registeredPocs .items ():
41
+ if isinstance (pocInstance , dict ):
42
+ continue
43
+ requires = getRequires (pocName , pocInstance )
44
+ if not requires :
45
+ continue
46
+ install_requires += list (requires )
47
+ infoMsg = "install_requires:\n " + "\n " .join (install_requires )
48
+ logger .log (CUSTOM_LOGGING .SYSINFO , infoMsg )
49
+ return
50
+
51
+ for pocName , pocInstance in kb .registeredPocs .items ():
19
52
if isinstance (pocInstance , dict ):
20
- violation = checkJsonInfo (pocname , pocInstance )
53
+ violation = checkJsonInfo (pocName , pocInstance )
21
54
else :
22
- violation = checkPocInfo (pocname , pocInstance )
55
+ violation = checkPocInfo (pocName , pocInstance )
23
56
return violation
24
57
25
58
26
- def checkJsonInfo (pocname , pocInstance ):
59
+ def checkJsonInfo (pocName , pocInstance ):
27
60
infos = []
28
- infoMsg = "checking %s" % pocname
61
+ infoMsg = "checking %s" % pocName
29
62
logger .log (CUSTOM_LOGGING .SYSINFO , infoMsg )
30
63
if 'pocInfo' in pocInstance :
31
64
for attr in POC_ATTRS :
32
65
if attr in pocInstance ['pocInfo' ] and pocInstance ['pocInfo' ].get (attr ):
33
66
continue
34
67
infos .append (attr )
35
68
if infos :
36
- warnMsg = "missing %s in %s" % (infos , pocname )
69
+ warnMsg = "missing %s in %s" % (infos , pocName )
37
70
logger .log (CUSTOM_LOGGING .WARNING , warnMsg )
38
71
return False
39
72
return True
40
73
41
74
42
- def checkPocInfo (pocname , pocInstance ):
75
+ def checkPocInfo (pocName , pocInstance ):
43
76
infos = []
44
- infoMsg = "checking %s" % pocname
77
+ infoMsg = "checking %s" % pocName
45
78
logger .log (CUSTOM_LOGGING .SYSINFO , infoMsg )
46
79
for attr in POC_ATTRS :
47
80
if hasattr (pocInstance , attr ) and getattr (pocInstance , attr ):
48
81
continue
49
82
infos .append (attr )
50
83
if infos :
51
- warnMsg = "missing %s in %s" % (infos , pocname )
84
+ warnMsg = "missing %s in %s" % (infos , pocName )
52
85
logger .log (CUSTOM_LOGGING .WARNING , warnMsg )
53
86
return False
54
87
return True
@@ -59,3 +92,8 @@ def isOldVersionPoc(poc):
59
92
if _ not in poc :
60
93
return False
61
94
return True
95
+
96
+
97
+ def getRequires (pocName , pocInstance ):
98
+ if hasattr (pocInstance , "install_requires" ):
99
+ return getattr (pocInstance , "install_requires" )
0 commit comments