Skip to content

Instantly share code, notes, and snippets.

@shaneharter
Created October 16, 2014 17:14
Show Gist options
  • Save shaneharter/b50a48530666f211cd56 to your computer and use it in GitHub Desktop.
Save shaneharter/b50a48530666f211cd56 to your computer and use it in GitHub Desktop.
with make_temp_dir(listing_id) as tmpdir:
logger.console('Downloading assets for %s to %s' % (listing_id, tmpdir))
photoset = photos.Photoset(filenames, tmpdir, limit=MAXIMUM_PHOTOS, subprocessor=logged_popen)
photoset.load()
if photoset.count() < MINIMUM_PHOTOS:
raise RuntimeWarning('Too few conforming photos')
photoset.process()
def make_temp_dir(listing_id):
""" A context manager for the temp directory to ensure we clean up after ourselves """
temp_dir = tempfile.mkdtemp(prefix='%s.' % str(listing_id))
try:
yield temp_dir
finally:
shutil.rmtree(temp_dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment