File: autoradioctrl

package info (click to toggle)
autoradio 3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,784 kB
  • sloc: python: 10,213; sh: 68; makefile: 16
file content (57 lines) | stat: -rwxr-xr-x 1,969 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# GPL. (C) 2007-2009 Paolo Patruno.

# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 2 of the License, or 
# (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
# 

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'autoradio.settings'
from django.conf import settings

from django.core import management
import autoradio.settings
import autoradio.autoradio_config
import sys, optparse, autoradio.daemon
from autoradio import  _version_


def initdb(cwd):
    p = optparse.OptionParser(usage="usage: %prog [options]",version="%prog "+_version_)
    p.add_option("--syncdb", action="store_true",dest="syncdb", help="initialize autoradio DB (default %default)", default=False)
    p.add_option("--changeuser", action="store_true",dest="changeuser", help="change user to the user in config file (default %default)", default=False)
    (options, args) = p.parse_args()


    import django
    django.setup()

    if (not options.syncdb):
        p.print_help()


    if (options.changeuser):
        dae=autoradio.daemon.Daemon()
        dae.switchuser(user=autoradio.autoradio_config.user,group=autoradio.autoradio_config.group,env=None)
        #os.chdir(cwd)

    if (options.syncdb):
        management.call_command("migrate",no_initial_data=True )


if __name__ == '__main__':

    cwd=os.getcwd()

    sys.exit(initdb(cwd))  # (this code was run as script)