def logerror(fmt, *args): if (not defined("_WIN32") or defined("__CYGWIN__")) and dosyslog: ap = va_list() va_start(ap, fmt) vsyslog(LOG_ERR, fmt, ap) va_end(ap) else: print(fmt.format(*args), file=sys.stderr, end="")
def _cleanup_test_output(ctx: test_ctx): if not defined("DISABLE_STDOUT_REDIRECTION"): if not ctx.verbose: if ctx.old_stdout != INVALID_FD: try: os.dup2(ctx.old_stdout, STDOUT_FILENO) except OSError: pass ctx.old_stdout = INVALID_FD if ctx.old_stderr != INVALID_FD: try: os.dup2(ctx.old_stderr, STDERR_FILENO) except OSError: pass ctx.old_stderr = INVALID_FD if ctx.null_fd != INVALID_FD: try: os.close(ctx.null_fd) except OSError: pass ctx.null_fd = INVALID_FD if ctx.output_file != sys.__stdout__: try: ctx.output_file.close() except OSError: pass ctx.output_file = sys.__stdout__
def _setup_test_output(ctx): # Setup test output handles # \return zero on success, non-zero on failure if not defined("DISABLE_STDOUT_REDIRECTION"): # Stop output to stdout and stderr from being displayed # if using non-verbose output if not ctx.verbose: # Keep a copy of STDOUT and STDERR try: ctx.old_stdout = os.dup(STDOUT_FILENO) except OSError as exc: ctx.old_stdout = INVALID_FD print("Failed to duplicate stdout handle: {:d}".format( exc.errno)) return 1 try: ctx.old_stderr = os.dup(STDERR_FILENO) except OSError as exc: ctx.old_stderr = INVALID_FD _cleanup_test_output(ctx) print("Failed to duplicate stderr handle: {:d}".format( exc.errno)) return 1 # Redirect STDOUT_FILENO and STDERR_FILENO to /dev/null or "nul" try: ctx.null_fd = os.open(os.devnull, os.O_WRONLY) except OSError as exc: ctx.null_fd = INVALID_FD _cleanup_test_output(ctx) print("Failed to open null handle: {:d}".format(exc.errno)) return 1 try: os.dup2(ctx.null_fd, STDOUT_FILENO) os.dup2(ctx.null_fd, STDERR_FILENO) except OSError: _cleanup_test_output(ctx) return 1 try: ctx.output_file = os.fdopen(ctx.old_stdout, "w") except OSError as exc: ctx.output_file = sys.__stdout__ _cleanup_test_output(ctx) print("Failed to open FILE for output handle: {:d}".format( exc.errno)) return 1 #endif return 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. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import sys import os from libusb._platform import is_windows, defined if is_windows and defined("_WIN32_WCE"): # No support for selective redirection of STDOUT on WinCE. DISABLE_STDOUT_REDIRECTION = True else: STDOUT_FILENO = sys.__stdout__.fileno() STDERR_FILENO = sys.__stderr__.fileno() INVALID_FD = -1 class test_result: """Values returned from a test function to indicate test result""" # Indicates that the test ran successfully. TEST_STATUS_SUCCESS = 0 # Indicates that the test failed one or more test. TEST_STATUS_FAILURE = 1
# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA import sys import os import getopt import ctypes as ct import libusb as usb from libusb._platform import defined from ezusb import FX_KNOWN_DEVICES, FX_TYPE_MAX, FX_TYPE_NAMES, IMG_TYPE_NAMES, FX_TYPE_UNDEFINED from ezusb import ezusb_load_ram from ezusb import verbose if not defined("_WIN32") or defined("__CYGWIN__"): #include <syslog.h> dosyslog = False # bool if not defined("FXLOAD_VERSION"): FXLOAD_VERSION = " (libusb)" # __DATE__ + " (libusb)" def logerror(fmt, *args): if (not defined("_WIN32") or defined("__CYGWIN__")) and dosyslog: ap = va_list() va_start(ap, fmt) vsyslog(LOG_ERR, fmt, ap) va_end(ap) else: