added function to get timestamp from pyc file
This commit is contained in:
parent
3662ab1e7b
commit
ec1bd2ba1f
16
hy/utils.py
16
hy/utils.py
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import imp
|
import imp
|
||||||
import marshall
|
import marshall
|
||||||
|
import struct
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
MAGIC = imp.get_magic()
|
MAGIC = imp.get_magic()
|
||||||
@ -13,7 +15,17 @@ def _write_long(fp, int_):
|
|||||||
fp.write(chr((int_ >> 24) & 0xff))
|
fp.write(chr((int_ >> 24) & 0xff))
|
||||||
|
|
||||||
|
|
||||||
def write_pyc(filename, cfile=None, dfile='source'):
|
def get_mtime(fp):
|
||||||
|
'''Get the last modified date from the 4-byte timestamp in the pyc file.
|
||||||
|
'''
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
f.seed(4)
|
||||||
|
moddate = f.read(4)
|
||||||
|
modtime = time.asctime(time.localtime(struct.unpack('L', moddate)[0]))
|
||||||
|
return modtime
|
||||||
|
|
||||||
|
|
||||||
|
def write_pyc(filename, codeobject, cfile=None, dfile='source'):
|
||||||
"""Byte-compile one Python source file to Python bytecode.
|
"""Byte-compile one Python source file to Python bytecode.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
@ -33,8 +45,6 @@ def write_pyc(filename, cfile=None, dfile='source'):
|
|||||||
timestamp = long(os.stat(filename).st_mtime)
|
timestamp = long(os.stat(filename).st_mtime)
|
||||||
codestring = f.read()
|
codestring = f.read()
|
||||||
|
|
||||||
codeobject = compile(codestring, dfile or self.filename,'exec')
|
|
||||||
|
|
||||||
# Add on the .pyc (or .pyo) filename extension.
|
# Add on the .pyc (or .pyo) filename extension.
|
||||||
if cfile is None:
|
if cfile is None:
|
||||||
cfile = filename + (__debug__ and 'c' or 'o')
|
cfile = filename + (__debug__ and 'c' or 'o')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user