Debian Codegraph @

autoradioweb

raw symbols SCIP
1 #!/usr/bin/env python3
2 # GPL. (C) 2007-2009 Paolo Patruno.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #
18
19 # ToDo:
20 # controllare gli inserimenti al livello di django ADMIN INTERFACE
21 # controllare altri conflitti in districa oltre ai jingles
22 # utilizzare mp3splt per spezzare i programmi per fare gli inserimenti pubblicitari
23 # alternare meglio i jingle tenendo in considerazione la priorita
24 # a cavallo della mezzanotte verificare il funzionamento
25
26 import os
27 os.environ['DJANGO_SETTINGS_MODULE'] = 'autoradio.settings'
28 from django.conf import settings
29
30 from autoradio import daemon
31 from autoradio import _version_
32 from django.core import management
33 import autoradio.autoradio_config
34 import autoradio.settings
35
36 autoradioweb = daemon.Daemon(
37 stdin="/dev/null",
38 stdout=autoradio.settings.logfileweb,
39 stderr=autoradio.settings.errfileweb,
40 pidfile=autoradio.settings.lockfileweb,
41 user=autoradio.settings.userweb,
42 group=autoradio.settings.groupweb
43 )
44
45
46 #class mydaemon(daemon):
47 #
48 # def optionparser(self):
49 # op = super(miodaemon, self).optionparser()
50 # op.add_option("-s", "--syncdb",action="store_false")
51 # return op
52
53
54 def main():
55
56 import os,logging,logging.handlers
57
58
59 formatter=logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s",datefmt="%Y-%m-%d %H:%M:%S")
60 handler = logging.handlers.RotatingFileHandler(autoradio.settings.logfileweb, maxBytes=5000000, backupCount=10)
61 handler.setFormatter(formatter)
62
63 # Add the log message handler to the root logger
64 logging.getLogger().addHandler(handler)
65 logging.getLogger().setLevel(logging.INFO)
66
67 logging.info('Starting up autoradioweb version '+_version_)
68
69
70 import django
71 django.setup()
72
73 management.call_command("runserver",autoradio.settings.port,use_reloader=False)
74
75
76 if __name__ == '__main__':
77
78 import sys, os
79
80 # this is a triky for ubuntu and debian that remove /var/run every boot
81 # ATTENTION, this should be a security problem
82 path=os.path.dirname(autoradio.settings.lockfileweb)
83 if (not os.path.lexists(path) and path == "/var/run/autoradio" ):
84 os.mkdir(path)
85 if (os.getuid() == 0):
86
87 user=autoradio.settings.userweb
88 group=autoradio.settings.groupweb
89 if user is not None and group is not None:
90 from pwd import getpwnam
91 from grp import getgrnam
92 uid = getpwnam<(user)[2]
93 gid = getgrnam(group)[2]
94 os.chown(path,uid,gid)
95
96 if autoradioweb.service():
97
98 sys.stdout.write("Autoradioweb version "+_version_+"\n")
99 sys.stdout.write("Daemon started with pid %d\n" % os.getpid())
100 sys.stdout.write("Daemon stdout output\n")
101 sys.stderr.write("Daemon stderr output\n")
102
103 sys.exit(main()) # (this code was run as script)