Esempio n. 1
0
 def download_thumbnail(self, redownload=False):
     if self.thumbnail_url is None:
         return
     if (not self.thumbnail_exists()) or redownload:
         util.ensure_dir_exists(settings.IMAGE_DOWNLOAD_CACHE_DIR)
         cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
                 util.hash_string(self.thumbnail_url))
         if os.path.exists(cache_path) and not redownload:
             image_file = file(cache_path, 'rb')
         else:
             url = self.thumbnail_url[:8] + self.thumbnail_url[8:].replace(
                 '//', '/')
             image_file = try_to_download_thumb(url)
             if image_file is None:
                 return
             util.copy_obj(cache_path, image_file)
         self.save_thumbnail(image_file)
Esempio n. 2
0
 def download_thumbnail(self, redownload=False):
     if self.thumbnail_url is None:
         return
     if (not self.thumbnail_exists()) or redownload:
         util.ensure_dir_exists(settings.IMAGE_DOWNLOAD_CACHE_DIR)
         cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
                                   util.hash_string(self.thumbnail_url))
         if os.path.exists(cache_path) and not redownload:
             image_file = file(cache_path, 'rb')
         else:
             url = self.thumbnail_url[:8] + self.thumbnail_url[8:].replace(
                 '//', '/')
             image_file = try_to_download_thumb(url)
             if image_file is None:
                 return
             util.copy_obj(cache_path, image_file)
         self.save_thumbnail(image_file)
Esempio n. 3
0
 def test_thumbnails(self):
     width, height = Item.THUMBNAIL_SIZES[0]
     dir = '%dx%d' % (width, height)
     self.channel.update_items(
         feedparser_input=open(test_data_path('thumbnails.xml')))
     self.channel.download_item_thumbnails()
     items = self.channel.items.all()
     self.assertEquals(
         items[0].thumbnail_url, "http://www.getmiro.com/images/"
         "x11-front-page-screenshots/02.jpg")
     thumb_path = os.path.join(settings.MEDIA_ROOT, Item.THUMBNAIL_DIR, dir,
                               '%d.jpeg' % items[0].id)
     cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
                               util.hash_string(items[0].thumbnail_url))
     self.assert_(os.path.exists(thumb_path))
     self.assert_(os.path.exists(cache_path))
     self.assert_(items[0].thumbnail_exists())
     self.assert_(not items[1].thumbnail_exists())
     self.assertEquals(items[1].thumb_url(width, height),
                       self.channel.thumb_url(width, height))
Esempio n. 4
0
 def test_thumbnails(self):
     width, height = Item.THUMBNAIL_SIZES[0]
     dir = '%dx%d' % (width, height)
     self.channel.update_items(
         feedparser_input=open(test_data_path('thumbnails.xml')))
     self.channel.download_item_thumbnails()
     items = self.channel.items.all()
     self.assertEquals(items[0].thumbnail_url,
             "http://www.getmiro.com/images/"
             "x11-front-page-screenshots/02.jpg")
     thumb_path = os.path.join(settings.MEDIA_ROOT, Item.THUMBNAIL_DIR,
             dir, '%d.jpeg' % items[0].id)
     cache_path = os.path.join(settings.IMAGE_DOWNLOAD_CACHE_DIR,
             util.hash_string(items[0].thumbnail_url))
     self.assert_(os.path.exists(thumb_path))
     self.assert_(os.path.exists(cache_path))
     self.assert_(items[0].thumbnail_exists())
     self.assert_(not items[1].thumbnail_exists())
     self.assertEquals(items[1].thumb_url(width, height),
             self.channel.thumb_url(width, height))
Esempio n. 5
0
 def check_password(self, password):
     hashed = util.hash_string(password)
     return self.hashed_password == hashed