-
Notifications
You must be signed in to change notification settings - Fork 7
/
py_config_doc_check.py
executable file
·70 lines (60 loc) · 1.72 KB
/
py_config_doc_check.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
#!/usr/bin/env python
# This file checkes the filename lengths of all files in a directory.
# Any files over 32 characters in length must be shortened.
import sys
from string import *
import os
# --- ------
# GOOD
def process_string( p_string ):
p_string = translate( p_string, maketrans( "#()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if (( -1 != find( a, "$g_" ) )&
( -1 == find( p_string, "$HTTP_COOKIE_VARS" ) )&
( -1 == find( p_string, "_include_" ) )&
( -1 == find( p_string, "_path" ) )):
return a
return ""
# --- ------
# ===========================
# MAIN
# ===========================
config_file = "/home/www/mantis/config_inc.php"
config_doc_file = "/home/www/mantis/doc/configuration.html"
config_list = []
config_doc_list = []
config_strings = {}
config_doc_strings = {}
# open config file
file = open( config_file )
config_list = file.readlines()
file.close()
# populate dictionary
for i in config_list:
string_key = process_string( i )
if ( len( string_key ) > 0 ):
config_strings[string_key] = 1
# open config doc file
file = open( config_doc_file )
config_doc_list = file.readlines()
file.close()
# populate dictionary
for i in config_doc_list:
string_key = process_string( i )
if ( len( string_key ) > 0 ):
config_doc_strings[string_key] = 1
# check for missing
config_keys = config_strings.keys()
config_keys.sort()
for i in config_keys:
if ( not config_doc_strings.has_key( i ) ):
print "Missing: "+i
print "----------------------------------"
# check for unused
config_doc_keys = config_doc_strings.keys()
config_doc_keys.sort()
for i in config_doc_keys:
if ( not config_strings.has_key( i ) ):
print "Unused: "+i
print "----------------------------------"