예제 #1
0
    def check_availability(self):
        """
        Perform check against Default Storage.
        """
        try:
            name = default_storage.get_valid_name('Informer Storage')

            # Save data.
            content = ContentFile('File used by StorageInformer checking.')
            path = default_storage.save(name, content)

            # Check properties.
            default_storage.size(path)
            default_storage.url(path)
            default_storage.path(path)
            default_storage.modified_time(path)
            default_storage.created_time(path)

            # And remove file.
            default_storage.delete(path)

            storage = default_storage.__class__.__name__
        except Exception as error:
            raise InformerException(
                'A error occured when trying access your database: %s' % error)
        else:
            return True, 'Your %s is operational.' % storage
예제 #2
0
 def test_download_does_not_save_new_image_if_exist(self):
     """
     Scenario: Download existing image
     Expected:
     - created time of the image is not changed (image is *not* saved twice)
     - created time of the thumbnail is not changed (its thumbnail is *not* generated again)
     """
     url = 'http://s1.proxy03.twitpic.com/photos/large/399879761.jpg'
     download(url)
     image_created_time1 = default_storage.created_time(self.image_path)
     thumb_created_time1 = default_storage.created_time(self.thumb_image_path)
     download(url)
     image_created_time2  = default_storage.created_time(self.image_path)
     thumb_created_time2 = default_storage.created_time(self.thumb_image_path)
     self.assertEqual(image_created_time1, image_created_time2)
     self.assertEqual(thumb_created_time1, thumb_created_time2)
예제 #3
0
파일: views.py 프로젝트: ddgromit/mimicme
def expert_recording(request,phrase_id):
    try:
        phrase = Phrase.objects.get(id=int(phrase_id))
    except Phrase.DoesNotExist:
        raise Exception('phrase with id does not exist: ' + str(phrase_id))

    upload_params = "phrase_id=" + str(phrase.id) + "&type=expert"
    upload_params_encoded = urllib.quote_plus(upload_params)


    # Expert info
    filename = "expert" + str(phrase.id) + ".mp3"
    exists = default_storage.exists(filename)
    created_time = None
    size = None
    if exists:
        created_time = default_storage.created_time(filename)
        size = default_storage.size(filename)

    return render(request,'expert_recording.html',{
        'phrase':phrase,
        'upload_params_encoded':upload_params_encoded,
        'expert_url':lib.expert_url(phrase_id),

        'filename':filename,
        'exists':exists,
        'created_time':created_time,
        'size':size,
    })
예제 #4
0
파일: models.py 프로젝트: jcushman/perma
 def write_resource_record(file_path, url, content_type):
     self.write_warc_resource_record(
         default_storage.open(file_path),
         url.encode('utf8'),
         content_type,
         default_storage.created_time(file_path),
         out)
예제 #5
0
 def test_modified_time(self):
     with self.save_file():
         modified_time = default_storage.modified_time("test.txt")
         logging.info("modified time: %s", modified_time)
         self.assertTrue(is_naive(modified_time))
         self.assertLess(abs(modified_time - make_naive(timezone.now(), utc)), timedelta(seconds=10))
         self.assertEqual(default_storage.accessed_time("test.txt"), modified_time)
         self.assertEqual(default_storage.created_time("test.txt"), modified_time)
예제 #6
0
 def testModifiedTime(self):
     with self.save_file():
         modified_time = default_storage.modified_time("foo.txt")
         # Check that the timestamps are roughly equals.
         self.assertLess(abs(modified_time - make_naive(timezone.now(), utc)), timedelta(seconds=10))
         # All other timestamps are slaved to modified time.
         self.assertEqual(default_storage.accessed_time("foo.txt"), modified_time)
         self.assertEqual(default_storage.created_time("foo.txt"), modified_time)
예제 #7
0
 def test_collected_images_sorted_by_created_time(self):
     images = collected_images()
     for i in images:
         print '%s %s' % (i, default_storage.created_time(TWITTER_IMAGE_PATH + i))
     order_of_image2 = images.index('test_collected_images__test_2.jpg')
     order_of_image1 = images.index('test_collected_images__test_1.jpg')
     order_of_image0 = images.index('test_collected_images__test.jpg')
     self.assertLess(order_of_image2, order_of_image1)
     self.assertLess(order_of_image1, order_of_image0)
예제 #8
0
파일: graphs.py 프로젝트: yorickvP/kninfra
def view(request, graph, ext):
    if graph not in GRAPHS:
        raise Http404
    timeout, update, exts = GRAPHS[graph]
    if ext not in exts:
        raise Http404
    graph_fn = graph + '.' + ext
    path = os.path.join(settings.GRAPHS_PATH, graph_fn)
    # Check if we should update the graph
    if (not default_storage.exists(path)
            or datetime.datetime.now() - default_storage.created_time(path) >
            datetime.timedelta(seconds=timeout)):
        update(default_storage.path(os.path.join(settings.GRAPHS_PATH, graph)))
    return HttpResponse(FileWrapper(default_storage.open(path, 'rb')),
                        content_type=mimetypes.guess_type(path)[0])
예제 #9
0
def view(request, graph, ext):
    if not graph in GRAPHS:
        raise Http404
    timeout, update, exts = GRAPHS[graph]
    if not ext in exts:
        raise Http404
    graph_fn = graph + '.' + ext
    path = os.path.join(settings.GRAPHS_PATH, graph_fn)
    # Check if we should update the graph
    if (not default_storage.exists(path) or
            datetime.datetime.now() - default_storage.created_time(path)
                > datetime.timedelta(seconds=timeout)):
        update(default_storage.path(
                    os.path.join(settings.GRAPHS_PATH, graph)))
    return HttpResponse(FileWrapper(default_storage.open(path)),
                                content_type=mimetypes.guess_type(path)[0])
예제 #10
0
 def handle(self, *args, **kwargs):
     time = datetime.datetime.now()
     delta = datetime.timedelta(days=1)
     for file in default_storage.listdir(EDITED_PREVIEWS_ROOT)[1]:
         if default_storage.created_time('%s/%s' % (EDITED_PREVIEWS_ROOT, file)) + delta < time:
             default_storage.delete('%s/%s' % (EDITED_PREVIEWS_ROOT, file))
예제 #11
0
def collected_images():
    dir_names, file_names = default_storage.listdir(TWITTER_IMAGE_PATH)
    compare_by_created_time = lambda(name): default_storage.created_time(TWITTER_IMAGE_PATH + name)
    file_names.sort(key=compare_by_created_time, reverse=True)
    return file_names