summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-config/mv_common.py
blob: 64ff2d6826838e78d394082e7c047213e69d7027 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
import logging, os
import commands
config_file = "mv_config"
data_config = __import__(config_file, globals(), locals(), [])

def runcmd(cmd):
    if data_config.NOOPDEBUG=="FALSE":
        pass
    else:
        cmd = "echo "+cmd
    logging.debug("    %s",cmd)
    cmdout = commands.getstatusoutput(cmd)
    logging.debug("    %s",cmdout)
    return cmdout[0]

def services(systemconfig):
    logging.debug("______Start of services______")
    logging.debug("__End services")

def cp_and_log(srcfile,destfile):
    #return
    if not os.path.exists(srcfile):
        logging.info("%s is not present, skipping...",srcfile)
    else:
        cmd = ("rsync -arhp %s %s") %(srcfile,destfile)
        runcmd(cmd)


def add_service(daemon):
    logging.info("    Adding service %s",daemon)
    cmd = "add_service.sh %s" %daemon
    runcmd(cmd)

def remove_service(daemon):
    logging.info("    Removing service %s",daemon)
    cmd = "remove_service.sh %s" %daemon
    runcmd(cmd)

def pkg_blacklist_check(pkg):
    cmd = '''grep -q %s /etc/blacklist.package''' %pkg
    rc = runcmd(cmd)
    if rc == 0:
        return True
    else:
        return False

def pkg_installed_check(pkg):
    logging.debug("    Checking if %sis installed",pkg)
    cmd = "pacman -Q %s " %pkg
    rc = runcmd(cmd)
    if rc == 0:
        return True
    else:
        return False


def pacinstall(pkg):
    logging.info("    Checking %s for install",pkg)
    #extra pkg check
    if pkg == "xine":
        pacinstall("xine-ui")
    elif pkg == "dvdcss":
        pacinstall("libdvdcss")
    elif pkg == "webmin":
        add_service("webmin")

    if  not pkg_blacklist_check(pkg):
        if pkg_installed_check(pkg):
            logging.info("    %s is already installed, will not install",pkg)
        else:
            logging.info("    Installing %s",pkg)
            cmd ='''pacman --noconfirm -Sf %s ''' %pkg
            runcmd(cmd)
    else:
        logging.info("    %s is blacklisted, will not install",pkg)

def pacremove(pkg):
    logging.info("    Checking %s for removal",pkg)
    if pkg == "xine":
        pacremove("xine-ui")
    elif pkg == "dvdcss":
        pacremove("libdvdcss")
    elif pkg == "webmin":
        remove_service("webmin")

    if  not pkg_blacklist_check(pkg):
        if not pkg_installed_check(pkg):
            logging.info("    %s is not installed, will not remove",pkg)
        else:
            logging.info("    Removing %s",pkg)
            cmd ='''pacman --noconfirm -R  %s ''' %pkg
    else:
        logging.info("    %s is blacklisted, will not remove",pkg)

def getpid(process):
    return commands.getoutput('pidof %s' % process)


def restartLCD(RESTART_LCD):
    if  RESTART_LCD :
        logging.info("    Restarting lcd server")
        cmd = "killall -9 mythlcdserver"
        runcmd(cmd)
    else:
        logging.debug("    Not restarting MYTHLCD server")


def reloadfe(dbhost,RESTART_LCD):
    logging.debug("____Start of reloadfe____")
    logging.info("    Clearing Backend cache")
    cmd = '''/usr/bin/backend_control.sh  clearcache  behost %s''' %dbhost
    runcmd(cmd)
    restartLCD(RESTART_LCD)
    for pid in getpid("mythfrontend"):
        cmd = ''' kill -s USR1 %s ''' %pid
        #runcmd(cmd)
        logging.info("    Reloading frontend with pid of %s",pid)

    logging.debug("__End of reloadfe\n")


def restartfe(RESTART_LCD):
    logging.debug("____Start of restartfe____")
    logging.info("    Restarting frontend")
    restartLCD(RESTART_LCD)
    cmd="killall -9 mythfrontend"
    runcmd(cmd)
    cmd="killall -9 welcome"
    runcmd(cmd)
    logging.debug("__End of restartfe\n")


def udev_trigger():
    logging.info("    Triggering udev")
    cmd = "udevadm settle"
    runcmd(cmd)
    cmd = "udevadm trigger"
    runcmd(cmd)
    cmd = "udevadm settle"
    runcmd(cmd)
    cmd = "udevadm trigger"
    runcmd(cmd)