File: autoplayerd

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 (90 lines) | stat: -rwxr-xr-x 3,012 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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GPL. (C) 2013 Paolo Patruno.

# Authors: Paolo Patruno <p.patruno@iperbole.bologna.it> 
# Based on :
# mpDris2 from Jean-Philippe Braun <eon@patapon.info>,
#              Mantas Mikul─Śnas <grawity@gmail.com>
# mpDris from: Erik Karlsson <pilo@ayeon.org>
# Some bits taken from quodlibet mpris plugin by <christoph.reiter@gmx.at>

import os,autoradio.daemon as daemon
from autoradio import _version_
import autoradio.autoradio_config
import autoradio.settings
from autoradio import _version_

playerd = daemon.Daemon(
        stdin="/dev/null",
        stdout=autoradio.settings.logfileplayer,
        stderr=autoradio.settings.errfileplayer,
        pidfile=autoradio.settings.lockfileplayer,
        user=autoradio.settings.userplayer,
        group=autoradio.settings.groupplayer
)


def main ():

    import logging,logging.handlers

    formatter=logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s",datefmt="%Y-%m-%d %H:%M:%S")
    handler = logging.handlers.RotatingFileHandler(autoradio.settings.logfileplayer, maxBytes=5000000, backupCount=10)
    handler.setFormatter(formatter)
    
    # Add the log message handler to the root logger
    logging.getLogger().addHandler(handler)
    logging.getLogger().setLevel(logging.INFO)

    logging.info('Starting up autoplayerd version '+_version_)

#   # Use logging for ouput at different *levels*.
#   #
#   logging.getLogger().setLevel(logging.INFO)
#   log = logging.getLogger("autoplayer")
#   handler = logging.StreamHandler(sys.stderr)
#   log.addHandler(handler)

    try:
        from autoradio.autoplayer import player
    except:
        logging.info('gstreamer1 import error')
        logging.info('try to use old gstreamer0')
        from autoradio.autoplayer import player_gstreamer0 as player

    player.main(autoradio.settings.busaddressplayer,autoradio.settings.audiosinkplayer)


if __name__ == '__main__':

#  main()# (this code was run as script)

    import sys, os

    # this is a triky for ubuntu and debian that remove /var/run every boot
    # ATTENTION, this should be a security problem
    path=os.path.dirname(autoradio.settings.lockfileplayer)
    if (not os.path.lexists(path) and path == "/var/run/autoradio" ):
        os.mkdir(path)
        if (os.getuid() == 0):
            user=autoradio.settings.userplayer
            group=autoradio.settings.groupplayer
            if user is not None and group is not None:
                from pwd import getpwnam
                from grp import getgrnam
                uid = getpwnam<(user)[2]
                gid = getgrnam(group)[2]
                os.chown(path,uid,gid)

    if playerd.service(noptions=1000):

        sys.stdout.write("Playerd version "+_version_+"\n")
        sys.stdout.write("Daemon started with pid %d\n" % os.getpid())
        sys.stdout.write("Daemon stdout output\n")
        sys.stderr.write("Daemon stderr output\n")

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