def _print_style_issues(): base_path = os.path.sep.join(__file__.split(os.path.sep)[:-1]).lstrip("./") style_issues = test.static_checks.get_issues( os.path.join(base_path, "stem")) style_issues.update( test.static_checks.get_issues(os.path.join(base_path, "test"))) style_issues.update( test.static_checks.get_issues(os.path.join(base_path, "run_tests.py"))) # If we're doing some sort of testing (unit or integ) and pyflakes is # available then use it. Its static checks are pretty quick so there's not # much overhead in including it with all tests. if CONFIG["argument.unit"] or CONFIG["argument.integ"]: if system.is_available("pyflakes"): style_issues.update( test.static_checks.pyflakes_issues( os.path.join(base_path, "stem"))) style_issues.update( test.static_checks.pyflakes_issues( os.path.join(base_path, "test"))) style_issues.update( test.static_checks.pyflakes_issues( os.path.join(base_path, "run_tests.py"))) else: test.output.print_line( "Static error checking requires pyflakes. Please install it from ...\n http://pypi.python.org/pypi/pyflakes\n", *ERROR_ATTR) if CONFIG["argument.style"]: if system.is_available("pep8"): style_issues.update( test.static_checks.pep8_issues(os.path.join(base_path, "stem"))) style_issues.update( test.static_checks.pep8_issues(os.path.join(base_path, "test"))) style_issues.update( test.static_checks.pep8_issues( os.path.join(base_path, "run_tests.py"))) else: test.output.print_line( "Style checks require pep8. Please install it from...\n http://pypi.python.org/pypi/pep8\n", *ERROR_ATTR) if style_issues: test.output.print_line("STYLE ISSUES", term.Color.BLUE, term.Attr.BOLD) for file_path in style_issues: test.output.print_line("* %s" % file_path, term.Color.BLUE, term.Attr.BOLD) for line_number, msg in style_issues[file_path]: line_count = "%-4s" % line_number test.output.print_line(" line %s - %s" % (line_count, msg)) print
def is_wide_characters_supported(): """ Checks if our version of curses has wide character support. This is required to print unicode. :returns: **bool** that's **True** if curses supports wide characters, and **False** if it either can't or this can't be determined """ try: # Gets the dynamic library used by the interpretor for curses. This uses # 'ldd' on Linux or 'otool -L' on OSX. # # atagar@fenrir:~/Desktop$ ldd /usr/lib/python2.6/lib-dynload/_curses.so # linux-gate.so.1 => (0x00a51000) # libncursesw.so.5 => /lib/libncursesw.so.5 (0x00faa000) # libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x002f1000) # libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00158000) # libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00398000) # /lib/ld-linux.so.2 (0x00ca8000) # # atagar$ otool -L /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_curses.so # /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_curses.so: # /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0) # /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) # /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.6) import _curses lib_dependency_lines = None if system.is_available('ldd'): lib_dependency_lines = system.call('ldd %s' % _curses.__file__) elif system.is_available('otool'): lib_dependency_lines = system.call('otool -L %s' % _curses.__file__) if lib_dependency_lines: for line in lib_dependency_lines: if 'libncursesw' in line: return True except: pass return False
def _isWideCharactersAvailable(): """ True if curses has wide character support (which is required to print unicode). False otherwise. """ try: # gets the dynamic library used by the interpretor for curses import _curses cursesLib = _curses.__file__ # Uses 'ldd' (Linux) or 'otool -L' (Mac) to determine the curses # library dependencies. # # atagar@fenrir:~/Desktop$ ldd /usr/lib/python2.6/lib-dynload/_curses.so # linux-gate.so.1 => (0x00a51000) # libncursesw.so.5 => /lib/libncursesw.so.5 (0x00faa000) # libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x002f1000) # libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00158000) # libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00398000) # /lib/ld-linux.so.2 (0x00ca8000) # # atagar$ otool -L /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_curses.so # /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload/_curses.so: # /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0) # /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) # /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.6) libDependencyLines = None if system.is_available("ldd"): libDependencyLines = system.call("ldd %s" % cursesLib) elif system.is_available("otool"): libDependencyLines = system.call("otool -L %s" % cursesLib) if libDependencyLines: for line in libDependencyLines: if "libncursesw" in line: return True except: pass return False
def __init__(self, processName, processPid = "", resolveRate = None, handle = None): """ Initializes a new resolver daemon. When no longer needed it's suggested that this is stopped. Arguments: processName - name of the process being resolved processPid - pid of the process being resolved resolveRate - time between resolving connections (in seconds, None if chosen dynamically) handle - name used to query this resolver, this is the processName if undefined """ threading.Thread.__init__(self) self.setDaemon(True) self.processName = processName self.processPid = processPid self.resolveRate = resolveRate self.handle = handle if handle else processName self.defaultRate = CONFIG["queries.connections.minRate"] self.lastLookup = -1 self.overwriteResolver = None self.defaultResolver = Resolver.PROC osType = os.uname()[0] self.resolverOptions = getSystemResolvers(osType) log.info("Operating System: %s, Connection Resolvers: %s" % (osType, ", ".join(self.resolverOptions))) # sets the default resolver to be the first found in the system's PATH # (left as netstat if none are found) for resolver in self.resolverOptions: # Resolver strings correspond to their command with the exception of bsd # resolvers. resolverCmd = resolver.replace(" (bsd)", "") if resolver == Resolver.PROC or system.is_available(resolverCmd): self.defaultResolver = resolver break self._connections = [] # connection cache (latest results) self._resolutionCounter = 0 # number of successful connection resolutions self._isPaused = False self._halt = False # terminates thread if true self._cond = threading.Condition() # used for pausing the thread self._subsiquentFailures = 0 # number of failed resolutions with the default in a row self._resolverBlacklist = [] # resolvers that have failed to resolve # Number of sequential times the threshold rate's been too low. This is to # avoid having stray spikes up the rate. self._rateThresholdBroken = 0
def _print_style_issues(): base_path = os.path.sep.join(__file__.split(os.path.sep)[:-1]).lstrip("./") style_issues = test.static_checks.get_issues(os.path.join(base_path, "stem")) style_issues.update(test.static_checks.get_issues(os.path.join(base_path, "test"))) style_issues.update(test.static_checks.get_issues(os.path.join(base_path, "run_tests.py"))) # If we're doing some sort of testing (unit or integ) and pyflakes is # available then use it. Its static checks are pretty quick so there's not # much overhead in including it with all tests. if CONFIG["argument.unit"] or CONFIG["argument.integ"]: if system.is_available("pyflakes"): style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "stem"))) style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "test"))) style_issues.update(test.static_checks.pyflakes_issues(os.path.join(base_path, "run_tests.py"))) else: test.output.print_line("Static error checking requires pyflakes. Please install it from ...\n http://pypi.python.org/pypi/pyflakes\n", *ERROR_ATTR) if CONFIG["argument.style"]: if system.is_available("pep8"): style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "stem"))) style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "test"))) style_issues.update(test.static_checks.pep8_issues(os.path.join(base_path, "run_tests.py"))) else: test.output.print_line("Style checks require pep8. Please install it from...\n http://pypi.python.org/pypi/pep8\n", *ERROR_ATTR) if style_issues: test.output.print_line("STYLE ISSUES", term.Color.BLUE, term.Attr.BOLD) for file_path in style_issues: test.output.print_line("* %s" % file_path, term.Color.BLUE, term.Attr.BOLD) for line_number, msg in style_issues[file_path]: line_count = "%-4s" % line_number test.output.print_line(" line %s - %s" % (line_count, msg)) print
# count how many tests have been skipped. skipped_test_count = 0 # loads and validates our various configurations test_config = stem.util.conf.get_config("test") settings_path = os.path.join(test.runner.STEM_BASE, "test", "settings.cfg") test_config.load(settings_path) load_user_configuration(test_config) # check that we have 2to3 and python3 available in our PATH if CONFIG["argument.python3"]: for required_cmd in ("2to3", "python3"): if not system.is_available(required_cmd): test.output.print_line("Unable to test python 3 because %s isn't in your path" % required_cmd, *test.runner.ERROR_ATTR) sys.exit(1) if CONFIG["argument.python3"] and sys.version_info[0] != 3: python3_destination = os.path.join(CONFIG["integ.test_directory"], "python3") if _python3_setup(python3_destination): python3_runner = os.path.join(python3_destination, "run_tests.py") exit_status = os.system("python3 %s %s" % (python3_runner, " ".join(sys.argv[1:]))) sys.exit(exit_status) else: sys.exit(1) # failed to do python3 setup if not CONFIG["argument.unit"] and not CONFIG["argument.integ"] and not CONFIG["argument.style"]: test.output.print_line("Nothing to run (for usage provide --help)\n")
print # TODO: note unused config options afterward? base_path = os.path.sep.join(__file__.split(os.path.sep)[:-1]).lstrip("./") style_issues = test.check_whitespace.get_issues(os.path.join(base_path, "stem")) style_issues.update(test.check_whitespace.get_issues(os.path.join(base_path, "test"))) style_issues.update(test.check_whitespace.get_issues(os.path.join(base_path, "run_tests.py"))) # If we're doing some sort of testing (unit or integ) and pyflakes is # available then use it. Its static checks are pretty quick so there's not # much overhead in including it with all tests. if CONFIG["argument.unit"] or CONFIG["argument.integ"]: if system.is_available("pyflakes"): style_issues.update(test.check_whitespace.pyflakes_issues(os.path.join(base_path, "stem"))) style_issues.update(test.check_whitespace.pyflakes_issues(os.path.join(base_path, "test"))) style_issues.update(test.check_whitespace.pyflakes_issues(os.path.join(base_path, "run_tests.py"))) else: test.output.print_line("Static error checking requires pyflakes. Please install it from ...\n http://pypi.python.org/pypi/pyflakes\n", *ERROR_ATTR) if CONFIG["argument.style"]: if system.is_available("pep8"): style_issues.update(test.check_whitespace.pep8_issues(os.path.join(base_path, "stem"))) style_issues.update(test.check_whitespace.pep8_issues(os.path.join(base_path, "test"))) style_issues.update(test.check_whitespace.pep8_issues(os.path.join(base_path, "run_tests.py"))) else: test.output.print_line("Style checks require pep8. Please install it from...\n http://pypi.python.org/pypi/pep8\n", *ERROR_ATTR) if style_issues: