1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from __future__
import print_function
23 from mediagoblin
.db
.models
import LocalUser
24 from mediagoblin
.gmg_commands
import util
as commands_util
25 from mediagoblin
.submit
.lib
import (
26 submit_media
, get_upload_file_limits
,
27 FileUploadLimit
, UserUploadLimit
, UserPastUploadLimit
)
29 from mediagoblin
import mg_globals
32 def parser_setup(subparser
):
33 subparser
.add_argument(
35 help="Name of user this media entry belongs to")
36 subparser
.add_argument(
38 help="Local file on filesystem")
39 subparser
.add_argument(
40 "-d", "--description",
41 help="Description for this media entry")
42 subparser
.add_argument(
44 help="Title for this media entry")
45 subparser
.add_argument(
48 "License this media entry will be released under. "
50 subparser
.add_argument(
53 "Comma separated list of tags for this media entry."))
54 subparser
.add_argument(
57 "Slug for this media entry. "
58 "Will be autogenerated if unspecified."))
60 subparser
.add_argument(
63 help="Don't process eagerly, pass off to celery")
67 # Run eagerly unless explicetly set not to
69 os
.environ
['CELERY_ALWAYS_EAGER'] = 'true'
71 app
= commands_util
.setup_app(args
)
74 user
= app
.db
.LocalUser
.query
.filter(
75 LocalUser
.username
==args
.username
.lower()
78 print("Sorry, no user by username '%s'" % args
.username
)
81 # check for the file, if it exists...
82 filename
= os
.path
.split(args
.filename
)[-1]
83 abs_filename
= os
.path
.abspath(args
.filename
)
84 if not os
.path
.exists(abs_filename
):
85 print("Can't find a file with filename '%s'" % args
.filename
)
88 upload_limit
, max_file_size
= get_upload_file_limits(user
)
90 def maybe_unicodeify(some_string
):
91 # this is kinda terrible
92 if some_string
is None:
95 return six
.text_type(some_string
, 'utf-8')
102 submitted_file
=open(abs_filename
, 'rb'), filename
=filename
,
103 title
=maybe_unicodeify(args
.title
),
104 description
=maybe_unicodeify(args
.description
),
105 license
=maybe_unicodeify(args
.license
),
106 tags_string
=maybe_unicodeify(args
.tags
) or u
"",
107 upload_limit
=upload_limit
, max_file_size
=max_file_size
)
108 except FileUploadLimit
:
109 print("This file is larger than the upload limits for this site.")
110 except UserUploadLimit
:
111 print("This file will put this user past their upload limits.")
112 except UserPastUploadLimit
:
113 print("This user is already past their upload limits.")