base_about.py 4.56 KB
#!/usr/bin/python3

# -*- coding: UTF-8 -*-# enable debugging
from mysql.connector import MySQLConnection, Error
from read_dbconfig import read_db_config
import tornado.ioloop
import tornado.web
import  tornado.escape
import  tornado
import os.path
import sys
from subprocess import Popen, PIPE
#from itertools import izip
#from baseclasses.htmltools import htmltools

from ncauth.ncauth_base import ncauth_base
class base_about(ncauth_base):
    
    def get(self):
         self.redirect("/")
    
    @tornado.web.authenticated
    def post(self): 
        nav=all
        subnav=all
        content=all
        msglvl=""  
        msg=False
        module="about"
        mainfnc="show"
        loader =tornado. template.Loader(os.path.join(os.path.dirname(__file__), "../templates"))
        navigation=loader.load("navigation.html").generate(nav=nav)
        subnavigation=loader.load("subnav_"+module+"_"+mainfnc+".html").generate(subnav=subnav)
        gitlastchange=self.gitlastchanges()
        gitversions=self.gitversions()
        mailstuff=self.mailcheck()
        mailstufflist=self.mailchecktuple()
        maincontent=loader.load("content_"+module+"_"+mainfnc+".html").generate(gitlastchange=gitlastchange, gitversions=gitversions,mailstuff=mailstuff,mailstufflist=mailstufflist)
        self.render('base.html', navigation=navigation, subnavigation=subnavigation, maincontent=maincontent, msg=msg, msglvl=msglvl)
    
    def printabout(self):
        #p = Popen("bash", stdout=PIPE, stdin=PIPE)
        #p.stdin.write("git log \n")
        #p.stdin.close()
        # print(p.stdout.read())
        #p1 = str(Popen(['git', 'log','-n10','--pretty=oneline'], stdout=PIPE) .communicate()[0])
       #print('<div class="alert alert-info">')
       self.gitversions()
       #print('<br>')
       self.gitlastchanges()
       #print('</div>')
        
        
    def gitlastchanges(self):
        old_dir = os.getcwd()
        os.chdir( os.path.join(os.path.dirname(__file__), "") )
        os.chdir( '..')
        p1 = str(Popen(['git', 'log','-n10','--pretty=format:"%ci %s"'], stdout=PIPE) .communicate()[0])
        #p2 = Popen(['grep', '*'], stdin=p1.stdout, stdout=PIPE).communicate()[0]
       # p1=str("<br />".join(p1.split("\n")))
        thatLine = p1.replace('\\n', '<br />')
        thatLine = thatLine.replace('b\'"', '<br>"')
        print('<br>')
      #  h.crt_info_bx('letzte &Auml;nderungen:')
        print(str(thatLine))
        return thatLine
        
    def gitversions(self):
         #p = Popen("bash", stdout=PIPE, stdin=PIPE)
        #p.stdin.write("git log \n")
        #p.stdin.close()
        # print(p.stdout.read())
        #p1 = str(Popen(['git', 'log','-n10','--pretty=oneline'], stdout=PIPE) .communicate()[0])
        os.chdir( os.path.join(os.path.dirname(__file__), "") )
        os.chdir( '..')
        p1 = Popen(['git', 'tag','-n'], stdout=PIPE)
        p2 = str(Popen(['sort', '-V','-r'], stdin=p1.stdout, stdout=PIPE).communicate()[0])
       # p1=str("<br />".join(p1.split("\n")))
        thatLine = p2.replace('\\n', '<br />')
        thatLine = thatLine.replace('b\'', '<br>')
        print('<br>')
        #h.crt_info_bx('Versionen:')
        print(str(thatLine))
        
        return thatLine


    def mailcheck(self):
        old_dir = os.getcwd()
        os.chdir( os.path.join(os.path.dirname(__file__), "") )
        os.chdir( '..')
        p1 = str(Popen(['/usr/sbin/postqueue','-p'],stdout=PIPE) .communicate()[0])
        thatLine = p1.replace('\\n', '<br />')
        thatLine = thatLine.replace('b\'"', '<br>"')
        print(str(thatLine))
        return thatLine
        
    def mailchecktuple(self):
        old_dir = os.getcwd()
        os.chdir( os.path.join(os.path.dirname(__file__), "") )
        os.chdir( '..')
#        p1 = Popen(['/usr/sbin/postqueue','-p'],stdout=PIPE)
        p1 = str(Popen("/usr/sbin/postqueue -p | awk 'NR % 4 == 2' | awk   '{print $1 \"\\n\" $7 }' |egrep -v '^-' | egrep -v '^$' " ,  stdout=PIPE, shell=True).communicate()[0])
#        p3 = Popen(['egrep', '-v','"\'-\'"'], stdin=p2.stdout, stdout=PIPE)
#        p4 = Popen(['egrep', '-v','"^$"'], stdin=p3.stdout, stdout=PIPE)
#        p5 = Popen(['egrep', '-v','"^\("'], stdin=p4.stdout, stdout=PIPE).communicate()[0]
        thatLine = p1.replace('\\n', ';')
        thatLine = thatLine.replace('b\'', '')
        thatLine = thatLine.replace('\'', '')
        #print(str(thatLine))
		
		
        list = [item for item in thatLine.split(';') if item.strip()]
#        tuple = (item for item in thatLine.split(';') if item.strip())
        i = iter(list)
        dict = (zip(i, i))
        return dict