mirror of
https://github.com/evennia/evennia.git
synced 2026-04-03 14:37:17 +02:00
Some minor cleanups here and there.
This commit is contained in:
parent
ed6def0c88
commit
1feb3a80a5
3 changed files with 27 additions and 10 deletions
|
|
@ -8,7 +8,8 @@ from src.typeclasses.managers import TypedObjectManager
|
|||
from src.typeclasses.managers import returns_typeclass, returns_typeclass_list
|
||||
from src.utils import utils
|
||||
from src.utils.utils import to_unicode
|
||||
from src.utils import logger
|
||||
|
||||
ObjAttribute = None
|
||||
|
||||
__all__ = ("ObjectManager",)
|
||||
|
||||
|
|
@ -104,11 +105,13 @@ class ObjectManager(TypedObjectManager):
|
|||
"""
|
||||
Returns all objects having the given attribute_name defined at all.
|
||||
"""
|
||||
from src.objects.models import ObjAttribute
|
||||
global _ObjAttribute
|
||||
if not ObjAttribute:
|
||||
from src.objects.models import ObjAttribute as _ObjAttribute
|
||||
lstring = ""
|
||||
if location:
|
||||
lstring = ", db_obj__db_location=location"
|
||||
attrs = eval("ObjAttribute.objects.filter(db_key=attribute_name%s)" % lstring)
|
||||
attrs = eval("_ObjAttribute.objects.filter(db_key=attribute_name%s)" % lstring)
|
||||
return [attr.obj for attr in attrs]
|
||||
|
||||
@returns_typeclass_list
|
||||
|
|
@ -118,7 +121,9 @@ class ObjectManager(TypedObjectManager):
|
|||
attrname set to the given value. Note that no conversion is made
|
||||
to attribute_value, and so it can accept also non-strings.
|
||||
"""
|
||||
from src.objects.models import ObjAttribute
|
||||
global _ObjAttribute
|
||||
if not ObjAttribute:
|
||||
from src.objects.models import ObjAttribute as _ObjAttribute
|
||||
lstring = ""
|
||||
if location:
|
||||
lstring = ", db_obj__db_location=location"
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ def reset_server():
|
|||
It also checks so the warm-reset mechanism works as it should.
|
||||
"""
|
||||
from src.server.sessionhandler import SESSIONS
|
||||
print _(" Initial setup finished. Resetting/Reloading Server.")
|
||||
print _(" Initial setup complete. Resetting/reloading Server.")
|
||||
SESSIONS.server.shutdown(mode='reset')
|
||||
|
||||
def handle_setup(last_step):
|
||||
|
|
|
|||
|
|
@ -129,6 +129,15 @@ class ANSIParser(object):
|
|||
(r'(?<!\\){(b[0-5]{3})', self.parse_rgb) # {b123 - background colour
|
||||
]
|
||||
|
||||
# matching for cleaning out escaped colour codes (used with sub)
|
||||
|
||||
self.clean_escapes = [
|
||||
(r"\\{", "{"),
|
||||
(r"\\%r", "%r"),
|
||||
(r"\\%b", "%b"),
|
||||
(r"\\%c", "%c")
|
||||
]
|
||||
|
||||
# obs - order matters here, we want to do the xterms first since
|
||||
# they collide with some of the other mappings otherwise.
|
||||
self.ansi_map = self.xterm256_map + self.mux_ansi_map + self.ext_ansi_map
|
||||
|
|
@ -137,6 +146,9 @@ class ANSIParser(object):
|
|||
self.ansi_sub = [(re.compile(sub[0], re.DOTALL), sub[1])
|
||||
for sub in self.ansi_map]
|
||||
|
||||
self.escape_sub = [(re.compile(sub[0], re.DOTALL), sub[1])
|
||||
for sub in self.clean_escapes]
|
||||
|
||||
# prepare matching ansi codes overall
|
||||
self.ansi_regex = re.compile("\033\[[0-9;]+m")
|
||||
|
||||
|
|
@ -160,8 +172,10 @@ class ANSIParser(object):
|
|||
|
||||
if self.do_xterm256:
|
||||
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: return ANSI_BACK_BLACK
|
||||
|
|
@ -216,11 +230,9 @@ class ANSIParser(object):
|
|||
if strip_ansi:
|
||||
# remove all ANSI escape codes
|
||||
string = self.ansi_regex.sub("", string)
|
||||
# strip the \ in front of escaped colour codes, like \{r.
|
||||
string = re.sub(r"\\{", "{", string)
|
||||
string = re.sub(r"\\%r", "%r", string)
|
||||
string = re.sub(r"\\%b", "%b", string)
|
||||
string = re.sub(r"\\%c", "%c", string)
|
||||
for sub in self.escape_sub:
|
||||
# strip the \ in front of escaped colour codes, like \{r.
|
||||
string = sub[0].sub(sub[1], string)
|
||||
return string
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue