Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Last active June 11, 2018 07:33
Show Gist options
  • Save VMuliadi/56ae0b4836c074e4fb3aa39f069934d0 to your computer and use it in GitHub Desktop.
Save VMuliadi/56ae0b4836c074e4fb3aa39f069934d0 to your computer and use it in GitHub Desktop.
Removing old .sprocket and preserve latest file when using Sprocket Integration on Ruby on Rails Web Apps
import os
import glob
from datetime import datetime
def get_youngest(list_of_file):
list_of_ctime = []
for ctime in list_of_file:
list_of_ctime.append(ctime['ctime'])
# Remove youngest sprock
for file in list_of_file:
if str(min(list_of_ctime)) == str(file['ctime']):
list_of_file.remove(file)
# Delete older sprockets
for file in list_of_file:
os.remove(file['filename'])
list_of_file_attr = []
for file in glob.glob('/home/zoodev/current/public/assets/.sprockets-manifest-*'):
file_dictionary = {}
file_dictionary['filename'] = file
file_dictionary['ctime'] = os.path.getctime(file)
list_of_file_attr.append(file_dictionary)
get_youngest(list_of_file_attr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment