~pygame/pygame/trunk

« back to all changes in this revision

Viewing changes to test/util/build_page/libs/build_client/callproc.py

  • Committer: pygame
  • Date: 2017-01-10 00:31:42 UTC
  • Revision ID: git-v1:2eea4f299a2e791f884608d7ed601558634af73c
commit 1639c41a8cb3433046882ede92c80ce69d59016b
Author: Thomas Kluyver <takowl@gmail.com>
Date:   Sun Jan 8 18:46:46 2017 +0000

    Build newer versions of libogg and libvorbis into Linux base images

    Closes #317
    Closes #323

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
################################################################################
 
2
 
 
3
# StdLib
 
4
import subprocess
 
5
import os
 
6
import sys
 
7
 
 
8
# User Libs
 
9
from helpers import ProgressIndicator
 
10
 
 
11
################################################################################
 
12
 
 
13
def get_cmd_str(cmd):
 
14
    if isinstance(cmd, str): 
 
15
        return cmd
 
16
    else:
 
17
        cmd = [c for c in cmd if c]
 
18
        if sys.platform == 'win32': cmd = subprocess.list2cmdline(cmd)
 
19
        else: cmd = ' '.join(cmd)
 
20
        return cmd
 
21
 
 
22
def log_cmd(cmd, dir):
 
23
    print "executing:", cmd, 'from dir', os.path.abspath(dir or os.getcwd())
 
24
 
 
25
################################################################################
 
26
 
 
27
def ExecuteAssertSuccess(cmd, *args, **keywords):
 
28
    retcode, output = GetReturnCodeAndOutput(cmd, *args, **keywords)
 
29
    if retcode != 0:
 
30
        cmd_line = get_cmd_str(cmd)
 
31
        raise Exception("calling: "+cmd_line+" failed with output:\n"+output)
 
32
    return retcode, output
 
33
 
 
34
################################################################################
 
35
 
 
36
def GetReturnCodeAndOutput(cmd, dir=None, env=None, bufsize=-1, lineprintdiv=1):
 
37
    cmd = get_cmd_str(cmd)
 
38
    log_cmd(cmd, dir)
 
39
    
 
40
    proc = subprocess.Popen (
 
41
        cmd, cwd = dir, env = env, shell = True, bufsize = bufsize, 
 
42
        stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
 
43
        universal_newlines = 1,
 
44
    )
 
45
 
 
46
    response = []
 
47
    progress = ProgressIndicator(lineprintdiv)
 
48
 
 
49
    while proc.poll() is None:
 
50
        response += [proc.stdout.readline()]
 
51
        if response[-1] is "": break
 
52
        progress()
 
53
 
 
54
    progress.finish()
 
55
    return proc.wait(), ''.join(response) + proc.stdout.read() # needed ubuntu
 
56
 
 
57
################################################################################
 
58
 
 
59
def InteractiveGetReturnCodeAndOutput(cmd, input_string, dir=None, 
 
60
                                               env=None, bufsize=-1):
 
61
    cmd = get_cmd_str(cmd)
 
62
    log_cmd(cmd, dir)
 
63
 
 
64
    proc = subprocess.Popen (
 
65
        cmd, cwd = dir, env = env, shell = True, bufsize = bufsize, 
 
66
        stdin = subprocess.PIPE,    stdout = subprocess.PIPE, 
 
67
        stderr = subprocess.STDOUT, universal_newlines = 1
 
68
    )
 
69
        
 
70
    print "---------------"
 
71
    response = proc.communicate(input_string)[0]
 
72
    return proc.wait(), response
 
73
 
 
74
################################################################################
 
 
b'\\ No newline at end of file'