#!/usr/bin/env python # Copyright (C) 2005,2006 Krzysztof Kozlowski # License: GNU General Public License version 2 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Homepage: http://www.kozik.net.pl # # Ostatnia zmiana: 30.01.2006 # # Skrypt wyszukujacy moduly perla i listujacy zduplikowane (.pm) import dircache from stat import * import re import os # Stad zaczniemy poszukiwania : PERL_DIR = '/usr/lib/perl5/' PERL_MOD_SUF = '.pm' # Sprawdzenie wersji Perla... ale po co ? Po nic :) list = dircache.listdir(PERL_DIR) reg = re.compile('[0-9]\.[0-9]\.[0-9]') PERL_VER = '' for dir in list: match = reg.search(dir) if (not(match)): continue PERL_VER = dir print 'Wersja Perla: ' + PERL_VER # ################################################## # Funkcje : # # Dodanie do listy "list" modulu "name" w "path": # Zwraca powiekszona liste def add_module(list, name, path): if not(list.has_key(name)): list[name] = [] list[name].append(path) return list # Pobranie nazwy pakietu (modulu) z pliku "file" # Zwraca jego nazwe lub pusty string def get_package_from_module(file): f=open(file,'r') fcont=f.readlines() f.close() reg = re.compile('package\s*(([\w_]*)(::[_\w]*)*)\s*;') for line in fcont: match = reg.search(line) if (match): return str(match.group(1)) return '' # Rekurencyjna funkcja do wyszukania modulow w katalogu "path" # Zwraca liste modulow def find_modules_in_dir(path): modules = {} list = dircache.listdir(path) for one in list: full = os.path.join(path, one) mode = os.stat(full)[ST_MODE] if S_ISDIR(mode): # Katalog modules2 = find_modules_in_dir(full) for k, v in modules2.iteritems(): for mod in v: modules = add_module(modules, k, mod) continue filename = os.path.basename(full) if (filename.endswith(PERL_MOD_SUF)): # Perl module module_name = get_package_from_module(full) if (module_name != ''): modules = add_module(modules, module_name, full) return modules # ################################################## modules = find_modules_in_dir(PERL_DIR) print print 'Katalog: ' + PERL_DIR for mod_name,mod_paths in modules.iteritems(): if len(mod_paths) > 1: print 'Modul ' + mod_name for path in mod_paths: print ' ' + str(path)