correct getting duration from content. try to improve error management
--- a/annot-server/utils.py Sat Oct 25 05:43:01 2014 +0200
+++ b/annot-server/utils.py Sat Oct 25 06:44:33 2014 +0200
@@ -117,19 +117,6 @@
self.end_date= self.parse_date(str(end_date))
elif self.start_date and self.duration:
self.end_date = self.start_date + datetime.timedelta(seconds=self.duration)
- elif self.start_date and self.base_url:
- # get duration from api
- content_url = self.base_url + AnnotationsSynchronizer.LDT_CONTENT_REST_API_PATH + content_id + "/?format=json"
- self.logger.debug("get duration " + content_url) #@UndefinedVariable
- r = requests.get(content_url, params=self.post_param)
- self.logger.debug("get duration resp " + repr(r)) #@UndefinedVariable
- self.duration = int(r.json()['duration'])
- self.logger.debug("get duration " + repr(self.duration)) #@UndefinedVariable
-
- self.end_date = self.start_date + datetime.timedelta(seconds=int(self.duration/1000))
-
- if self.end_date and self.deltas:
- self.end_date = self.end_date + datetime.timedelta(milliseconds=self.deltas[-1][1])
self.content_file = content_file
self.project_id = project_id
@@ -239,8 +226,8 @@
if ensemble_parent is None:
- self.logger.error("Can not process file") #@UndefinedVariable
- sys.exit()
+ self.logger.error("Ensemble parent is None - Can not process file") #@UndefinedVariable
+ raise Exception("Ensemble parent is None - can not process file")
if self.replace:
for ens in ensemble_parent.iterchildren(tag=u"ensemble"):
@@ -278,6 +265,25 @@
decoupage_id = decoupage.get('id', '') if decoupage is not None else None
+ if self.end_date is None and self.start_date and self.base_url:
+ # get duration from api
+ content_url = self.base_url + AnnotationsSynchronizer.LDT_CONTENT_REST_API_PATH + content_id + "/?format=json"
+ self.logger.debug("get duration " + content_url) #@UndefinedVariable
+ r = requests.get(content_url, params=self.post_param)
+ self.logger.debug("get duration resp " + repr(r)) #@UndefinedVariable
+ if r.status_code == requests.codes.ok:
+ self.duration = int(r.json()['duration'])
+ else:
+ self.logger.error("Can not get duration form content : %r " % r)
+ r.raise_for_status()
+ self.logger.debug("get duration " + repr(self.duration)) #@UndefinedVariable
+
+ self.end_date = self.start_date + datetime.timedelta(seconds=int(self.duration/1000))
+
+ if self.end_date and self.deltas:
+ self.end_date = self.end_date + datetime.timedelta(milliseconds=self.deltas[-1][1])
+
+
filters = self.get_filter()
--- a/annot-server/webapp/admin.py Sat Oct 25 05:43:01 2014 +0200
+++ b/annot-server/webapp/admin.py Sat Oct 25 06:44:33 2014 +0200
@@ -189,11 +189,16 @@
'logger' : logger,
}
- sync = utils.AnnotationsSynchronizer(**sync_args)
- sync.export_annotations()
+ error = None
+ try:
+ sync = utils.AnnotationsSynchronizer(**sync_args)
+ sync.export_annotations()
+ except Exception as e:
+ error = repr(e) + " - " + str(e)
+
logs = [ line for line in stream.getvalue().split("\n")]
- return self.render('admin/sync_event_session.html', event_session=event_session, sync_args=repr(sync_args), logs=logs)
+ return self.render('admin/sync_event_session.html', event_session=event_session, sync_args=repr(sync_args), error=error, logs=logs)
admin.add_view(EventView(database.db_session))
--- a/annot-server/webapp/templates/admin/sync_event_session.html Sat Oct 25 05:43:01 2014 +0200
+++ b/annot-server/webapp/templates/admin/sync_event_session.html Sat Oct 25 06:44:33 2014 +0200
@@ -2,6 +2,13 @@
{% block body %}
<h3>Sync on project {{event_session.project_id}}</h3>
+ {% if error %}
+ <h3 style="color: red">KO</h3>
+ <div>{{error}}</div>
+ {% else %}
+ <h3 style="color: green">Ok</h3>
+ {% endif %}
+
<h4>Sync arguments</h4>
<pre>
{{sync_args}}