# vim: sw=4 ts=4 expandtab ai
# main.py --search files -o=table -p ". 7"
+CONF = '''
+[DEFAULT]
+search = 'files'
+outtype = 'outtable'
+
+[files]
+ignore_dirs = ['/dev', '/proc', '/sys', '/mnt']
+start_path = '.'
+count = 5
+
+[debs]
+count = 12
+'''
+
+from ConfigParser import ConfigParser, NoOptionError
+
+class FindITConfig(ConfigParser):
+ def __init__(self, config):
+ ConfigParser.__init__(self)
+ if isinstance(config, basestring):
+ self.read(config)
+ else:
+ self.readfp(config)
+ self._section = None
+
+ def __getitem__(self, item):
+ try:
+ return self.get('DEFAULT', item)
+ except NoOptionError:
+ if self.has_section(item):
+ self._section = item
+ return self
+ else:
+ return self.get(self._section, item)
+
+ def __setitem__(self, item, value):
+ return self.set(self._section, item, str(value))
+
+ def get(self, section, option):
+ value = ConfigParser.get(self, section, option)
+ try:
+ return eval(value)
+ except SyntaxError:
+ return value
+
+from StringIO import StringIO
+config = FindITConfig(StringIO(CONF))
-# Dummy config
-
-Config = {}
-
-Config['search'] = 'files'
-Config['outtype'] = 'outtable'
-
-# files
-Config['ignore_dirs'] = ['/dev', '/proc', '/sys', '/mnt']
-Config['start_path'] = '.'
-Config['count'] = 5
-
-# # debs
-# Config['count'] = 7
-
-
-# if __name__ == '__main__':
-# config = Config
-# print config['search']
from heapq import nlargest
from misc import size_hum_read, _
+from config import config
#==============================================================================
class Control(object):
def __init__(self, ui):
- count = 12
+ count = config['debs']['count']
print ui
if ui == 'cli':
from heapq import nlargest
from misc import size_hum_read, _
+from config import config
#==============================================================================
class Control(object):
- def __init__(self, ui, config):
+ def __init__(self, ui):
if ui == 'cli':
- self.present = Cli_Presentation(config)
+ self.present = Cli_Presentation()
elif ui == 'gtk':
- self.present = Gtk_Presentation(config, self.start_search)
+ self.present = Gtk_Presentation(self.start_search)
elif ui == 'hildon':
- self.present = Hildon_Presentation(config, self.start_search)
+ self.present = Hildon_Presentation(self.start_search)
# self.present - for updating windows in interactive presentations
- self.abstrac = Abstraction(config, self.present)
+ self.abstrac = Abstraction(self.present)
# Used only in non-interactive presentations
self.present.start_search(self.start_search)
class Abstraction(object):
- def __init__(self, config, presentation):
- self.ignore_dirs = config['ignore_dirs']
+ def __init__(self, presentation):
+ self.ignore_dirs = config['files']['ignore_dirs']
self.presentation = presentation
def filegetter(self, startdir, get_stopit):
#==============================================================================
class Cli_Presentation(object):
- def __init__(self, config):
- self.outtype = config['outtype']
- self.start_path = config['start_path']
- self.count = config['count']
+ def __init__(self):
+ self.outtype = config['files']['outtype']
+ self.start_path = config['files']['start_path']
+ self.count = config['files']['count']
self.stopit = False
self.toplevel = None
class Gtk_Presentation(object):
- def __init__(self, config, start_func):
+ def __init__(self, start_func):
import gtk
- self.config = config
-
# "Start path" entry
self.path_entry = gtk.Entry()
- self.path_entry.set_text(self.config['start_path'])
+ self.path_entry.set_text(config['files']['start_path'])
# "Files quantity" label
qty_label = gtk.Label(_('Files quantity'))
self.qty_spin.set_numeric(True)
self.qty_spin.set_range(0, 65536)
self.qty_spin.set_increments(1, 10)
- self.qty_spin.set_value(self.config['count'])
+ self.qty_spin.set_value(config['files']['count'])
# "Start" button
self.start_btn = gtk.Button(_('Start'))
for btn in reversed(self.out_rbtns):
hbox.pack_end(btn, False, False, 0)
# Activate radio button
- if btn.get_name() == self.config['outtype']:
+ if btn.get_name() == config['outtype']:
btn.set_active(True)
self.statusbar = gtk.Statusbar()
gtk.main_iteration()
self.show_current_status = show_current_status
- self.show_out_toplevel(None, self.config['outtype'], [(1, 'path', 'bytesize')])
+ self.show_out_toplevel(None, config['outtype'], [(1, 'path', 'bytesize')])
#=== Functions ============================================================
def start_btn_released(self, btn, start_func):
class Hildon_Presentation(object):
- def __init__(self, config, start_func):
+ def __init__(self, start_func):
import gtk
import hildon
- self.config = config
-
def start_search(self, start_func):
pass
import sys
-from config import Config
+from config import config
from misc import _
__progname__ = 'FindIT'
class Control(object):
def __init__(self):
- config = Config ###()
self.abstrac = Abstraction()
if(len(sys.argv) > 1):
Cli_Presentation(self.abstrac) ###
else:
- Gtk_Presentation(config, self.abstrac) ###
+ Gtk_Presentation(self.abstrac) ###
#==============================================================================
parser.add_option('--license', action='callback', callback=self._license)
(options, args) = parser.parse_args()
- config = {}
- config['search'] = options.search
- config['outtype'] = options.output
- config['ignore_dirs'] = ['/dev', '/proc', '/sys', '/mnt']
- config['start_path'], config['count'] = options.params.split()
-
- self.show_search_toplevel(config)
+ self.show_search_toplevel()
def _about(self, *a):
print self.abstrac.comments
print self.abstrac.license
sys.exit()
- def show_search_toplevel(self, config):
+ def show_search_toplevel(self):
search_module = __import__(config['search'] + '.search')
- search_toplevel = search_module.search.Control('cli', config).run()
+ search_toplevel = search_module.search.Control('cli').run()
#==============================================================================
class Gtk_Presentation(object):
"""Main window class."""
- def __init__(self, config, abstrac):
+ def __init__(self, abstrac):
import gtk
- self.config = config
-
def _create_menu():
"""Create main menu."""
menubar = gtk.MenuBar()
# Activate radio tool button
for btn in search_tbtns:
- if btn.get_name() == self.config['search']:
+ if btn.get_name() == config['search']:
btn.set_active(True)
return toolbar
self.vbox = gtk.VBox(False, 4)
self.vbox.pack_start(menu, False, False, 0)
self.vbox.pack_start(toolbar, False, False, 0)
- self.show_search_toplevel(None, self.config['search'])
+ self.show_search_toplevel(None, config['search'])
window.add(self.vbox)
window.show_all()
print 'Entering <' + searchtype + '> search mode...'
search_module = __import__(searchtype + '.search')
- search_toplevel = search_module.search.Control('gtk', self.config).run()
+ search_toplevel = search_module.search.Control('gtk').run()
try:
self.vbox.remove(self.vbox.get_children()[2])
class Hildon_Presentation(object):
"""Main window class."""
- def __init__(self, config):
+ def __init__(self):
import gtk
import hildon
- self.config = config
#==============================================================================