]> git.parisson.com Git - telemeta.git/commitdiff
add cleanup management script
authoryomguy <yomguy@parisson.com>
Tue, 13 Dec 2011 14:32:47 +0000 (15:32 +0100)
committeryomguy <yomguy@parisson.com>
Tue, 13 Dec 2011 14:32:47 +0000 (15:32 +0100)
telemeta/htdocs/timeside/js/player.js
telemeta/htdocs/timeside/js/timeside.js
telemeta/management/commands/telemeta-cleanup.py [new file with mode: 0644]

index cdc7f065586ec4b0a66fea95b4192b42886aaa09..4b6a1a0e8c1df4a1bb111b42ec66763e32285025 100644 (file)
@@ -29,7 +29,7 @@
 
 //playerDiv, sound, durationInMsec, visualizers, markerMap);
 Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
-    
+
     //sound duration is in milliseconds because the soundmanager has that unit,
     //player (according to timeside syntax) has durations in seconds
     // newMarkerCallback must be either a string or a function, the necessary checks is done in Timeside.load
@@ -63,7 +63,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         }
 
         var onReadyWithImage = configObject.onReadyWithImage;
-        
+
         if(typeof onReadyWithImage === 'function'){
             var onReadyWithImageNamespace = 'imgRefreshed.temp_'+new Date().getTime(); //get an unique namespace
             this.bind(onReadyWithImageNamespace,function(data){
@@ -109,7 +109,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
                 var soundOptions = sound;
                 if(sMan.canPlayURL(soundOptions.url)){ //this actually checks only if the url is well formed, not if the file is there
                     //check if we specified a valid sound duration, otherwise the sound must be loaded
-                    
+
                     sound = sMan.createSound(soundOptions);
                 }else{
                     this.soundErrorMsg = 'bad sound parameter (soundManager.canPlayURL returned false)';
@@ -159,24 +159,24 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
 
         this.playState = 0; //0: not playing, 1: loading, 2:buffering, 3 playing (sound heard)
         //container is the div #player
-       
+
         this.getContainer = function(){
             return container;
         };
-        
-        
+
+
 
         var sd = this.toSec(soundDurationInMsec);
         this.getSoundDuration = function(){
             return sd;
         };
-        
+
         this.soundPosition =  sound.position ? this.toSec(sound.position) : 0;
-       
-        
+
+
+
         //
-        
+
         //initializing markermap and markerui
         var map = new Timeside.classes.MarkerMap();
         this.getMarkerMap = function(){
@@ -190,7 +190,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
                 this.newMarker = newMarker;
             }
         }
-       
+
         //build the innerHTML as array, then join it. This is usually faster than string concatenation in some browsers.
         //Note that the player image (see below) is not created now, however, if it was, it should be given a src
         //as NOT specifying any src for image tags can be harmful,
@@ -220,7 +220,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         "</div>"];
 
         container.html(html.join(''));
-        
+
         var control = container.find('.ts-control');
 
         //bind events to buttons:
@@ -420,11 +420,11 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         //set sound position:
         var oldSoundPosition = this.soundPosition;
         this.soundPosition = newPositionInSeconds;
-        
+
         //resume playing if it was playing:
         if(wasPlaying){
             var player = this;
-            
+
             //delay a little bit the play resume, this might avoid fast pointer repositioning
             //(it should not be the case, but it happens. why??)
             setTimeout(function(){
@@ -445,7 +445,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
     //the value is in seconds
     //markerCrossedOffsetMargin : 0.5,
     play : function(){
-        
+
         if(this.soundErrorMsg){
             alert(this.soundErrorMsg);
             return false;
@@ -458,7 +458,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
             //together with this.soundErrorMsg != "", so we should have catch the case above
             return false;
         }
-        
+
 
         var fireOnMarkerPosition = function(seconds){}; //does nothing by default
         var map = player.getMarkerMap();
@@ -495,7 +495,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
                             data.currentSoundPosition = seconds;
                             data.nextMarkerTimeInterval = marker ? [offs-margin, offs+margin] : undefined;
                             player.fire('markerCrossed',data);
-                            
+
                             if(idx<len){
                                 intervalUpperBound =  offs+margin;
                                 intervalLowerBound =  offs-margin;
@@ -513,7 +513,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         var sPosInMsec = player.toMsec(player.soundPosition);
         var bufferingString = this.msgs.buffering;
         var loadingString = this.msgs.loading;
-        
+
         var updateWaitBar = this.setWait;
         //building immediately data events to be passed instead of bulding them in the loop whileplaying
         var loadData = {
@@ -547,15 +547,15 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
             playState = this.playState = 1;
             this.fire('playStateChanged',loadData);
         }
-        
+
         var playOptions = {
-            
+
             position: sPosInMsec,
             whileplaying: function(){
 
                 var sPos = this.position;
                 var buffering = this.isBuffering || typeof sPos != 'number' || sPos < sPosInMsec;
-                
+
                 //var buffering = this.isBuffering; //this refers to the soundmanager sound obj
                 //Now, what are we doing here below? we could simply check whether is buffering or not..
                 //Unfortunately, when buffering some playState (isBuffering = false) are also fired, randomly
@@ -599,7 +599,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
 
             },
             onfinish: function() {
-                
+
                 //whileplaying is NOT called onsinfish. We must update the pointer:
                 //note that for small length sounds (wg, 5 secs) the pointer shifts abruptly from the last
                 //whileplaying position to the end. We tried with a setTimeout function but the visual effect is not
@@ -679,7 +679,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
 
     setWait: function(msg){
         var wait = undefined;
-      
+
         wait = this.getWaitElement();
         if(!wait || msg === undefined){
             return;
@@ -689,7 +689,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         }
 
         var visible = wait.css('display') != 'none';
-        
+
         if(msg && !visible){
             wait.show();
             this.fire('waitShown');
@@ -727,11 +727,11 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
             }
         },100);
     },
-    
+
     resize: function() {
         var height;
         var container = this.getContainer();
-        
+
         var wave = container.find('.ts-wave');
 
         height = wave.height();
@@ -772,7 +772,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         var container = this.getContainer();
         var imageC = container.find('.ts-image-container');
         var image = imageC.find('.ts-image');
-        
+
 
         var size = this.getImageSize();
 
@@ -784,9 +784,9 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         if(!imageNotYetCreated && image.attr('src')==imgSrc){
             return;
         }
-        
+
         var player= this;
-        
+
         if(imageNotYetCreated){
             image = this.$J('<img/>');
         }
@@ -823,7 +823,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         this.isImgRefreshing = true;
         this.fire('imgRefreshing');
         image.attr('src', imgSrc);
-       
+
     },
     getImageSize: function(){
         var wave = this.getContainer().find('.ts-wave');
@@ -879,7 +879,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
                 idx++;
             }
         }
-        
+
         if(idx< len){
             offset = markers[idx].offset;
         }
@@ -1006,9 +1006,9 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         //TODO: think about if clearing or not: we assign some bindings in the constructor, too:
         //        map.clear();
         //        ruler.clear();
-       
+
         var rulerAdd = ruler.add;
-            
+
         if(markers){
             //add markers to the map. No listeners associated to it (for the moment)
             for(var i =0; i< markers.length; i++){
@@ -1020,7 +1020,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
                 rulerAdd.apply(ruler,[marker.offset, i, marker.isEditable]);
             });
         }
-        
+
         //the function above calls map.add:
         //add bindings when adding a marker:
         map.bind('add',function(data){
@@ -1043,7 +1043,7 @@ Timeside.classes.Player = Timeside.classes.TimesideClass.extend({
         });
 
         //and now add a binding to the map when we move a marker:
-          
+
         map.bind('move', function(data){
             var from = data.fromIndex;
             var to = data.toIndex;
index 646d8c77629259a761321009ad5451b26163c664..c764d46effc21e2cd0312d94914a8a2e24472069 100644 (file)
@@ -89,7 +89,7 @@ var Timeside = {
  * MIT Licensed.
  * (Inspired by base2 and Prototype)
  */
+
 /*
  * In few words: the lightest and most-comprehensive way to implement inhertance and OOP in javascript. Usages can be found below.
  * Basically,
@@ -118,7 +118,7 @@ var Timeside = {
  *           this._super();         //!!!ERROR: methods defined in the init function don't have acces to _super
  *       }
  *       this.alert = function(){   //another public method, !!!WARNING: this will be put in the MyClass scope (NOT in the prototype)
- *           alert('ok');           
+ *           alert('ok');
  *       }
  *   },
  *   count:0,                       //public property
@@ -131,7 +131,7 @@ var Timeside = {
  *      this._super();                  //call the super constructor
  *  }
  *  alert: function(){                  //override a method
- *      this._super();                  //call the super method, ie alerts 'no'. WARNING: However, as long as there is an alert written 
+ *      this._super();                  //call the super method, ie alerts 'no'. WARNING: However, as long as there is an alert written
  *                                      //in the init method of the superclass (see above), THAT method will be called
  *  }
  * });
@@ -209,7 +209,7 @@ var Timeside = {
 
         // Populate our constructed prototype object
         Class.prototype = prototype;
-        
+
         // Enforce the constructor to be what we expect
         Class.constructor = Class;
 
@@ -233,7 +233,7 @@ Timeside.classes.TimesideClass = Timeside.Class.extend({
         //(ie, every instance has its own copy)
         this.listenersMap={};
     },
-    
+
     cssPrefix : 'ts-', //actually almost uneuseful, still here for backward compatibility with old code (TODO: remove?)
     $J : jQuery, //reference to jQuery for faster lookup inside methods
     $TU : Timeside.utils, //reference to Timeside variable for faster lookup inside methods
@@ -265,7 +265,7 @@ Timeside.classes.TimesideClass = Timeside.Class.extend({
                 cb.apply(optionalThisArgInCallback,[data]);
             };
         }
-        
+
         if(listenersMap.hasOwnProperty(eventType)){
             listenersMap[eventType].push(callback);
         }else{
@@ -342,7 +342,7 @@ Timeside.classes.TimesideClass = Timeside.Class.extend({
             callbacks[i](dataArgument);
         }
     },
-    
+
     /*
      *formats (ie returns a string representation of) a time which is in the form seconds,milliseconds (eg 07.6750067)
      * formatArray is an array of strings which can be:
@@ -363,7 +363,7 @@ Timeside.classes.TimesideClass = Timeside.Class.extend({
         if(!(formatArray)){
             formatArray = ['mm','ss'];
         }
-        
+
         //marker offset is in float format second.decimalPart
         var pInt = parseInt;
         var round = Math.round;
@@ -375,7 +375,7 @@ Timeside.classes.TimesideClass = Timeside.Class.extend({
         time-=minutes*factor;
         var seconds = pInt(time);
         time-=seconds;
-        
+
         //here below the function to format a number
         //ceilAsPowerOfTen is the ceil specifiedas integer indicating the relative power of ten
         //(0: return the number as it is, 1: format as "0#" and so on)
@@ -475,7 +475,7 @@ Timeside.classes.TimesideArray = Timeside.classes.TimesideClass.extend({
     //2) each(m, callback) iterates over the elements from m executing callback
     //3) each(m,n,callback) iterates over the elements from m (inclusive) to n-1 (inclusive) executing callback
 
-    //NOTE: writing   each : function(startInclusive, endExclusive, callback) throws an error in chrome, as the last 
+    //NOTE: writing   each : function(startInclusive, endExclusive, callback) throws an error in chrome, as the last
     //argument (even if it is a function) is a number. Why?????
     //Anyway, we write the function arguments as empty
     each : function(){
@@ -512,7 +512,7 @@ Timeside.classes.TimesideArray = Timeside.classes.TimesideClass.extend({
         for(var i = startInclusive; i<endExclusive; i++){
             callback(i,me[i]);
         }
-    
+
     },
 
     //clears the array and the events associated to it, ie removes all its elements and calls unbind(). Returns the array of the removed elements
@@ -695,7 +695,7 @@ Timeside.load =function(config){
         s.onerror = function() {
             Timeside.utils.flashFailed = true;
             //end('SoundManager error. If your browser does not support HTML5, Flash player (version '+soundManager.flashVersion+'+) must be installed.\nIf flash is installed, try to:\n - Reload the page\n - Empty the cache (see browser preferences/options/tools) and reload the page\n - Restart the browser');
-            
+
             //and load all anyway:
             loadAll();
         };
diff --git a/telemeta/management/commands/telemeta-cleanup.py b/telemeta/management/commands/telemeta-cleanup.py
new file mode 100644 (file)
index 0000000..7bb614c
--- /dev/null
@@ -0,0 +1,33 @@
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from telemeta.models import *
+from telemeta.util.unaccent import unaccent
+import logging
+import codecs
+
+class Command(BaseCommand):
+    help = "Cleanup DB : multiple analyses, data cache, export cache, etc.."
+    args = "None"
+
+    def handle(self, *args, **options):
+
+        items = MediaItem.objects.all()
+        a_counter = 0
+
+        print 'Cleaning multiple analyses per item...'
+        for item in items:
+
+            analyses = MediaItemAnalysis.objects.filter(item=item)
+            ids = []
+            for analysis in analyses:
+                id = analysis.analyzer_id
+                if id in ids:
+                    print 'item : ' + item.code + ' analyzer_id : ' + id
+                    analysis.delete()
+                    a_counter += 1
+                else:
+                    ids.append(id)
+
+        print "Done, cleaned %s analyses" % str(a_counter)
+