Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/relive #76

Draft
wants to merge 15 commits into
base: foss4g
Choose a base branch
from
75 changes: 53 additions & 22 deletions voctopublish/api_client/c3tt_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(self, url, group, host, secret):
self.group = group
self.host = host
self.secret = secret
self.ticket_id = None

def _gen_signature(self, method, args):
"""
Expand Down Expand Up @@ -72,16 +71,21 @@ def _gen_signature(self, method, args):
hash_ = hmac.new(bytes(self.secret, 'utf-8'), bytes(sig_args, 'utf-8'), hashlib.sha256)
return hash_.hexdigest()

def _open_rpc(self, method, args=[]):
def _open_rpc(self, method, ticket=None, args=[]):
"""
create xmlrpc client
:param method:
:param ticket: optional, either a numeric ticket_id or an instance of Ticket class
:param args:
:return: attributes of the answer
"""
logging.debug('creating XML RPC proxy: ' + self.url + "?group=" + self.group + "&hostname=" + self.host)
if self.ticket_id:
args.insert(0, self.ticket_id)
if ticket is not None:
# the ticket parameter can be either a numeric ticket_id or an instance of Ticket class
if isinstance(ticket, int) or isinstance(ticket, str):
args.insert(0, ticket)
else:
args.insert(0, ticket.id)

try:
proxy = xmlrpc.client.ServerProxy(self.url + "?group=" + self.group + "&hostname=" + self.host)
Expand Down Expand Up @@ -139,69 +143,96 @@ def get_version(self):
"""
return str(self._open_rpc("C3TT.getVersion"))

def assign_next_unassigned_for_state(self, ticket_type, to_state):
def assign_next_unassigned_for_state(self, ticket_type, to_state, property_filters = []):
"""
check for new ticket on tracker and get assignment
this also sets the ticket id in the c3tt client instance and has therefore be called before any ticket related
function
:param ticket_type: type of ticket
:param to_state: ticket state the returned ticket will be in after this call
:parm property_filters: return only tickets matching given properties
:return: ticket id or None in case no ticket is available for the type and state in the request
"""
ret = self._open_rpc("C3TT.assignNextUnassignedForState", [ticket_type, to_state])
ret = self._open_rpc("C3TT.assignNextUnassignedForState", args=[ticket_type, to_state, property_filters])
# if we get no xml here there is no ticket for this job
if not ret:
return None
else:
self.ticket_id = ret['id']
return ret['id']
return ret

def get_assigned_for_state(self, ticket_type, state, property_filters = []):
"""
Get first assigned ticket in state $state
function
:param ticket_type: type of ticket
:param to_state: ticket state the returned ticket will be in after this call
:parm property_filters: return only tickets matching given properties
:return: ticket id or None in case no ticket is available for the type and state in the request
"""
ret = self._open_rpc("C3TT.getAssignedForState", args=[ticket_type, state, property_filters])
# if we get no xml here there is no ticket for this job
if not ret:
return None
else:
if len(ret) > 1:
logging.warn("multiple tickets assined, fetching first one")
return ret[0]

def get_tickets_for_state(self, ticket_type, to_state, property_filters = []):
"""
Get all tickets in state $state from projects assigned to the workerGroup, unless workerGroup is halted
function
:param ticket_type: type of ticket
:param to_state: ticket state the returned ticket will be in after this call
:parm property_filters: return only tickets matching given properties
:return: ticket id or None in case no ticket is available for the type and state in the request
"""
ret = self._open_rpc("C3TT.getTicketsForState", args=[ticket_type, to_state, property_filters])
# if we get no xml here there is no ticket for this job
if not ret:
return None
else:
return ret

def set_ticket_properties(self, properties):
def set_ticket_properties(self, ticket, properties):
"""
set ticket properties
:param properties:
:return: Boolean
"""
ret = self._open_rpc("C3TT.setTicketProperties", [properties])
ret = self._open_rpc("C3TT.setTicketProperties", ticket, args=[properties])
if not ret:
logging.error("no xml in answer")
return False
else:
return True

def get_ticket_properties(self):
def get_ticket_properties(self, ticket):
"""
get ticket properties
:return:
"""
ret = self._open_rpc("C3TT.getTicketProperties")
ret = self._open_rpc("C3TT.getTicketProperties", ticket)
if not ret:
logging.error("no xml in answer")
return None
else:
return ret

def set_ticket_done(self):
def set_ticket_done(self, ticket):
"""
set Ticket status on done
:return:
"""
ret = self._open_rpc("C3TT.setTicketDone")
logging.debug(str(ret))

def set_ticket_failed(self, error):
def set_ticket_failed(self, ticket, error):
"""
set ticket status on failed an supply a error text
:param error:
"""
self._open_rpc("C3TT.setTicketFailed", [error.encode('ascii', 'xmlcharrefreplace')])

def get_ticket_id(self):
"""
get the id of the ticket assigned to the client instance
:return: Ticket id or None if no ID is assigned yet
"""
return self.ticket_id
self._open_rpc("C3TT.setTicketFailed", ticket, [error.encode('ascii', 'xmlcharrefreplace')])


class C3TTException(Exception):
Expand Down
62 changes: 43 additions & 19 deletions voctopublish/api_client/voctoweb_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import time
import tempfile
import operator
import paramiko
#import paramiko
import requests
import glob

Expand Down Expand Up @@ -265,18 +265,27 @@ def upload_file(self, local_filename, remote_filename, remote_folder):

logging.info("uploading " + remote_filename + " done")


def get_event(self):
"""
Gets event on the voctoweb API host via GUID
:return:
"""
try:
url = self.api_url[:-4] + "public/events/" + self.t.guid
print(url)
r = requests.get(url)
except requests.exceptions.BaseHTTPError as e_:
raise VoctowebException("error while checking event id with public API") from e_
return r

def create_or_update_event(self):
"""
Create a new event on the voctoweb API host
:return:
"""
logging.info('creating event on ' + self.api_url + ' in conference ' + self.t.voctoweb_slug)

# prepare some variables for the api call
url = self.api_url + 'events'
if self.t.voctoweb_event_id:
url += '/' + self.t.voctoweb_event_id

if self.t.url:
if self.t.url.startswith('//'):
event_url = 'https:' + self.t.url
Expand All @@ -297,6 +306,17 @@ def create_or_update_event(self):
for link in self.t.links:
description = '\n\n'.join([description, '<a href="' + link + '">' + link + '</a>'])

images = {}
# only publish images if we already have them, which is not the case for relive only events
if hasattr(self.t, 'local_filename_base'):
images = {
'thumb_filename': self.t.local_filename_base + ".jpg",
'poster_filename': self.t.local_filename_base + "_preview.jpg",
'timeline_filename': self.t.local_filename_base + ".timeline.jpg",
'thumbnails_filename': self.t.local_filename_base + ".thumbnails.vtt",
'release_date': str(time.strftime("%Y-%m-%d"))
}

# API code https://github.com/voc/voctoweb/blob/master/app/controllers/api/events_controller.rb
headers = {'CONTENT-TYPE': 'application/json'}
payload = {'api_key': self.api_key,
Expand All @@ -308,32 +328,36 @@ def create_or_update_event(self):
'subtitle': self.t.subtitle,
'link': event_url,
'original_language': self.t.languages[0],
'thumb_filename': self.t.local_filename_base + ".jpg",
'poster_filename': self.t.local_filename_base + "_preview.jpg",
'timeline_filename': self.t.local_filename_base + ".timeline.jpg",
'thumbnails_filename': self.t.local_filename_base + ".thumbnails.vtt",
'conference_id': self.t.voctoweb_slug,
#'conference_id': self.t.voctoweb_slug,
'description': description,
'date': self.t.date,
'persons': self.t.people,
'tags': self.t.voctoweb_tags,
'promoted': False,
'release_date': str(time.strftime("%Y-%m-%d"))
}
}
logging.debug("api url: " + url + ' header: ' + str(headers) + ' payload: ' + str(payload))

**images
}
}
# call voctoweb api
try:
# TODO make ssl verify a config option
# r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)

# prepare some variables for the api call
url = self.api_url + 'events'
logging.debug("api url: " + url + ' header: ' + str(headers) + ' payload: ' + json.dumps(payload))
if self.t.voctoweb_event_id:
r = requests.patch(url, headers=headers, data=json.dumps(payload))
try:
logging.info("trying to patch event " + self.t.guid)
r = requests.patch(url + '/' + self.t.guid, headers=headers, data=json.dumps(payload))
except:
logging.info("... faild, trying to create new event " + self.t.guid)
r = requests.post(url, headers=headers, data=json.dumps(payload))
else:
logging.info("trying to create new event " + self.t.guid)
r = requests.post(url, headers=headers, data=json.dumps(payload))

except requests.packages.urllib3.exceptions.MaxRetryError as e:
raise VoctowebException("Error during creation of event: " + str(e)) from e

print()
return r

def create_recording(self, local_filename, filename, folder, language, hq, html5, single_language=False):
Expand Down
Loading