Small enhancements to mtime handling

* Use directories mtime (so deleted or renamed files are taken into account)
* Set the tarfile mtime close to the version
This commit is contained in:
Laurent Bachelier 2012-01-29 11:47:26 +01:00
commit 863a32b96e
2 changed files with 8 additions and 3 deletions

View file

@ -20,6 +20,7 @@
from __future__ import with_statement
from datetime import datetime
from time import mktime, strptime
import tarfile
import os
import shutil
@ -110,6 +111,8 @@ class WeboobRepos(ReplApplication):
print 'Create archive for %s' % name
with closing(tarfile.open(tarname, 'w:gz')) as tar:
tar.add(module_path, arcname=name, exclude=self._archive_excludes)
tar_mtime = mktime(strptime(str(module.version), '%Y%m%d%H%M'))
os.utime(tarname, (tar_mtime, tar_mtime))
# Copy icon.
icon_path = os.path.join(module_path, 'favicon.png')

View file

@ -211,7 +211,7 @@ class Repository(object):
try:
module = Module(__import__(name, fromlist=[str(name)]))
except Exception, e:
print 'ERROR: %s' % e
print >>sys.stderr, 'ERROR: %s' % e
else:
m = ModuleInfo(module.name)
m.version = self.get_tree_mtime(module_path)
@ -227,8 +227,10 @@ class Repository(object):
self.save(filename)
@staticmethod
def get_tree_mtime(path):
def get_tree_mtime(path, include_root=False):
mtime = 0
if include_root:
mtime = int(datetime.fromtimestamp(os.path.getmtime(path)).strftime('%Y%m%d%H%M'))
for root, dirs, files in os.walk(path):
for f in files:
if f.endswith('.pyc'):
@ -453,7 +455,7 @@ class Repositories(object):
try:
repository.retrieve_index(dest_path)
except RepositoryUnavailable, e:
print 'Error: %s' % e
print >>sys.stderr, 'Error: %s' % e
else:
self.repositories.append(repository)