Source

vasm / panedui.py

  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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
#!/usr/bin/env python

#    This file is part of VASM.
#
#    VASM is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v3 as published by
#    the Free Software Foundation.
#
#    VASM 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.
#
#    You should have received a copy of the GNU General Public License
#    along with VASM.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "Moises Henriquez"
__author_email__ = "moc.liamg@xnl.E0M"[::-1]

import sys
import gtk
sys.path.append("./modules")
from support import widgets
from support import dialogs
from support.vectorlinux import utils
import os
import imp
import pango
import gobject
import subprocess as sp
import pathbar
import psutil
import time
import logging
from optparse import OptionParser

logger = logging.getLogger('vasm')

_ = utils._

def get_category_image(category):
    """ Returns the path or icon name for the category provided """
    iconsdir = os.path.join(os.getcwd(),
                            "modules/support/data/icons")
    caticon = os.path.join(iconsdir, "category_%s.png"% category.lower().replace(" ", "_"))
    generic = os.path.join(iconsdir, "category_unknown.png")
    if os.path.exists(caticon):
        return caticon
    return generic

def get_category_description(category):
    """ Returns a descriptive string about the current category """
    cats = {
        "System": "Global system settings.",
        "Hardware": "System hardware setup.",
        "Personal": "User personalization and application preferences.",
        "Network": "Networking and security settings.",
    }
    if category in cats:
        return cats[category]
    return "%s settings"%category

class WhiteLabel(gtk.Label):
    def __init__(self, txt):
        gtk.Label.__init__(self)
        self.set_markup(txt)
        style = self.get_style().copy()
        newfg = self.get_colormap().alloc_color("white")
        style.fg[gtk.STATE_NORMAL] = newfg
        self.set_style(style)

class WhiteDLabel(widgets.DLabel):
    def __init__(self, txt):
        widgets.DLabel.__init__(self, markup=txt)
        style = self.get_style().copy()
        newfg = self.get_colormap().alloc_color("white")
        style.fg[gtk.STATE_NORMAL] = newfg
        self.set_style(style)

class ShortCutLabel(gtk.EventBox):
    """ shortcut label used in the left panel"""
    def __init__(self, label):
        gtk.EventBox.__init__(self)
        self.modify_bg(gtk.STATE_NORMAL, widgets.vlbluecolor)
        self.label = label
        self._label = WhiteLabel(label)
        self.add(self._label)

class WhiteButton(gtk.Button):
    def __init__(self, lbl):
        gtk.Button.__init__(self, lbl.replace(" ", "\n"))
        self.set_property('relief', gtk.RELIEF_NONE)
        lb = self.get_children()[-1]
        lb.set_property('xalign', 0.0)
        style = lb.get_style().copy()
        colfg = lb.get_colormap().alloc_color("white")
        style.fg[gtk.STATE_NORMAL] = colfg
        lb.set_style(style)
        for state in (gtk.STATE_NORMAL, gtk.STATE_PRELIGHT,
                      gtk.STATE_ACTIVE, gtk.STATE_SELECTED):
            self.modify_fg(state, widgets.vlbluecolor)

class AuthButton(gtk.Button):
    def __init__(self, lbl):
        gtk.Button.__init__(self, lbl)
        img = gtk.Image()
        self.set_property('relief', gtk.RELIEF_NONE)
        img.set_from_stock(gtk.STOCK_DIALOG_AUTHENTICATION,
                           gtk.ICON_SIZE_BUTTON)
        self.set_image(img)
        self.modify_fg(gtk.STATE_NORMAL, widgets.vlbluecolor)
        wlist = self.get_children()[-1].get_children()[-1].get_children()
        lb = None
        for widget in wlist:
            if isinstance(widget, gtk.Label):
                lb = widget
        style = lb.get_style().copy()
        colfg = lb.get_colormap().alloc_color("white")
        style.fg[gtk.STATE_NORMAL] = colfg
        lb.set_style(style)

class VASM(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        #self.connect("destroy", gtk.main_quit)
        self.connect('delete-event', self.do_exit)
        self.connect("window-state-event", self.on_window_state)
        self.connect('destroy', gtk.main_quit)
        self.body = gtk.VBox()
        self.viewers = gtk.VBox()
        self.categories = []
        self.subcategories = []
        self.discover_modules()
        self.add_subcategory_launchers()
        self.set_title("VASM")
        iconpath = os.path.join(os.getcwd(), 
            "modules/support/data/icons/package-utilities.png")
        self.set_icon_from_file(iconpath)
        pane = gtk.HPaned()
        pane.set_position(130)
        leftpane = self.get_left_pane()
        leftbody= gtk.VBox()
        leftpane.add(leftbody)
        imgevent = gtk.EventBox()
        img = gtk.Image()
        img.set_from_pixbuf(
            gtk.gdk.pixbuf_new_from_file_at_size(
                os.path.join(os.getcwd(), 
                    "modules/support/data/vasmcc-logo_trimmed.png"),
                120, 80
            )
        )
        imgevent.add(img)
        imgevent.modify_bg(gtk.STATE_NORMAL, widgets.vlbluecolor)
        imgevent.modify_bg(gtk.STATE_INSENSITIVE, widgets.vlbluecolor)
        imgevent.connect("button-press-event", self.on_logo_click)
        leftbody.pack_start(imgevent, False, True, 4)
        # add some empty space
        leftbody.pack_start(gtk.Label(), False, False, 12)
        self.leftbody = leftpane
        pane.pack1(leftpane)
        
        # add the viewers box to a scrolledwindow
        scroll = gtk.ScrolledWindow()
        scroll.set_shadow_type(gtk.SHADOW_NONE)
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self._home_ = self.viewers
        scroll.add_with_viewport(self.viewers)
        self.scrollw = scroll
        escroll = gtk.EventBox()
        escroll.add(scroll)
        rightbody = gtk.VBox()
        # --- Add the header ----
        vasm_banner = gtk.Label()
        vasm_banner.set_use_markup(True)
        vasm_banner.set_markup(
            "<span size='larger'>%s</span>"%
            "VectorLinux Administration and System Menu")
        fontdesc = pango.FontDescription("sans, 12")
        vasm_banner.modify_font(fontdesc)
        vasm_banner.set_property('xalign', 0.0)
        topbannerbox = gtk.HBox()
        topbannerbox.pack_start(vasm_banner, True, True, 4)
        rightbody.pack_start(topbannerbox, False, True, 4)
        
        # create the toolbar
        self.fancytoolbar = pathbar.PathBar()
        part = pathbar.PathPart(self.fancytoolbar, "VASM Home",
                                callback = self.return_home)
        self.fancytoolbar.append(part)
        #part2 = pathbar.PathPart(self.fancytoolbar, "Date and Time")
        #self.fancytoolbar.append(part2)
        rightbody.pack_start(self.fancytoolbar, False, True, 2)
        # - add a separator
        sep = gtk.HSeparator()
        rightbody.pack_start(sep, False, True, 2)
        
        # -- Add the scroll window ---
        self.RIGHT_PARENT = gtk.VBox()
        rightbody.pack_start(self.RIGHT_PARENT, True, True, 0)
        self.RIGHT_PARENT.pack_start(escroll, True, True, 0)
        #rightbody.pack_start(escroll, True, True, 2)
        #self.rightbody = gtk.VBox()
        #self.rightbody.pack_start(rightbody, True, True, 0)
        pane.pack2(rightbody)
        self.pane = pane
        #pane.pack2(escroll)

        # Add a place holder to embed the module's toolbar at the bottom of the scrollview
        self._active_toolbar = gtk.HBox()
        rightbody.pack_start(self._active_toolbar, False, True, 2)
        # display the default exit button when we start up
        self._show_home_toolbar()

        self.add_leftpane_category_shortcuts(leftbody)
        self.set_default_size(640, 480)
        self.set_position(gtk.WIN_POS_CENTER)
        self.expand_last_view()

        self.body.pack_start(pane, True, True, 0)
        self.add(self.body)
        self._module_stack = [self._home_,]

    def do_exit(self, widget=None, window=None, event=None):
        # check for child processes.
        allpids = psutil.get_process_list()
        mainpid = os.getpid()
        for proc in allpids:
            if proc.parent.ppid == mainpid:
                ques = (
                    proc.exe,
                    _("is still running."), " ",
                    _("Force closing the program can have unwanted results."),
                    " ", _("Would you like to force close it and exit now?"))
                res = dialogs.question(' '.join(ques),
                                       parent = self,
                                       title = _("External applications running."))
                
                if res == gtk.RESPONSE_YES:
                    proc.terminate()
                else:
                    return True
        logger.info("Exiting VASM")
        return False
        #return gtk.main_quit()
    def _fork_embedding(self):
        window = self._external_window
        if window is None:
            return False
        viewport = self.scrollw.get_children()[0]
        if len(viewport.get_children()) > 0:
            viewport.remove(viewport.get_children()[0])
        # reparent the child
        alloc = self.RIGHT_PARENT.get_allocation()
        _x = alloc[0]
        _y = alloc[1]
        _width = alloc[2]
        _height = alloc[3]
        # resize the window to the size of the parent
        window.move_resize(
        _x,_y,_width, _height)
        window.reparent(viewport.window, 0, 0)
        self._external_window = None
        return True
    
    def _fork_monitoring(self):
        flag = self._flag
        # generator here
        
        while True:
            if not flag.is_set():
                time.sleep(1)
                return True
            else:
                self._enable_left_pane()
                break
        return False
        
    def embed_external(self, gtk_gdk_window, end_flag):
        """ embed gtk_gdk_window into the right pane """
        self._external_window = gtk_gdk_window
        self._flag = end_flag
        gobject.idle_add(self._fork_embedding, priority=100)
        gobject.idle_add(self._fork_monitoring)
        

    def show_module(self, body):
        """ Navigate into a module """
        body.show_all()
        self._module_stack.append(body)
        viewport = self.scrollw.get_children()[0]
        if len(viewport.get_children()) > 0:
            viewport.remove(viewport.get_children()[0])
        part2 = pathbar.PathPart(self.fancytoolbar, label=body.title, callback=self.jump_to_module)
        self.fancytoolbar.append_no_callback(part2)
        # embed the modules toolbar to the bottom of the right pane
        self._display_module_actionbuttons(body)
        
        # disable events for left pane
        self._disable_left_pane()
        return viewport.add(body)

    def _display_module_actionbuttons(self, moduleobject):
        """ Embeds the module's action area into the main screen so that the content
        can scroll freely, while the action buttons are always visible """
        bar = moduleobject.action_area
        holder = self._active_toolbar
        if holder.get_children():
            holder.remove(holder.get_children()[0])
        holder.pack_start(bar, True, True, 4)
        holder.show_all()
        return

    def _show_home_toolbar(self):
        """ Display the default toolbar (just an exit button )"""
        holder = self._active_toolbar
        if holder.get_children():
            holder.remove(holder.get_children()[0])
        bar = gtk.HBox()
        bt = gtk.Button(stock=gtk.STOCK_QUIT)
        bar.pack_end(bt, False, False, 4)
        bt.connect('clicked', gtk.main_quit)
        holder.pack_start(bar, True, True, 4)
        holder.show_all()
    
    def jump_to_module(self, widget=None, data=None):
        parts = self.fancytoolbar.get_parts()
        id = parts.index(data) + 1
        for mod in self._module_stack[id::][::-1]:
            mod.close_module()
        lastmod = self._module_stack[-1]
        return self._display_module_actionbuttons(lastmod)
    
    def close_module(self, body):
        """ close a module"""
        self._module_stack.pop()
        viewport = self.scrollw.get_children()[0]
        prev = self._module_stack[-1]
        logger.debug("Close module \"%s\""%body.title)
        if len(viewport.get_children()) > 0:
            viewport.remove(viewport.get_children()[0])
            self.fancytoolbar.remove(self.fancytoolbar.get_last())
        # see if we are home.
        if len(self._module_stack) == 1:
            self._enable_left_pane()
            # Display the home toolbar
        self._show_home_toolbar()
        return viewport.add(prev)
    
    def return_home(self, widget=None, data=None):
        viewport = self.scrollw.get_children()[0]
        viewport.remove(viewport.get_children()[0])
        # Cleanup the fancy toolbar
        self.fancytoolbar.remove_all_but_first(do_callback=False)
        # restore events for left pane
        self._enable_left_pane()
        # clear out the module stack
        self._module_stack = [self._home_,]
        # show the home toolbar
        self._show_home_toolbar()
        return viewport.add(self._home_)
    
    def _disable_left_pane(self):
        return self.leftbody.set_property('sensitive', False)
    
    def _enable_left_pane(self):
        return self.leftbody.set_property('sensitive', True)

    def on_window_state(self, window, event):
        """ Re-arrange the launchers on the right pane when the window size changes"""
        width, height = window.get_default_size()
        nwidth, nheight = window.get_size()
        if nwidth > width and nheight > height:
            for category in self.viewers:
                category.iconview.set_columns(-1)
                category.iconview.queue_draw()
                category.iconview.queue_resize()
        elif window.get_size() == window.get_default_size():
            for category in self.viewers:
                category.iconview.set_columns(2)
                category.iconview.queue_draw()
                category.iconview.queue_resize()
        else:
            for category in self.viewers:
                category.iconview.set_columns(-1)
                category.iconview.queue_draw()
                category.iconview.queue_resize()
        
    def on_logo_click(self, widget, event):
        """ Show the about dialog when the logo is clicked"""
        if event.button != 1:
            return
        about = dialogs.AboutVASM(parent=self)
        if about.run():
            about.destroy()
    
    def _slide_scrollview(self, adjustment, slideto):
        """ smoothly slide the value of the scrollview to the specified value
        """
        current = adjustment.get_value()
        if slideto > current:
            while slideto > current:
                adjustment.set_value(current + 1)
                current = adjustment.get_value()
            return False
        else:
            while current > 0.0:
                adjustment.set_value(current - 1)
                current = adjustment.get_value()
            return False
        return False

    def ensure_category_visibility(self, widget):
        """ Programattically scroll the right pane to ensure that the currently
        highlighted area is visible when the user moves the mouse over the
        indicating button"""
        parent = widget.get_parent()
        siblings = []
        
        for bt in parent.get_children():
            if isinstance(bt, WhiteButton):
                siblings.append(bt)
        pos = siblings.index(widget) + 1
        pct = float(float(pos) / float(len(siblings)))# * 100
        adj = self.scrollw.get_vadjustment()
        nowsize = self.get_size()
        defsize = self.get_default_size()
        pct = pct * 100
        alloc = self.scrollw.get_allocation()
        max = float(adj.get_upper() - alloc[-1])
        if nowsize[0] > defsize[0]: return
        if pct > 50:
            if adj.get_value() < max:
                gobject.idle_add(self._slide_scrollview, adj, max)
        else:
            if adj.get_value() > 0.0:
                gobject.idle_add(self._slide_scrollview, adj, 0.0)

    def highlight_area(self, widget, event):
        """ Highlight this button's category"""
        for category in self.viewers:
            if category.label == widget.get_label().replace("\n"," "):
                category.highlight()
        # Set the category description
        self.catdesc.set_markup(get_category_description(widget.get_label()))
        self.ensure_category_visibility(widget)
        return
    
    def unhighlight_area(self, widget, event):
        """ Restore colors on all categories """
        for category in self.viewers:
            category.un_highlight()
        self.catdesc.set_markup("")
        return
    
    def add_leftpane_category_shortcuts(self, holder):
        """ Create the widgets on the left pane """
        for category in self.viewers:
            bt = WhiteButton(category.label)
            bt.connect("enter-notify-event", self.highlight_area)
            bt.connect("leave-notify-event", self.unhighlight_area)
            holder.pack_start(bt, False, False, 2)
        
        # Add a label to describe this category there.
        # Do this inside a box, because of padding
        lbox = gtk.HBox()
        self.catdesc = WhiteDLabel("")
        lbox.pack_start(self.catdesc, True, True, 4)
        holder.pack_start(lbox, True, True, 12)
        # add the button to launch as root        
        if os.geteuid() == 0: return
        btauth = AuthButton("More Settings")
        btauth.connect("clicked", self.launch_vasm_root)
        holder.pack_end(btauth, False, False, 4)
        return

    def launch_vasm_root(self, widget):
        ### Close the current UI and open it up as root
        if not utils.test_su_helpers():
            # No su helpers are found... abort this because we do not have
            # an interactive tty
            tx = ("No authentication helpers were found on the system.  "
                  "Vasm is unable to switch to root mode.  Please login as root "
                  "and run vasm again.")
            dialogs.error(tx)
            return
        @utils.launch_external_gui
        def run_as_root():
            # find the command for this process
            script = os.path.abspath(__file__)
            proc = sp.Popen(["vsuper","python", script])
            proc.communicate()
        logger.info("Escalating privileges and re-launching vasm.")
        run_as_root()
        self.destroy()
    
    
    def get_left_pane(self):
        """ returns a panel to be used in the left pane
        """
        ebox = gtk.EventBox()
        ebox.connect("leave-notify-event", self.leftpane_leave_event)
        ebox.modify_bg(
            gtk.STATE_NORMAL, widgets.vlbluecolor)
        ebox.modify_bg(
            gtk.STATE_INSENSITIVE, widgets.vlbluecolor
        )
        return ebox

    def leftpane_leave_event(self, widget, event):
        for category in self.viewers:
            category.un_highlight()

    def expand_last_view(self):
        """ Expand the last iconview in the view area to fill the blank space """
        last = self.viewers.get_children()[-1]
        self.viewers.set_child_packing(
            last, True, True, 2, gtk.PACK_START)
    
    def _create_subcategory(self, parent, subname):
        """ Create a subcategory launcher """
        sub = widgets.VasmSubModule(
            parent = self,
            module_title = subname,
            icon = get_category_image(subname),
            parent_category=parent,
        )
        sub.__run__ = sub.launch
        return sub
    
    def add_option(self, module):
        """ Add module launcher to the appriopriate view """
        wholder = None
            # add the launcher to the right category
        for holder in self.categories:
            if holder.label == module.VASM_CATEGORY:
                wholder = holder
                break
        if wholder is None:
            wholder = widgets.SettingsHolder(
                label=module.VASM_CATEGORY,
                icon=get_category_image(module.VASM_CATEGORY),
                parent = self)
            # Append to the list of existing holders
            self.categories.append(wholder)
            # we need to pack this because it didn't exist
            self.viewers.pack_start(wholder, False, True, 2)
        # Now that we have the placeholder (view), add the launcher there.
        wholder.add_launcher(
            label=module.VASM_LABEL,
            icon=module.VASM_ICON,
            actuator = self.run_module(module))    

    def run_module(self, module):
        self._active_module_ = module.VASM_LABEL
        return module.__run__
    
    def run_submodule(self, submodule):
        self._active_module_ = submodule.title
        return submodule.launch

    def _get_subcategory_object(self, parent, sub):
        """ Check self.subcategories for sub or create a new one """
        for obj in self.subcategories:
            if obj._parent_category == parent and obj.title == sub:
                return obj
        subc = self._create_subcategory(parent, sub)
        return subc
    
    def add_subcategory_launchers(self):
        for sub in self.subcategories:
            #print sub._parent_category, "/", sub.title
            wholder = None
            for holder in self.categories:
                if holder.label == sub._parent_category:
                    wholder = holder
                    break
            if wholder is None:
                wholder = widgets.SettingsHolder(
                    label = sub._parent_category,
                    icon = get_category_image(sub._parent_category),
                    parent = self
                )
                self.categories.append(wholder)
                self.viewers.pack_start(wholder, False, True, 2)
            wholder.add_launcher(
                label = sub.title,
                icon = sub.icon,
                actuator = self.run_submodule(sub)
            )

    def discover_modules(self):
        """ Discover the modules pluggable into vasm """
        modulesdir = os.path.join(os.getcwd(), "modules")
        logger.debug("Searching for modules")
        for fname in sorted(os.listdir(modulesdir)):
            viewer = None
            if fname.endswith(".py") and fname !="__init__.py":
                pyname = fname[:-3]
                vasm_mod = self.load_module(pyname, fname, [modulesdir])
                # check if this is a sub category
                if self.test_has_subcategory(vasm_mod):
                    if vasm_mod.__vasm_test__():
                        logger.debug("Adding module %s"% vasm_mod.__name__)
                        parent, child = vasm_mod.VASM_CATEGORY.split("/")
                        subc = self._get_subcategory_object(parent, child)
                        # add the option to the subcategory
                        subc.members.append(vasm_mod)
                    
                        if not subc in self.subcategories:
                            self.subcategories.append(subc)
                    # That's it for subcategories.  the subcategory will load its own
                    # launchers when opened
                elif self.test_vasm_module(vasm_mod):
                    if vasm_mod.__vasm_test__():
                        # Module has paseed the test.  Add to the views
                        self.add_option(vasm_mod)

    def load_module(self, name, fname, path=["/home/vluser/devel/vasm/modules"]):
        """ return a named module found in the given path"""
        mod = imp.find_module(name, path)
        ret = imp.load_module(name, mod[0], fname, mod[2])
        return ret
    
    def test_has_subcategory(self, module):
        """ Check if this module belongs in a subcategory.
        if it does, just make sure the subcategory exists, and move on. """
        if not hasattr(module, "VASM_CATEGORY"):
            return False
        return "/" in module.VASM_CATEGORY

    def get_parent_and_sub(self, module):
        """ Get the parent and sub titles"""
        parent, sub = module.VASM_CATEGORY.split("/")
        return parent, sub
    
    def test_vasm_module(self, module):
        """ Check if the module in question is a valid vasm module
        
        Returns True when a module can be loaded on to vasm.
        False otherwise. """
        if not hasattr(module, 'VASM_CATEGORY'):
            return False
        if not hasattr(module, "__vasm_test__"):
            return False
        if not hasattr(module, "__run__"):
            return False
        return True

def main():
    logger.info("Starting vasm GTK+2 UI as uid=%s"% os.geteuid())
    gtk.gdk.threads_init()
    gobject.threads_init()
    w = VASM()
    w.show_all()
    gtk.main()

if __name__ == '__main__':
    # process commandline options
    parser = OptionParser()
    parser.add_option("-v", "--verbose", dest="verbose",
        help = "Verbosity level")
    (options, args) = parser.parse_args()
    
    if options.verbose is not None:
        logger.setLevel(logging.DEBUG)
    main()