Changed "*.*" to "*" in files.search so it possible find files w/o extension
[findit] / src / files / search.py
index 22f22e6..0440610 100755 (executable)
@@ -6,8 +6,9 @@ from os import walk
 from os.path import join, abspath, normcase, isdir, getsize
 from heapq import nlargest
 from fnmatch import fnmatch
+from sys import platform
 
-from misc import size_hum_read, _, NotebookWCloseBtns
+from misc import size_hum_read, _
 from config import config
 
 OUTTYPES = [
@@ -21,8 +22,8 @@ OUTTYPES = [
 
 class Control(object):
 
-    def __init__(self, ui, params):
-        self.present = eval(ui + '_Presentation(self.start_search, params)')
+    def __init__(self, ui, outtype, params):
+        self.present = eval(ui + '_Presentation(self.start_search, outtype, params)')
         self.abstrac = Abstraction(self.present)
 
         self.toplevel = self.present.toplevel
@@ -31,9 +32,15 @@ class Control(object):
         filelist = []
         outtype, start_path, count, file_filter = get_criteria()
         search_func = self.abstrac.filegetter(start_path, file_filter, get_stopit)
+
         for fsize, fpath in nlargest(count, search_func):
             filelist.append([int(fsize), fpath, size_hum_read(fsize)])
-        self.present.show_out_toplevel(outtype, filelist)
+
+        if not filelist:
+            self.present.nothing_founded()
+            return
+        results = [filelist, start_path]
+        self.present.show_out_toplevel(outtype, results)
 
     def run(self):
         self.present.run()
@@ -62,7 +69,11 @@ class Abstraction(object):
                 # Store only necessary files
                 for mask in file_filter:
                     if fnmatch(fname, mask):
-                        flpath = abspath(join(dirpath, fname))
+                        if platform == 'win32':
+                            # Crutch for non-unicode names
+                            flpath = unicode(join(dirpath, fname), '1251')
+                        else:
+                            flpath = join(dirpath, fname)
                         # Show current path
                         self.presentation.show_current_status(flpath)
                         # Stop search via 'stopit' signal
@@ -81,18 +92,23 @@ class Abstraction(object):
 #==============================================================================
 
 class Cli_Presentation(object):
-    def __init__(self, start_func, params):
+    def __init__(self, start_func, outtype, params):
         self.start_func = start_func
 
-        self.outtype = params['outtype']
-        self.start_path = params['start_path']
-        self.count = params['count']
+        self.outtype = outtype
+        self.start_path = params[0]
+        self.count = params[1]
+        try:
+            self.file_filter = params[2].split(';')
+        except IndexError:
+            self.file_filter = '*'
+
         self.stopit = False
 
         self.toplevel = None
 
     def get_data(self):
-        return self.outtype, self.start_path, int(self.count)
+        return self.outtype, self.start_path, int(self.count), self.file_filter
 
     def get_stopit(self):
         return False
@@ -109,6 +125,9 @@ class Cli_Presentation(object):
         print '\\' + '\r',
         ### print current_path
 
+    def nothing_founded(self):
+        print _('Nothing founded!')
+
     def run(self):
         self.start_func(self.get_data, self.get_stopit)
 
@@ -116,9 +135,10 @@ class Cli_Presentation(object):
 
 class Gtk_Presentation(object):
 
-    def __init__(self, start_func, __):
+    def __init__(self, start_func, *unused):
         import gtk
         global gtk  # for show_current_status()
+        from misc import NotebookWCloseBtns
 
         self.nb = NotebookWCloseBtns()
         self.nb.notebook.set_scrollable(True)
@@ -147,7 +167,7 @@ class Gtk_Presentation(object):
         self.qty_spin.set_value(config['files']['count'])
 
         # "Filter" label
-        filter_label = gtk.Label(_('Filter'))
+        filter_label = gtk.Label(_('Filter (semicolon separated)'))
         # "Filter" entry
         self.filter_entry = gtk.Entry()
         self.filter_entry.set_text(config['files']['filter'])
@@ -263,7 +283,7 @@ class Gtk_Presentation(object):
         file_filter = self.filter_entry.get_text().split(';')
         # If no filter - show all files
         if file_filter == ['']:
-            file_filter = ['*.*']
+            file_filter = ['*']
         return out, \
             self.path_entry.get_text(), int(self.qty_spin.get_value()), \
             file_filter
@@ -276,12 +296,14 @@ class Gtk_Presentation(object):
         self.statusbar.push(self.context_id, current_path)
         gtk.main_iteration()
 
+    def nothing_founded(self):
+        self.statusbar.push(self.context_id, _('Nothing founded!'))
+
     def run(self):
         pass
 
     #=== Output type selecting ================================================
     def show_out_toplevel(self, outtype, results):
-        print 'Entering <' + outtype['name'] + '> output mode...'
         out_submodule = __import__('files.' + outtype['name'], None, None, outtype)
         self.out_toplevel = out_submodule.Gtk_Presentation(results).toplevel
         self.nb.new_tab(self.out_toplevel, outtype['label'])