예제 #1
0
def start_proc_manager(config, logfile):
    from pycopia import proctools
    from pycopia import scheduler
    from pycopia import asyncio

    asyncio.start_sigio()
    pm = proctools.get_procmanager()

    for name, serverlist in config.VHOSTS.items():
        for servername in serverlist:
            print "Starting %s for %s." % (servername, name)
            p = pm.spawnpipe("%s/fcgi_server -n %s" %
                             (config.LIBEXEC, servername),
                             persistent=True,
                             logfile=logfile)
            asyncio.poller.register(p)
            scheduler.sleep(1.0)  # give it time to init...
    if config.USEFRONTEND:
        lighttpd = proctools.which("lighttpd")
        pm.spawnpipe("%s -D -f %s" % (lighttpd, LTCONFIG),
                     persistent=True,
                     logfile=logfile)
    try:
        while 1:
            asyncio.poller.loop()
            for proc in pm.getprocs():
                if proc.readable():
                    print proc.read(4096)
    except KeyboardInterrupt:
        asyncio.poller.unregister_all()
        for proc in pm.getprocs():
            proc.kill()
            proc.wait()
        if os.path.exists(config.PIDFILE):
            os.unlink(config.PIDFILE)
예제 #2
0
def start_proc_manager(config, logfile):
    from pycopia import proctools
    from pycopia import scheduler
    from pycopia import asyncio

    asyncio.start_sigio()
    pm = proctools.get_procmanager()

    for name, serverlist in config.VHOSTS.items():
        for servername in serverlist:
            print "Starting %s for %s." % (servername, name)
            p = pm.spawnpipe("%s/fcgi_server -n %s" % (config.LIBEXEC, servername), persistent=True, logfile=logfile)
            asyncio.poller.register(p)
            scheduler.sleep(1.0) # give it time to init...
    if config.USEFRONTEND:
        lighttpd = proctools.which("lighttpd")
        pm.spawnpipe("%s -D -f %s" % (lighttpd, LTCONFIG), persistent=True, logfile=logfile)
    try:
        while 1:
            asyncio.poller.loop()
            for proc in pm.getprocs():
                if proc.readable():
                    print proc.read(4096)
    except KeyboardInterrupt:
        asyncio.poller.unregister_all()
        for proc in pm.getprocs():
            proc.kill()
            proc.wait()
        if os.path.exists(config.PIDFILE):
            os.unlink(config.PIDFILE)
예제 #3
0
def start_proc_manager(config, logfile):
    from pycopia import proctools
    from pycopia import scheduler
    from pycopia import asyncio

    pm = proctools.get_procmanager()
    libexec = config.get("LIBEXEC", "/usr/libexec/pycopia")

    for name, serverlist in config.VHOSTS.items():
        for servername in serverlist:
            print "Starting %s for %s." % (servername, name)
            p = pm.spawnpipe("%s/fcgi_server -n %s" % (libexec, servername), persistent=True, logfile=logfile)
            asyncio.poller.register(p)
            #scheduler.sleep(1.0) # give it time to init...
    if config.USEFRONTEND:
        lighttpd = proctools.which("lighttpd")
        if asyncio.poller:
            pm.spawnpipe("%s -D -f %s" % (lighttpd, LTCONFIG), persistent=True, logfile=logfile)
        else: # no servers, just run frontend alone
            pm.spawnpipe("%s -f %s" % (lighttpd, LTCONFIG))
    try:
        asyncio.poller.loop()
        print "No servers, exited loop."
    except KeyboardInterrupt:
        pass
    if asyncio.poller:
        asyncio.poller.unregister_all()
        for proc in pm.getprocs():
            proc.killwait()
    if os.path.exists(config.PIDFILE):
        os.unlink(config.PIDFILE)
예제 #4
0
파일: website.py 프로젝트: wildone/pycopia
def start_proc_manager(config, logfile):
    from pycopia import proctools
    from pycopia import scheduler
    from pycopia import asyncio

    pm = proctools.get_procmanager()
    libexec = config.get("LIBEXEC", "/usr/libexec/pycopia")

    for name, serverlist in config.VHOSTS.items():
        for servername in serverlist:
            print "Starting %s for %s." % (servername, name)
            p = pm.spawnpipe("%s/fcgi_server -n %s" % (libexec, servername),
                             persistent=True,
                             logfile=logfile)
            asyncio.poller.register(p)
            #scheduler.sleep(1.0) # give it time to init...
    if config.USEFRONTEND:
        lighttpd = proctools.which("lighttpd")
        if asyncio.poller:
            pm.spawnpipe("%s -D -f %s" % (lighttpd, LTCONFIG),
                         persistent=True,
                         logfile=logfile)
        else:  # no servers, just run frontend alone
            pm.spawnpipe("%s -f %s" % (lighttpd, LTCONFIG))
    try:
        asyncio.poller.loop()
        print "No servers, exited loop."
    except KeyboardInterrupt:
        pass
    if asyncio.poller:
        asyncio.poller.unregister_all()
        for proc in pm.getprocs():
            proc.killwait()
    if os.path.exists(config.PIDFILE):
        os.unlink(config.PIDFILE)
예제 #5
0
def check(config):
    "Check the lighttpd configuration."
    from pycopia import proctools
    pm = proctools.get_procmanager()
    lighttpd = proctools.which("lighttpd")
    proc = pm.spawnpipe("%s -p -f %s" % (lighttpd, LTCONFIG))
    out = proc.read()
    es = proc.wait()
    if es:
        print out
    else:
        print "Error: %s" % (es,)
예제 #6
0
파일: website.py 프로젝트: wildone/pycopia
def check(config):
    "Check the lighttpd configuration."
    from pycopia import proctools
    pm = proctools.get_procmanager()
    lighttpd = proctools.which("lighttpd")
    proc = pm.spawnpipe("%s -p -f %s" % (lighttpd, LTCONFIG))
    out = proc.read()
    es = proc.wait()
    if es:
        print out
    else:
        print "Error: %s" % (es, )
예제 #7
0
파일: sudo.py 프로젝트: tijmengit/pycopia
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Run things as root (or another user) via sudo.
"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from pycopia import proctools
from pycopia.aid import IF

SUDO = proctools.which("sudo")


def sudo(command, user=None, password=None, extraopts=None, logfile=None):
    opts = "-S %s" % ("-u %s" % user if user else "")
    cmd = "%s %s %s %s" % (SUDO, opts, extraopts or "", command)
    proc = proctools.spawnpipe(cmd, logfile=logfile, merge=0)
    if password:
        proc.readerr(9)  # discard password prompt
        proc.write("%s\r" % (password, ))
        proc.readerr(1)  # discard newline
    return proc


def sudo_reset():
    proc = proctools.spawnpipe("%s -k" % (SUDO, ), merge=0)
예제 #8
0
#
#    This library 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
#    Lesser General Public License for more details.

"""
Wrapper for the 'rsync' program. See the rsync manpage for more details.

"""


from pycopia import proctools

try:
    RSYNC = proctools.which("rsync")
except ValueError:
    raise ImportError, "rsync program not found!"

TESTED_VERSIONS = ["rsync  version 2.5.5  protocol version 26"]

def rsync(src, dst, password=None, extraopts=None, logfile=None):
    """rsync(src, dst, [password, [extraopts, [logfile]]])

Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
  or   rsync [OPTION]... [USER@]HOST:SRC DEST
  or   rsync [OPTION]... SRC [SRC]... DEST
  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
예제 #9
0
import os
import zipfile
import struct
import stat
from cStringIO import StringIO

from pycopia import proctools
from pycopia import scheduler
from pycopia import socket
from pycopia import dictlib
from pycopia import timelib
from pycopia import aid

# Will raise an exception if not found.
try:
    ADB = proctools.which("adb")
except proctools.NotFoundError, err:
    raise ImportError, err


class Error(Exception):
    pass


class AdbError(Error):
    pass


class AdbQuit(Error):
    """Signals that the device connection must quit."""
예제 #10
0
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Use wxcut and wxpaste to get and set the X selection.

"""

from pycopia import proctools

try:
    WXCOPY = proctools.which("wxcopy")
    WXPASTE = proctools.which("wxpaste")
except ValueError:
    raise ImportError, "wxcopy or wxpaste program not found! Install WindowMaker for these."

WXCOPY_OPTIONS = '-clearselection'
WXPASTE_OPTIONS = ''


def wxcopy(text, callback=None, logfile=None, extraoptions="", async=False):
    pm = proctools.get_procmanager()
    command = "%s %s %s" % (WXCOPY, WXCOPY_OPTIONS, extraoptions)
    copy = pm.spawnpipe(command, logfile=logfile, async=async)
    copy.write(text)
    copy.close()
    return copy.wait()
예제 #11
0
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.
"""
Start and control an alsaplayer deamon instance.
"""

from pycopia import proctools
import os

try:
    PLAYER = proctools.which("alsaplayer")
except ValueError:
    raise ImportError, "alsaplayer program not found!"

DEVICE = os.environ.get("ALSAPLAYERDEVICE", "default")


def get_alsaplayer(session=0,
                   name="alsaplayer",
                   device=DEVICE,
                   extraopts="",
                   logfile=None):
    """Return a process object for the alsaplayer."""
    opts = "-i daemon -q -n %s -s '%s' -d %s --nosave" % (session, name,
                                                          device)
    CMD = "%s %s %s" % (PLAYER, opts, extraopts)
예제 #12
0
파일: CA.py 프로젝트: wildone/pycopia
configuration file and environment variables. But it's still limited and tedious.

The pyOpenSSL based modules are better. Use those if you can.
"""

from __future__ import absolute_import
from __future__ import print_function
#from __future__ import unicode_literals
from __future__ import division

import os
import errno
from pycopia import environ
from pycopia import proctools

OPENSSL = proctools.which("openssl")

SSL_CONFIG = "/etc/pycopia/ssl/openssl.cnf"

# CA config, matches what's in the config file.
CA_DIR = "/etc/pycopia/ssl/CA"
CAKEY = "cakey.pem"
CAREQ = "careq.pem"
CACERT = "cacert.pem"
CADAYS = 1095


class Error(Exception):
    pass

예제 #13
0
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.
"""
Use wxcut and wxpaste to get and set the X selection.

"""

from pycopia import proctools

WXCOPY = proctools.which("wxcopy")
WXPASTE = proctools.which("wxpaste")

WXCOPY_OPTIONS = '-clearselection'
WXPASTE_OPTIONS = ''


def wxcopy(text, callback=None, logfile=None, extraoptions="", async=False):
    pm = proctools.get_procmanager()
    command = "%s %s %s" % (WXCOPY, WXCOPY_OPTIONS, extraoptions)
    copy = pm.spawnpipe(command, logfile=logfile, async=async)
    copy.write(text)
    copy.close()
    return copy.wait()

예제 #14
0
파일: sshlib.py 프로젝트: wildone/pycopia
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    Lesser General Public License for more details.
"""
Wrapper for the ssh program.

Provides get_ssh, ssh_command, and scp functions.

"""

import sys, os

from pycopia import proctools
from pycopia import expect

SSH = proctools.which("ssh")
SCP = proctools.which("scp")
KEYGEN = proctools.which("ssh-keygen")
KEYSCAN = proctools.which("ssh-keyscan")


class SSHRetry(RuntimeError):
    pass


#                  |01234567890123456789
TESTED_VERSIONS = [
    "OpenSSH_3.4p1, SSH protocols 1.5/2.0, OpenSSL 0x0090605f",
    "OpenSSH_3.5p1, SSH protocols 1.5/2.0, OpenSSL 0x0090701f",
    "OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f",
    "OpenSSH_3.8.1p1, OpenSSL 0.9.7d 17 Mar 2004",
예제 #15
0
파일: netcat.py 프로젝트: xiangke/pycopia
#
#    This library 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
#    Lesser General Public License for more details.

"""
Wrapper for the netcat program. Allows TCP port forwarding to stdio. If your
netcat (nc) is suid to root, you can forward privileged ports, such as SMTP.

"""

import sys
from pycopia import proctools

NETCAT = proctools.which("nc")

TESTED_VERSIONS = ["[v1.10]"]


def get_netcat(host, port, callback=None, logfile=None, extraoptions=""):
    """get_netcat(host, port, [prompt], [callback], [logfile], [extraoptions])
Returns a Netcat object (an Expect subclass) attached to a netcat client.

The logfile parameter should be a file-like object (has a 'write' method).
"""
    cmd = "%s %s %s %s" %(NETCAT, extraoptions, host, port)
    pm = proctools.get_procmanager()
    proc = pm.spawnpipe(cmd, callback=callback, logfile=logfile, merge=0)
    return proc
예제 #16
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Wrapper for the netcat program. Allows TCP port forwarding to stdio. If your
netcat (nc) is suid to root, you can forward privileged ports, such as SMTP.

"""

import sys
from pycopia import proctools

try:
    NETCAT = proctools.which("nc")
except proctools.NotFoundError:
    NETCAT = proctools.which("netcat")

TESTED_VERSIONS = ["[v1.10]"]


def get_netcat(host, port, callback=None, logfile=None, extraoptions=""):
    """get_netcat(host, port, [prompt], [callback], [logfile], [extraoptions])
Returns a Netcat object (an Expect subclass) attached to a netcat client.

The logfile parameter should be a file-like object (has a 'write' method).
"""
    cmd = "%s %s %s %s" %(NETCAT, extraoptions, host, port)
    pm = proctools.get_procmanager()
    proc = pm.spawnpipe(cmd, callback=callback, logfile=logfile, merge=0)
예제 #17
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Wrapper for the 'rsync' program. See the rsync manpage for more details.

"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

from pycopia import proctools

RSYNC = proctools.which("rsync")

TESTED_VERSIONS = ["rsync  version 2.5.5  protocol version 26"]

def rsync(src, dst, password=None, extraopts=None, logfile=None):
    """rsync(src, dst, [password, [extraopts, [logfile]]])

Usage: rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
  or   rsync [OPTION]... [USER@]HOST:SRC DEST
  or   rsync [OPTION]... SRC [SRC]... DEST
  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]

You might want to set the RSYNC_RSH environment variable first.
    """
예제 #18
0
파일: sshlib.py 프로젝트: ktosiu/pycopia
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Wrapper for the ssh program.

Provides get_ssh, ssh_command, and scp functions.
"""

import sys, os

from pycopia import proctools
from pycopia import expect

SSH = proctools.which("ssh")
SCP = proctools.which("scp")
KEYGEN = proctools.which("ssh-keygen")
KEYSCAN = proctools.which("ssh-keyscan")

class SSHRetry(RuntimeError):
    pass

#                  |01234567890123456789
TESTED_VERSIONS = ["OpenSSH_3.4p1, SSH protocols 1.5/2.0, OpenSSL 0x0090605f",
                   "OpenSSH_3.5p1, SSH protocols 1.5/2.0, OpenSSL 0x0090701f",
                   "OpenSSH_3.6.1p2, SSH protocols 1.5/2.0, OpenSSL 0x0090701f",
                   "OpenSSH_3.8.1p1, OpenSSL 0.9.7d 17 Mar 2004",
                   "OpenSSH_4.5p1, OpenSSL 0.9.8a 11 Oct 2005",
                   "OpenSSH_4.3p2"
                   ]
예제 #19
0
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.
"""
Wrapper for the netcat program. Allows TCP port forwarding to stdio. If your
netcat (nc) is suid to root, you can forward privileged ports, such as SMTP.

"""

import sys
from pycopia import proctools

NETCAT = proctools.which("nc")

TESTED_VERSIONS = ["[v1.10]"]


def get_netcat(host, port, callback=None, logfile=None, extraoptions=""):
    """get_netcat(host, port, [prompt], [callback], [logfile], [extraoptions])
Returns a Netcat object (an Expect subclass) attached to a netcat client.

The logfile parameter should be a file-like object (has a 'write' method).
"""
    cmd = "%s %s %s %s" % (NETCAT, extraoptions, host, port)
    pm = proctools.get_procmanager()
    proc = pm.spawnpipe(cmd, callback=callback, logfile=logfile, merge=0)
    return proc
예제 #20
0
파일: sudo.py 프로젝트: xiangke/pycopia
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Run things as root (or another user) via sudo.

"""
from pycopia import proctools
from pycopia.aid import IF

try:
    SUDO = proctools.which("sudo")
except ValueError:
    raise ImportError, "'sudo' program not found in PATH"

def sudo(command, user=None, password=None, extraopts=None, logfile=None):
    opts = "-S %s" % (IF(user, "-u %s" % (user,), ""),)
    cmd = "%s %s %s %s" % (SUDO, opts, extraopts or "", command)
    proc = proctools.spawnpipe(cmd, logfile=logfile, merge=0)
    if password:
        proc.readerr(9) # discard password prompt
        proc.write("%s\r" % (password,))
        proc.readerr(1) # discard newline
    return proc

def sudo_reset():
    proc = proctools.spawnpipe("%s -k" % (SUDO,), merge=0)
예제 #21
0
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Use nsupdate to update a DNS server (running Bind version 9.x).

"""

import sys, os
from pycopia import proctools

NSUPDATE = proctools.which("nsupdate")

class _DNSUpdate(proctools.ProcessPipe):
    def __init__(self, cmd, logfile=None,  env=None, callback=None, merge=0, async=False):
        proctools.ProcessPipe.__init__(self, cmd, logfile,  env, callback, merge, async)
        self._zone=None
        self._dnsclass = "IN" # default class
        self._ttl = 86400 # default ttl

    def close(self):
        self.write(chr(4)) # ^D
        super(_DNSUpdate, self).close()

    def _readerr_fill(self):
        try:
            c = self._readerr(1024)
예제 #22
0
파일: CA.py 프로젝트: bharathi26/pycopia
configuration file and environment variables. But it's still limited and tedious.

The pyOpenSSL based modules are better. Use those if you can.
"""

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division


import os
import errno
from pycopia import environ
from pycopia import proctools

OPENSSL = proctools.which("openssl")

SSL_CONFIG="/etc/pycopia/ssl/openssl.cnf"

# CA config, matches what's in the config file.
CA_DIR = "/etc/pycopia/ssl/CA"
CAKEY = "cakey.pem"
CAREQ = "careq.pem"
CACERT = "cacert.pem"
CADAYS = 1095


class Error(Exception):
    pass

class SSLExecError(Error):
예제 #23
0
파일: netcat.py 프로젝트: wildone/pycopia
#    This library 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
#    Lesser General Public License for more details.

"""
Wrapper for the netcat program. Allows TCP port forwarding to stdio. If your
netcat (nc) is suid to root, you can forward privileged ports, such as SMTP.

"""

import sys
from pycopia import proctools

try:
    NETCAT = proctools.which("nc")
except proctools.NotFoundError:
    NETCAT = proctools.which("netcat")

TESTED_VERSIONS = ["[v1.10]"]


def get_netcat(host, port, callback=None, logfile=None, extraoptions=""):
    """get_netcat(host, port, [prompt], [callback], [logfile], [extraoptions])
Returns a Netcat object (an Expect subclass) attached to a netcat client.

The logfile parameter should be a file-like object (has a 'write' method).
"""
    cmd = "%s %s %s %s" %(NETCAT, extraoptions, host, port)
    pm = proctools.get_procmanager()
    proc = pm.spawnpipe(cmd, callback=callback, logfile=logfile, merge=0)
예제 #24
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Simple Python wrapper for the 'redir' program.
Note that to use this to redirect privileged TCP ports as a regular user you
must make your 'redir' program suid to root. This is a bad security practice,
but is necessary for some scenarios. just be aware.

"""

from pycopia import proctools

try:
    REDIR = proctools.which("redir")
except ValueError:
    raise ImportError, "'redir' program not found in PATH"

def redir(lport, cport, laddr=None, caddr=None, extraopts=None):
    """redir(lport, cport, laddr=None, caddr=None, extraopts=None)
Redirect local port to client port, possible to another host is caddr is given.
Optionally bind to a specific IP if laddr is also given.
    """
    opts = "--lport=%d --cport=%d" % (lport, cport)
    if laddr:
        opts += " --laddr=%s" % (laddr,)
    if caddr:
        opts += " --caddr=%s" % (caddr,)
    cmd = "%s %s %s" % (REDIR, opts, extraopts or "")
    proc = proctools.spawnpipe(cmd, merge=0)
예제 #25
0
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Start and control an alsaplayer deamon instance.
"""

from pycopia import proctools
import os

try:
    PLAYER = proctools.which("alsaplayer")
except ValueError:
    raise ImportError, "alsaplayer program not found!"

DEVICE = os.environ.get("ALSAPLAYERDEVICE", "default")

def get_alsaplayer(session=0, name="alsaplayer", device=DEVICE, extraopts="", logfile=None):
    """Return a process object for the alsaplayer."""
    opts = "-i daemon -q -n %s -s '%s' -d %s --nosave" % (session, name, device)
    CMD = "%s %s %s" % (PLAYER, opts, extraopts)
    aplayer = proctools.spawnpipe(CMD, logfile=logfile)
    return aplayer