(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
errors_as_exceptions=False, *k, **kw)
| 859 | |
| 860 | |
| 861 | def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False, |
| 862 | errors_as_exceptions=False, *k, **kw): |
| 863 | |
| 864 | cmd = p4_build_cmd(["-G"] + cmd) |
| 865 | if verbose: |
| 866 | sys.stderr.write("Opening pipe: {}\n".format(' '.join(cmd))) |
| 867 | |
| 868 | # Use a temporary file to avoid deadlocks without |
| 869 | # subprocess.communicate(), which would put another copy |
| 870 | # of stdout into memory. |
| 871 | stdin_file = None |
| 872 | if stdin is not None: |
| 873 | stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode) |
| 874 | if not isinstance(stdin, list): |
| 875 | stdin_file.write(stdin) |
| 876 | else: |
| 877 | for i in stdin: |
| 878 | stdin_file.write(encode_text_stream(i)) |
| 879 | stdin_file.write(b'\n') |
| 880 | stdin_file.flush() |
| 881 | stdin_file.seek(0) |
| 882 | |
| 883 | p4 = subprocess.Popen( |
| 884 | cmd, stdin=stdin_file, stdout=subprocess.PIPE, *k, **kw) |
| 885 | |
| 886 | result = [] |
| 887 | try: |
| 888 | while True: |
| 889 | entry = marshal.load(p4.stdout) |
| 890 | |
| 891 | if bytes is not str: |
| 892 | # Decode unmarshalled dict to use str keys and values. Special cases are handled below. |
| 893 | decoded_entry = {} |
| 894 | for key, value in entry.items(): |
| 895 | key = key.decode() |
| 896 | if isinstance(value, bytes) and p4KeyWhichCanBeDirectlyDecoded(key): |
| 897 | value = value.decode() |
| 898 | decoded_entry[key] = value |
| 899 | # Parse out data if it's an error response |
| 900 | if decoded_entry.get('code') == 'error' and 'data' in decoded_entry: |
| 901 | decoded_entry['data'] = decoded_entry['data'].decode() |
| 902 | entry = decoded_entry |
| 903 | if skip_info: |
| 904 | if 'code' in entry and entry['code'] == 'info': |
| 905 | continue |
| 906 | for key in p4KeysContainingNonUtf8Chars(): |
| 907 | if key in entry: |
| 908 | entry[key] = metadata_stream_to_writable_bytes(entry[key]) |
| 909 | if cb is not None: |
| 910 | cb(entry) |
| 911 | else: |
| 912 | result.append(entry) |
| 913 | except EOFError: |
| 914 | pass |
| 915 | exitCode = p4.wait() |
| 916 | if exitCode != 0: |
| 917 | if errors_as_exceptions: |
| 918 | if len(result) > 0: |
no test coverage detected