Skip to content

Instantly share code, notes, and snippets.

@nicksnell
Created March 13, 2013 11:10
Show Gist options
  • Select an option

  • Save nicksnell/5151161 to your computer and use it in GitHub Desktop.

Select an option

Save nicksnell/5151161 to your computer and use it in GitHub Desktop.
Deploy CMS - rebuild all image variations manually
import os.path
from deploy.utils.importing import import_object
def _get_variation_path(path, variation):
return os.path.join(
os.path.dirname(path),
variation.lower().replace(' ', '-'),
os.path.basename(path)
)
def rebuild_all_variations(attachments, variations):
for attachment in attachments:
path = attachment.path
for key, value in variations.items():
process = variation['process']
args = variation['args'] if variation.has_key('args') else []
save_path = _get_variation_path(path, key)
try:
process_callable = import_object(process)
except ImportError, e:
raise RuntimeError('Unable to import variation processor "%s" for attachment "%s"' % (
process, path
))
try:
process_callable(attachment, save_path, *args)
except Exception, e:
raise RuntimeError('Unable to process variation "%s" using "%s": %s' % (
path, process, e
))
if __name__ == '__main__':
# Example...
things = request.db.find(Something)
variation_spec = {
'inpage': {
'process': 'deploy.cms.utils.variations.inpage_attachment',
'args': []
},
}
for thing in things:
rebuild_all_variations(thing.images, variation_spec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment