Skip to content

Commit

Permalink
scripts
Browse files Browse the repository at this point in the history
git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@635 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
prescience committed Jan 14, 2002
1 parent 8c5ed03 commit 34b22f7
Show file tree
Hide file tree
Showing 9 changed files with 1,185 additions and 0 deletions.
70 changes: 70 additions & 0 deletions py_config_doc_check.py
@@ -0,0 +1,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 "----------------------------------"
120 changes: 120 additions & 0 deletions py_lang_check.py
@@ -0,0 +1,120 @@
# /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

# --- ------
def gather_lang_strings( p_lang_file ):
global lang_strings

lang_file = open( p_lang_file )
lang_lines = lang_file.readlines()
lang_file.close()

for i in lang_lines:
lang_string = process_string( i )
if ( len( lang_string ) > 0 ):
lang_strings[lang_string] = 1
# --- ------
def gather_php_strings( p_php_file ):
global php_strings

php_file = open( p_php_file )
php_lines = php_file.readlines()
php_file.close()

for i in php_lines:
p_string = translate( i, maketrans( "()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if ( found( a, "$s_" ) ):
php_strings[a] = 1
# --- ------
def found( p_string, p_sub_str ):
if ( -1 != find( p_string, p_sub_str ) ):
return 1
else:
return 0
# --- ------
def remove_used_strings():
global string_count_list

keys = string_count_list.keys()
keys.sort()
for i in keys:
if ( string_count_list[i] > 0 ):
del( string_count_list[i] )

# --- ------
def process_string( p_string ):
p_string = translate( p_string, maketrans( "()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if ( -1 != find( a, "$s_" ) ):
return a
return ""
# --- ------
def process_string_file( p_lang_file ):
global lang_strings, php_strings

lang_keys = lang_strings.keys()
lang_keys.sort()
php_keys = php_strings.keys()
php_keys.sort()

lang_file = open( p_lang_file )
lang_lines = lang_file.readlines()
lang_file.close()
lang_file = open( p_lang_file+".new", "w" )
for i in lang_lines:
lang_string = process_string( i )
if ( len( lang_string ) > 0 ):
if ( lang_string not in php_keys ):
#print lang_string
continue
lang_file.write( i )
lang_file.close()
# --- ------
def init():
global lang_file_list, php_file_list, lang_dir

php_directory = ".";
if ( len(sys.argv) < 2 ):
php_file_list = os.listdir( php_directory )
elif ( 2 == len(sys.argv) ):
php_file_list.append( sys.argv[1] )
else:
print "ERROR in program arguments"
sys.exit(1)

lang_file_list = os.listdir( lang_dir )
# --- ------

# ===========================
# MAIN
# ===========================
lang_dir = "/home/www/mantis/lang/"
lang_file_list = []
php_file_list = []

php_strings = {}
lang_strings = {}
# --- ------

init()
print "Pre Processing Files"
for php_file in php_file_list:
if ( found( php_file, ".php" ) ):
gather_php_strings( php_file )

#lang_file_list = ["strings_english.txt"]
for lang_file in lang_file_list:
lang_strings = {}
if ( found( lang_file, ".txt" ) ):
print "Processing File: "+lang_file
gather_lang_strings( lang_dir+lang_file )
process_string_file( lang_dir+lang_file )
83 changes: 83 additions & 0 deletions py_lang_check_duplicates.py
@@ -0,0 +1,83 @@
# /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

# --- ------
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()

lang_file = open( p_lang_file+".new", "w" )
for i in lang_lines:
lang_string = process_string( i )
if ( len( lang_string ) > 0 ):
if ( 1 == lang_strings.has_key( lang_string ) ):
print "DUPLICATE: "+lang_string
found_duplicates = 1
continue
lang_strings[lang_string] = 1
match_found = 1
lang_file.write( i )
lang_file.close()

# if there are no duplcaites then remove the .new file
if ( 0 == found_duplicates ):
os.system( 'rm ' + p_lang_file+".new" )
# --- ------
def found( p_string, p_sub_str ):
if ( -1 != find( p_string, p_sub_str ) ):
return 1
else:
return 0
# --- ------
def remove_used_strings():
global string_count_list

keys = string_count_list.keys()
keys.sort()
for i in keys:
if ( string_count_list[i] > 0 ):
del( string_count_list[i] )

# --- ------
# GOOD
def process_string( p_string ):
p_string = translate( p_string, maketrans( "()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if ( -1 != find( a, "$s_" ) ):
return a
return ""
# --- ------
def init():
global lang_file_list, lang_dir

lang_file_list = os.listdir( lang_dir )
lang_file_list.sort()
# --- ------

# ===========================
# MAIN
# ===========================
lang_dir = "/home/www/mantis/lang/"
lang_file_list = []
lang_strings = {}
found_duplicates = 0
# --- ------

init()
#lang_file_list = ["strings_english.txt"]
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 )
92 changes: 92 additions & 0 deletions py_lang_check_missing.py
@@ -0,0 +1,92 @@
# /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

# --- ------
def gather_english_strings( p_lang_file ):
global english_strings

lang_file = open( p_lang_file )
english_strings = lang_file.readlines()
lang_file.close()
# --- ------
def process_lang_strings( p_lang_file ):
global lang_strings, english_strings

lang_file = open( p_lang_file )
lang_lines = lang_file.readlines()
lang_file.close()

for i in lang_lines:
string_key = process_string( i )
if ( len( string_key ) > 0 ):
lang_strings[string_key] = i

lang_file = open( p_lang_file+".new", "w" )

# print header part
for i in lang_lines:
if ( found( i, "?>" ) ):
break
lang_file.write( i )

header = 0;
for i in english_strings:
if ( 0 == header ):
if ( found( i, "?>" ) ):
lang_file.write( i )
header = 1
continue
else:
string_key = process_string( i )
if (( len( string_key ) > 0 )&( lang_strings.has_key( string_key ) )):
lang_file.write( lang_strings[string_key] )
else:
lang_file.write( i )

lang_file.close()
# --- ------
def found( p_string, p_sub_str ):
if ( -1 != find( p_string, p_sub_str ) ):
return 1
else:
return 0
# --- ------
# GOOD
def process_string( p_string ):
p_string = translate( p_string, maketrans( "()\\;<>:\".,", " " ) )
words = split( p_string )
for a in words:
if ( -1 != find( a, "$s_" ) ):
return a
return ""
# --- ------
def init():
global lang_file_list, lang_dir

lang_file_list = os.listdir( lang_dir )
lang_file_list.sort()
# --- ------

# ===========================
# MAIN
# ===========================
lang_dir = "/home/www/mantis/lang/"
lang_file_list = []
lang_strings = {}
english_strings = {}
# --- ------

init()
print "Loading: strings_english.txt"
gather_english_strings( lang_dir+"strings_english.txt" )
for lang_file in lang_file_list:
lang_strings = {}
if (( not found( lang_file, "english" ) )&( found( lang_file, "txt" ) )):
print "Processing: "+lang_file
process_lang_strings( lang_dir+lang_file )
23 changes: 23 additions & 0 deletions py_line_length.py
@@ -0,0 +1,23 @@
# /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

directory = ".";
if ( len(sys.argv) < 1 ):
directory = sys.argv[1]

dirlist = os.listdir( directory )
file_count = len( dirlist )

print "Checking filename length (over 32 characters)."
print "Checking "+str( file_count )+" files:\n"
for a in dirlist:
if ( len( a ) > 32 ):
print a+"\n"

print "\nFinished checking files.\n"

0 comments on commit 34b22f7

Please sign in to comment.