summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/mv_misc.py
blob: d03bdca66b0fce64c16f77f2e0d43708da2308da (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
# -*- coding: utf-8 -*-
import logging, mv_common
import os, re
from urllib2 import Request, urlopen, URLError, HTTPError

config_file = "mv_config"
data_config = __import__(config_file, globals(), locals(), [])

def setup_zip(MVROOT,zipcode):
    logging.debug("____Setting up the zipcode____")

    if zipcode:
        cmd="%s/bin/restore_default_settings.sh -c ZIP -c %s" %(MVROOT,zipcode)
        mv_common.runcmd(cmd)
        #Let's also speed things up for those in North America
        cmd="mkdir /usr/bin/perlbin/vendor/tv_grabbers_non_na"
        mv_common.runcmd(cmd)
        cmd="mv  /usr/bin/perlbin/vendor/tv_grab_*  /usr/bin/perlbin/vendor/tv_grabbers_non_na"
        mv_common.runcmd(cmd)
        cmd="mv  /usr/bin/perlbin/vendor/tv_grabbers_non_na/tv_grab_na*  /usr/bin/perlbin/vendor/"
        mv_common.runcmd(cmd)
    else:
        logging.debug("    Zipcode is not set")

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

def setup_tz(timezone,TEMPLATES):
    logging.info("____Setting up the timezone____")

    if not timezone:
        timezone="unknown"
    logging.info("    Setting timezone to %s",timezone)
    mv_common.remove_file("/etc/localtime")
    #try:
        #logging.debug("    Removing /etc/localtime")
        #os.remove("/etc/localtime")
    #except:
        #logging.debug("    Couldn't remove /etc/localtime")
        #pass

    srclink="/usr/share/zoneinfo/%s" %timezone
    logging.debug("    symlinking %s to /etc/localtime",srclink)
    try:
        os.symlink(srclink,"/etc/localtime")
    except:
        logging.critical("    Couldn't make symlink for /etc/localtime")

    #cmd = '''sed -e "s/^TIMEZONE=.*$/TIMEZONE=\\"%s\\" /" /etc/rc.conf > $TEMPLATES/rc.conf''' %re.escape(timezone)
    #mv_common.runcmd(cmd)

    if os.path.exists("/etc/php/php.ini"):
        logging.info("    Changing timezone for php")
        cmd = '''sed -i "s/^.*date.timezone.*$/date.timezone=%s/" ${BASE}/etc/php/php.ini''' %re.escape(timezone)
        mv_common.runcmd(cmd)

    #mv_common.cp_and_log(TEMPLATES+"/rc.conf","/etc/rc.conf")
    logging.info("__End of timezone\n")



def setup_sleep(systemconfig):
    logging.debug("____Setting up sleep____")
    autoshutdown = systemconfig.get("AutoShutdown")
    stime1 = systemconfig.get("Shutdowntime")
    stime2 = systemconfig.get("Shutdowntime2")
    cstime1=''

    if autoshutdown == "1" :
        if  not stime1 == "-1" :
            cstime1 = stime1
            cshutdown = cstime1
        if  not stime2 == "-1" :
            if cstime1 :
                cshutdown = "%s,%s" %(cstime1,stime2)
            else:
                cshutdown = stime2
        logging.debug("    Shutdown time at %s",cshutdown)
        cmd='''sed -e "s/HOUR/%s/g" %s/cron.template | crontab - -u mythtv''' %(cshutdown,systemconfig.get("TEMPLATES"))
        mv_common.runcmd(cmd)
    else:
        logging.info("    Shutdown not enabled")
        cmd='''sed -e "/00 HOUR.*/d" %s/cron.template | crontab - -u mythtv''' %systemconfig.get("TEMPLATES")
        mv_common.runcmd(cmd)

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