Changed erroneous DateField to DateTimeField in ObjectDB, so you might have to resync your database. Fixed lots of formatting issues in the info and list commands. Resolved issue105.

This commit is contained in:
Griatch 2010-09-05 14:42:09 +00:00
parent 76624cd6f3
commit a2291953f2
8 changed files with 232 additions and 137 deletions

View file

@ -89,7 +89,7 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
try:
try:
wanted_cache_key = python_path
print "inport cmdsets: cache=", CACHED_CMDSETS
cmdsetclass = CACHED_CMDSETS.get(wanted_cache_key, None)
errstring = ""
if not cmdsetclass:
@ -125,14 +125,6 @@ def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False):
emit_to_obj.msg(errstring)
raise
def get_cached_cmdsets():
"""
Get the currently live cache from outside this module.
Calling a routine avoids update-problems when importing
the variable from an external module.
"""
return CACHED_CMDSETS
# classes
class CmdSetHandler(object):

View file

@ -212,8 +212,7 @@ class Msg(SharedMemoryModel):
#@date_sent.setter
def date_sent_set(self, value):
"Setter. Allows for self.date_sent = value"
self.db_date_sent = value
self.save()
raise Exception("You cannot edit date_sent!")
#@date_sent.deleter
def date_sent_del(self):
"Deleter. Allows for del self.date_sent"

View file

@ -9,54 +9,6 @@ from src.scripts.models import ScriptDB
from src.utils import create
from src.utils import logger
def format_script_list(scripts):
"Takes a list of scripts and format the output."
if not scripts:
return "<No scripts>"
string = "id obj\t\tkey\t\tinterval\trepeats\tnext\tpersistent"
for script in scripts:
obj = None
interval = None
repeats = None
try:
obj = script.obj
except AttributeError:
pass
try:
interval = script.interval
except AttributeError:
pass
try:
repeats = script.repeats
except AttributeError:
pass
try:
next_repeat = script.time_until_next_repeat()
except:
pass
if not obj:
obj = "<Global>"
if not interval:
interval = "N/A"
else:
interval = "%ss" % interval
if not repeats:
repeats = "N/A"
else:
repeats = "%ss" % repeats
if not next_repeat:
next_repeat = "N/A"
else:
next_repeat = "%ss" % next_repeat
string += "\n %s %s\t\t%s\t%s\t%s\t%s\t%s\n %s (%s)" % \
(script.id, obj, script.key, interval,
repeats, next_repeat, script.persistent,
script.typeclass_path, script.desc)
return string
class ScriptHandler(object):
"""
Implements the handler. This sits on each game object.

View file

@ -99,7 +99,7 @@ class Attribute(SharedMemoryModel):
# by each child class to this abstact class)
db_obj = None # models.ForeignKey("RefencedObject")
# time stamp
db_date_created = models.DateField(editable=False, auto_now_add=True)
db_date_created = models.DateTimeField(editable=False, auto_now_add=True)
# Database manager
objects = managers.AttributeManager()
@ -197,8 +197,7 @@ class Attribute(SharedMemoryModel):
#@date_created.setter
def date_created_set(self, value):
"Setter. Allows for self.date_created = value"
self.db_date_created = value
self.save()
raise Exception("Cannot edit date_created!")
#@date_created.deleter
def date_created_del(self):
"Deleter. Allows for del self.date_created"
@ -360,7 +359,7 @@ class TypedObject(SharedMemoryModel):
# (the type class is what defines what kind of Object this is)
db_typeclass_path = models.CharField(max_length=255, null=True)
# Creation date
db_date_created = models.DateField(editable=False, auto_now_add=True)
db_date_created = models.DateTimeField(editable=False, auto_now_add=True)
# Permissions (access these through the 'permissions' property)
db_permissions = models.CharField(max_length=512, blank=True)
@ -441,8 +440,7 @@ class TypedObject(SharedMemoryModel):
#@date_created.setter
def date_created_set(self, value):
"Setter. Allows for self.date_created = value"
self.db_date_created = value
self.save()
raise Exception("Cannot change date_created!")
#@date_created.deleter
def date_created_del(self):
"Deleter. Allows for del self.date_created"

View file

@ -8,7 +8,7 @@ import os
import textwrap
import datetime
from django.conf import settings
from src.utils import ansi
def is_iter(iterable):
"""
@ -145,7 +145,8 @@ def datetime_format(dtobj):
Takes a datetime object instance (e.g. from django's DateTimeField)
and returns a string.
"""
year, month, day = dtobj.year, dtobj.date, dtobj.day
year, month, day = dtobj.year, dtobj.month, dtobj.day
hour, minute, second = dtobj.hour, dtobj.minute, dtobj.second
now = datetime.datetime.now()
@ -307,3 +308,30 @@ def inherits_from(obj, parent):
else:
parent_path = "%s.%s" % (parent.__class__.__module__, parent.__class__.__name__)
return any(True for obj_path in obj_paths if obj_path == parent_path)
def format_table(table, extra_space=1):
"""
Takes a table of collumns: [[val,val,val,...], [val,val,val,...], ...]
where each val will be placed on a separate row in the column. All
collumns must have the same number of rows (some positions may be
empty though).
The function formats the columns to be as wide as the wides member
of each column.
extra_space defines how much extra padding should minimum be left between
collumns.
first_row_ansi defines an evential colour string for the first row.
"""
if not table:
return [[]]
max_widths = [max([len(str(val))
for val in col]) for col in table]
ftable = []
for irow in range(len(table[0])):
ftable.append([str(col[irow]).ljust(max_widths[icol]) + " " * extra_space
for icol, col in enumerate(table)])
return ftable