from os.path import join, abspath, normcase, basename, isdir, getsize
from heapq import nlargest
from os.path import join, abspath, normcase, basename, isdir, getsize
from heapq import nlargest
- def __init__(self, ui):
- ignore_dirs = ['/dev', '/proc', '/sys', '/mnt']
- start_path = '.'
- count = 7
+ def __init__(self, ui, config):
+ self.config = config
- print ui
- if ui == 'cli':
- self.present = Cli_Presentation(start_path, count, self.start_search)
- elif ui == 'gtk':
- self.present = Gtk_Presentation(start_path, count, self.start_search)
+ self.present = eval(ui + '_Presentation(config, self.start_search)')
+ self.abstrac = Abstraction(self.config, self.present)
- def start_search(self, get_data, get_stopit, label, kill_func):
+ def start_search(self, get_data, get_stopit):
- start_path, count, outtype = get_data()
- search_func = self.abstrac.filegetter(start_path, get_stopit, label)
+ outtype, start_path, count = get_data()
+ search_func = self.abstrac.filegetter(start_path, get_stopit)
for fsize, fpath in nlargest(count, search_func):
filelist.append([int(fsize), fpath, size_hum_read(fsize)])
self.present.show_out_toplevel(None, outtype, filelist)
def run(self):
for fsize, fpath in nlargest(count, search_func):
filelist.append([int(fsize), fpath, size_hum_read(fsize)])
self.present.show_out_toplevel(None, outtype, filelist)
def run(self):
#==============================================================================
class Abstraction(object):
#==============================================================================
class Abstraction(object):
- def __init__(self, ignore_dirs, presentation):
- self.ignore_dirs = ignore_dirs
+ def __init__(self, config, presentation):
+ self.ignore_dirs = config['ignore_dirs']
ignore_dirs = self.ignore_dirs
for ign_dir in ignore_dirs[:]:
for dirname in dirnames[:]:
ignore_dirs = self.ignore_dirs
for ign_dir in ignore_dirs[:]:
for dirname in dirnames[:]:
flpath = abspath(join(dirpath, fname))
self.presentation.show_current_status(flpath)
flpath = abspath(join(dirpath, fname))
self.presentation.show_current_status(flpath)
#==============================================================================
class Cli_Presentation(object):
#==============================================================================
class Cli_Presentation(object):
- def __init__(self, start_func):
+ def __init__(self, config, start_func):
+ self.start_func = start_func
+
+ self.outtype = config['outtype']
+ self.start_path = config['start_path']
+ self.count = config['count']
- # get_data, get_stopit, label, kill_func)
- start_func(self.get_data, self.get_stopit, self.kill_wind)
- pass
+
+ self.toplevel = None
+
+ def get_data(self):
+ return self.outtype, self.start_path, int(self.count)
+
+ def get_stopit(self):
+ return False
+
+ def show_out_toplevel(self, _, outtype, results):
+ out_submodule = __import__('files.' + outtype, None, None, outtype)
+ out_submodule.Cli_Presentation(results).toplevel
#==============================================================================
class Gtk_Presentation(object):
#==============================================================================
class Gtk_Presentation(object):
# "Files quantity" spin
self.qty_spin = gtk.SpinButton()
self.qty_spin.set_numeric(True)
self.qty_spin.set_range(0, 65536)
self.qty_spin.set_increments(1, 10)
# "Files quantity" spin
self.qty_spin = gtk.SpinButton()
self.qty_spin.set_numeric(True)
self.qty_spin.set_range(0, 65536)
self.qty_spin.set_increments(1, 10)
self.stop_btn.set_sensitive(False)
self.stop_btn.connect('clicked', self.stop_btn_clicked)
# Output selection
self.stop_btn.set_sensitive(False)
self.stop_btn.connect('clicked', self.stop_btn_clicked)
# Output selection
- self.outtable_rbtn = gtk.RadioButton(None, 'Table')
- self.outtable_rbtn.set_name('outtable')
- outdiagram_rbtn = gtk.RadioButton(self.outtable_rbtn, 'Diagram')
+ outtable_rbtn = gtk.RadioButton(None, _('Table'))
+ outtable_rbtn.set_name('outtable')
+ outdiagram_rbtn = gtk.RadioButton(outtable_rbtn, _('Diagram'))
- out2_rbtn = gtk.RadioButton(self.outtable_rbtn, 'Another 2')
- out2_rbtn.set_name('outanother2')
- out_rbtns = [self.outtable_rbtn, outdiagram_rbtn, out1_rbtn, out2_rbtn]
+ self.out_rbtns = [outtable_rbtn, outdiagram_rbtn, out1_rbtn]
hbox = gtk.HBox(False, 4)
hbox.pack_start(qty_label, False, False, 0)
hbox.pack_start(self.qty_spin, False, False, 0)
hbox.pack_start(self.start_btn, False, False, 0)
hbox.pack_start(self.stop_btn, False, False, 0)
hbox = gtk.HBox(False, 4)
hbox.pack_start(qty_label, False, False, 0)
hbox.pack_start(self.qty_spin, False, False, 0)
hbox.pack_start(self.start_btn, False, False, 0)
hbox.pack_start(self.stop_btn, False, False, 0)
hbox.pack_end(btn, False, False, 0)
hbox.pack_end(btn, False, False, 0)
self.statusbar = gtk.Statusbar()
self.context_id = self.statusbar.get_context_id('Current walked file')
self.statusbar = gtk.Statusbar()
self.context_id = self.statusbar.get_context_id('Current walked file')
def show_current_status(current_path):
self.statusbar.push(self.context_id, current_path)
gtk.main_iteration()
self.show_current_status = show_current_status
def show_current_status(current_path):
self.statusbar.push(self.context_id, current_path)
gtk.main_iteration()
self.show_current_status = show_current_status
-# self.show_out_toplevel(None, 'outtable', [(11, 22, 33)])
+ self.show_out_toplevel(None, self.config['outtype'], [(1, 'path', 'bytesize')])
#=== Functions ============================================================
def start_btn_released(self, btn, start_func):
self.stopit = False
self.stop_btn.set_sensitive(True)
self.start_btn.set_sensitive(False)
#=== Functions ============================================================
def start_btn_released(self, btn, start_func):
self.stopit = False
self.stop_btn.set_sensitive(True)
self.start_btn.set_sensitive(False)
#=== Output type selecting ================================================
def show_out_toplevel(self, btn, outtype, results):
print 'Entering <' + outtype + '> output mode...'
out_submodule = __import__('files.' + outtype, None, None, outtype)
try:
#=== Output type selecting ================================================
def show_out_toplevel(self, btn, outtype, results):
print 'Entering <' + outtype + '> output mode...'
out_submodule = __import__('files.' + outtype, None, None, outtype)
try:
- out_toplevel = out_submodule.Gtk_Presentation(results).toplevel
- self.current_outtoplevel = out_toplevel
- self.vbox.add(out_toplevel)
- out_toplevel.show_all()
-# out_submodule.Gtk_Presentation().show_results(results)
+ self.out_toplevel = out_submodule.Gtk_Presentation(results).toplevel
+ self.vbox.add(self.out_toplevel)
+ self.out_toplevel.show_all()
+### out_submodule.Gtk_Presentation().show_results(results)
+
+#==============================================================================
+
+class Hildon_Presentation(object):
+
+ def __init__(self, config, start_func):
+ import gtk
+ import hildon
+
+ self.config = config
+
+ def run(self):
+ pass