Resolved merge conflicts against master.

This commit is contained in:
Griatch 2015-10-20 00:07:39 +02:00
commit c7e1a6a086
56 changed files with 270 additions and 263 deletions

View file

@ -134,10 +134,8 @@ class ANSIParser(object):
if convert:
colval = 16 + (red * 36) + (green * 6) + blue
#print "RGB colours:", red, green, blue
return "\033[%s8;5;%s%s%sm" % (3 + int(background), colval/100, (colval % 100)/10, colval%10)
else:
#print "ANSI convert:", red, green, blue
# xterm256 not supported, convert the rgb value to ansi instead
if red == green and red == blue and red < 2:
if background:

View file

@ -245,7 +245,7 @@ def create_help_entry(key, entrytext, category="General", locks=None):
return new_help
except IntegrityError:
string = "Could not add help entry: key '%s' already exists." % key
logger.log_errmsg(string)
logger.log_err(string)
return None
except Exception:
logger.log_trace()

View file

@ -113,7 +113,7 @@ class _SaverMutable(object):
elif self._db_obj:
self._db_obj.value = self
else:
logger.log_errmsg("_SaverMutable %s has no root Attribute to save to." % self)
logger.log_err("_SaverMutable %s has no root Attribute to save to." % self)
def _convert_mutables(self, data):
"converts mutables to Saver* variants and assigns .parent property"

View file

@ -246,8 +246,6 @@ class EvForm(object):
ix0 = match.end()
else:
break
#print "cell_coords:", cell_coords
#print "table_coords:", table_coords
# get rectangles and assign EvCells
for key, (iy, leftix, rightix) in cell_coords.items():
@ -256,7 +254,6 @@ class EvForm(object):
dy_up = 0
if iy > 0:
for i in range(1,iy):
#print "dy_up:", [form[iy-i][ix] for ix in range(leftix, rightix)]
if all(form[iy-i][ix] == cellchar for ix in range(leftix, rightix)):
dy_up += 1
else:
@ -265,7 +262,6 @@ class EvForm(object):
dy_down = 0
if iy < nform-1:
for i in range(1,nform-iy-1):
#print "dy_down:", [form[iy+i][ix]for ix in range(leftix, rightix)]
if all(form[iy+i][ix] == cellchar for ix in range(leftix, rightix)):
dy_down += 1
else:
@ -280,13 +276,10 @@ class EvForm(object):
# we have all the coordinates we need. Create EvCell.
data = self.cells_mapping.get(key, "")
#if key == "1":
# print "creating cell '%s' (%s):" % (key, data)
# print "iy=%s, iyup=%s, iydown=%s, leftix=%s, rightix=%s, width=%s, height=%s" % (iy, iyup, iydown, leftix, rightix, width, height)
options = { "pad_left":0, "pad_right":0, "pad_top":0, "pad_bottom":0, "align":"l", "valign":"t", "enforce_size":True}
options.update(custom_options)
#if key=="4":
#print "options:", options
mapping[key] = (iyup, leftix, width, height, EvCell(data, width=width, height=height,**options))
@ -297,7 +290,6 @@ class EvForm(object):
dy_up = 0
if iy > 0:
for i in range(1,iy):
#print "dy_up:", [form[iy-i][ix] for ix in range(leftix, rightix)]
if all(form[iy-i][ix] == tablechar for ix in range(leftix, rightix)):
dy_up += 1
else:
@ -306,7 +298,6 @@ class EvForm(object):
dy_down = 0
if iy < nform-1:
for i in range(1,nform-iy-1):
#print "dy_down:", [form[iy+i][ix]for ix in range(leftix, rightix)]
if all(form[iy+i][ix] == tablechar for ix in range(leftix, rightix)):
dy_down += 1
else:
@ -320,13 +311,10 @@ class EvForm(object):
# we have all the coordinates we need. Create Table.
table = self.tables_mapping.get(key, None)
#print "creating table '%s' (%s):" % (key, data)
#print "iy=%s, iyup=%s, iydown=%s, leftix=%s, rightix=%s, width=%s, height=%s" % (iy, iyup, iydown, leftix, rightix, width, height)
options = { "pad_left":0, "pad_right":0, "pad_top":0, "pad_bottom":0,
"align":"l", "valign":"t", "enforce_size":True}
options.update(custom_options)
#print "options:", options
if table:
table.reformat(width=width, height=height, **options)

View file

@ -221,6 +221,82 @@ class EvMenuCmdSet(CmdSet):
"""
self.add(CmdEvMenuNode())
def dedent_strip_nodetext_formatter(nodetext, has_options):
return dedent(nodetext).strip()
def dedent_nodetext_formatter(nodetext, has_options):
return dedent(nodetext)
def evtable_options_formatter(optionlist):
if not optionlist:
return ""
# column separation distance
colsep = 4
nlist = len(optionlist)
# get the widest option line in the table.
table_width_max = -1
table = []
for key, desc in optionlist:
if not (key or desc):
continue
table_width_max = max(table_width_max,
max(m_len(p) for p in key.split("\n")) +
max(m_len(p) for p in desc.split("\n")) + colsep)
raw_key = strip_ansi(key)
if raw_key != key:
# already decorations in key definition
table.append(ANSIString(" {lc%s{lt%s{le: %s" % (raw_key, key, desc)))
else:
# add a default white color to key
table.append(ANSIString(" {lc%s{lt{w%s{n{le: %s" % (raw_key, raw_key, desc)))
ncols = (_MAX_TEXT_WIDTH // table_width_max) + 1 # number of ncols
nlastcol = nlist % ncols # number of elements left in last row
# get the amount of rows needed (start with 4 rows)
nrows = 4
while nrows * ncols < nlist:
nrows += 1
ncols = nlist // nrows # number of full columns
nlastcol = nlist % nrows # number of elements in last column
# get the final column count
ncols = ncols + 1 if nlastcol > 0 else ncols
if ncols > 1:
# only extend if longer than one column
table.extend([" " for i in xrange(nrows - nlastcol)])
# build the actual table grid
table = [table[icol * nrows : (icol * nrows) + nrows] for icol in xrange(0, ncols)]
# adjust the width of each column
for icol in xrange(len(table)):
col_width = max(max(m_len(p) for p in part.split("\n")) for part in table[icol]) + colsep
table[icol] = [pad(part, width=col_width + colsep, align="l") for part in table[icol]]
# format the table into columns
return unicode(EvTable(table=table, border="none"))
def underline_node_formatter(nodetext, optionstext):
nodetext_width_max = max(m_len(line) for line in nodetext.split("\n"))
options_width_max = max(m_len(line) for line in optionstext.split("\n"))
total_width = max(options_width_max, nodetext_width_max)
separator1 = "_" * total_width + "\n\n" if nodetext_width_max else ""
separator2 = "\n" + "_" * total_width + "\n\n" if total_width else ""
return separator1 + nodetext + separator2 + optionstext
def null_node_formatter(nodetext, optionstext):
return nodetext + "\n\n" + optionstext
#------------------------------------------------------------
#
# Menu main class
@ -305,9 +381,20 @@ class EvMenu(object):
self._startnode = startnode
self._menutree = self._parse_menudata(menudata)
self._nodetext_formatter = nodetext_formatter
self._options_formatter = nodetext_formatter
self._node_formatter = node_formatter
if nodetext_formatter is not None:
self._nodetext_formatter = nodetext_formatter
else:
self._nodetext_formatter = dedent_strip_nodetext_formatter
if options_formatter is not None:
self._options_formatter = options_formatter
else:
self._options_formatter = evtable_options_formatter
if node_formatter is not None:
self._node_formatter = node_formatter
else:
self._node_formatter = underline_node_formatter
if startnode not in self._menutree:
raise EvMenuError("Start node '%s' not in menu tree!" % startnode)
@ -380,89 +467,16 @@ class EvMenu(object):
growing to make use of the screen space.
"""
#
# handle the node text
#
nodetext = self._nodetext_formatter(nodetext, len(optionlist))
if self._nodetext_formatter:
# use custom formatter
nodetext = self._nodetext_formatter(nodetext, len(optionlist))
else:
nodetext = dedent(nodetext).strip()
nodetext_width_max = max(m_len(line) for line in nodetext.split("\n"))
#
# handle the options
#
optionstext = self._options_formatter(optionlist)
if self._options_formatter:
# use custom formatter
optionstext = self._options_formatter(optionlist)
elif optionlist:
# column separation distance
colsep = 4
nlist = len(optionlist)
# get the widest option line in the table.
table_width_max = -1
table = []
for key, desc in optionlist:
table_width_max = max(table_width_max,
max(m_len(p) for p in key.split("\n")) +
max(m_len(p) for p in desc.split("\n")) + colsep)
raw_key = strip_ansi(key)
if raw_key != key:
# already decorations in key definition
table.append(ANSIString(" {lc%s{lt%s{le: %s" % (raw_key, key, desc)))
else:
# add a default white color to key
table.append(ANSIString(" {lc%s{lt{w%s{n{le: %s" % (raw_key, raw_key, desc)))
ncols = (_MAX_TEXT_WIDTH // table_width_max) + 1 # number of ncols
nlastcol = nlist % ncols # number of elements left in last row
# get the amount of rows needed (start with 4 rows)
nrows = 4
while nrows * ncols < nlist:
nrows += 1
ncols = nlist // nrows # number of full columns
nlastcol = nlist % nrows # number of elements in last column
# get the final column count
ncols = ncols + 1 if nlastcol > 0 else ncols
if ncols > 1:
# only extend if longer than one column
table.extend([" " for i in xrange(nrows-nlastcol)])
# build the actual table grid
table = [table[icol*nrows:(icol*nrows) + nrows] for icol in xrange(0, ncols)]
# adjust the width of each column
for icol in xrange(len(table)):
col_width = max(max(m_len(p) for p in part.split("\n")) for part in table[icol]) + colsep
table[icol] = [pad(part, width=col_width + colsep, align="l") for part in table[icol]]
# format the table into columns
optionstext = unicode(EvTable(table=table, border="none"))
else:
optionstext = ""
options_width_max = max(m_len(line) for line in optionstext.split("\n"))
#
# format the entire node
#
if self._node_formatter:
# use custom formatter
return self._node_formatter(nodetext, optionstext)
else:
# build the page
total_width = max(options_width_max, nodetext_width_max)
separator1 = "_" * total_width + "\n\n" if nodetext_width_max else ""
separator2 = "\n" + "_" * total_width + "\n\n" if total_width else ""
return separator1 + nodetext + separator2 + optionstext
return self._node_formatter(nodetext, optionstext)
def _execute_node(self, nodename, raw_string):
"""
@ -769,7 +783,7 @@ def test_start_node(caller):
def test_look_node(caller):
text = "Looking again will take you back to the previous message."
text = ""
options = {"key": ("{yL{nook", "l"),
"desc": "Go back to the previous menu.",
"goto": "test_start_node"}

View file

@ -1225,9 +1225,6 @@ class EvTable(object):
self._borders()
# equalize widths within each column
#print [col.options for col in self.worktable]
#print [[cell.get_width() for cell in col] for col in self.worktable]
#print [[cell.get_height() for cell in col] for col in self.worktable]
cwidths = [max(cell.get_width() for cell in col) for col in self.worktable]
if self.width or self.maxwidth and self.maxwidth < sum(cwidths):
@ -1281,7 +1278,6 @@ class EvTable(object):
# get minimum possible cell heights for each collumn
cheights_min = [max(cell.get_min_height() for cell in (col[iy] for col in self.worktable)) for iy in xrange(nrowmax)]
chmin = sum(cheights_min)
#print "cheights_min:", cheights_min
if chmin > self.height:
# we cannot shrink any more
@ -1309,7 +1305,6 @@ class EvTable(object):
# we must tell cells to crop instead of expanding
options["enforce_size"] = True
#print "cheights2:", cheights
# reformat table (for vertical align)
for ix, col in enumerate(self.worktable):
@ -1323,7 +1318,6 @@ class EvTable(object):
# calculate actual table width/height in characters
self.cwidth = sum(cwidths)
self.cheight = sum(cheights)
#print "actual table width, height:", self.cwidth, self.cheight, self.width, self.height
def _generate_lines(self):
"""

View file

@ -61,12 +61,9 @@ class SharedMemoryModelBase(ModelBase):
instance_key = cls._get_cache_key(args, kwargs)
# depending on the arguments, we might not be able to infer the PK, so in that case we create a new instance
#print "SharedMemoryModelBase.__call__ 1: calledby:", calledby(3)
#print "SharedMemoryModelBase.__call__ 2: instance_key:", instance_key
if instance_key is None:
return new_instance()
cached_instance = cls.get_cached_instance(instance_key)
#print "SharedMemoryModelBase.__call__ 3: cached_instance:", cached_instance
if cached_instance is None:
cached_instance = new_instance()
cls.cache_instance(cached_instance, new=True)
@ -114,7 +111,6 @@ class SharedMemoryModelBase(ModelBase):
"Helper method to create property wrappers with unique names (must be in separate call)"
def _get(cls, fname):
"Wrapper for getting database field"
#print "_get:", fieldname, wrappername,_GA(cls,fieldname)
if _GA(cls, "_is_deleted"):
raise ObjectDoesNotExist("Cannot access %s: Hosting object was already deleted." % fname)
return _GA(cls, fieldname)
@ -196,12 +192,9 @@ class SharedMemoryModelBase(ModelBase):
for fieldname, field in ((fname, field) for fname, field in attrs.items()
if fname.startswith("db_") and type(field).__name__ != "ManyToManyField"):
foreignkey = type(field).__name__ == "ForeignKey"
#print fieldname, type(field).__name__, field
wrappername = "dbid" if fieldname == "id" else fieldname.replace("db_", "", 1)
#print fieldname, wrappername
if wrappername not in attrs:
# makes sure not to overload manually created wrappers on the model
#print "wrapping %s -> %s" % (fieldname, wrappername)
create_wrapper(cls, fieldname, wrappername, editable=field.editable, foreignkey=foreignkey)
return super(SharedMemoryModelBase, cls).__new__(cls, name, bases, attrs)
@ -452,9 +445,7 @@ def flush_cache(**kwargs):
else:
yield cls
#print "start flush ..."
for cls in class_hierarchy([SharedMemoryModel]):
#print cls
cls.flush_instance_cache()
# run the python garbage collector
return gc.collect()
@ -534,8 +525,8 @@ def conditional_flush(max_rmem, force=False):
if ((now - LAST_FLUSH) < AUTO_FLUSH_MIN_INTERVAL) and not force:
# too soon after last flush.
logger.log_warnmsg("Warning: Idmapper flush called more than "\
"once in %s min interval. Check memory usage." % (AUTO_FLUSH_MIN_INTERVAL/60.0))
logger.log_warn("Warning: Idmapper flush called more than "\
"once in %s min interval. Check memory usage." % (AUTO_FLUSH_MIN_INTERVAL/60.0))
return
if os.name == "nt":

View file

@ -3,10 +3,10 @@ Logging facilities
These are thin wrappers on top of Twisted's logging facilities; logs
are all directed either to stdout (if Evennia is running in
interactive mode) or to game/logs.
interactive mode) or to $GAME_DIR/server/logs.
The log_file() function uses its own threading system to log to
arbitrary files in game/logs.
arbitrary files in $GAME_DIR/server/logs.
Note: All logging functions have two aliases, log_type() and
log_typemsg(). This is for historical, back-compatible reasons.

View file

@ -1009,8 +1009,6 @@ class PrettyTable(object):
if self.rowcount == 0 and (not options["print_empty"] or not options["border"]):
return ""
#print "prettytable:", self._rows
# Get the rows we need to print, taking into account slicing, sorting, etc.
rows = self._get_rows(options)
@ -1373,10 +1371,7 @@ def from_csv(fp, field_names = None, **kwargs):
if field_names:
table.field_names = field_names
else:
if py3k:
table.field_names = [x.strip() for x in next(reader)]
else:
table.field_names = [x.strip() for x in next(reader)]
table.field_names = [x.strip() for x in next(reader)]
for row in reader:
table.add_row([x.strip() for x in row])

View file

@ -174,7 +174,6 @@ class TestCrop(TestCase):
class TestDedent(TestCase):
def test_dedent(self):
#print "Did TestDedent run?"
# Empty string, return empty string
self.assertEqual("", utils.dedent(""))
# No leading whitespace

View file

@ -1177,7 +1177,7 @@ def init_new_player(player):
Deprecated.
"""
from evennia.utils import logger
logger.log_depmsg("evennia.utils.utils.init_new_player is DEPRECATED and should not be used.")
logger.log_dep("evennia.utils.utils.init_new_player is DEPRECATED and should not be used.")
def string_similarity(string1, string2):