[Pymoul-svn] SF.net SVN: pymoul: [53] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-20 16:32:04
|
Revision: 53
http://pymoul.svn.sourceforge.net/pymoul/?rev=53&view=rev
Author: tiran
Date: 2007-01-20 08:32:00 -0800 (Sat, 20 Jan 2007)
Log Message:
-----------
Minor linux fixes
KiImage fixes and first tests
Modified Paths:
--------------
pymoul/trunk/src/moul/file/kiimage.py
pymoul/trunk/src/moul/file/tests/test_kiimage.py
Added Paths:
-----------
pymoul/trunk/src/moul/config/linux.py
pymoul/trunk/src/moul/file/tests/avatar_clean.jpg
Removed Paths:
-------------
pymoul/trunk/src/moul/config/linux2.py
Copied: pymoul/trunk/src/moul/config/linux.py (from rev 51, pymoul/trunk/src/moul/config/linux2.py)
===================================================================
--- pymoul/trunk/src/moul/config/linux.py (rev 0)
+++ pymoul/trunk/src/moul/config/linux.py 2007-01-20 16:32:00 UTC (rev 53)
@@ -0,0 +1,57 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""Linux configuration for pyMoul
+
+XXX: untested!
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id$"
+__revision__ = "$Revision$"
+
+import os
+from moul.log import LOG
+LOG.warning('Linux support is not tested')
+
+MOUL_DIR = "Uru Live"
+INI_FILE = ('pyMoul', 'pymoul.ini')
+EXEC_NAME = "UruLauncher"
+HOME = os.environ['HOME']
+
+def getMoulUserDataDir():
+ """Get path of MOUL data directory
+
+ The MOUL data directory contains log files, chatlogs, KI images and many
+ more things.
+ """
+ moul_data = os.path.join(HOME, MOUL_DIR)
+
+def getPyMoulIniLocation():
+ """Get path to the pyMoul ini file
+ """
+ ini_file = os.path.join(HOME, *INI_FILE)
+ return ini_file
+
+def _startMOUL(installdir, *args):
+ """Start MOUL
+ """
+ # P_DETACH is similar to P_NOWAIT, but the new process is detached from
+ # the console of the calling process.
+ mode = os.P_DETACH
+ path = os.path.join(installdir, EXEC_NAME)
+ args = (EXEC_NAME,) + args
+ return os.spawnv(mode, path, args)
Deleted: pymoul/trunk/src/moul/config/linux2.py
===================================================================
--- pymoul/trunk/src/moul/config/linux2.py 2007-01-20 15:28:50 UTC (rev 52)
+++ pymoul/trunk/src/moul/config/linux2.py 2007-01-20 16:32:00 UTC (rev 53)
@@ -1,57 +0,0 @@
-# pyMoul - Python interface to Myst Online URU Live
-# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
-
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-"""Linux configuration for pyMoul
-
-XXX: untested!
-"""
-__author__ = "Christian Heimes"
-__version__ = "$Id$"
-__revision__ = "$Revision$"
-
-import os
-from moul.log import LOG
-LOG.warning('Linux support is not tested')
-
-MOUL_DIR = "Uru Live"
-INI_FILE = ('pyMoul', 'pymoul.ini')
-EXEC_NAME = "UruLauncher"
-HOME = os.environ('HOME')
-
-def getMoulUserDataDir():
- """Get path of MOUL data directory
-
- The MOUL data directory contains log files, chatlogs, KI images and many
- more things.
- """
- moul_data = os.path.join(HOME, MOUL_DIR)
-
-def getPyMoulIniLocation():
- """Get path to the pyMoul ini file
- """
- ini_file = os.path.join(HOME, *INI_FILE)
- return ini_file
-
-def _startMOUL(installdir, *args):
- """Start MOUL
- """
- # P_DETACH is similar to P_NOWAIT, but the new process is detached from
- # the console of the calling process.
- mode = os.P_DETACH
- path = os.path.join(installdir, EXEC_NAME)
- args = (EXEC_NAME,) + args
- return os.spawnv(mode, path, args)
Modified: pymoul/trunk/src/moul/file/kiimage.py
===================================================================
--- pymoul/trunk/src/moul/file/kiimage.py 2007-01-20 15:28:50 UTC (rev 52)
+++ pymoul/trunk/src/moul/file/kiimage.py 2007-01-20 16:32:00 UTC (rev 53)
@@ -23,27 +23,37 @@
import os
import tempfile
+import struct
JPEG_HEADER = "\377\330\377"
-class KIImage(object):
+class KiImage(object):
+ """Ki image handler
- def __init__(self, filename):
- assert os.path.isfile(filename)
- self._filename = filename
- self._fd = None
- self.open()
+ MOUL's KI images have four leading bytes of junk that encode the file
+ size. The class allowes to add, remove and verify the header.
+ """
+
+ def __init__(self, fd_name):
+ if isinstance(fd_name, basestring):
+ name = fd_name
+ fd = open(fd_name, 'rb')
+ else:
+ name = getattr(fd_name, 'name', '<UNKNOWN>')
+ fd = fd_name
+
+ self._filename = name
+ self._fd = fd
+ self._size = None
- def open(self):
- if not self._fd:
- self._fd = open(filename, 'rb')
-
def close(self):
if self._fd:
self._fd.close()
self._fd = None
def getSize(self):
+ if self._size is not None:
+ return self._size
fd = self._fd
opos = fd.tell()
size = 0
@@ -52,9 +62,11 @@
size = fd.tell()
finally:
fd.seek(opos)
+ self._size = size
return size
def moulHeaderToSize(self, header=None):
+ # XXX use struct
if header is None:
fd = self._fd
fd.seek(0)
@@ -65,8 +77,9 @@
return size
def sizeToMoulHeader(self, size=None):
+ # XXX use struct
if size is None:
- size = self.getSize() + 4
+ size = self.getSize() + 4 # XXX +4 ?
leading = 4* [None]
for i in (3,2,1,0):
l = size >> 8*i
@@ -77,7 +90,7 @@
def verifyMoulHeader(self, header=None):
header_size = self.moulHeaderToSize(header)
file_size = self.getSize()
- if header_size == file_size:
+ if (header_size + 4) == file_size:
return True
return False
@@ -100,7 +113,7 @@
def removeMoulHeader(self):
if not self.isMoulImage():
- raise Exception
+ raise ValueError('Image has no MOUL header')
out = tempfile.TemporaryFile()
fd = self._fd
fd.seek(4)
@@ -108,8 +121,10 @@
return out
def addMoulHeader(self):
+ if self.isMoulImage():
+ raise ValueError('Image has already a MOUL header')
if not self.isJpeg():
- raise Exception
+ raise ValueError('File is not a JPEG')
out = tempfile.TemporaryFile()
header = self.sizeToMoulHeader()
fd = self._fd
Added: pymoul/trunk/src/moul/file/tests/avatar_clean.jpg
===================================================================
(Binary files differ)
Property changes on: pymoul/trunk/src/moul/file/tests/avatar_clean.jpg
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: pymoul/trunk/src/moul/file/tests/test_kiimage.py
===================================================================
--- pymoul/trunk/src/moul/file/tests/test_kiimage.py 2007-01-20 15:28:50 UTC (rev 52)
+++ pymoul/trunk/src/moul/file/tests/test_kiimage.py 2007-01-20 16:32:00 UTC (rev 53)
@@ -21,13 +21,49 @@
__version__ = "$Id$"
__revision__ = "$Revision$"
+import os
+from StringIO import StringIO
import unittest
from doctest import DocTestSuite
-import moul.file.kiimage
+from moul.file.kiimage import KiImage
+base = os.path.dirname(__file__)
+kiimg = os.path.join(base, 'avatar.jpg')
+kiclean = os.path.join(base, 'avatar_clean.jpg')
+
+class KiImageTest(unittest.TestCase):
+
+ def setUp(self):
+ self._ki = open(kiimg, 'rb')
+ self._clean = open(kiclean, 'rb')
+
+ def tearDown(self):
+ self._ki.close()
+ self._clean.close()
+
+ def test_openname(self):
+ k = KiImage(kiimg)
+ self.failUnless(k.isMoulImage())
+ self.failIf(k.isJpeg())
+
+ k = KiImage(kiclean)
+ self.failIf(k.isMoulImage())
+ self.failUnless(k.isJpeg())
+
+ def test_openfd(self):
+ k = KiImage(self._ki)
+ self.failUnless(k.isMoulImage())
+ self.failIf(k.isJpeg())
+
+ k = KiImage(self._clean)
+ self.failIf(k.isMoulImage())
+ self.failUnless(k.isJpeg())
+
+
def test_suite():
return unittest.TestSuite((
+ unittest.makeSuite(KiImageTest),
DocTestSuite('moul.file.kiimage')
))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|