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