src/ldtplatform/management/commands/replacedelete.py
author bellierp
Thu, 30 Mar 2017 16:17:24 +0200
changeset 333 77b56a7aaa7e
parent 332 324717f075f9
child 334 0ddcaaf893e9
permissions -rw-r--r--
change method names + new option (path)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
'''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
List flv and f4v medias, replace them with mp4 urls and update the content and projects.
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
'''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import csv
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import logging
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
     6
import re
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
from itertools import chain
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
import requests
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
from django.conf import settings
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
from django.contrib.sites.models import Site
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
from django.core.management.base import BaseCommand
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    13
from django.core import management
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
from lxml import etree
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
from ldt.ldt_utils import models
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
#this function replace bad suffixs and prefixs of some media URL
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
#by a new one, beginning with "http" and ending with ".mp4"
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    21
def to_https(source, vidpath, tomp4=1):
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    '''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    to https
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    '''
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    25
    if source[len(source)-3:len(source)] == 'MP4' or source[len(source)-3:len(source)] == 'mp4'\
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    26
        or not re.match(r".*\..{3}$", source):
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        tomp4 = 0
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    if tomp4 == 1:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
        source = source[0:len(source)-3]+"mp4"
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    30
    if source[0:5] == "https":
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    31
        return source
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    32
    elif source[0:4] == "http" or source[0:4] == "sftp":
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        return "https"+source[4:len(source)]
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    elif source[0:7] == "/video/":
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        return "https://media.iri.centrepompidou.fr"+source
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    elif source[0:6] == "video/" or source[0:6] == "audio/":
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        return "https://media.iri.centrepompidou.fr/"+source
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    elif vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/video/regardssignes/' or \
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/mp4:video/regardssignes/':
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        return "https://media.iri.centrepompidou.fr/video/regardssignes/"+source
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    41
    elif source[0:4] == "mp4:":
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    42
        if vidpath == 'rtmp://media.iri.centrepompidou.fr/ddc_player/':
330
61a9b0c4dac4 modify sources of mp4: files without extension
bellierp
parents: 327
diff changeset
    43
            if re.match(r".*\..{3}$", source):
61a9b0c4dac4 modify sources of mp4: files without extension
bellierp
parents: 327
diff changeset
    44
                return "https://media.iri.centrepompidou.fr/" + source[4:]
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    45
            return "https://media.iri.centrepompidou.fr/" + source[4:] + ".mp4"
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    46
    return "https://media.iri.centrepompidou.fr/video/ldtplatform/"+source
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
330
61a9b0c4dac4 modify sources of mp4: files without extension
bellierp
parents: 327
diff changeset
    48
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    49
def number_of_contents(source):    #this counts the number of contents linked to a media
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
    '''
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    51
    number_of_contents
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
    '''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    return len(models.Content.objects.filter(media_obj_id=source.id))
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    55
def number_of_projects(source):
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    '''
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    57
    number_of_projects
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    '''
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    59
    if number_of_contents(source) > 0:
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        return len(models.Project.objects.filter\
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
                (content=models.Content.objects.filter(media_obj_id=source.id)[0]))
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
    62
    return 0
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    64
def construct_youtube_embed(source):
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    65
    '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    66
    construct youtube video oembed link
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    67
    '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    68
    if re.match(r".*feature=player_embedded.+", source) != None:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    69
        return "http://www.youtube.com/oembed?url=http://youtube.com/watch?v="\
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    70
        + source[len(source)-11:] +"&format=json"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    71
    return "http://www.youtube.com/oembed?url=" + source + "&format=json"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    72
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
class Command(BaseCommand):
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    '''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    Command class
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    '''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    help = 'delete medias without contents, replace media\'s source by a new URL'
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    78
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    79
    def add_arguments(self, parser):
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    80
        '''
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    81
        add arguments
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    82
        '''
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    83
        parser.add_argument('-f',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    84
                            '--force',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    85
                            dest='force',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    86
                            action='store_true'
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    87
                            )
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    88
        parser.add_argument('-p',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    89
                            '--path',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    90
                            dest='path',
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    91
                            default=None
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    92
                            )
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    93
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    94
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
    95
    def construct_ldt_embed(self, ldtid):
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    96
        '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    97
        construct ldt embed
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    98
        '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
    99
        return "http://{base_url}ldtplatform/ldt/embed/v3/config?json_url=" \
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   100
                   "http://{base_url}ldtplatform/ldt/cljson/id/{ldt_id}&" \
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   101
                   "player_id=player_project_{ldt_id}&" \
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   102
                   "ldt_id={ldt_id}".format(base_url=self.base_url, ldt_id=ldtid)
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   103
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   104
    def clean_media_project(self, element, force, newsrc=None):
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   105
        '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   106
        change media objects' videopath and source if necessary
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   107
        change project .ldt
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   108
        '''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   109
        basesrc = element.src
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   110
        if force:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   111
            element.videopath = ''
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   112
            element.save()
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   113
        if newsrc != None:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   114
            if force:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   115
                element.src = newsrc
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   116
                element.save()
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   117
            self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   118
                "Media",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   119
                basesrc,
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   120
                "Yes",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   121
                "changing source/videopath",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   122
                newsrc, "\'\'"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   123
                ])
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   124
        if number_of_projects(element) == 0:
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   125
            self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   126
                "Project",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   127
                element.src,
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   128
                "Yes",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   129
                "initializing object(no project)"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   130
                ])
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   131
            if force:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   132
                mycontentid = models.Content.objects.filter(media_obj_id=element.id)[0].iri_id
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   133
                try:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   134
                    management.call_command('initfrontproject', mycontentid)
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   135
                except Exception:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   136
                    self.mycsvfile.writerow([
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   137
                        "Project",
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   138
                        element.src,
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   139
                        "No",
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   140
                        "socket error"
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   141
                        ])
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   142
                    return
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   143
                self.stdout.write(" Initializing project", ending='')
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   144
            else:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   145
                self.stdout.write(" Project has to be initialized ", ending='')
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   146
                return
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   147
        ldtproj = models.Project.objects.filter\
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   148
        (content=models.Content.objects.filter(media_obj_id=element.id)[0])
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   149
        for singleproject in ldtproj:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   150
            root = etree.XML(singleproject.ldt.encode('utf-8'), self.parser)
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   151
            if root.xpath('medias/media') == []:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   152
                self.stdout.write(" le .ldt ne contient pas de media", ending='')
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   153
                continue
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   154
            if root.xpath('medias/media')[0].get("video") != '':
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   155
                embedurl = self.construct_ldt_embed(singleproject.ldt_id)
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   156
                if force:
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   157
                    root.xpath('medias/media')[0].set("video", '')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   158
                self.stdout.write(" changing videopath arg in .ldt ", ending='')
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   159
                self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   160
                    "Project",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   161
                    embedurl,
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   162
                    "Yes",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   163
                    "changing .ldt /medias/media/video",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   164
                    "\'\'"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   165
                    ])
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   166
                singleproject.ldt = etree.tostring(root)
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   167
                singleproject.save()
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   168
                self.logger.info("%s DONE\n", embedurl)
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   169
        element.save()
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   170
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   171
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    def handle(self, *args, **options):
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
        '''
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
        handle
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
        '''
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   177
        self.base_url = Site.objects.get_current().domain + settings.BASE_URL
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   178
        self.parser = etree.XMLParser(encoding='utf-8')
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   179
        self.logger = logging.getLogger(__name__)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   180
        path = options['path']
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   181
        force = options['force']
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   182
        if not path:
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   183
            path = 'mediaInformations.csv'
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   184
        try:
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   185
            csvfile = open(path, 'wb')
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   186
        except IOError:
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   187
            self.stdout.write('file can\'t be opened')
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   188
            self.logger.error('cant open file')
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   189
            return
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   190
        self.mycsvfile = csv.writer(csvfile)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   191
        self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   192
            "Object type",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   193
            "which object",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
            "Change ?",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   195
            "What(if Y)/Why (if N)",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   196
            "How"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   197
            ])
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   198
        j = 0
324
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   199
        files1 = models.Media.objects.all() #this list contains every media
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   200
        for elem1 in files1:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   201
            if number_of_contents(elem1) == 0:
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   202
                if force:
324
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   203
                    elem1.delete()  #if there is no content
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   204
                    #linked to the media, the media is removed for the database
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   205
                    self.stdout.write(" No content found, media has been removed")
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   206
                else:
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   207
                    self.stdout.write(" No content found, media will be removed")
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   208
                self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   209
                    "Media",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   210
                    elem1.src,
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   211
                    "Yes",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   212
                    "deleting object (no content)"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   213
                    ])
324
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   214
                j += 1
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   215
                continue
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   216
            if elem1.src.lower() == to_https(elem1.src, elem1.videopath).lower():
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   217
                self.clean_media_project(elem1, force)
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   218
            if re.match(r".*\.youtube\.com.*", elem1.src) != None\
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   219
            or re.match(r".*youtu\.be.+", elem1.src) != None:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   220
                myembed = construct_youtube_embed(elem1.src)
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   221
                if requests.get(myembed).status_code == 404:
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   222
                    self.stdout.write("%s : Video doesn't exists"% elem1.src)
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   223
                    if number_of_projects(elem1) > 0:
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   224
                        ldtproj = models.Project.objects.get(id=models.Content.objects.filter\
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   225
                        (media_obj_id=elem1.id)[0].front_project_id).ldt
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   226
                        root = etree.XML(ldtproj.encode('utf-8'), self.parser)
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   227
                        if root.xpath('annotations/content/ensemble/decoupage/elements/element')\
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   228
                        == []:
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   229
                            if force:
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   230
                                elem1.delete()
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   231
                                self.stdout.write("video doesn't exist anymore : media deleted")
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   232
                            self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   233
                                "Media/Content/Project",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   234
                                elem1.src,
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   235
                                "Yes",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   236
                                "deleting(Video doesn't exist anymore + empty projects)"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   237
                                ])
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   238
                            j += 1
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   239
                else:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   240
                    self.clean_media_project(elem1, force)
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   241
        if force:
324
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   242
            self.stdout.write("%s files deleted"%j)
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   243
        else:
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   244
            self.stdout.write("%s files to delete"%j)
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
        i = 0
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
        files = list(chain(
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
            models.Media.objects.filter(src__iregex=r".*.flv$"),
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
            models.Media.objects.filter(src__iregex=r".*.f4v$"),
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   249
            models.Media.objects.filter(src__iregex=r".*.m4v$"),
330
61a9b0c4dac4 modify sources of mp4: files without extension
bellierp
parents: 327
diff changeset
   250
            models.Media.objects.filter(src__iregex=r".*.mp4$").exclude(src__iregex=r"^https://.*"),
61a9b0c4dac4 modify sources of mp4: files without extension
bellierp
parents: 327
diff changeset
   251
            models.Media.objects.filter(src__iregex=r"^mp4:.*").exclude(src__iregex=r".*\..{3}$")
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
        ))
327
c3998a528fd9 delete well formed source links videopaths, check youtube videos, change m4v source links
bellierp
parents: 324
diff changeset
   253
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
        for elem in files:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
            self.stdout.write(" \n%s/%s files done"%(i+1, len(files)), ending='')
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
            i += 1
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   257
            if number_of_contents(elem) == 0:
324
dffa18e6cba4 add list of files without contents in mediaInformations.csv
bellierp
parents: 323
diff changeset
   258
                continue
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
            mysrc = elem.src
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   260
            newsource = to_https(elem.src, elem.videopath)
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
            try:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
                res = requests.head(newsource, timeout=10).status_code
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
            except requests.ConnectionError:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
                self.stdout.write(" connection error", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   265
                self.logger.error("CONNECTION ERROR FOR %s", elem.title)
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
                try:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
                    res = requests.head(elem, timeout=10).status_code
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
                except requests.ConnectionError:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   269
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   270
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   272
                        "No",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   273
                        "connection error",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   274
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   275
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
                    continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
                except (requests.exceptions.MissingSchema, requests.exceptions.InvalidSchema):
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   278
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   279
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   281
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
                        "missing schema on base source!",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   283
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   284
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
                    continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
                except requests.exceptions.Timeout:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   287
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   288
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   290
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
                        "TIMEOUT!",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   292
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   293
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
                    continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
                else:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   296
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   297
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   299
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
                        "use source link : website doesn't work with https",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   301
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   302
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
                    continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
            except (requests.exceptions.MissingSchema, requests.exceptions.InvalidSchema):
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
                self.stdout.write(" Missing schema !", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   306
                self.logger.warning("MISSING SCHEMA FOR %s", elem.title)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   307
                self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   308
                    "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
                    mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   310
                    "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
                    "missing schema!",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   312
                    newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   313
                    ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
                continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
            except requests.exceptions.Timeout:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
                self.stdout.write(" Timeout !", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   317
                self.logger.warning("Timeout FOR %s", elem.title)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   318
                self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   319
                    "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
                    mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   321
                    "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
                    "TIMEOUT!",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   323
                    newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   324
                    ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
                continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
            if res > 400:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
                try:
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   328
                    ressrc = requests.head(to_https(elem.src, elem.videopath, 0),\
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
                    timeout=10).status_code
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
                except (requests.exceptions.Timeout, requests.ConnectionError):
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
                    self.stdout.write(" can't access source/new files", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   332
                    self.logger.warning("can't access %s", elem.title)
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
                    res = "connection error"
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   334
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   335
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   337
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
                        "website doesn't exist anymore",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   339
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   340
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
                    continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
                if ressrc == 404:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
                    self.stdout.write(" can't access source/new files", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   344
                    self.logger.warning("can't access %s", elem.title)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   345
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   346
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   348
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
                        "can't access source/new files",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   350
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   351
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
                elif ressrc == 200:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
                    self.stdout.write(
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
                        " file not transcoded yet :"
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   355
                        "keep source extension or wait transcoding to be done",\
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
                        ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   357
                    self.logger.warning("%s not transcoded yet", elem.title)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   358
                    self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   359
                        "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
                        mysrc,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   361
                        "No",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
                        "file not transcoded yet : keep source extension",
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   363
                        newsource
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   364
                        ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
                continue
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
            self.stdout.write(" It works", ending='')
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
            alreadyin = False
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
            for everyelem in models.Media.objects.all():
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
                if newsource == everyelem.src:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
                    alreadyin = True
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
                    break
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
            if alreadyin:
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
                self.stdout.write(" element already in table", ending='')
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   374
                self.logger.warning("%s already in table", elem.title)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   375
                self.mycsvfile.writerow([
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   376
                    "Media",
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
                    newsource,
332
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   378
                    "No",
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   379
                    "new source already in table"
324717f075f9 better informations about objects changed
bellierp
parents: 331
diff changeset
   380
                    ])
323
bdffbceb0730 add media migration command
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
                continue
333
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   382
            self.clean_media_project(elem, force, newsource)
77b56a7aaa7e change method names + new option (path)
bellierp
parents: 332
diff changeset
   383
        csvfile.close()