Automatically inject a UUID into any factory object, rather than special-casing terminals. This will be very useful for introspection via dbus

This commit is contained in:
Chris Jones 2012-10-18 11:39:28 -07:00
parent 68847a9bb9
commit 6a4e47090b
3 changed files with 18 additions and 7 deletions

View File

@ -20,7 +20,7 @@ True
""" """
from borg import Borg from borg import Borg
from util import dbg, err from util import dbg, err, inject_uuid
# pylint: disable-msg=R0201 # pylint: disable-msg=R0201
# pylint: disable-msg=W0613 # pylint: disable-msg=W0613
@ -91,7 +91,9 @@ class Factory(Borg):
return(None) return(None)
dbg('Factory::make: created a %s' % product) dbg('Factory::make: created a %s' % product)
return(func(**kwargs)) output = func(**kwargs)
inject_uuid(output)
return(output)
def make_window(self, **kwargs): def make_window(self, **kwargs):
"""Make a Window""" """Make a Window"""

View File

@ -14,7 +14,6 @@ import gobject
import pango import pango
import subprocess import subprocess
import urllib import urllib
import uuid
from util import dbg, err, gerr from util import dbg, err, gerr
import util import util
@ -89,7 +88,6 @@ class Terminal(gtk.VBox):
command = None command = None
clipboard = None clipboard = None
pid = None pid = None
uuid = None
matches = None matches = None
config = None config = None
@ -133,9 +131,6 @@ class Terminal(gtk.VBox):
self.pending_on_vte_size_allocate = False self.pending_on_vte_size_allocate = False
self.uuid = uuid.uuid4()
dbg('assigning Terminal a TERMINATOR_UUID of: %s' % self.uuid.urn)
self.vte = vte.Terminal() self.vte = vte.Terminal()
self.vte._expose_data = None self.vte._expose_data = None
if not hasattr(self.vte, "set_opacity") or \ if not hasattr(self.vte, "set_opacity") or \

View File

@ -28,6 +28,7 @@ import gtk
import os import os
import pwd import pwd
import inspect import inspect
import uuid
# set this to true to enable debugging output # set this to true to enable debugging output
DEBUG = False DEBUG = False
@ -276,3 +277,16 @@ def enumerate_descendants(parent):
len(terminals), parent)) len(terminals), parent))
return(containers, terminals) return(containers, terminals)
def make_uuid():
"""Generate a UUID for an object"""
return uuid.uuid4()
def inject_uuid(target):
"""Inject a UUID into an existing object"""
uuid = make_uuid()
if not hasattr(target, "uuid") or target.uuid == None:
dbg("Injecting UUID %s into: %s" % (uuid, target))
target.uuid = uuid
else:
dbg("Object already has a UUID: %s" % target)