1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from mediagoblin import mg_globals
from mediagoblin.db.models import MediaEntry
from mediagoblin.gmg_commands import util as commands_util
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
from mediagoblin.tools.pluginapi import hook_handle
def reprocess_parser_setup(subparser):
subparser.add_argument(
'--available', '-a',
action="store_true",
help="List available actions for a given media entry")
subparser.add_argument(
'--state', '-s',
help="Reprocess media entries in this state"
" such as 'failed' or 'processed'")
subparser.add_argument(
'--type', '-t',
help="The type of media to be reprocessed such as 'video' or 'image'")
subparser.add_argument(
'--media_id',
nargs='*',
help="The media_entry id(s) you wish to reprocess.")
subparser.add_argument(
'--thumbnails',
action="store_true",
help="Regenerate thumbnails for all processed media")
def _set_media_type(args):
if args[0].media_id:
if len(args[0].media_id) == 1:
media_type = MediaEntry.query.filter_by(id=args[0].media_id[0])\
.first().media_type.split('.')[-1]
if not args[0].type:
args[0].type = media_type
elif args[0].type != media_type:
raise Exception(_('The --type that you set does not match the'
'type of the given media_id.'))
elif len(args[0].media_id) > 1:
media_types = []
for id in args[0].media_id:
media_types.append(MediaEntry.query.filter_by(id=id).first()
.media_type.split('.')[-1])
for type in media_types:
if media_types[0] != type:
raise Exception((u'You cannot reprocess different'
' media_types at the same time.'))
if not args[0].type:
args[0].type = media_types[0]
elif args[0].type != media_types[0]:
raise Exception(_('The --type that you set does not match the'
' type of the given media_ids.'))
def _reprocess_all(args):
if not args[0].type:
if args[0].thumbnails:
if args[0].available:
print _('Available options for regenerating all processed'
' media thumbnails: \n'
'\t --size: max_width max_height'
' (defaults to config specs)')
else:
#TODO regenerate all thumbnails
pass
elif args[0].state == 'failed':
if args[0].available:
print _('\n Available reprocess actions for all failed'
' media_entries: \n \t --initial_processing')
else:
#TODO reprocess all failed entries
pass
else:
raise Exception(_('You must set --type when trying to reprocess'
' all media_entries, unless you set --state'
' to "failed".'))
else:
_run_reprocessing(args)
def _run_reprocessing(args):
if args[0].available:
if args[0].state == 'failed':
print _('\n Available reprocess actions for all failed'
' media_entries: \n \t --initial_processing')
else:
result = hook_handle(('reprocess_action', args[0].type), args)
if not result:
print _('Sorry there is no available reprocessing for {}'
' entries in the {} state'.format(args[0].type,
args[0].state))
else:
return hook_handle(('media_reprocess', args[0].type), args)
def _set_media_state(args):
if args[0].media_id:
if len(args[0].media_id) == 1:
args[0].state = MediaEntry.query.filter_by(id=args[0].media_id[0])\
.first().state
elif len(args[0].media_id) > 1:
media_states = []
for id in args[0].media_id:
media_states.append(MediaEntry.query.filter_by(id=id).first()
.state)
for state in media_states:
if state != media_states[0]:
raise Exception(_('You can only reprocess media that is in'
' the same state.'))
args[0].state = media_states[0]
if not args[0].state:
args[0].state = 'processed'
def reprocess(args):
commands_util.setup_app(args[0])
_set_media_state(args)
_set_media_type(args)
import ipdb
ipdb.set_trace()
if not args[0].media_id:
return _reprocess_all(args)
return _run_reprocessing(args)
|