-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpy_lang_check_duplicates.py
executable file
·60 lines (53 loc) · 1.42 KB
/
py_lang_check_duplicates.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
#!/usr/bin/env python
# This reports duplicate strings
import sys
from string import *
import os
# --- ------
def process_lang_strings( p_lang_file ):
global lang_strings, found_duplicates
lang_file = open( p_lang_file )
lang_lines = lang_file.readlines()
lang_file.close()
# reports duplicates for each file
line_number = 0;
for i in lang_lines:
line_number = line_number+1
lang_string = process_string( i )
if ( len( lang_string ) > 0 ):
if ( 1 == lang_strings.has_key( lang_string ) ):
print "DUPLICATE: "+lang_string+" (line #"+str(line_number)+")"
found_duplicates = 1
continue
lang_strings[lang_string] = 1
match_found = 1
# --- ------
def found( p_string, p_sub_str ):
if ( -1 != find( p_string, p_sub_str ) ):
return 1
else:
return 0
# --- ------
def process_string( p_string ):
p_string = translate( p_string, maketrans( "()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if ( -1 != find( a, "$" ) ):
return a
return ""
# --- ------
# ===========================
# MAIN
# ===========================
lang_dir = os.getcwd()
lang_strings = {}
found_duplicates = 0
lang_file_list = os.listdir( lang_dir )
lang_file_list.sort()
print "Checking for Duplicates"
for lang_file in lang_file_list:
lang_strings = {}
found_duplicates = 0
if ( found( lang_file, ".txt" ) ):
print "Processing: "+lang_file
process_lang_strings( lang_dir+"\\"+lang_file )