Add a security warning about large frame sizes.
[xiph/unicode.git] / icebreaker / icebreaker.py
blob3bfa46c40c9f2dc7120cb68416245f3464b91260
1 #!/usr/bin/env python
3 import sys, os
4 from sqlobject import *
5 import datetime
6 from datetime import datetime
7 from time import strptime
9 # Import variables from config file.
10 execfile('config.py')
12 class playlists(SQLObject):
13 _connection = conn
14 name = StringCol()
15 description = StringCol()
16 position = IntCol()
17 monday = StringCol()
18 tuesday = StringCol()
19 wednesday = StringCol()
20 thursday = StringCol()
21 friday = StringCol()
22 saturday = StringCol()
23 sunday = StringCol()
24 current = BoolCol()
26 class Log:
27 """file like for writes with auto flush after each write
28 to ensure that everything is logged, even during an
29 unexpected exit."""
30 def __init__(self, f):
31 self.f = f
32 def write(self, s):
33 self.f.write(s)
34 self.f.flush()
36 def main():
37 #change to data directory if needed
38 os.chdir("/mnt/icebreaker/")
39 #redirect outputs to a logfile
40 sys.stdout = sys.stderr = Log(open(LOGFILE, 'a+'))
41 #ensure the that the daemon runs a normal user
42 # os.setegid(100) #set group
43 # os.seteuid(1000) #set user
44 #change all 1's to 0 in current
45 while BLAH
46 #check date/time
47 n=datetime.now().strftime("%H:%M")
48 #find day of week
49 d=datetime.weekday(n)
50 #check playlists table for list
51 #put in a loop, iterate through the database and parse all times, comparing starts.
53 start = #time from playlists :: compare to current time, use timedelta
54 stop = #time from playlists :: find way to make it stick
55 # convert string time to real time object
56 start1=datetime.time(datetime(*strptime(start, "%H:%M")[0:6])).strftime("%H:%M")
57 stop1=datetime.time(datetime(*strptime(stop, "%H:%M")[0:6])).strftime("%H:%M")
59 # make days in columns
60 # time in tuples per playlist :: make in [start:stop],[start:stop] form?
64 # set a boolean to 'list'
66 #### Move this to list script
67 #if list not true
68 # shuffle from files
70 #change 0 for current list to 1
73 if __name__ == "__main__":
74 # do the UNIX double-fork magic, see Stevens' "Advanced
75 # Programming in the UNIX Environment" for details (ISBN 0201563177)
76 try:
77 pid = os.fork()
78 if pid > 0:
79 # exit first parent
80 sys.exit(0)
81 except OSError, e:
82 print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror)
83 sys.exit(1)
85 # decouple from parent environment
86 os.chdir("/") #don't prevent unmounting....
87 os.setsid()
88 os.umask(0)
90 # do second fork
91 try:
92 pid = os.fork()
93 if pid > 0:
94 # exit from second parent, print eventual PID before
95 #print "Daemon PID %d" % pid
96 open(PIDFILE,'w').write("%d"%pid)
97 sys.exit(0)
98 except OSError, e:
99 print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror)
100 sys.exit(1)
102 # start the daemon main loop
103 main()