--- univention-updater/modules/univention/management/console/handlers/update/__init__.py +++ univention-updater/modules/univention/management/console/handlers/update/__init__.py @@ -41,6 +41,7 @@ import univention.debug as ud import univention.config_registry from univention.updater import UniventionUpdater +from json import JsonReader, JsonWriter import os import subprocess, string, time @@ -125,7 +126,13 @@ command_description = { values = { }, ), - + 'update/tail_file': umch.command( + short_description = _('Get tail of logfile' ), + method = 'tail_file', + values = { + 'filename': umc.String( _( 'Name of the log file' ), required = False ), + }, + ), } @@ -146,6 +153,7 @@ class handler(umch.simpleHandler): self.ucr_reinit = False + self.tail_fn2fd = {} def overview(self, object): _d = ud.function('update.handler.overview') @@ -389,6 +397,49 @@ class handler(umch.simpleHandler): self.finished(object.id(), stdout) + def tail_file(self, object): + _d = ud.function('update.handler.tail_file') + + logfn = object.options.get('filename') + if not logfn in ('/var/log/univention/updater.log'): + self.finished(object.id(), '%s: access not allowed by UMC module' % logfn) + return + + # create fd if fd is not present + if not logfn in self.tail_fn2fd: + fd = open(logfn,'r+') + self.tail_fn2fd[logfn] = fd + else: + fd = self.tail_fn2fd[logfn] + + curpos = fd.tell() + fd.seek(0,2) # seek to file end + endpos = fd.tell() + fd.seek(curpos,0) # seek back to cur pos + pendingbytes = endpos - curpos + data = fd.read(pendingbytes) # get pending data + ud.debug(ud.ADMIN, ud.PROCESS, 'update.handler.tail_file: %d %d %d %d' % (curpos, endpos, pendingbytes, len(data))) + + self.finished(object.id(), {'data': data, 'test': 'das ist ein test'}) + + def _web_tail_file(self, object, res): + _d = ud.function('update.handler._web_tail_file') + content_type = 'application/json' + content = '' + + data = {} + data['identifier'] = 'data' + data['label'] = 'updater data' + data['items'] = [ res.dialog ] + try: + json = JsonWriter() + content = json.write(data) + except: + ud.debug(ud.ADMIN, ud.PROCESS, 'update.handler._web_tail_file: failed to create JSON: %s' % (traceback.format_exc().replace('%','#')) ) + res.dialog = { 'Content-Type': content_type, 'Content': content } + self.revamped( object.id(), res, rawresult = True ) + + ####################### # The revamp functions ####################### @@ -506,7 +557,39 @@ class handler(umch.simpleHandler): frame_release = umcd.Frame([list_release], _('Release information')) frame_component = umcd.Frame([list_component], _('Components')) - res.dialog = [frame_release, frame_component] + javascript = umcd.HTML ("""""" % (self._sessionid)) + divitems = umcd.HTML('
TEST
') + + list_test = umcd.List() + list_test.add_row([divitems, javascript]) + frame_test = umcd.Frame([list_test], _('LOG TEST')) + + res.dialog = [frame_test, frame_release, frame_component] if frame_info: res.dialog.insert( 0, frame_info )