def format_runtime(runtime): retVal = "" if runtime.days: retVal = format_unit(runtime.days, 'duration-day', length="long", locale=web.get_locale()) + ', ' mins, seconds = divmod(runtime.seconds, 60) hours, minutes = divmod(mins, 60) # ToDo: locale.number_symbols._data['timeSeparator'] -> localize time separator ? if hours: retVal += '{:d}:{:02d}:{:02d}s'.format(hours, minutes, seconds) elif minutes: retVal += '{:2d}:{:02d}s'.format(minutes, seconds) else: retVal += '{:2d}s'.format(seconds) return retVal
def render_task_status(tasklist): #helper function to apply localize status information in tasklist entries renderedtasklist = list() # task2 = task for task in tasklist: if task['user'] == current_user.nickname or current_user.role_admin(): # task2 = copy.deepcopy(task) # = task if task['formStarttime']: task['starttime'] = format_datetime(task['formStarttime'], format='short', locale=web.get_locale()) # task2['formStarttime'] = "" else: if 'starttime' not in task: task['starttime'] = "" # localize the task status if isinstance(task['stat'], int): if task['stat'] == worker.STAT_WAITING: task['status'] = _(u'Waiting') elif task['stat'] == worker.STAT_FAIL: task['status'] = _(u'Failed') elif task['stat'] == worker.STAT_STARTED: task['status'] = _(u'Started') elif task['stat'] == worker.STAT_FINISH_SUCCESS: task['status'] = _(u'Finished') else: task['status'] = _(u'Unknown Status') # localize the task type if isinstance(task['taskType'], int): if task['taskType'] == worker.TASK_EMAIL: task['taskMessage'] = _(u'E-mail: ') + task['taskMess'] elif task['taskType'] == worker.TASK_CONVERT: task['taskMessage'] = _(u'Convert: ') + task['taskMess'] elif task['taskType'] == worker.TASK_UPLOAD: task['taskMessage'] = _(u'Upload: ') + task['taskMess'] elif task['taskType'] == worker.TASK_CONVERT_ANY: task['taskMessage'] = _(u'Convert: ') + task['taskMess'] else: task['taskMessage'] = _( u'Unknown Task: ') + task['taskMess'] renderedtasklist.append(task) return renderedtasklist
def results_show(result_id): result = TaskResult.query.get(result_id) if not result: abort(404) if result.owner_id != current_user.id: abort(404) controls = { item.number: item for item in Control.query.filter_by(language=get_locale()) } return render_template( 'results/show.html', result=result, all_controls=controls, active=ACTIVE, )
def _nightly_available_updates(self, request_method): tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone) if request_method == "GET": repository_url = 'https://api.github.com/repos/janeczku/calibre-web' status, commit = self._load_remote_data(repository_url +'/git/refs/heads/master') parents = [] if status['message'] != '': return json.dumps(status) if 'object' not in commit: status['message'] = _(u'Unexpected data while reading update information') return json.dumps(status) if commit['object']['sha'] == status['current_commit_hash']: status.update({ 'update': False, 'success': True, 'message': _(u'No update available. You already have the latest version installed') }) return json.dumps(status) # a new update is available status['update'] = True try: r = requests.get(repository_url + '/git/commits/' + commit['object']['sha']) r.raise_for_status() update_data = r.json() except requests.exceptions.HTTPError as e: status['error'] = _(u'HTTP Error') + ' ' + str(e) except requests.exceptions.ConnectionError: status['error'] = _(u'Connection error') except requests.exceptions.Timeout: status['error'] = _(u'Timeout while establishing connection') except requests.exceptions.RequestException: status['error'] = _(u'General error') if status['message'] != '': return json.dumps(status) if 'committer' in update_data and 'message' in update_data: status['success'] = True status['message'] = _( u'A new update is available. Click on the button below to update to the latest version.') new_commit_date = datetime.datetime.strptime( update_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz parents.append( [ format_datetime(new_commit_date, format='short', locale=web.get_locale()), update_data['message'], update_data['sha'] ] ) # it only makes sense to analyze the parents if we know the current commit hash if status['current_commit_hash'] != '': try: parent_commit = update_data['parents'][0] # limit the maximum search depth remaining_parents_cnt = 10 except IndexError: remaining_parents_cnt = None if remaining_parents_cnt is not None: while True: if remaining_parents_cnt == 0: break # check if we are more than one update behind if so, go up the tree if parent_commit['sha'] != status['current_commit_hash']: try: r = requests.get(parent_commit['url']) r.raise_for_status() parent_data = r.json() parent_commit_date = datetime.datetime.strptime( parent_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz parent_commit_date = format_datetime( parent_commit_date, format='short', locale=web.get_locale()) parents.append([parent_commit_date, parent_data['message'].replace('\r\n','<p>').replace('\n','<p>')]) parent_commit = parent_data['parents'][0] remaining_parents_cnt -= 1 except Exception: # it isn't crucial if we can't get information about the parent break else: # parent is our current version break else: status['success'] = False status['message'] = _(u'Could not fetch update information') # a new update is available status['update'] = True if 'body' in commit: status['success'] = True status['message'] = _( u'A new update is available. Click on the button below to update to the latest version.') new_commit_date = datetime.datetime.strptime( commit['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz parents.append( [ format_datetime(new_commit_date, format='short', locale=web.get_locale()), commit['message'], commit['sha'] ] ) # it only makes sense to analyze the parents if we know the current commit hash if status['current_commit_hash'] != '': try: parent_commit = commit['parents'][0] # limit the maximum search depth remaining_parents_cnt = 10 except IndexError: remaining_parents_cnt = None if remaining_parents_cnt is not None: while True: if remaining_parents_cnt == 0: break # check if we are more than one update behind if so, go up the tree if commit['sha'] != status['current_commit_hash']: try: r = requests.get(parent_commit['url']) r.raise_for_status() parent_data = r.json() parent_commit_date = datetime.datetime.strptime( parent_data['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') - tz parent_commit_date = format_datetime( parent_commit_date, format='short', locale=web.get_locale()) parents.append([parent_commit_date, parent_data['message'], parent_data['sha']]) parent_commit = parent_data['parents'][0] remaining_parents_cnt -= 1 except Exception: # it isn't crucial if we can't get information about the parent break else: # parent is our current version break status['history'] = parents[::-1] return json.dumps(status) return ''