# HG changeset patch # User sirebral # Date 1250757945 18000 # Node ID 8bc955faf8191b09da3c54dc37b2ba3e52d3dcf0 # Parent 449a8900f9ace67a6637ab63830fb53ae5d6d8b2 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates. diff -r 449a8900f9ac -r 8bc955faf819 orpg/main.py --- a/orpg/main.py Thu Aug 20 03:00:39 2009 -0500 +++ b/orpg/main.py Thu Aug 20 03:45:45 2009 -0500 @@ -36,6 +36,8 @@ from orpg.dirpath import dir_struct +from orpg import minidom + import orpg.player_list import orpg.tools.pluginui as pluginUI @@ -613,7 +615,7 @@ filename = dir_struct["user"] + "layout.xml" temp_file = open(filename) txt = temp_file.read() - xml_dom = self.xml.parseXml(txt)._get_documentElement() + xml_dom = xml.parseXml(txt)._get_documentElement() temp_file.close() """ Would a component work better? @@ -743,7 +745,7 @@ #Load the layout if one exists layout = xml_dom.getElementsByTagName("DockLayout") try: - textnode = self.xml.safe_get_text_node(layout[0]) + textnode = xml.safe_get_text_node(layout[0]) self._mgr.LoadPerspective(textnode._get_nodeValue()) except: pass xml_dom.unlink() @@ -872,7 +874,7 @@ filename = dir_struct["user"] + "layout.xml" temp_file = open(filename) txt = temp_file.read() - xml_dom = self.xml.parseXml(txt)._get_documentElement() + xml_dom = xml.parseXml(txt)._get_documentElement() temp_file.close() (x_size,y_size) = self.GetClientSize() (x_pos,y_pos) = self.GetPositionTuple() @@ -885,12 +887,12 @@ xml_dom.setAttribute("maximized", str(max)) layout = xml_dom.getElementsByTagName("DockLayout") try: - textnode = self.xml.safe_get_text_node(layout[0]) + textnode = xml.safe_get_text_node(layout[0]) textnode._set_nodeValue(str(self._mgr.SavePerspective())) except: - elem = self.xml.minidom.Element('DockLayout') + elem = minidom.Element('DockLayout') elem.setAttribute("DO_NO_EDIT","True") - textnode = self.xml.safe_get_text_node(elem) + textnode = xml.safe_get_text_node(elem) textnode._set_nodeValue(str(self._mgr.SavePerspective())) xml_dom.appendChild(elem) temp_file = open(filename, "w") diff -r 449a8900f9ac -r 8bc955faf819 orpg/orpg_version.py --- a/orpg/orpg_version.py Thu Aug 20 03:00:39 2009 -0500 +++ b/orpg/orpg_version.py Thu Aug 20 03:45:45 2009 -0500 @@ -4,7 +4,7 @@ #BUILD NUMBER FORMAT: "YYMMDD-##" where ## is the incremental daily build index (if needed) DISTRO = "Traipse Dev" DIS_VER = "Ornery Orc" -BUILD = "090820" +BUILD = "090820-01" # This version is for network capability. PROTOCOL_VERSION = "1.2" diff -r 449a8900f9ac -r 8bc955faf819 orpg/orpg_xml.py --- a/orpg/orpg_xml.py Thu Aug 20 03:00:39 2009 -0500 +++ b/orpg/orpg_xml.py Thu Aug 20 03:45:45 2009 -0500 @@ -29,13 +29,19 @@ from orpg import minidom import string -class xml: +from orpg.tools.orpg_log import logger +from orpg.tools.decorators import debugging + +class xml: + @debugging def __init__(self): pass - + + @debugging def toxml(self, root, pretty=0): return root.toxml(pretty) - + + @debugging def parseXml(self, s): "parse and return doc" try: @@ -45,7 +51,8 @@ except Exception, e: print e return None - + + @debugging def safe_get_text_node(self, xml_dom): """ returns the child text node or creates one if doesnt exist """ t_node = xml_dom._get_firstChild() @@ -53,14 +60,16 @@ t_node = minidom.Text("") t_node = xml_dom.appendChild(t_node) return t_node - + + @debugging def strip_unicode(self, txt): for i in xrange(len(txt)): if txt[i] not in string.printable: try: txt = txt.replace(txt[i], '&#' + str(ord(txt[i])) + ';') except: txt = txt.replace(txt[i], '{?}') return txt - + + @debugging def strip_text(self, txt): # The following block strips out 8-bit characters u_txt = "" diff -r 449a8900f9ac -r 8bc955faf819 orpg/tools/decorators.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/orpg/tools/decorators.py Thu Aug 20 03:45:45 2009 -0500 @@ -0,0 +1,146 @@ +import warnings +import functools + +from orpg.orpgCore import * + +def deprecated(msg=None): + """ + This is a decorator which can be used to mark functions + as deprecated. It will result in a warning being emitted + when the function is used. + """ + def wrap(func): + @functools.wraps(func) + def new_func(*args, **kwargs): + out = msg + if not out: + out = "Call to deprecated function %s." + else: + out = "Call to deprecated function %s.\n" + out + + warnings.warn_explicit( + out % (func.__name__), + category=DeprecationWarning, + filename=func.func_code.co_filename, + lineno=func.func_code.co_firstlineno + 1 + ) + return func(*args, **kwargs) + return new_func + return wrap + +def pending_deprecation(msg=None): + """ + This is a decorator which can be used to mark functions + as deprecated. It will result in a warning being emitted + when the function is used. + """ + def wrap(func): + @functools.wraps(func) + def new_func(*args, **kwargs): + out = msg + if not out: + out = "%s is Pending Deprecation." + else: + out = "%s is Pending Deprecation.\n" + out + + warnings.warn_explicit( + out % (func.__name__), + category=PendingDeprecationWarning, + filename=func.func_code.co_filename, + lineno=func.func_code.co_firstlineno + 1 + ) + return func(*args, **kwargs) + return new_func + return wrap + +def synchronized(lock): + """ + Synchronization decorator. + """ + + @functools.wraps(func) + def new_func(*args, **kwargs): + lock.acquire() + try: + return func(*args, **kwargs) + finally: + lock.release() + return new_func + +class memoized(object): + """ + Decorator that caches a function's return value each time it is called. + If called later with the same arguments, the cached value is returned, and + not re-evaluated. + """ + def __init__(self, func): + self.func = func + self.cache = {} + + def __call__(self, *args, **kwargs): + try: + return self.cache[args + kwargs.values()] + except KeyError: + self.cache[args] = value = self.func(*args, **kwargs) + return value + except TypeError: + # uncachable -- for instance, passing a list as an argument. + # Better to not cache than to blow up entirely. + return self.func(*args) + def __repr__(self): + """ + Return the function's docstring. + """ + return self.func.__doc__ + +def debugging(func): + """ + Decorator to print Enter/Exit debugging info + """ + + @functools.wraps(func) + def new_func(*args, **kwargs): + from orpg.tools.orpg_log import logger + + if not ORPG_DEBUG & logger.log_level: + return func(*args, **kwargs) + + if str(args[0].__class__).startswith(' 1: + args_s += ', ' + ', '.join([str(attr) for attr in args[1:]]) + kwargs_s = "" + for k,v in kwargs.iteritems(): + kwargs_s += ', ' + k + '=' + str(v) + + call_str = '%(cls)s->%(fnc)s(%(args)s%(kwargs)s)' % { + 'cls':cls, + 'fnc':func.__name__, + 'args':args_s, + 'kwargs':kwargs_s} + try: + logger.debug("Enter " + call_str) + return func(*args, **kwargs) + finally: + logger.debug("Exit " + call_str) + else: + try: + logger.debug("Enter " + func.__name__) + return func(*args, **kwargs) + finally: + logger.debug("Exit " + func.__name__) + return new_func + +""" +Cannot use this decorator till we stop supporting py2.5 +as class decorators did not land till py2.6 I am just adding it here +So when we do we can convert all singleton classes to use it +""" +def singleton(cls): + instances = {} + def getinstance(): + if cls not in instances: + instances[cls] = cls() + return instances[cls] + return getinstance diff -r 449a8900f9ac -r 8bc955faf819 upmana/updatemana.py --- a/upmana/updatemana.py Thu Aug 20 03:00:39 2009 -0500 +++ b/upmana/updatemana.py Thu Aug 20 03:45:45 2009 -0500 @@ -3,11 +3,11 @@ from orpg.orpgCore import * #import tempfile import shutil + from orpg.dirpath import dir_struct from orpg.tools.orpg_log import logger from orpg.tools.decorators import debugging from upmana.validate import validate -from orpg.dirpath import dir_struct from mercurial import ui, hg, commands, repo, revlog, cmdutil, util diff -r 449a8900f9ac -r 8bc955faf819 upmana/validate.py --- a/upmana/validate.py Thu Aug 20 03:00:39 2009 -0500 +++ b/upmana/validate.py Thu Aug 20 03:45:45 2009 -0500 @@ -35,3 +35,5 @@ def ini_entry(self, entry_name, ini_file): pass + +validate = Validate()