From 34b22f7395baa35546e309783b04b45200206784 Mon Sep 17 00:00:00 2001 From: prescience Date: Mon, 14 Jan 2002 02:10:45 +0000 Subject: [PATCH] scripts git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@635 f5dc347c-c33d-0410-90a0-b07cc1902cb9 --- py_config_doc_check.py | 70 ++++++++++ py_lang_check.py | 120 ++++++++++++++++ py_lang_check_duplicates.py | 83 +++++++++++ py_lang_check_missing.py | 92 ++++++++++++ py_line_length.py | 23 +++ py_lineterm.py | 244 ++++++++++++++++++++++++++++++++ py_php_lint.py | 205 +++++++++++++++++++++++++++ py_release.py | 272 ++++++++++++++++++++++++++++++++++++ py_release_check.py | 76 ++++++++++ 9 files changed, 1185 insertions(+) create mode 100755 py_config_doc_check.py create mode 100755 py_lang_check.py create mode 100755 py_lang_check_duplicates.py create mode 100755 py_lang_check_missing.py create mode 100755 py_line_length.py create mode 100755 py_lineterm.py create mode 100755 py_php_lint.py create mode 100755 py_release.py create mode 100755 py_release_check.py diff --git a/py_config_doc_check.py b/py_config_doc_check.py new file mode 100755 index 0000000..3ced460 --- /dev/null +++ b/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 "----------------------------------" \ No newline at end of file diff --git a/py_lang_check.py b/py_lang_check.py new file mode 100755 index 0000000..3586d0c --- /dev/null +++ b/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 ) \ No newline at end of file diff --git a/py_lang_check_duplicates.py b/py_lang_check_duplicates.py new file mode 100755 index 0000000..d5df0b6 --- /dev/null +++ b/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 ) diff --git a/py_lang_check_missing.py b/py_lang_check_missing.py new file mode 100755 index 0000000..145bd6e --- /dev/null +++ b/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 ) diff --git a/py_line_length.py b/py_line_length.py new file mode 100755 index 0000000..4c48298 --- /dev/null +++ b/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" diff --git a/py_lineterm.py b/py_lineterm.py new file mode 100755 index 0000000..2d2fcb6 --- /dev/null +++ b/py_lineterm.py @@ -0,0 +1,244 @@ +#!/usr/local/bin/python +# +# lineterm.py +# +# +# +# Usage: python lineterm.py [options] files +# +# Options: +# -h, --help : Show this message +# -m, --mac : Convert file(s) to Mac format (carriage returns) +# -p, --pc : Convert file(s) to PC format (carriage return/linefeeds) +# -u, --unix : Convert file(s) to Unix format (linefeeds) +# -v, --verbose : Show the number of CRs, LFs, and CR/LFs for the file(s) +# +# Arguments: +# files : any file or group of files (wildcards allowed) +# +# Note: +# Does not currently recurse directories or distinguish between +# binary and ASCII file types. Creates a ~temp file in the current +# directory when converting files to a different format. +# + +import os, getopt, sys, curses + +def main(): + convertToMac = 0 + convertToPC = 0 + convertToUNIX = 0 + isVerbose = 0 + + try: + opts, args = getopt.getopt( sys.argv[1:], "hmpuv:", ["help", "mac", "pc", "unix", "verbose"] ) + + except getopt.GetoptError: + # print help information and exit: + usage() + sys.exit( 2 ) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + sys.exit() + if o in ("-m", "--mac"): + # print "output reached" + # output = a + convertToMac = 1 + if o in ("-p", "--pc"): + convertToPC = 1 + if o in ("-u", "--unix"): + convertToUNIX = 1 + if o in ("-v", "--verbose"): + isVerbose = 1 + + if len(args) == 0: + usage() + sys.exit() + + for FILE in args: + fileType = readFile( FILE, isVerbose ) + if fileType != "Undefined": + if convertToMac == 1: + toMac( FILE, fileType ) + if convertToPC == 1: + toPC( FILE, fileType ) + if convertToUNIX == 1: + toUNIX( FILE, fileType ) + else: + print "file " + print FILE + print " is undefined, therefore conversion was aborted" + +def toMac( fileName, fileType ): + FILE = open( fileName, "r" ) + + os.system( "touch ~temp" ) + OUTFILE = open( "~temp", "w" ) + + char = FILE.read( 1 ) + last = 0; + + while char: + if fileType == "UNIX": + if char == chr(0x0a): # LINE FEED + OUTFILE.write( chr(0x0d) ) # replace LF with CR + else: + OUTFILE.write( char ) + elif fileType == "MAC": + OUTFILE.write( char ) # file already in mac format + elif fileType == "PC": + if last == chr(0x0a): # if last character was CR + if char == chr(0x0d): # ...and this one is LF + OUTFILE.write( chr(0x0d) ) # then replace CR/LF with CR + elif char == chr(0x0a): + last = chr(0x0a); + else: + OUTFILE.write( char ) + char = FILE.read( 1 ) + + + FILE.close() + OUTFILE.close() + os.system( "mv ~temp " + fileName + ".MAC" ) + + print "MAC" + + +def toPC( fileName, fileType ): + FILE = open( fileName, "r" ) + + os.system( "touch ~temp" ) + OUTFILE = open( "~temp", "w" ) + + char = FILE.read( 1 ) + + while char: + if fileType == "UNIX": + if char == chr(0x0a): # LF + OUTFILE.write( chr(0x0d) ) # replace LF with CR/LF + OUTFILE.write( chr(0x0a) ) + else: + OUTFILE.write( char ) + elif fileType == "MAC": + if char == chr(0x0d): + OUTFILE.write( chr(0x0d) ) # replace CR with CR/LF + OUTFILE.write( chr(0x0a) ) + elif fileType == "PC": + OUTFILE.write( char ) # file already in PC format + char = FILE.read( 1 ) + + FILE.close() + OUTFILE.close() + os.system( "mv ~temp " + fileName + ".PC" ) + + print "PC" + +def toUNIX( fileName, fileType ): + FILE = open( fileName, "r" ) + + os.system( "touch ~temp" ) + OUTFILE = open( "~temp", "w" ) + + char = FILE.read( 1 ) + last = 0 + + while char: + if fileType == "UNIX": + OUTFILE.write( char ) # file already in UNIX format + elif fileType == "MAC": + if char == chr(0x0d): + OUTFILE.write( chr(0x0a) ) + elif fileType == "PC": + if last == chr(0x0d): # if last character was CR + if char == chr(0x0a): # ...and this one is LF + OUTFILE.write( chr(0x0a) ) # then replace CR/LF with LF + elif char == chr(0x0d): + last = chr(0x0d); + else: + OUTFILE.write( char ) + char = FILE.read( 1 ) + + FILE.close() + OUTFILE.close() + os.system( "mv ~temp " + fileName + ".UNIX" ) + + print "UNIX" + + +def readFile( fileName, isVerbose ): + numCR = 0 + numLF = 0 + numCRLF = 0 + + FILE = open( fileName, "r" ) + + char = FILE.read( 1 ) + last = 0 + + while char: + if char == chr(0x0a): # LINE FEED + numLF = numLF + 1 + if last == chr(0x0d): # CR/LF + numCRLF = numCRLF + 1 + elif char == chr(0x0d): # CARRIAGE RETURN + numCR = numCR + 1 + else: + pass + + last = char + char = FILE.read( 1 ) + + FILE.close() + + fileType = "Undefined" + + if numCRLF > 0: + print fileName, ": PC Format (CR/LF)" + fileType = "PC" + elif numCR > 0: + if numLF == 0: + print fileName, ": MAC Format (CR only)" + fileType = "MAC" + elif numCR > numLF: + print fileName, ": mix of CR and LF... probably MAC Format" + elif numCR == numLF: + print fileName, ": mix of CR and LF... undetermined format" + else: + print fileName, ": mix of CR and LF... probably UNIX Format" + elif numLF > 0: + print fileName, ": UNIX Format (LF only)" + fileType = "UNIX" + else: + print fileName, ": This file had no terminators" + + if isVerbose: + print "CR: ", numCR + print "LF: ", numLF + print "CRLF: ", numCRLF + + return fileType + +def usage(): + print '''\ + Usage: python lineterm.py [options] files + + Options: + -h, --help : Show this message + -m, --mac : Convert file(s) to Mac format (carriage returns) + -p, --pc : Convert file(s) to PC format (carriage return/linefeeds) + -u, --unix : Convert file(s) to Unix format (linefeeds) + -v, --verbose : Show the number of CRs, LFs, and CR/LFs for the file(s) + + Arguments: + files : any file or group of files (wildcards allowed) + + Note: + Does not currently recurse directories or distinguish between + binary and ASCII file types. Creates a ~temp file in current + directory when converting files. + ''' + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/py_php_lint.py b/py_php_lint.py new file mode 100755 index 0000000..6cfc5eb --- /dev/null +++ b/py_php_lint.py @@ -0,0 +1,205 @@ +# /usr/bin/env python + +import sys +from string import * +import os +import time + +# FUNCTIONS + +# -------------------------------------------------------------------- +# --- process_function ----------------------------------------------- +# -------------------------------------------------------------------- + +def process_function( p_source_lines, p_start_pos ): + total_open_brace = 0 + + for i in range( p_start_pos, len( p_source_lines ) ): + total_open_brace = total_open_brace + count( p_source_lines[i], '{' ) + total_open_brace = total_open_brace - count( p_source_lines[i], '}' ) + + if ( find( p_source_lines[i], 'return ') > 0 ): + return p_source_lines[i] + + if ( total_open_brace == 0 ): + return ' ' + +# -------------------------------------------------------------------- +# --- process_api_file ----------------------------------------------- +# -------------------------------------------------------------------- + +def process_api_file( p_file_name ): + global total_lines, function_list + + infile = open( 'mantis/'+p_file_name, 'r' ) + source_lines = infile.readlines() + infile.close() + + for i in range( len( source_lines ) ): + source_line = source_lines[i] + stripped_source_line = strip( source_line ) + # source_line = strip( source_lines[i] ) + if ( find( stripped_source_line, 'function' ) == 0 ): + open_paren_pos = find( stripped_source_line, '(' ) + close_paren_pos = find( stripped_source_line, ')' ) + + underscore_first = find( p_file_name, '_' )+1 + underscore_last = rfind( p_file_name, '_' ) + + module_name = p_file_name[underscore_first:underscore_last] + function_name = stripped_source_line[9:open_paren_pos] + function_params = stripped_source_line[open_paren_pos+2:close_paren_pos-1] + line_number = i + return_value = process_function( source_lines, line_number ) + + function_list.append( ( p_file_name, + module_name, + function_name, + function_params, + line_number, + return_value ) ) + + process_function( source_lines, i ) + + total_lines = total_lines + len( source_lines ) + +# -------------------------------------------------------------------- +# --- process_file --------------------------------------------------- +# -------------------------------------------------------------------- + +def process_file( p_file_name ): + global function_list, file_function_list + + infile = open( 'mantis/'+p_file_name, 'r' ) + source_lines = infile.readlines() + infile.close() + + for j in range ( len( function_list ) ): + function_name = function_list[j][2] + for i in range( len( source_lines ) ): + + if ( find( source_lines[i], ' '+function_name ) > -1 ): + file_function_list.append( ( p_file_name, function_name, i ) ) + #print ' '+p_file_name+'('+str( i )+'): \t'+function_name + if ( find( source_lines[i], '\t'+function_name ) > -1 ): + file_function_list.append( ( p_file_name, function_name, i ) ) + +# -------------------------------------------------------------------- +# --- print_function_item -------------------------------------------- +# -------------------------------------------------------------------- + +def print_function_item( p_function_item ): + file_name = p_function_item[0] + module_name = p_function_item[1] + function_name = p_function_item[2] + function_param = p_function_item[3] + line_number = p_function_item[4] + return_value = p_function_item[5] + + print_string = '['+module_name+'] ('+str( line_number )+') '+function_name+'()' + print print_string + print_string = ' paramcount: '+str( len( split( strip( function_param ), ' ' ) ) ) + print print_string + if ( len( strip( return_value ) ) > 0 ): + print ' return value: ' + strip( return_value ) + #print_function_parameters( function_param ) + +# -------------------------------------------------------------------- +# --- print_function_parameters -------------------------------------- +# -------------------------------------------------------------------- + +def print_function_parameters( p_function_parameters ): + if ( len( p_function_parameters ) > 0 ): + param_list = split( p_function_parameters, ' ' ) + + for i in range( len( param_list ) ): + comma_pos = find( param_list[i], ',' ) + if ( comma_pos > 0 ): + print " "+param_list[i][:comma_pos] + else: + print " "+param_list[i] + else: + print "NO PARAMETERS" + print "--------------------------" + +# -------------------------------------------------------------------- +# --- print_function_counts ------------------------------------------ +# -------------------------------------------------------------------- + +def print_function_counts(): + global function_count_list + + keys = function_count_list.keys() + keys.sort() + for i in range ( len( keys ) ): + if ( function_count_list[keys[i]] > 0 ): + print keys[i]+'\t'+str( function_count_list[keys[i]] ) + +# -------------------------------------------------------------------- +# --- tally_function_counts ------------------------------------------ +# -------------------------------------------------------------------- + +def tally_function_counts(): + global function_list, file_function_list, function_count_list + + # build map # use -1 since we want to discount the definition + for i in range( len( function_list ) ): + function_list_key = function_list[i][2] + function_count_list[function_list_key] = -1 + + # process functions and file_function + for j in range( len( file_function_list ) ): + file_function_name = file_function_list[j][1] + + if ( file_function_name == 'email_close' ): + print file_function_list[j][0] + print file_function_list[j][1] + print file_function_list[j][2] + + function_count_list[file_function_name] = function_count_list[file_function_name] + 1 + +# -------------------------------------------------------------------- +# --- GLOBAL VARIABLES ----------------------------------------------- +# -------------------------------------------------------------------- + +# file_name, module_name, function_name, function_params, line_number, return_value +function_list = [] # info for each function +# file_name, function_name, line number +file_function_list = [] # functions found in each file +# function_name, count +function_count_list = {} # contains counts occurances of functions +total_lines = 0 + +# -------------------------------------------------------------------- +# --- MAIN ----------------------------------------------------------- +# -------------------------------------------------------------------- + +dir_list = os.listdir( "mantis" ) +dir_list.sort() +for i in range( len( dir_list ) ): + file_name = dir_list[i] + if ( find( file_name, 'core_' ) != -1 ): + print "Processing: "+file_name; + process_api_file( file_name ) + +for i in range( len( function_list ) ): + function_item = function_list[i] + #print_function_item( function_item ) + +print len( function_list ) +print total_lines + +dir_list = os.listdir( "mantis" ) +dir_list.sort() +for i in range( len( dir_list ) ): + file_name = dir_list[i] + if ( find( file_name, 'php' ) != -1 ): + print "Processing: "+file_name; + process_file( file_name ) + +tally_function_counts() +print_function_counts() + +# -------------------------------------------------------------------- +# --- END ------------------------------------------------------------ +# -------------------------------------------------------------------- \ No newline at end of file diff --git a/py_release.py b/py_release.py new file mode 100755 index 0000000..d22497b --- /dev/null +++ b/py_release.py @@ -0,0 +1,272 @@ +# /usr/bin/env python + +import sys +from string import * +import os +import time + +# FUNCTIONS + +def check_keys( p_line, p_keys ): + p_list = split( p_line, " " ); + if ( len( p_list ) < 1 ): + return -1; + + for i in range( len(p_keys) ): + if ( find( p_list[0], p_keys[i] ) != -1 ): + return p_keys[i]; + return -1; + +# END FUNCTIONS + +# initialize globals +step_counter = 0 + +# flags +scp_flag = 1; +removedir_flag = 1; +remove_tar_flag = 0; + + +replacement_table = { + "$g_hostname" : "$g_hostname = \"localhost\";", + "$g_port" : "$g_port = 3306; # 3306 is default", + "$g_db_username" : "$g_db_username = \"root\";", + "$g_db_password" : "$g_db_password = \"\";", + "$g_database_name" : "$g_database_name = \"bugtracker\";", + + "$g_path" : "$g_path = \"http://your_web_address/mantis/\";", + + "$g_use_iis" : "$g_use_iis = OFF;", + + "$g_show_version" : "$g_show_version = ON;", + + "$g_administrator_email" : "$g_administrator_email = \"administrator@nowhere\";", + "$g_webmaster_email" : "$g_webmaster_email = \"webmaster@nowhere\";", + "$g_from_email" : "$g_from_email = \"noreply@nowhere\";", + "$g_to_email" : "$g_to_email = \"nobody@nowhere\";", + "$g_return_path_email" : "$g_return_path_email = \"admin@nowhere\";", + + "$g_allow_signup" : "$g_allow_signup = ON;", + "$g_enable_email_notification" : "$g_enable_email_notification = ON;", + "$g_notify_developers_on_new" : "$g_notify_developers_on_new = ON;", + + "$g_validate_email" : "$g_validate_email = ON;", + "$g_check_mx_record" : "$g_check_mx_record = ON;", + "$g_hide_user_email" : "$g_hide_user_email = OFF;", + "$g_use_x_priority" : "$g_use_x_priority = ON;", + + "$g_use_bcc" : "$g_use_bcc = ON;", + "$g_use_phpMailer" : "$g_use_phpMailer = OFF;", + "$g_phpMailer_method" : "$g_phpMailer_method = 0;", + "$g_smtp_host" : "$g_smtp_host = \"localhost\";", + + "$g_default_language" : "$g_default_language = \"english\";", + + "$g_window_title" : "$g_window_title = \"Mantis\";", + "$g_page_title" : "$g_page_title = \"Mantis\";", + + "$g_show_report" : "$g_show_report = BOTH;", + "$g_show_update" : "$g_show_update = BOTH;", + "$g_show_view" : "$g_show_view = BOTH;", + + "$g_show_source" : "$g_show_source = OFF;", + + "$g_show_footer_menu" : "$g_show_footer_menu = OFF;", + + + "$g_show_project_in_title" : "$g_show_project_in_title = ON;", + + "$g_show_assigned_names" : "$g_show_assigned_names = ON;", + "$g_show_priority_text" : "$g_show_priority_text = OFF;", + + "$g_use_jpgraph" : "$g_use_jpgraph = OFF;", + "$g_jpgraph_path" : "$g_jpgraph_path = \"./jpgraph/\"; # dont forget the ending slash!", + + "$g_cookie_time_length" : "$g_cookie_time_length = 30000000;", + + "$g_wait_time" : "$g_wait_time = 2;", + + "$g_content_expire" : "$g_content_expire = 0;", + + "$g_short_date_format" : "$g_short_date_format = \"m-d\";", + "$g_normal_date_format" : "$g_normal_date_format = \"m-d H:i\";", + "$g_complete_date_format" : "$g_complete_date_format = \"m-d-y H:i T\";", + + "$g_news_limit_method" : "$g_news_limit_method = BY_LIMIT;", + "$g_news_view_limit" : "$g_news_view_limit = 7;", + "$g_news_view_limit_days" : "$g_news_view_limit_days = 30;", + + "$g_default_new_account_access_level" : "$g_default_new_account_access_level = REPORTER;", + + "$g_default_limit_view" : "$g_default_limit_view = 50;", + "$g_default_show_changed" : "$g_default_show_changed = 6;", + + "$g_min_refresh_delay" : "$g_min_refresh_delay = 10; # in minutes", + + "$g_default_advanced_report" : "$g_default_advanced_report = BOTH;", + "$g_default_advanced_view" : "$g_default_advanced_view = BOTH;", + "$g_default_advanced_update" : "$g_default_advanced_update = BOTH;", + "$g_default_refresh_delay" : "$g_default_refresh_delay = 30; # in minutes", + "$g_default_redirect_delay" : "$g_default_redirect_delay = 2; # in seconds", + "$g_default_email_on_new" : "$g_default_email_on_new = ON;", + "$g_default_email_on_assigned" : "$g_default_email_on_assigned = ON;", + "$g_default_email_on_feedback" : "$g_default_email_on_feedback = ON;", + "$g_default_email_on_resolved" : "$g_default_email_on_resolved = ON;", + "$g_default_email_on_closed" : "$g_default_email_on_closed = ON;", + "$g_default_email_on_reopened" : "$g_default_email_on_reopened = ON;", + "$g_default_email_on_bugnote" : "$g_default_email_on_bugnote = ON;", + "$g_default_email_on_status" : "$g_default_email_on_status = 0; # @@@ Unused", + "$g_default_email_on_priority" : "$g_default_email_on_priority = 0; # @@@ Unused", + + "$g_reporter_summary_limit" : "$g_reporter_summary_limit = 10;", + "$g_summary_pad" : "$g_summary_pad = 5;", + + "$g_date_partitions" : "$g_date_partitions = array( 1, 2, 3, 7, 30, 60, 90, 180, 365);", + + "$g_bugnote_order" : "$g_bugnote_order = \"ASC\";", + + "$g_allow_file_upload" : "$g_allow_file_upload = OFF;", + "$g_file_upload_method" : "$g_file_upload_method = DISK;", + "$g_max_file_size" : "$g_max_file_size = 5000000;", + + "$g_allow_html_tags" : "$g_allow_html_tags = ON;", + "$g_allow_href_tags" : "$g_allow_href_tags = ON;", + + "$g_primary_table_tags" : "$g_primary_table_tags = \"\";", + + "$g_hr_size" : "$g_hr_size = 1;", + "$g_hr_width" : "$g_hr_width = 50;", + + "$g_ldap_server" : "$g_ldap_server = \"192.168.192.38\";", + "$g_ldap_root_dn" : "$g_ldap_root_dn = \"dc=traffic,dc=redflex,dc=com,dc=au\";", + "$g_ldap_organisation" : "$g_ldap_organisation = \"(organizationname=*Traffic)\";", + "$g_use_ldap_email" : "$g_use_ldap_email = OFF;", + + "$g_reopen_bug_threshold" : "$g_reopen_bug_threshold = DEVELOPER;", + "$g_quick_proceed " : "$g_quick_proceed = ON;", + "$g_login_method" : "$g_login_method = CRYPT;", + "$g_limit_reporters" : "$g_limit_reporters = ON;", + "$g_allow_close_immediately": "$g_allow_close_immediately = OFF;", + + "$g_php" : "$g_php = \".php3\";" + "$g_icon_path" : "$g_icon_path = $g_path.\"images/\";" + } + +# check to see if parameter is properly supplied +print '' +print '[ 00 ] Checking number of parameters' +print '[ 01 ] Number of parameters: ' + str(len(sys.argv)) +if ( len(sys.argv) < 2 ): + print 'You must supply a release number' + sys.exit() + +print '[ 02 ] Release number: ' + str(len(sys.argv)) +release = sys.argv[1] +release_name = 'mantis-' + str(sys.argv[1]) + +mantis_directory = '/home/www/mantis-' + str(release) +mantis_image_directory = mantis_directory + '/images' +mantis_doc_directory = mantis_directory + '/doc' +mantis_lang_directory = mantis_directory + '/lang' +print '[ 03 ] Making directory: ' + mantis_directory +res = os.system( 'mkdir ' + mantis_directory ) + +print '[ 04 ] Making Mantis image directory' +res = os.system( 'mkdir ' + mantis_image_directory ) +print '[ 04a] Making Mantis doc directory' +res = os.system( 'mkdir ' + mantis_doc_directory ) +print '[ 04b] Making Mantis lang directory' +res = os.system( 'mkdir ' + mantis_lang_directory ) + +print '[ 05 ] Copying Mantis files' +res = os.system( 'cp /home/www/mantis/* ' + mantis_directory ) + +print '[ 06 ] Copying Mantis image files' +res = os.system( 'cp /home/www/mantis/images/* ' + mantis_image_directory ) +print '[ 06a] Copying Mantis doc files' +res = os.system( 'cp /home/www/mantis/doc/* ' + mantis_doc_directory ) +print '[ 06a] Copying Mantis lang files' +res = os.system( 'cp /home/www/mantis/lang/* ' + mantis_lang_directory ) + +# read in config file +print '[ 07 ] Reading in original config file' +infile = open( '/home/www/mantis/config_inc.php', 'r' ) +config_file = infile.readlines() +infile.close() + +# open config file for writing +print '[ 08 ] Opening new config file' +outfile = open( mantis_directory + '/config_inc.php', 'w' ) + +print '[ 09 ] Processing file... Inserting default values' + +config_file_len = len( config_file ) + +### BEGIN REPLACEMENTS +# perform replacements for default values +for i in range ( config_file_len ): + line = strip( config_file[i] ) + +# DO common replacements +# check to see if a replacement is needed + key = check_keys ( line, replacement_table.keys() ) + if ( key != -1 ): + print '[ 10 ] Processing Value : ' + key + config_file[i] = replacement_table[key]; + +# DO specialized replacements +# set version + if ( find( line, '$g_mantis_version' ) != -1 ): + config_file[i] = "$g_mantis_version = \"" + release + "\";" + +# comment out error_reporting() + if ( find( line, 'error_reporting' ) != -1 ): + if ( find( line, '#' ) == -1 ): + config_file[i] = "#" + line + +### END REPLACEMENTS + +# write out the new config file +print '[ 11 ] Writing new config file' +for i in range ( config_file_len ): + line = strip( config_file[i] ) + +# skip empty lines + if (len(line)==0): + outfile.write( '\n' ) + continue + +# print properly formatted output + if (line[0]=="<"): + outfile.write( line + '\n' ) + elif (line[0]=="?"): + outfile.write( line ) + else: + outfile.write( '\t' + line + '\n' ) + +# close config file +print '[ 12 ] Closing new config file' +outfile.close() + +print '[ 13 ] Creating TAR archive' +res = os.system( 'tar cf ' + release_name + '.tar ' + release_name ) +print '[ 14 ] GZIPping TAR archive' +res = os.system( 'gzip ' + release_name + '.tar' ) + +if ( scp_flag==1 ): + print '[ 15 ] SCP\'ing file to SourceForge' + res = os.system( 'scp ' + release_name + '.tar.gz prescience@shell.sourceforge.net:/home/groups/m/ma/mantisbt/htdocs/' ) + +print '[ 16 ] Performing cleanup' + +if ( removedir_flag==1 ): + print '[ 17 ] Removing directory' + res = os.system( 'rm -rf ' + mantis_directory ) + +if ( remove_tar_flag==1 ): + print '[ 17 ] Removing TAR archive' + res = os.system( 'rm ' + release_name + '.tar.gz' ) + + +print "[ 18 ] Finished\n" \ No newline at end of file diff --git a/py_release_check.py b/py_release_check.py new file mode 100755 index 0000000..cd4d909 --- /dev/null +++ b/py_release_check.py @@ -0,0 +1,76 @@ +# /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, "_cookie" ) )& + ( -1 == find( p_string, "_enum_" ) )& + ( -1 == find( p_string, "_color" ) )& + ( -1 == find( p_string, "g_html_tags" ) )& + ( -1 == find( p_string, "g_language_choices_arr" ) )& + ( -1 == find( p_string, "g_db_table_prefix" ) )& + ( -1 == find( p_string, "_path" ) )): + return a + return "" +# --- ------ + +# =========================== +# MAIN +# =========================== +config_file = "/home/www/mantis/config_inc.php" +py_release_file = "/home/www/py_release.py" +config_list = [] +py_release_list = [] +config_strings = {} +py_release_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( py_release_file ) +py_release_list = file.readlines() +file.close() + +# populate dictionary +for i in py_release_list: + string_key = process_string( i ) + if ( len( string_key ) > 0 ): + py_release_strings[string_key] = 1 + +# check for missing +config_keys = config_strings.keys() +config_keys.sort() +for i in config_keys: + if ( not py_release_strings.has_key( i ) ): + print "Missing: "+i +print "----------------------------------" + +# check for unused +py_release_keys = py_release_strings.keys() +py_release_keys.sort() +for i in py_release_keys: + if ( not config_strings.has_key( i ) ): + print "Unused: "+i +print "----------------------------------" \ No newline at end of file