Wednesday 21 August 2013

django time does not work correctly

django time does not work correctly

I have a django application and I Setting up Django and my web server with
uWSGI and nginx. I have a function that sets access time for my file, this
is my function:
from shutil import move
from time import mktime
from os import utime
def spool(self, time=None):
if time:
try:
time = mktime(time.timetuple())
utime(path(self.tempdir) / path(self.filename), (time, time))
except (error, AttributeError, OverflowError, ValueError):
raise InvalidTimeError
try:
move(path(self.tempdir) / path(self.filename),
path(self.spool_dir) / path(self.filename))
except IOError:
raise NoSpoolPermissionError
when I run this function with python command the access time is correct:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561550 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 11:27:30.000000000 +0430
Modify: 2013-08-21 11:27:30.000000000 +0430
Change: 2013-08-21 11:24:00.142143170 +0430
Birth: -
but when I run the function in my django application the output is:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 242 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561542 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 21:15:00.000000000 +0430
Modify: 2013-08-21 21:15:00.000000000 +0430
Change: 2013-08-21 11:44:42.982093206 +0430
Birth: -
as you can see the access time is <<2013-08-21 21:15:00>> but It must be
<<2013-08-21 11:44:42>> and I have no idea what happend. linux date
command output is:
root@demo:~# date
Wed Aug 21 11:44:55 IRDT 2013
and python datetime output:
>>> datetime.datetime.now()
datetime.datetime(2013, 8, 21, 11, 45, 57, 886360)

No comments:

Post a Comment