Commit 770b8755 by Sam Thomson

sort to get the most recent compressed file

rely on the fact that compressed filenames always increase. os.listdir returns filenames in arbitrary order, so they must be sorted (in reverse order) to get the most recent
parent 4c3313b3
...@@ -100,7 +100,7 @@ def get_version(source_files, verbosity=0): ...@@ -100,7 +100,7 @@ def get_version(source_files, verbosity=0):
def get_version_from_file(path, filename): def get_version_from_file(path, filename):
regex = re.compile(r'^%s$' % (get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'([A-Za-z0-9]+)'))) regex = re.compile(r'^%s$' % (get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'([A-Za-z0-9]+)')))
for f in os.listdir(path): for f in sorted(os.listdir(path), reverse=True):
result = regex.match(f) result = regex.match(f)
if result and result.groups(): if result and result.groups():
return result.groups()[0] return result.groups()[0]
...@@ -108,7 +108,7 @@ def get_version_from_file(path, filename): ...@@ -108,7 +108,7 @@ def get_version_from_file(path, filename):
def remove_files(path, filename, verbosity=0): def remove_files(path, filename, verbosity=0):
regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'[A-Za-z0-9]+')))) regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'[A-Za-z0-9]+'))))
if os.path.exists(path): if os.path.exists(path):
for f in sorted(os.listdir(path), reverse=True): for f in os.listdir(path):
if regex.match(f): if regex.match(f):
if verbosity >= 1: if verbosity >= 1:
print "Removing outdated file %s" % f print "Removing outdated file %s" % f
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment