[Pymoul-svn] SF.net SVN: pymoul: [159] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-12 13:36:27
|
Revision: 159
http://pymoul.svn.sourceforge.net/pymoul/?rev=159&view=rev
Author: tiran
Date: 2007-02-12 05:36:09 -0800 (Mon, 12 Feb 2007)
Log Message:
-----------
Added mac pathes
First work on DNI time module
Modified Paths:
--------------
pymoul/trunk/src/moul/log.py
pymoul/trunk/src/moul/osdependent/darwin/__init__.py
pymoul/trunk/src/moul/osdependent/linux/__init__.py
pymoul/trunk/src/moul/time/__init__.py
pymoul/trunk/src/moul/time/cavern.py
pymoul/trunk/src/moul/time/dni.py
pymoul/trunk/src/moul/time/tests/test_cavern.py
Modified: pymoul/trunk/src/moul/log.py
===================================================================
--- pymoul/trunk/src/moul/log.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/log.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -117,7 +117,7 @@
shdlr = logging.StreamHandler(sys.stderr)
shdlr.setFormatter(format)
root.addHandler(shdlr)
- _systemInfo()
+ #_systemInfo()
else:
_installMemoryHdlr()
_systemInfo()
Modified: pymoul/trunk/src/moul/osdependent/darwin/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -30,9 +30,17 @@
LOG = getLogger('moul.darwin')
LOG.critical('Darwin/Mac support is not tested')
-MOUL_DIR = "Uru Live"
-EXEC_NAME = "UruLauncher"
-HOME = os.environ['HOME']
+HOME = os.path.expanduser('~')
+MOUL_DIR = "Library/Preferences/UruLive Preferences/p_drive/My Documents/Uru Live"
+APP_PATH = "Uru Live.app/Contents/Resources/Game.app/Contents/Resources/transgaming/c_drive/Program Files/Uru Live/"
+APP_NAME = "Uru Live.app"
+EXEC_NAME = "???" # XXX
+UPDATER = "Uru Live.app/Contents/Resources/Game.app/Contents/Resources/URU Live Updater.app/Contents/MacOS/URU Live Updater"
+LOCATIONS = [
+ "/Applications",
+ "%s/Applications" % HOME,
+ ]
+PYMOUL_DIR = "Library/Preferences/pyMoul"
def getMoulUserDataDir():
"""Get path of MOUL data directory
@@ -45,7 +53,7 @@
def getPyMoulDataDir():
"""Get path to the pyMoul ini directory
"""
- inidir= os.path.join(HOME, '.pymoul')
+ inidir= os.path.join(HOME, PYMOUL_DIR)
return inidir
def startMoul(installdir, *args, **kwargs):
Modified: pymoul/trunk/src/moul/osdependent/linux/__init__.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -31,10 +31,10 @@
LOG = getLogger('moul.linux')
LOG.critical('Linux support is not tested')
+HOME = os.path.expanduser('~')
MOUL_DIR = ".urulive"
INI_FILE = ('pyMoul', 'pymoul.ini')
EXEC_NAME = "UruLauncher"
-HOME = os.environ['HOME']
PROCESSES = ('urulauncher', 'uruexplorer')
LOCATIONS = [
"%s/dev/pymoul/MystOnline" % HOME,
Modified: pymoul/trunk/src/moul/time/__init__.py
===================================================================
--- pymoul/trunk/src/moul/time/__init__.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/time/__init__.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -20,3 +20,9 @@
__author__ = "Christian Heimes"
__version__ = "$Id$"
__revision__ = "$Revision$"
+
+from moul.osdependent import __FROZEN__
+# pytz is an egg
+if not __FROZEN__:
+ import pkg_resources
+ pkg_resources.require("pytz>=2006p")
Modified: pymoul/trunk/src/moul/time/cavern.py
===================================================================
--- pymoul/trunk/src/moul/time/cavern.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/time/cavern.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -24,17 +24,15 @@
__all__ = ['CavernTime']
from datetime import datetime
-
-from moul.osdependent import __FROZEN__
-# pytz is an egg
-if not __FROZEN__:
- import pkg_resources
- pkg_resources.require("pytz>=2006p")
-
from pytz import all_timezones
from pytz import timezone
from pytz import utc as UTC
+from moul.time.utils import td2sec
+from moul.time.utils import diffTD
+from moul.time.utils import utcnow
+from moul.time.utils import normalizeTZ
+
## not used in the current version
#SUPPORTED_TZ = ('America', 'Canada', 'Etc', 'Europe', 'US')
#ADDITIONAL_TZ = ('GMT', 'UTC')
@@ -73,42 +71,6 @@
PACIFIC_TZ_NAME = ('US/Pacific', 'PST', 'PDT') # PST / PDT
PACIFIC_TZ = timezone(PACIFIC_TZ_NAME[0])
-def diffTD(td1, td2):
- """Difference of two time delta objects -> int
-
- >>> from datetime import timedelta
- >>> type(diffTD(timedelta(0, 3600), timedelta(0, -3600)))
- <type 'int'>
- >>> diffTD(timedelta(0, 3600), timedelta(0, -3600))
- 7200
- >>> diffTD(timedelta(0, 3600), timedelta(0, 3600))
- 0
- >>> diffTD(timedelta(0, -3600), timedelta(0, -3600))
- 0
- >>> diffTD(timedelta(0, -7200), timedelta(0, -3600))
- -3600
- >>> diffTD(timedelta(0, -3600), timedelta(0, -7200))
- 3600
- >>> diffTD(timedelta(0, 3600, 1), timedelta(0, -3600))
- Traceback (most recent call last):
- ...
- ValueError: Can't handle microseconds
- """
- if td1.microseconds or td2.microseconds:
- raise ValueError("Can't handle microseconds")
- return (td1.seconds + 86400 * td1.days) - (td2.seconds + 86400 * td2.days)
-
-def td2int(td):
- """timedelta to int
-
- >>> from datetime import timedelta
- >>> td2int(timedelta(0, 3600))
- 3600
- >>> td2int(timedelta(0, -3600))
- -3600
- """
- return td.seconds + 86400 * td.days
-
class CavernTime(object):
"""Cavern time calculator
@@ -167,41 +129,27 @@
_cavern_name = CAVERN_TZ_NAME
_pacific = PACIFIC_TZ
_pacific_name = PACIFIC_TZ_NAME
-
- @staticmethod
- def _utcnow():
- """Get current time in UTC
- """
- return UTC.localize(datetime.utcnow())
- @staticmethod
- def _normalize(tz, utc_dt=None):
- """Normalize a datetime object with UTC tz using another tz
- """
- if utc_dt is None:
- utc_dt = self._utcnow()
- return tz.normalize(utc_dt.astimezone(tz))
-
def __call__(self):
- now = self._utcnow()
+ now = utcnow()
result = {}
for id, tz in (('cavern', self._cavern), ('pacific', self._pacific)):
- result[id] = self._normalize(tz, now)
+ result[id] = normalizeTZ(tz, now)
return result
def info(self):
- now = self._utcnow()
+ now = utcnow()
result = {}
for id, tz in (('cavern', self._cavern), ('pacific', self._pacific)):
info = result.setdefault(id, {})
- utcoffset = td2int(tz.utcoffset(now))
+ utcoffset = td2sec(tz.utcoffset(now))
signum = utcoffset < 0 and '-' or '+'
info['tz'] = tz
info['utcoffset'] = signum,int(utcoffset/3600), float((utcoffset%3600)/3600.0)
- info['datetime'] = self._normalize(tz, now)
+ info['datetime'] = normalizeTZ(tz, now)
info['name'] = str(tz)
info['id'] = tz._tzname
- info['dst'] = td2int(tz.dst(now))
+ info['dst'] = td2sec(tz.dst(now))
result['utc'] = {'datetime' : now}
return result
Modified: pymoul/trunk/src/moul/time/dni.py
===================================================================
--- pymoul/trunk/src/moul/time/dni.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/time/dni.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -15,53 +15,94 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-"""pyMoul D'ni time tool
+"""pyMoul D'ni time tool
+
+Based on informations from http://www.dpwr.net/archive.php?showarticle=2193
+
+official sources say that:
+00:00:00:00, Leefo 1, 9654 DE = 10:35:18 UTC, April 21, 1998 CE
+>>> LEEFO_1_TABLE = [
+... datetime(1998, 4, 21, 10, 35, 18, 0, UTC),
+... datetime(1999, 4, 21, 16, 24, 3, 0, UTC),
+... datetime(2000, 4, 20, 22, 12, 48, 0, UTC),
+... datetime(2001, 4, 21, 4, 1, 33, 0, UTC),
+... datetime(2002, 4, 21, 9, 50, 18, 0, UTC),
+... datetime(2003, 4, 21, 15, 39, 3, 0, UTC),
+... ]
+
+>>> dni = DniTime()
+>>> dni.fromUTC(LEEFO_1_TABLE[1])
+>>> dni.get()
+(9655, 0, 0, 0, 0, 0, 0)
+
"""
__author__ = "Christian Heimes"
__version__ = "$Id$"
__revision__ = "$Revision$"
+from datetime import datetime
from operator import mul
+from pytz import utc as UTC
+import sys
+from moul.time.utils import td2sec
+from moul.time.utils import utcnow
-FARAH_1 = -7656 # hahrtee fahrah 1 starts at April 21st 7656 B.C
+
+FAHRAH_1 = -7656 # hahrtee fahrah 1 starts at April 21st 7656 B.C
+
+# name -> amount of smaller element, e.g. a hartee fahrah as 625 hahr
DNI_FACTORS = (
('hahrtee fahrah', 625),
- ('hahr', 10),
- ('vai-lee', 29),
- ('yahr', 5),
- ('gahr-tah-vo', 25),
- ('tah-vo', 25),
- ('gor-ahn', 25),
- ('pro-rahn', 1),
-)
+ ('hahr', 10), # year
+ ('vai-lee', 29), # month
+ ('yahr', 5), # day (~30h and 14min)
+ # bell - each yahr has 25 bells (~74 min)
+ ('gahr-tah-vo', 25), # ~6h 3min
+ ('tah-vo', 25), # ~14,5 min
+ ('gor-ahn', 25), # ~34,8 seconds
+ ('pro-rahn', None), # ~1.39 seconds
+ )
-VAILATEE = (
- ('Leefo', ( 4, 21), ( 5, 27)), # 1: April 21st to May 27th
- ('Leebro', ( 5, 28), ( 7, 3)), # 2: May 28th to July 3rd
- ('Leesahn', ( 7, 3), ( 8, 8)), # 3: July 3rd to August 8th
- ('Leetar', ( 8, 9), ( 9, 15)), # 4: August 9th and September 14th
- ('Leevot', ( 9, 14), (10, 20)), # 5: September 14th to October 20th
- ('Leevofo', (10, 21), (11, 26)), # 6: October 21st to November 26th
- ('Leevobro', (11, 26), ( 1, 1)), # 7: November 26th to January 1st
- ('Leevosahn', ( 1, 2), ( 2, 7)), # 8: January 2nd to February 7th
- ('Leevotar', ( 2, 7), ( 3, 15)), # 9: February 7th to March 15th
- ('Leenovoo', ( 3, 16), ( 4, 21)), # 10: March 16th to April 21st
-)
+# list of month names with approx. dates
+VAILEETEE = (
+ 'Leefo', # 1: April 21st to May 27th
+ 'Leebro', # 2: May 28th to July 3rd
+ 'Leesahn', # 3: July 3rd to August 8th
+ 'Leetar', # 4: August 9th and September 14th
+ 'Leevot', # 5: September 14th to October 20th
+ 'Leevofo', # 6: October 21st to November 26th
+ 'Leevobro', # 7: November 26th to January 1st
+ 'Leevosahn', # 8: January 2nd to February 7th
+ 'Leevotar', # 9: February 7th to March 15th
+ 'Leenovoo', # 10: March 16th to April 21st
+ )
-PRORAHN_PER_HAHR = reduce(mul,
- [float(factor) for name, factor in DNI_FACTORS[1:-1]])
+# 00:00:00:00, Leefo 1, 9654 DE
+BASE = datetime(1998, 4, 21, 10, 35, 18, 0, UTC)
+BASE_HAHR = 9654
+SECONDS_PER_HAHR = 31556925
+PRORAHN_PER_HAHR = 22656250
+FACTOR_SH = float(SECONDS_PER_HAHR) / float(PRORAHN_PER_HAHR)
+FACTOR_HS = float(PRORAHN_PER_HAHR) / float(SECONDS_PER_HAHR)
-# Official SI year 365.25 days = 31.557.600 seconds
-YEAR_SI = 31557600
-# Sidereal year: 365.256 363 051 days (365 d 6 h 9 min 9 s)
-# YEAR_SIDEREAL = (((((365 * 24) + 6 ) * 60 ) + 9 ) * 60 ) + 9
-YEAR = float(YEAR_SI)
+def valueCheck(typ, minv, maxv):
+ """Value and type checking decorator
+ """
+ def wrapper(func):
+ def checker(self, value):
+ if not isinstance(value, typ):
+ raise TypeError("%s <%s>" % (value, type(value)))
+ if value < minv or value > maxv:
+ raise ValueError("%s not in (%i, %i)" % (value, minv, maxv))
+ return func(self, value)
+ checker.__doc__ = func.__doc__
+ checker.__name__ = func.__name__
+ return checker
+ return wrapper
-FACTOR = YEAR / PRORAHN_PER_HAHR
-
class DniTime(object):
- """D'ni time handler
+ """D'ni time representation
The D'ni were using a complex calendar based on a pentovigesimal (25)
numbering system.
@@ -91,11 +132,97 @@
gorahn minute 36 seconds
prorahn second about 1.3929 seconds
"""
- _fahrah = None # millenium (625 years)
- _hahr = None # year (1 year)
- _vailee = None # month (10 per year)
- _yahr = None # day (29 per vailee)
- _gahrtahvo = None # section (about 6h, 3min)
- _tahvo = None # quarter (about 14,5min)
- _gorahn = None # minute (about 36 seconds)
- _prorahn = None # second (1,4 seconds)
+ def __init__(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
+ gorahn=0, prorahn=0):
+ self.set(hahr, vailee, yahr, gahrtahvo, tahvo, gorahn, prorahn)
+
+ def set(self, hahr=0, vailee=0, yahr=0, gahrtahvo=0, tahvo=0,
+ gorahn=0, prorahn=0):
+ self.hahr = hahr
+ self._prorahn = 0
+ self.vailee = vailee
+ self.yahr = yahr
+ self.gahrtahvo = gahrtahvo
+ self.tahvo = tahvo
+ self.gorahn = gorahn
+ self._addProrahn(prorahn)
+
+ def get(self):
+ return (self.hahr, self.vailee, self.yahr, self.gahrtahvo, self.tahvo,
+ self.gorahn, self.prorahn)
+
+ def fromUTC(self, utc_dt=None):
+ """Convert from UTC datetime
+ """
+ if utc_dt is None:
+ utc_dt = utcnow()
+ sec = td2sec(utc_dt - BASE)
+ prorahn = sec * FACTOR_HS
+ self.set(hahr=BASE_HAHR, prorahn=prorahn)
+
+ def toUTC(self):
+ """Convert to UTC datetime value
+ """
+ raise NotImplementedError
+
+ def _getHahr(self):
+ return self._hahr
+ @valueCheck(int, 0, sys.maxint)
+ def _setHahr(self, value):
+ self._hahr = value
+ hahr = property(_getHahr, _setHahr)
+
+ def _getVailee(self):
+ return self._prorahn // 2265625
+ @valueCheck(int, 0, 10)
+ def _setVailee(self, value):
+ self._addProrahn(value * 2265625)
+ vailee = property(_getVailee, _setVailee)
+
+ def getVaileeName(self):
+ return VAILEETEE[self.vailee]
+
+ def _getYahr(self):
+ return self._prorahn // 78125
+ @valueCheck(int, 0, 29)
+ def _setYahr(self, value):
+ self._addProrahn(value * 78125)
+ yahr = property(_getYahr, _setYahr)
+
+ def _getBell(self):
+ return self.gahrtahvo // 5
+ bell = property(_getBell)
+
+ def _getGahrtahvo(self):
+ return self._prorahn // 15625
+ @valueCheck(int, 0, 5)
+ def _setGahrtahvo(self, value):
+ self._addProrahn(value * 15625)
+ gahrtahvo = property(_getGahrtahvo, _setGahrtahvo)
+
+ def _getTahvo(self):
+ return self._prorahn // 625
+ @valueCheck(int, 0, 25)
+ def _setTahvo(self, value):
+ self._addProrahn(value * 625)
+ tahvo = property(_getTahvo, _setTahvo)
+
+ def _getGorahn(self):
+ return self._prorahn // 25
+ @valueCheck(int, 0, 25)
+ def _setGorahn(self, value):
+ self._addProrahn(value * 25)
+ gorahn = property(_getGorahn, _setGorahn)
+
+ def _getProrahn(self):
+ return self._prorahn % 25
+ @valueCheck(int, 0, 25)
+ def _setProrahn(self, value):
+ self._prorahn+= value
+ prorahn = property(_getProrahn, _setProrahn)
+
+ def _addProrahn(self, value):
+ self._prorahn += int(value)
+ addhahr = self._prorahn // PRORAHN_PER_HAHR
+ if addhahr:
+ self._hahr += addhahr
Modified: pymoul/trunk/src/moul/time/tests/test_cavern.py
===================================================================
--- pymoul/trunk/src/moul/time/tests/test_cavern.py 2007-02-10 16:01:28 UTC (rev 158)
+++ pymoul/trunk/src/moul/time/tests/test_cavern.py 2007-02-12 13:36:09 UTC (rev 159)
@@ -31,6 +31,7 @@
def test_suite():
return unittest.TestSuite((
DocTestSuite('moul.time.cavern'),
+ DocTestSuite('moul.time.utils'),
))
if __name__ == '__main__':
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|