Skip to content
Snippets Groups Projects
Commit e63c1a52 authored by Florent Thiery's avatar Florent Thiery
Browse files

add media deployment envsetup task for demokit, refs #26844

parent 42e41733
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import utils
CONTENT = [
"https://www.ubicast.eu/media/downloads/TradeshowDemoKit/medical_education.zip",
"https://www.ubicast.eu/media/downloads/TradeshowDemoKit/rich-media-sneak-peek.zip"
]
def setup(interactive=True):
cmds = list()
options = {
"ms_url": utils.get_conf('MS_SERVER_NAME'),
"ms_apikey": utils.get_conf('MS_API_KEY')
}
cmd_template = "./publish_zip_by_url.py -w {ms_url} -u %s -a {ms_apikey}".format(**options)
for c in CONTENT:
cmd = cmd_template % c
cmds.append(cmd)
utils.run_commands(cmds)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery, Stéphane Diemer
import argparse
import logging
import os
import requests
import imp
logger = logging.getLogger('mediaserver_client')
MiB = 1024 * 1024
session = None
MS_CLIENT_URL = 'https://raw.githubusercontent.com/UbiCastTeam/mediaserver-client/master/mediaserver_api_client.py'
MS_CLIENT_PATH = '/tmp/mediaserver_api_client.py'
def get_client_module():
# download and load client script
if os.path.exists(MS_CLIENT_PATH):
logger.info('MediaServer client is already downloaded: "%s".', MS_CLIENT_PATH)
else:
req = requests.get(MS_CLIENT_URL, timeout=10)
if not req.ok:
raise Exception('Failed to download MS client. Status: %s, response: %s' % (req.status_code, req.text))
with open(MS_CLIENT_PATH, 'w') as fo:
fo.write(req.text)
logger.info('MediaServer client downloaded: "%s".', MS_CLIENT_PATH)
ms_client = imp.load_source('ms_client', MS_CLIENT_PATH)
return ms_client
if __name__ == '__main__':
log_format = '%(asctime)s %(name)s %(levelname)s %(message)s'
logging.basicConfig(level=logging.DEBUG, format=log_format)
urllib3_logger = logging.getLogger('requests.packages.urllib3')
urllib3_logger.setLevel(logging.WARNING)
parser = argparse.ArgumentParser(description='Import media from a zip archive into a portal on the commandline')
parser.add_argument('-w', '--webtv', required=True, help='webtv url')
parser.add_argument('-u', '--url', required=True, help='media zip url')
parser.add_argument('-a', '--apikey', required=True, help='apikey')
args = parser.parse_args()
CONFIG = {
'SERVER_URL': args.webtv,
'API_KEY': args.apikey,
'PROXIES': {'http': '', 'https': ''},
'UPLOAD_CHUNK_SIZE': 5 * MiB,
'VERIFY_SSL': False,
'CLIENT_ID': 'python-api-client',
}
mscli = get_client_module()
msc = mscli.MediaServerClient()
msc.config = CONFIG
# ping
print(msc.api('/', method='get'))
with open('/tmp/file.zip', 'wb') as f:
f.write(requests.get(args.url).content)
# add media with a zip
#print(msc.add_media('Test multichunk upload zip', file_path='/tmp/file.zip'))
print(msc.add_media(file_path='/tmp/file.zip'))
# add user
# print(msc.api('users/add/', method='post', data={'email': 'test@test.com'}))
# add users with csv file; example file (header should be included):
# Firstname;Lastname;Email;Company
# Albert;Einstein;albert.einstein@test.com;Humanity
# msc.import_users_csv('users.csv')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment