Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up errors when yaml is invalid #109

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 32 additions & 30 deletions moban/main.py
Expand Up @@ -22,36 +22,38 @@


def main():
"""
program entry point
"""
parser = create_parser()
options = vars(parser.parse_args())
HASH_STORE.IGNORE_CACHE_FILE = options[constants.LABEL_FORCE]
moban_file = options[constants.LABEL_MOBANFILE]
if moban_file is None:
moban_file = mobanfile.find_default_moban_file()
if moban_file:
try:
count = handle_moban_file(moban_file, options)
if count:
sys.exit(count)
except (
exceptions.DirectoryNotFound,
exceptions.NoThirdPartyEngine,
exceptions.MobanfileGrammarException,
) as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)
else:
try:
count = handle_command_line(options)
if count:
sys.exit(count)
except exceptions.NoTemplate as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)

try:
"""
program entry point
"""
parser = create_parser()
options = vars(parser.parse_args())
HASH_STORE.IGNORE_CACHE_FILE = options[constants.LABEL_FORCE]
moban_file = options[constants.LABEL_MOBANFILE]
if moban_file is None:
moban_file = mobanfile.find_default_moban_file()
if moban_file:
try:
count = handle_moban_file(moban_file, options)
if count:
sys.exit(count)
except (
exceptions.DirectoryNotFound,
exceptions.NoThirdPartyEngine,
exceptions.MobanfileGrammarException,
) as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)
else:
try:
count = handle_command_line(options)
if count:
sys.exit(count)
except exceptions.NoTemplate as e:
reporter.report_error_message(str(e))
sys.exit(constants.ERROR)
except Exception as e:
print(e)

def create_parser():
"""
Expand Down
76 changes: 39 additions & 37 deletions moban/mobanfile.py
Expand Up @@ -23,45 +23,47 @@ def find_default_moban_file():


def handle_moban_file_v1(moban_file_configurations, command_line_options):
merged_options = None
target = extract_target(command_line_options)
if constants.LABEL_CONFIG in moban_file_configurations:
merged_options = merge(
command_line_options,
moban_file_configurations[constants.LABEL_CONFIG],
)
merged_options = merge(command_line_options, constants.DEFAULT_OPTIONS)
plugins_dirs = merged_options.get(constants.LABEL_PLUGIN_DIRS)
if plugins_dirs:
handle_plugin_dirs(plugins_dirs)

requires = moban_file_configurations.get(constants.LABEL_REQUIRES)
if requires:
handle_requires(requires)

targets = moban_file_configurations.get(constants.LABEL_TARGETS)
if targets:
if target:
# if command line option exists, append its template to targets
# issue 30
targets += target
number_of_templated_files = handle_targets(merged_options, targets)
else:
number_of_templated_files = 0
try:
merged_options = None
target = extract_target(command_line_options)
if constants.LABEL_CONFIG in moban_file_configurations:
merged_options = merge(
command_line_options,
moban_file_configurations[constants.LABEL_CONFIG],
)
merged_options = merge(command_line_options, constants.DEFAULT_OPTIONS)
plugins_dirs = merged_options.get(constants.LABEL_PLUGIN_DIRS)
if plugins_dirs:
handle_plugin_dirs(plugins_dirs)

requires = moban_file_configurations.get(constants.LABEL_REQUIRES)
if requires:
handle_requires(requires)

targets = moban_file_configurations.get(constants.LABEL_TARGETS)
if targets:
if target:
# if command line option exists, append its template to targets
# issue 30
targets += target
number_of_templated_files = handle_targets(merged_options, targets)
else:
number_of_templated_files = 0

if constants.LABEL_COPY in moban_file_configurations:
number_of_copied_files = handle_copy(
merged_options[constants.LABEL_TMPL_DIRS],
moban_file_configurations[constants.LABEL_COPY],
if constants.LABEL_COPY in moban_file_configurations:
number_of_copied_files = handle_copy(
merged_options[constants.LABEL_TMPL_DIRS],
moban_file_configurations[constants.LABEL_COPY],
)
else:
number_of_copied_files = 0
exit_code = reporter.convert_to_shell_exit_code(
number_of_templated_files + number_of_copied_files
)
else:
number_of_copied_files = 0
exit_code = reporter.convert_to_shell_exit_code(
number_of_templated_files + number_of_copied_files
)
reporter.report_up_to_date()
return exit_code

reporter.report_up_to_date()
return exit_code
except Exception as e:
print(e)

def handle_copy(template_dirs, copy_config):
copier = Copier(template_dirs)
Expand Down