Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
self.write_build_file("""
from pybuilder.core import task
@task
def spam (): pass
""")
reactor = self.prepare_reactor()
self.assertRaises(PyBuilderException, reactor.build)
def testForkWithException(self):
def test_func():
raise PyBuilderException("Test failure message")
try:
val = fork_process(Mock(), target=test_func)
val = fork_process(Mock(), target=test_func)
self.fail("should not have reached here, returned %s" % val)
except:
ex_type, ex, tb = sys.exc_info()
self.assertEquals(ex_type, PyBuilderException)
self.assertEquals(ex.message, "Test failure message")
self.assertTrue(tb)
"Project directory does not exist: %s", project_directory)
if not os.path.isdir(project_directory):
raise PyBuilderException(
"Project directory is not a directory: %s", project_directory)
project_descriptor_full_path = os.path.join(
project_directory, project_descriptor)
if not os.path.exists(project_descriptor_full_path):
raise PyBuilderException(
"Project directory does not contain descriptor file: %s",
project_descriptor_full_path)
if not os.path.isfile(project_descriptor_full_path):
raise PyBuilderException(
"Project descriptor is not a file: %s", project_descriptor_full_path)
return project_directory, project_descriptor_full_path
def description(self):
"""
Returns a human readable revision description as a string.
"""
if self.is_a_git_repo():
return self.get_git_description()
if self.is_a_svn_repo():
raise PyBuilderException(
"'description' is not implemented for svn repos")
raise PyBuilderException(
"Cannot determine VCS revision: project is neither a git nor a svn repo.")
reactor.prepare_build(property_overrides=options.property_overrides,
project_directory=options.project_directory,
exclude_optional_tasks=options.exclude_optional_tasks,
exclude_tasks=options.exclude_tasks,
exclude_all_optional=options.exclude_all_optional
)
if options.verbose or options.debug:
logger.debug("Verbose output enabled.\n")
reactor.project.set_property("verbose", True)
summary = reactor.build(
environments=options.environments, tasks=arguments)
except KeyboardInterrupt:
raise PyBuilderException("Build aborted")
except (Exception, SystemExit) as e:
successful = False
failure_message = str(e)
if options.debug:
traceback.print_exc(file=sys.stderr)
finally:
end = datetime.datetime.now()
if not options.very_quiet:
print_summary(
successful, summary, start, end, options, failure_message)
if not successful:
return 1
def verify_project_directory(project_directory, project_descriptor):
project_directory = os.path.abspath(project_directory)
if not os.path.exists(project_directory):
raise PyBuilderException(
"Project directory does not exist: %s", project_directory)
if not os.path.isdir(project_directory):
raise PyBuilderException(
"Project directory is not a directory: %s", project_directory)
project_descriptor_full_path = os.path.join(
project_directory, project_descriptor)
if not os.path.exists(project_descriptor_full_path):
raise PyBuilderException(
"Project directory does not contain descriptor file: %s",
project_descriptor_full_path)
if not os.path.isfile(project_descriptor_full_path):
raise PyBuilderException(
"Project descriptor is not a file: %s", project_descriptor_full_path)
return project_directory, project_descriptor_full_path
def verify_project_directory(project_directory, project_descriptor):
project_directory = os.path.abspath(project_directory)
if not os.path.exists(project_directory):
raise PyBuilderException(
"Project directory does not exist: %s", project_directory)
if not os.path.isdir(project_directory):
raise PyBuilderException(
"Project directory is not a directory: %s", project_directory)
project_descriptor_full_path = os.path.join(
project_directory, project_descriptor)
if not os.path.exists(project_descriptor_full_path):
raise PyBuilderException(
"Project directory does not contain descriptor file: %s",
project_descriptor_full_path)
if not os.path.isfile(project_descriptor_full_path):
raise PyBuilderException(
from pybuilder import __version__
from pybuilder.core import Logger
from pybuilder.errors import PyBuilderException
from pybuilder.execution import ExecutionManager
from pybuilder.reactor import Reactor
from pybuilder.scaffolding import start_project, update_project
from pybuilder.terminal import (BOLD, BROWN, RED, GREEN, bold, styled_text,
fg, italic, print_text, print_text_line,
print_error, print_error_line, draw_line)
from pybuilder.utils import format_timestamp, get_dist_version_string
PROPERTY_OVERRIDE_PATTERN = re.compile(r'^[a-zA-Z0-9_]+=.*')
class CommandLineUsageException(PyBuilderException):
def __init__(self, usage, message):
super(CommandLineUsageException, self).__init__(message)
self.usage = usage
class StdOutLogger(Logger):
def _level_to_string(self, level):
if Logger.DEBUG == level:
return "[DEBUG]"
if Logger.INFO == level:
return "[INFO] "
if Logger.WARN == level:
return "[WARN] "
return "[ERROR]"
def _do_log(self, level, message, *arguments):
def get_git_revision_count(self):
# NOTE: git rev-list HEAD --count does not work on RHEL6, hence we count ourselves.
exit_code, stdout, stderr = execute_command_and_capture_output(
"git", "rev-list", "HEAD")
if exit_code != 0:
raise PyBuilderException("Cannot determine git revision: git rev-list HEAD failed:\n{0}".
format(stderr))
return str(len(stdout.splitlines()))