Esempio n. 1
0
    def spawn(self, conf_file, once=False, wait=True, daemon=True, **kwargs):
        """Launch a subprocess for this server.

        :param conf_file: path to conf_file to use as first arg
        :param once: boolean, add once argument to command
        :param wait: boolean, if true capture stdout with a pipe
        :param daemon: boolean, if true ask server to log to console

        :returns : the pid of the spawned process
        """
        args = [self.cmd, conf_file]
        if once:
            args.append('once')
        if not daemon:
            # ask the server to log to console
            args.append('verbose')

        # figure out what we're going to do with stdio
        if not daemon:
            # do nothing, this process is open until the spawns close anyway
            re_out = None
            re_err = None
        else:
            re_err = subprocess.STDOUT
            if wait:
                # we're going to need to block on this...
                re_out = subprocess.PIPE
            else:
                re_out = open(os.devnull, 'w+b')
        proc = subprocess.Popen(args, stdout=re_out, stderr=re_err)
        pid_file = self.get_pid_file_name(conf_file)
        write_file(pid_file, proc.pid)
        self.procs.append(proc)
        return proc.pid
Esempio n. 2
0
    def spawn(self, conf_file, once=False, wait=True, daemon=True, **kwargs):
        """Launch a subprocess for this server.

        :param conf_file: path to conf_file to use as first arg
        :param once: boolean, add once argument to command
        :param wait: boolean, if true capture stdout with a pipe
        :param daemon: boolean, if true ask server to log to console

        :returns : the pid of the spawned process
        """
        args = [self.cmd, conf_file]
        if once:
            args.append("once")
        if not daemon:
            # ask the server to log to console
            args.append("verbose")

        # figure out what we're going to do with stdio
        if not daemon:
            # do nothing, this process is open until the spawns close anyway
            re_out = None
            re_err = None
        else:
            re_err = subprocess.STDOUT
            if wait:
                # we're going to need to block on this...
                re_out = subprocess.PIPE
            else:
                re_out = open(os.devnull, "w+b")
        proc = subprocess.Popen(args, stdout=re_out, stderr=re_err)
        pid_file = self.get_pid_file_name(conf_file)
        write_file(pid_file, proc.pid)
        self.procs.append(proc)
        return proc.pid
Esempio n. 3
0
 def test_write_file(self):
     with temptree([]) as t:
         file_name = os.path.join(t, 'test')
         utils.write_file(file_name, 'test')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test')
         # and also subdirs
         file_name = os.path.join(t, 'subdir/test2')
         utils.write_file(file_name, 'test2')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test2')
         # but can't over-write files
         file_name = os.path.join(t, 'subdir/test2/test3')
         self.assertRaises(IOError, utils.write_file, file_name, 'test3')
Esempio n. 4
0
 def test_write_file(self):
     with temptree([]) as t:
         file_name = os.path.join(t, 'test')
         utils.write_file(file_name, 'test')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test')
         # and also subdirs
         file_name = os.path.join(t, 'subdir/test2')
         utils.write_file(file_name, 'test2')
         with open(file_name, 'r') as f:
             contents = f.read()
         self.assertEquals(contents, 'test2')
         # but can't over-write files
         file_name = os.path.join(t, 'subdir/test2/test3')
         self.assertRaises(IOError, utils.write_file, file_name,
                           'test3')