Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmodel.py23
-rwxr-xr-xrecorded.py11
-rwxr-xr-xserialize.py24
3 files changed, 45 insertions, 13 deletions
diff --git a/model.py b/model.py
index 1eb55e9..523762b 100755
--- a/model.py
+++ b/model.py
@@ -370,24 +370,29 @@ class Model:
recd.recorderName = self.get_nickname()
recd.recorderHash = self.activity.Instance.keyHashPrintable
+ if self.activity.Instance.savePath:
+ recd.saveInternal = False
+
#to create a file, use the hardware_id+time *and* check if available or not
+ recd.type = type
nowtime = int(time.time())
recd.time = nowtime
- recd.type = type
+
+ stringType = constants.MEDIA_INFO[type]['istr']
+
+ # Translators: photo by photographer, e.g. "Photo by Mary"
+ recd.title = _('%(type)s by %(name)s') % {'type': stringType,
+ 'name': recd.recorderName}
- readable = constants.MEDIA_INFO[type]['istr'] + '_' + str(datetime.datetime.now()).replace(' ', '_')
- mediaThumbFilename = readable + str(recd.recorderHash) + "_" + str(recd.time)
+ mediaThumbFilename = utils.getUniqueFilepath(recd.title + " @ " + str(recd.time),
+ recd.activity.Instance.get_path())
mediaFilename = mediaThumbFilename
mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[type]['ext']
mediaFilepath = os.path.join( self.activity.Instance.get_path(), mediaFilename )
mediaFilepath = utils.getUniqueFilepath( mediaFilepath, 0 )
recd.mediaFilename = os.path.basename( mediaFilepath )
-
- stringType = constants.MEDIA_INFO[type]['istr']
-
- # Translators: photo by photographer, e.g. "Photo by Mary"
- recd.title = _('%(type)s by %(name)s') % {'type': stringType,
- 'name': recd.recorderName}
+ recd.oldFilename = mediaThumbFilename
+ recd.oldFilepath = mediaFilepath
color = sugar.profile.get_color()
recd.colorStroke = color.get_stroke_color()
diff --git a/recorded.py b/recorded.py
index 03523fd..d4e6d64 100755
--- a/recorded.py
+++ b/recorded.py
@@ -26,6 +26,7 @@ from instance import Instance
import utils
import datetime
import serialize
+import copy
class Recorded:
def __init__( self, activity ):
@@ -42,6 +43,10 @@ class Recorded:
self.mediaBytes = None
self.thumbBytes = None
self.tags = None
+
+ #set location of the files (if it may change upstream)
+ self.loc = self.activity.Instance.get_path()
+ self.saveInternal = True
#flag to alert need to re-datastore the title
self.metaChange = False
@@ -54,6 +59,8 @@ class Recorded:
self.mediaFilename = None
self.thumbFilename = None
self.audioImageFilename = None
+ self.oldFilename = None
+ self.oldFilepath = None
#for flagging when you are being saved to the datastore for the first time...
#and just because you have a datastore id, doesn't mean you're saved
@@ -146,7 +153,6 @@ class Recorded:
else:
return self.getThumbFilepath()
-
def getMediaFilepath(self):
if (self.datastoreId == None):
if (not self.buddy):
@@ -162,8 +168,7 @@ class Recorded:
if self.mediaFilename == None:
#creating a new filepath, probably just got here from the mesh
ext = constants.MEDIA_INFO[self.type]['ext']
- readable = constants.MEDIA_INFO[type]['istr'] + '_' + str(datetime.datetime.now()).replace(' ', '_')
- recdPath = os.path.join(self.activity.Instance.get_path(), readable+"_recdFile_"+self.mediaMd5+"."+ext)
+ recdPath = os.path.join(self.activity.Instance.get_path(), "recdFile_"+self.mediaMd5+"."+ext)
recdPath = utils.getUniqueFilepath(recdPath, 0)
self.mediaFilename = os.path.basename(recdPath)
mediaFilepath = os.path.join(self.activity.Instance.get_path(), self.mediaFilename)
diff --git a/serialize.py b/serialize.py
index 32b5db7..ad7ce24 100755
--- a/serialize.py
+++ b/serialize.py
@@ -4,8 +4,16 @@ import os
import gtk
import logging
import dbus
+import subprocess
+from datetime import datetime
+import time
+import tempfile
+import shutil
+import copy
from sugar.datastore import datastore
+from sugar import mime
+from sugar import env
import constants
from instance import Instance
@@ -253,7 +261,7 @@ def _saveMediaToDatastore(el, recd, activity):
recd.savedMedia = True
_saveXml(el, recd)
- else:
+ elif recd.saveInternal:
#this will remove the media from being accessed on the local disk since it puts it away into cold storage
#therefore this is only called when write_file is called by the activity superclass
mediaObject = datastore.create()
@@ -296,3 +304,17 @@ def _saveMediaToDatastore(el, recd, activity):
_saveXml(el, recd)
recd.mediaFilename = None
+ else:
+ if recd.metaChange:
+ oldMediaFilepath = copy.copy(recd.oldFilepath)
+ mediaThumbFilename = utils.getUniqueFilepath(recd.title + " @ " + str(recd.time),
+ recd.activity.Instance.get_path())
+ mediaFilename = mediaThumbFilename
+ mediaFilename = mediaFilename + "." + constants.MEDIA_INFO[recd.type]['ext']
+
+ mediaFilepath = os.path.join( recd.activity.Instance.get_path(), mediaFilename )
+ mediaFilepath = utils.getUniqueFilepath( mediaFilepath, 0 )
+ recd.mediaFilename = os.path.basename( mediaFilepath )
+ recd.oldFilepath = mediaFilepath
+
+ shutil.move(oldMediaFilepath, mediaFilepath)