dont save files with _1

This commit is contained in:
j 2011-12-30 00:43:03 +05:30
parent 6a22dba8fa
commit a9ae0ab5e6
3 changed files with 17 additions and 8 deletions

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division from __future__ import division, with_statement
import os.path import os.path
import re import re
@ -243,12 +243,13 @@ class File(models.Model):
resolution=config['resolutions'][0], resolution=config['resolutions'][0],
format=config['formats'][0]) format=config['formats'][0])
if created: if created:
stream.video.save(stream.name(), chunk) stream.video.name = stream.name()
with open(stream.video.path, 'w') as f:
f.write(chunk.read())
else: else:
f = open(stream.video.path, 'a') with open(stream.video.path, 'a') as f:
#FIXME: should check that chunk_id/offset is right #FIXME: should check that chunk_id/offset is right
f.write(chunk.read()) f.write(chunk.read())
f.close()
if done: if done:
stream.available = True stream.available = True
stream.save() stream.save()

View file

@ -136,6 +136,8 @@ def upload(request):
#float required? #float required?
position = float(os.path.splitext(name)[0]) position = float(os.path.splitext(name)[0])
fr, created = models.Frame.objects.get_or_create(file=f, position=position) fr, created = models.Frame.objects.get_or_create(file=f, position=position)
if fr.frame:
fr.frame.delete()
fr.frame.save(name, frame) fr.frame.save(name, frame)
os.chmod(fr.frame.path, 0644) os.chmod(fr.frame.path, 0644)
f.item.select_frame() f.item.select_frame()

View file

@ -971,6 +971,12 @@ class Item(models.Model):
for f in glob(path.replace('.jpg', '*.jpg')): for f in glob(path.replace('.jpg', '*.jpg')):
os.unlink(f) os.unlink(f)
def save_poster(self, data):
self.poster.name = self.path('poster.jpg')
poster = self.poster.path
with open(poster, 'w') as f:
f.write(data)
def prefered_poster_url(self): def prefered_poster_url(self):
external_posters = self.external_data.get('posters', {}) external_posters = self.external_data.get('posters', {})
service = self.poster_source service = self.poster_source
@ -996,12 +1002,12 @@ class Item(models.Model):
url = self.prefered_poster_url() url = self.prefered_poster_url()
if url: if url:
data = ox.net.readUrl(url) data = ox.net.readUrl(url)
self.poster.save('poster.jpg', ContentFile(data)) self.save_poster(data)
elif os.path.exists(poster): elif os.path.exists(poster):
with open(poster) as f: with open(poster) as f:
data = f.read() data = f.read()
if data: if data:
self.poster.save('poster.jpg', ContentFile(data)) self.save_poster(data)
def make_siteposter(self): def make_siteposter(self):
poster = self.path('siteposter.jpg') poster = self.path('siteposter.jpg')