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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| #!/usr/bin/python
# -*- coding: iso-8859-1 -*-
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
import os, glob
import fnmatch
class scanner:
def __init__(self):
self.widgets = gtk.glade.XML('scanner.glade',"window1")
self.autoConnect()
def autoConnect(self):
eventHandlers = {}
for (itemName,value) in self.__class__.__dict__.items():
if callable(value) and itemName.startswith('gtk_'):
eventHandlers[itemName[4:]] = getattr(self,itemName)
self.widgets.signal_autoconnect(eventHandlers)
def gtk_on_sc_fichier_valider_clicked(self, source=None, event=None):
file = self.widgets.get_widget('sc_fichier_entree').get_text()
extension = file.split("." )[-1]
nom = file.split(".")[0]
dossier = os.walk('.')
if file == '':
print 'Veuiller indiquer le nom d\'un fichier à chercher.'
if file !='':
#############################################################################
#Recherche et affiches les dossiers ou le "fichier" est present. #
#############################################################################
if os.path.isfile(file) :
#print'%s' %str(file), 'est un fichier'
for reps, sous_reps, fichiers in dossier :
for fichier in fichiers :
if fichier.endswith('.%s'%extension) :
print 'Trouver : %s'% fichiers.count(file),'fichier(s) ["%s"]'%str(file),', dans : "%s"'%os.path.join(reps)
else :
print 'Aucune correspondance, pour "%s".'%str(file)
#############################################################################
#############################################################################
#Recherche et affiches les dossiers ou le "dossier" est present. #
#############################################################################
if os.path.isdir(file) :
#print'%s' %str(file), 'est un dossier'
for reps, sous_reps, fichiers in dossier :
for dossiers in reps :
if dossiers == reps :
print 'Trouver : %s'% reps.count(dossiers),'dossier(s) ["%s"]'%str(file),', dans : "%s"'%os.path.join(reps)
else :
print 'Aucune correspondance, pour "%s".'%str(file)
#############################################################################
#############################################################################
#Recherche et affiches les dossiers ou l' "extension" est presente. #
#############################################################################
if file.endswith('.%s'%extension) == True :
#print'%s' %str(file), 'est une extension'
for reps, sous_reps, fichiers in dossier :
for fichier in fichiers :
if fichier.endswith('.%s'%extension) :
print 'Trouver : %s'% fichier.count(file),'fichier(s) ["%s"]'%str(file),', dans : "%s"'%os.path.join(reps)
print 'Ce fichier est : %s'%fichier
else :
print 'Aucune correspondance, pour "%s".'%str(file)
#############################################################################
#############################################################################
#Recherche et affiches les dossiers ou le "nom" est presente. #
#############################################################################
if file.startswith('%s'%nom) == True :
#print'%s' %str(file), 'est un nom de fichier ou dossier'
for reps, sous_reps, fichiers in dossier :
for fichier in fichiers :
if fichier.startswith('%s'%nom) :
print 'Trouver : %s'% fichier.count(file),'fichier(s) ["%s"]'%str(file),', dans : "%s"'%os.path.join(reps)
print 'Ce fichier est : %s'%fichier
else :
print 'Aucune correspondance, pour "%s".'%str(file)
#############################################################################
if __name__ == '__main__':
app = scanner()
gtk.main() |
Partager