From 6ead02a5106b259e9886ab7f750e2be2e152e446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Fri, 29 May 2020 18:13:55 +0300 Subject: [PATCH] All append methods are implemented for file templates. Added support for executable templates. --- .pytest_cache/v/cache/lastfailed | 185 +++++++++++++++++ .pytest_cache/v/cache/nodeids | 187 ++++++++++++++++++ .pytest_cache/v/cache/stepwise | 1 + calculate/templates/format/bind_format.py | 20 +- calculate/templates/format/compiz_format.py | 4 +- calculate/templates/format/contents_format.py | 1 + calculate/templates/format/diff_format.py | 51 +++-- calculate/templates/format/dovecot_format.py | 6 +- calculate/templates/format/json_format.py | 8 +- calculate/templates/format/kde_format.py | 5 +- calculate/templates/format/kernel_format.py | 5 +- calculate/templates/format/ldap_format.py | 5 +- calculate/templates/format/openrc_format.py | 5 +- calculate/templates/format/patch_format.py | 59 ++++-- calculate/templates/format/postfix_format.py | 5 +- calculate/templates/format/procmail_format.py | 4 +- calculate/templates/format/proftpd_format.py | 4 +- calculate/templates/format/samba_format.py | 6 +- .../templates/format/xml_gconf_format.py | 7 +- calculate/templates/format/xml_xfce_format.py | 8 +- template_action_draft.py | 119 ++++++----- tests/templates/format/test_bind.py | 64 ------ tests/templates/format/test_diff.py | 99 +++++----- tests/templates/format/test_patch.py | 31 +-- .../test-category/test-package-1.0/CONTENTS | 2 +- 25 files changed, 653 insertions(+), 238 deletions(-) create mode 100644 .pytest_cache/v/cache/lastfailed create mode 100644 .pytest_cache/v/cache/nodeids create mode 100644 .pytest_cache/v/cache/stepwise diff --git a/.pytest_cache/v/cache/lastfailed b/.pytest_cache/v/cache/lastfailed new file mode 100644 index 0000000..b930be7 --- /dev/null +++ b/.pytest_cache/v/cache/lastfailed @@ -0,0 +1,185 @@ +{ + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_dictionaries_have_no_sections_and_have_only_parameter_lines__it_will_be_processed_correctly": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_parameter__parameter_will_be_deleted": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_section__section_will_be_deleted": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_replace_mark_for_section__section_will_be_deleted": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_parameters_with_same_name_in_same_section__parameters_values_in_original_dictionary_changed_to_values_from_template": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_same_sections_which_contain_different_parameters__a_section_from_the_template_added_to_the_same_section_of_original_dictionary": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_string_keys_without_any_action_marks__the_dictionaties_just_merged": true, + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_tuple_keys_without_any_action_marks_as_their_keys__the_dictionaries_just_merged": true, + "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_input_is_text_document_the_method_returns_list_of_its_lines": true, + "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_lines_in_document_divided_using_backslash_as_continuation_symbol__method_returns_list_of_full_lines": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_comment_parameter_is_set_for_template__format_object_will_parse_comments_with_comment_symbol_from_this_parameter": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_bind.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_the_ignore_comments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_compiz.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_with_some_action_symbols__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_without_any_action_symbols__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_template_parser_flag_is_set_False__the_initialized_object_contains_correct_dictionary_for_contents_util_module": true, + "tests/templates/format/test_contents.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_diff.py::TestExecuteMethods::test_if_diff_patch_used_for_patching_of_directories__it_changes_files_in_directories_and_adds_ones": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_json.py::TestParsingMethods::test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_json.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_json.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_with_values_with_unicode_symbols__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_kde.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_kernel.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives_and_action_marks__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_access_to_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_access_to_parameters_and_comments": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_comments_to_type_sections__the_object_s_dictionary_collect_them": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_index_directives__the_object_s_dictionary_contains_correct_dictionary_with_index_elements_and_comments": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_and_access_to_constructions_with_action_marks__object_dictionary_contains_correct_dictionary_with_action_marks": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_syncrepl_parameters_and_comments": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_template_text_contains_some_access_to_constuctions_with_same_what_value_and_without_action_marks_for_whole_constructions__they_join_in_one_access_to_construction": true, + "tests/templates/format/test_ldap.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_openrc.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_postfix.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_procmail.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_parameters_s_have_it_as_its_first_element_inherited": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_any_values_the_document_object_contains_dictionary_with_this_items_to_delete": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_the_ignoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_similar_names_but_different_parameters__the_parameters_merged_in_one_section": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_parameters_contains_upper_case_symbols__it_becomes_lower_case": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_joinBefore_flag_is_set__the_document_object_contains_dictionary_with_sections_added_in_the_top_of_it": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_samba.py::TestParsingMethods::test_make_template": true, + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf__the_format_object_contains_correct_dictionary": true, + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary": true, + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary": true, + "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_joining_documents_1": true, + "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_with_package_value": true, + "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_without_package_value": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_source_parameter_but_without_append_link__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_append_parameter__a_value_of_the_parameter_will_be_checked": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter_in_its_digital_form__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_force_parameter__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed": true, + "tests/templates/test_template_action.py::TestTemplateAction::test_chmod_directory": true, + "tests/templates/test_template_action.py::TestTemplateAction::test_chown_directory": true, + "tests/templates/test_template_action.py::TestTemplateAction::test_create_directory": true, + "tests/templates/test_template_action.py::TestTemplateAction::test_link_directory": true, + "tests/templates/test_template_action.py::TestTemplateAction::test_remove_directory": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_binded_with_datavars_module__variables_available_in_a_template": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_calculate_tag_with_some_parameters__the_template_engine_object_will_collect_its_parameters": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_condition_and_it_is_True__the_template_engine_object_will_be_initialized_without_any_exceptions": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_env_parameter_in_which_module_name_is_assigned__the_variables_from_this_module_can_be_used_in_template_without_determining_of_their_module": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_existing_package_as_its_argument__it_works_correctly_and_pkg_function_returns_version_value": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_package_that_does_not_exist_in_its_argument__it_works_correctly_and_pkg_function_returns_empty_version_value": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_and_without_package_parameter_in_calculate_tag__the_pkg_function_returns_empty_version_value": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_but_with_package_parameter_in_calculate_tag__the_pkg_function_returns_version_value_of_the_package_from_package_parameter": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_calculate_tags__the_template_engine_will_parse_them_all_and_will_contain_all_parameters_and_result_of_all_conditions": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_conditions_and_it_is_False__the_template_engine_raises_ConditionFailed_exception": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_variables_in_its_text__the_rendered_text_will_contain_values_of_this_variables": true, + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_value_of_variable_is_set_using_save_tag__the_new_value_of_variable_can_be_used_in_template": true, + "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes__it_successfully_executes_even_after_read": true, + "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes_without_readings__it_successfully_executes": true, + "tests/utils/test_files.py::TestUtils::test_if_pipe_is_executed_using_Process_object__it_has_successfully_executed": true, + "tests/utils/test_files.py::TestUtils::test_if_single_correct_command_executed_using_Process_object__it_successfully_executes": true, + "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_contains_contents_dictionary__it_renders_CONTENTS_file_correctly": true, + "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_initialized_by_existing_package__it_contains_dictionary_of_items_from_contents_file": true, + "tests/utils/test_package.py::TestContents::test_if_new_directory_is_added_in_contents_file_using_add_dir_method__the_PackageContents_object_renders_the_contents_file_with_new_dir": true, + "tests/utils/test_package.py::TestContents::test_if_new_link_is_added_in_contents_file_using_add_sym_method__the_PackageContents_object_renders_the_contents_file_with_new_sym": true, + "tests/utils/test_package.py::TestContents::test_if_new_object_is_added_in_contents_file_using_add_obj_method__the_PackageContents_object_renders_the_contents_file_with_new_obj": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_but_without_a_slot_and_use_flags__the_PackageAtom_object_returns_atom_name_of_package": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_slot_value__the_PackageAtom_returns_atom_name_of_package_with_this_slot": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_uses_value__the_PackageAtom_object_returns_atom_name_of_package_with_this_use_flags": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_an_empty_slot_value__the_PackageAtom_object_returns_atom_name_of_package": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_slot_value__the_PackageAtom_object_looks_for_package_with_assigned_slot_value": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_use_flags_value__the_PackageAtom_object_looks_for_package_with_assigned_use_flags": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_correct_package_atom_name_that_matches_multiple_packages__the_PackageAtom_object_gets_info_for_package_with_older_version": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_incorrect_package_atom_name__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_package_atom_name_with_incorrect_use_flags__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, + "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_belongs_to_any_package__the_PackageAtom_object_contains_dictionary_with_an_owner_package": true, + "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_does_not_belong_to_any_package__the_PackageAtom_object_throws_the_PackageAtomError_exception": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_eq_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ge_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_gt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_le_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_lt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ne_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True": true, + "tests/vars/test_namespace.py::TestNamespace::test_init_default_path": true, + "tests/vars/test_namespace.py::TestNamespace::test_init_empty_namespace": true +} \ No newline at end of file diff --git a/.pytest_cache/v/cache/nodeids b/.pytest_cache/v/cache/nodeids new file mode 100644 index 0000000..8eb49c8 --- /dev/null +++ b/.pytest_cache/v/cache/nodeids @@ -0,0 +1,187 @@ +[ + "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_without_package_value", + "tests/templates/test_directory_processor.py::TestDirectoryProcessor::test_just_for_debug_with_package_value", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_initialized_accoding_to_dictionary_of_correct_template_parameters__the_TemplateParameters_object_contains_processed_parameters_as_its_attributes_including_default_values", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_append_parameter__a_value_of_the_parameter_will_be_checked", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_source_parameter__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_correct_source_parameter_with_append_link__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_source_parameter_with_unexisting_file_path__the_initialization_of_the_object_will_be_failed", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_as_dir_parameters_object_using_source_parameter_but_without_append_link__the_initialization_of_the_object_will_be_failed", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_force_parameter__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_force_parameter__the_initialization_of_the_object_will_be_failed", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_autoupdate_parameter__a_value_of_the_parameter_will_be_checked", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_autoupdate_parameter__the_initialization_of_the_object_will_be_failed", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chown_parameter_in_its_digital_form__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_incorrect_chown_parameter__the_initialization_of_the_object_will_be_failed", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter__the_object_will_be_initialized_successfully", + "tests/templates/test_parameters_processor.py::TestTemplateParameters::test_if_TemplateParameters_object_is_intialized_using_dictionary_with_correct_chmod_parameter_in_its_digital_form__the_object_will_be_initialized_successfully", + "tests/templates/test_template_action.py::TestTemplateAction::test_chown_directory", + "tests/templates/test_template_action.py::TestTemplateAction::test_chmod_directory", + "tests/templates/test_template_action.py::TestTemplateAction::test_create_directory", + "tests/templates/test_template_action.py::TestTemplateAction::test_link_directory", + "tests/templates/test_template_action.py::TestTemplateAction::test_remove_directory", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_calculate_tag_with_some_parameters__the_template_engine_object_will_collect_its_parameters", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_binded_with_datavars_module__variables_available_in_a_template", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_env_parameter_in_which_module_name_is_assigned__the_variables_from_this_module_can_be_used_in_template_without_determining_of_their_module", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_condition_and_it_is_True__the_template_engine_object_will_be_initialized_without_any_exceptions", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_conditions_and_it_is_False__the_template_engine_raises_ConditionFailed_exception", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_several_calculate_tags__the_template_engine_will_parse_them_all_and_will_contain_all_parameters_and_result_of_all_conditions", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_variables_in_its_text__the_rendered_text_will_contain_values_of_this_variables", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_value_of_variable_is_set_using_save_tag__the_new_value_of_variable_can_be_used_in_template", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_existing_package_as_its_argument__it_works_correctly_and_pkg_function_returns_version_value", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_with_package_that_does_not_exist_in_its_argument__it_works_correctly_and_pkg_function_returns_empty_version_value", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_but_with_package_parameter_in_calculate_tag__the_pkg_function_returns_version_value_of_the_package_from_package_parameter", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_contains_pkg_function_without_any_arguments_and_without_package_parameter_in_calculate_tag__the_pkg_function_returns_empty_version_value", + "tests/templates/test_template_engine.py::TestTemplateEngine::test_if_an_input_template_calculate_tag_contains_pkg_function_with_an_existing_package_in_its_argument__the_pkg_function_returns_version_value_of_the_package_from_package_parameter_without_any_exceptions", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_string_keys_without_any_action_marks__the_dictionaties_just_merged", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_tuple_keys_without_any_action_marks_as_their_keys__the_dictionaries_just_merged", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_same_sections_which_contain_different_parameters__a_section_from_the_template_added_to_the_same_section_of_original_dictionary", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_inputs_are_dictionaries_with_parameters_with_same_name_in_same_section__parameters_values_in_original_dictionary_changed_to_values_from_template", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_section__section_will_be_deleted", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_replace_mark_for_section__section_will_be_deleted", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_template_dictionary_has_delete_mark_for_parameter__parameter_will_be_deleted", + "tests/templates/format/test_base.py::TestJoinMethod::test_if_input_dictionaries_have_no_sections_and_have_only_parameter_lines__it_will_be_processed_correctly", + "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_input_is_text_document_the_method_returns_list_of_its_lines", + "tests/templates/format/test_base.py::TestLogicLinesMethod::test_if_lines_in_document_divided_using_backslash_as_continuation_symbol__method_returns_list_of_full_lines", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_bind.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_bind.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_bind.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_the_ignore_comments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_compiz.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_without_any_action_symbols__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_input_document_contains_a_few_lines_with_some_action_symbols__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_contents.py::TestParsingMethods::test_if_template_parser_flag_is_set_False__the_initialized_object_contains_correct_dictionary_for_contents_util_module", + "tests/templates/format/test_contents.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_diff.py::TestExecuteMethods::test_if_diff_patch_used_for_patching_of_several_files__it_changes_patched_file_correctly", + "tests/templates/format/test_diff.py::TestExecuteMethods::test_if_diff_patch_used_for_patching_of_directories__it_changes_files_in_directories_and_adds_ones", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_dovecot.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_json.py::TestParsingMethods::test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_json.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_json.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_with_values_with_unicode_symbols__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_kde.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_kde.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_kde.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_kernel.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_access_to_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_access_to_parameters_and_comments", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_syncrepl_parameters_and_comments", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_index_directives__the_object_s_dictionary_contains_correct_dictionary_with_index_elements_and_comments", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_comments_to_type_sections__the_object_s_dictionary_collect_them", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_doc_contains_some_type_sections_with_plain_directives_and_action_marks__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_template_text_contains_some_access_to_constuctions_with_same_what_value_and_without_action_marks_for_whole_constructions__they_join_in_one_access_to_construction", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_if_input_document_contains_syncrepl_and_access_to_constructions_with_action_marks__object_dictionary_contains_correct_dictionary_with_action_marks", + "tests/templates/format/test_ldap.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_openrc.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_patch.py::TestParsingMethods::test_if_input_patch_document_contains_only_regular_expressions_without_any_regex_flags__it_correctly_patches_input_document", + "tests/templates/format/test_patch.py::TestParsingMethods::test_if_input_patch_document_contains_regular_expressions_with_global_regex_flags_and_flags_as_attributes__it_correctly_patches_input_document_using_regex_flags", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_postfix.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_procmail.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_parameters_s_have_it_as_its_first_element_inherited", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_the_ignoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_any_values_the_document_object_contains_dictionary_with_this_items_to_delete", + "tests/templates/format/test_proftpd.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_similar_names_but_different_parameters__the_parameters_merged_in_one_section", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_joinBefore_flag_is_set__the_document_object_contains_dictionary_with_sections_added_in_the_top_of_it", + "tests/templates/format/test_samba.py::TestParsingMethods::test_if_input_document_parameters_contains_upper_case_symbols__it_becomes_lower_case", + "tests/templates/format/test_samba.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_samba.py::TestParsingMethods::test_make_template", + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary", + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_if_input_document_is_simple_gconf__the_format_object_contains_correct_dictionary", + "tests/templates/format/test_xml_gconf.py::TestParsingMethods::test_joining_documents_1", + "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary", + "tests/templates/format/test_xml_xfce.py::TestParsingMethods::test_joining_documents_1", + "tests/utils/test_files.py::TestUtils::test_if_single_correct_command_executed_using_Process_object__it_successfully_executes", + "tests/utils/test_files.py::TestUtils::test_if_pipe_is_executed_using_Process_object__it_has_successfully_executed", + "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes_without_readings__it_successfully_executes", + "tests/utils/test_files.py::TestUtils::test_if_a_pipe_Process_object_uses_for_several_writes__it_successfully_executes_even_after_read", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_lt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_le_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_gt_operation_and_the_left_version_value_is_less_than_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ge_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_ne_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_two_Version_objects_compared_using_eq_operation_and_the_left_version_value_is_less_than_or_equal_to_the_right_version__the_result_of_the_comparing_would_be_True", + "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_initialized_by_existing_package__it_contains_dictionary_of_items_from_contents_file", + "tests/utils/test_package.py::TestContents::test_if_PackageContents_object_contains_contents_dictionary__it_renders_CONTENTS_file_correctly", + "tests/utils/test_package.py::TestContents::test_if_new_directory_is_added_in_contents_file_using_add_dir_method__the_PackageContents_object_renders_the_contents_file_with_new_dir", + "tests/utils/test_package.py::TestContents::test_if_new_object_is_added_in_contents_file_using_add_obj_method__the_PackageContents_object_renders_the_contents_file_with_new_obj", + "tests/utils/test_package.py::TestContents::test_if_new_link_is_added_in_contents_file_using_add_sym_method__the_PackageContents_object_renders_the_contents_file_with_new_sym", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_but_without_a_slot_and_use_flags__the_PackageAtom_object_returns_atom_name_of_package", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_slot_value__the_PackageAtom_returns_atom_name_of_package_with_this_slot", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_an_empty_slot_value__the_PackageAtom_object_returns_atom_name_of_package", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parsed_a_correct_package_atom_name_with_a_uses_value__the_PackageAtom_object_returns_atom_name_of_package_with_this_use_flags", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_slot_value__the_PackageAtom_object_looks_for_package_with_assigned_slot_value", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_parses_a_correct_package_atom_name_without_version_value_but_with_use_flags_value__the_PackageAtom_object_looks_for_package_with_assigned_use_flags", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_incorrect_package_atom_name__the_PackageAtom_object_throws_the_PackageAtomError_exception", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_package_atom_name_with_incorrect_use_flags__the_PackageAtom_object_throws_the_PackageAtomError_exception", + "tests/utils/test_package.py::TestContents::test_if_the_PackageAtom_object_tried_to_parse_an_correct_package_atom_name_that_matches_multiple_packages__the_PackageAtom_object_gets_info_for_package_with_older_version", + "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_belongs_to_any_package__the_PackageAtom_object_contains_dictionary_with_an_owner_package", + "tests/utils/test_package.py::TestContents::test_if_the_get_file_package_method_of_the_PackageAtom_object_is_called_with_a_name_of_a_file_that_does_not_belong_to_any_package__the_PackageAtom_object_throws_the_PackageAtomError_exception", + "tests/vars/test_namespace.py::TestNamespace::test_init_empty_namespace", + "tests/vars/test_namespace.py::TestNamespace::test_init_default_path" +] \ No newline at end of file diff --git a/.pytest_cache/v/cache/stepwise b/.pytest_cache/v/cache/stepwise new file mode 100644 index 0000000..0637a08 --- /dev/null +++ b/.pytest_cache/v/cache/stepwise @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/calculate/templates/format/bind_format.py b/calculate/templates/format/bind_format.py index 9e8a2ba..4da7daa 100644 --- a/calculate/templates/format/bind_format.py +++ b/calculate/templates/format/bind_format.py @@ -4,6 +4,7 @@ # не весь файл -- выдаем ошибку. # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, OneOrMore, Word, alphanums, Literal,\ ZeroOrMore, Forward, Optional, Group, restOfLine,\ @@ -20,7 +21,7 @@ class BINDFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, join_before=False, - comment_symbol=''): + parameters=ParametersContainer()): processing_methods = [] super().__init__(processing_methods) @@ -28,7 +29,6 @@ class BINDFormat(BaseFormat): self._ignore_comments = ignore_comments self._comments_processing = True self._join_before = join_before - self._comment_symbol = comment_symbol self._last_comments_list = [] self._initialize_parser() @@ -114,20 +114,10 @@ class BINDFormat(BaseFormat): # Для парсинга комментариев. python_style_comment = originalTextFor(Literal('#') + restOfLine) - if not self._comment_symbol: - comments = (cppStyleComment | - python_style_comment).setParseAction( + comments = (cppStyleComment | + python_style_comment).setParseAction( self._create_comment_list - ) - else: - custom_style_comment = originalTextFor( - Literal(self._comment_symbol) + restOfLine - ) - comments = (cppStyleComment | - python_style_comment | - custom_style_comment).setParseAction( - self._create_comment_list - ) + ) # Для парсинга директивы include. include_line = (Optional(action_symbols, default='')('action') diff --git a/calculate/templates/format/compiz_format.py b/calculate/templates/format/compiz_format.py index 30529fc..5939f0e 100644 --- a/calculate/templates/format/compiz_format.py +++ b/calculate/templates/format/compiz_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ OneOrMore, alphanums, ParseException, restOfLine,\ @@ -20,7 +21,8 @@ class CompizFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_section_line, self._parse_parameter_line, diff --git a/calculate/templates/format/contents_format.py b/calculate/templates/format/contents_format.py index 548c177..cafb93c 100644 --- a/calculate/templates/format/contents_format.py +++ b/calculate/templates/format/contents_format.py @@ -22,6 +22,7 @@ class ContentsFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, join_before=False, + parameters=None, template_parser=True): processing_methods = [self._parse_dir_line, self._parse_sym_line, diff --git a/calculate/templates/format/diff_format.py b/calculate/templates/format/diff_format.py index 80a3177..83740a5 100644 --- a/calculate/templates/format/diff_format.py +++ b/calculate/templates/format/diff_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from calculate.utils.files import Process from calculate.templates.format.base_format import FormatError from os import path @@ -11,37 +12,48 @@ class DiffFormat(BaseFormat): EXECUTABLE = True def __init__(self, document_text: str, - join_before=False): + join_before=False, + parameters=ParametersContainer()): self._patch_text = document_text - self._root_path = '' + self._cwd_path = '/' self._last_level = 0 - # вынести в более общий класс или куда-то еще. - self._changed_files_list = [] + # Измененные файлы. + self.changed_files = dict() - def execute_format(self, root_path): + def execute_format(self, target_path): '''Метод для запуска работы формата.''' - if path.exists(root_path): - self._root_path = root_path - else: + self._cwd_path = target_path + if not path.isdir(self._cwd_path): + # Если target_path -- путь к файлу, запускаем все процессы из + # директории, в которой этот файл находится. + self._cwd_path = path.dirname(self._cwd_path) + + if not path.exists(self._cwd_path): raise FormatError('root path does not exist') if self._patch_text: - return self._patch_document() + self._patch_document() + return self.changed_files else: raise FormatError('empty patch file') def _patch_document(self): '''Метод, производящий наложение патча путем запуска процесса patch.''' + # Сначала определяем на каком уровне накладываем патч. + # Для этого запускаем утилиту patch с --dry-run и смотрим результат + # выполнения. for level in range(0, 4): patch_dry_run = Process('patch', '--dry-run', - '-p{}'.format(level), cwd=self._root_path) + '-p{}'.format(level), + cwd=self._cwd_path) patch_dry_run.write(self._patch_text) if patch_dry_run.success(): break patch_dry_run = Process('patch', '-R', '--dry-run', - '-p{}'.format(level), cwd=self._root_path) + '-p{}'.format(level), + cwd=self._cwd_path) patch_dry_run.write(self._patch_text) if patch_dry_run.success(): return '' @@ -49,13 +61,24 @@ class DiffFormat(BaseFormat): raise FormatError('correction failed') self._last_level = level - patch_run = Process('patch', '-p{}'.format(level), cwd=self._root_path) + patch_run = Process('patch', '-p{}'.format(level), + cwd=self._cwd_path) patch_run.write(self._patch_text) if patch_run.success(): - for line in patch_run: + for line in patch_run.read_lines(): if line.startswith('patching file'): - self._changed_files_list.append(line[13:].strip()) + changed_file_path = path.join(self._cwd_path, + line[13:].strip()) + if path.exists(changed_file_path): + self.changed_files.update({changed_file_path: + 'modify'}) + else: + self.changed_files.update({changed_file_path: + 'remove'}) + print('Changings: ') + for file_path, change_type in self.changed_files.items(): + print('{}: {}'.format(file_path, change_type)) return patch_run.read() else: return '' diff --git a/calculate/templates/format/dovecot_format.py b/calculate/templates/format/dovecot_format.py index 6441049..3bf8664 100644 --- a/calculate/templates/format/dovecot_format.py +++ b/calculate/templates/format/dovecot_format.py @@ -4,6 +4,7 @@ # документа. # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ OneOrMore, alphanums, ParseException, pyparsing_unicode,\ @@ -12,9 +13,9 @@ from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ class DovecotFormat(BaseFormat): FORMAT = 'dovecot' + EXECUTABLE = False _initialized = False - _comment_symbol = '' def __new__(cls, *args, **kwargs): if not cls._initialized: @@ -23,7 +24,8 @@ class DovecotFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_section_start_line, self._parse_include_line, diff --git a/calculate/templates/format/json_format.py b/calculate/templates/format/json_format.py index 6baed99..a7c9c6a 100644 --- a/calculate/templates/format/json_format.py +++ b/calculate/templates/format/json_format.py @@ -1,15 +1,19 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict import json class JSONFormat(BaseFormat): FORMAT = 'json' + EXECUTABLE = False - def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + def __init__(self, document_text: str, + ignore_comments=False, + join_before=False, + parameters=ParametersContainer()): processing_methods = [] super().__init__(processing_methods) self._ignore_comments = ignore_comments diff --git a/calculate/templates/format/kde_format.py b/calculate/templates/format/kde_format.py index 6a2c93f..e946e51 100644 --- a/calculate/templates/format/kde_format.py +++ b/calculate/templates/format/kde_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ OneOrMore, alphanums, ParseException, restOfLine,\ @@ -9,6 +10,7 @@ from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ class KDEFormat(BaseFormat): FORMAT = 'kde' + EXECUTABLE = False _initialized = False @@ -19,7 +21,8 @@ class KDEFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_section_line, self._parse_parameter_line, diff --git a/calculate/templates/format/kernel_format.py b/calculate/templates/format/kernel_format.py index 9a7ba71..c9cd342 100644 --- a/calculate/templates/format/kernel_format.py +++ b/calculate/templates/format/kernel_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ ZeroOrMore, OneOrMore, ParseException, restOfLine,\ @@ -9,6 +10,7 @@ from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ class KernelFormat(BaseFormat): FORMAT = 'kernel' + EXECUTABLE = False _initialized = False @@ -19,7 +21,8 @@ class KernelFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_parameter_line, self._parse_to_delete_line] diff --git a/calculate/templates/format/ldap_format.py b/calculate/templates/format/ldap_format.py index f8badf8..2ac50a4 100644 --- a/calculate/templates/format/ldap_format.py +++ b/calculate/templates/format/ldap_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ OneOrMore, alphanums, ParseException, restOfLine,\ @@ -10,6 +11,7 @@ from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ class LDAPFormat(BaseFormat): FORMAT = 'ldap' + EXECUTABLE = False _initialized = False @@ -20,7 +22,8 @@ class LDAPFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_type_line, self._parse_access_line, diff --git a/calculate/templates/format/openrc_format.py b/calculate/templates/format/openrc_format.py index b8f85dd..a703e94 100644 --- a/calculate/templates/format/openrc_format.py +++ b/calculate/templates/format/openrc_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import Word, Literal, printables, originalTextFor, ZeroOrMore,\ OneOrMore, ParseException, restOfLine,\ @@ -9,6 +10,7 @@ from pyparsing import Word, Literal, printables, originalTextFor, ZeroOrMore,\ class OpenRCFormat(BaseFormat): FORMAT = 'openrc' + EXECUTABLE = False _initialized = False @@ -19,7 +21,8 @@ class OpenRCFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_parameter_line, self._parse_to_delete_line] diff --git a/calculate/templates/format/patch_format.py b/calculate/templates/format/patch_format.py index 862b258..7a8e839 100644 --- a/calculate/templates/format/patch_format.py +++ b/calculate/templates/format/patch_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat, FormatError +from ..template_engine import ParametersContainer from collections import OrderedDict import re try: @@ -11,18 +12,23 @@ except ImportError: class PatchFormat(BaseFormat): FORMAT = 'patch' + EXECUTABLE = False FORMAT_PARAMETERS = {'multiline', 'dotall', 'comment'} - def __init__(self, document_text: str, multiline=False, dotall=False, - comment_symbol='', join_before=False): + def __init__(self, document_text: str, + ignore_comments=False, + join_before=False, + parameters=ParametersContainer()): processing_methods = OrderedDict() super().__init__(processing_methods) - self._multiline_flag = multiline - self._dotall_flag = dotall + self.changed_files = dict() + + self._multiline_flag = parameters.multiline + self._dotall_flag = parameters.dotall self._parsed_patch = None - self._document_to_patch = '' + self._document_text = document_text self._FLAG_VALUES = {'True': True, 'False': False, 'true': True, @@ -33,8 +39,6 @@ class PatchFormat(BaseFormat): self._XML_ROOT_LINE = '\ {0}' - self._parse_patch(document_text) - def _parse_patch(self, patch_text): '''Метод, составляющий из текста шаблона xml документ и разбирающий его с помощью lxml.''' @@ -44,21 +48,34 @@ class PatchFormat(BaseFormat): except Exception: raise FormatError('can not parse patch document') - def execute_format(self, document_to_patch): + def join_template(self, template): + tmp_multiline = template._multiline_flag + tmp_dotall = template._dotall_flag + + template._multiline_flag = self._multiline_flag + template._dotall_flag = self._dotall_flag + + self._document_text = template._join(self._document_text) + + template._multiline_flag = tmp_multiline + template._dotall_flag = tmp_dotall + + def _join(self, input_text): '''Метод для запуска наложения патча.''' - if not document_to_patch.strip() == '': - self._document_to_patch = document_to_patch + self._parse_patch(self._document_text) - if self._parse_patch is None: - return False + if not input_text.strip() == '': + self._document_to_patch = input_text else: - if not self._patch_document(document_to_patch): - raise FormatError('Error: Can not run patch.') - else: - after_patch = self._document_to_patch - self._document_to_patch = '' - # Пока что возвращает результат наложения шаблона, это временно - return after_patch + return input_text + + if not self._patch_document(input_text): + raise FormatError('Error: Can not run patch.') + else: + after_patch = self._document_to_patch + self._document_to_patch = '' + + return after_patch def _patch_document(self, document_to_patch): '''Метод, обходящий теги шаблона и использующий указанные в нем @@ -160,3 +177,7 @@ class PatchFormat(BaseFormat): self._document_to_patch) continue return True + + @property + def document_text(self): + return self._document_text diff --git a/calculate/templates/format/postfix_format.py b/calculate/templates/format/postfix_format.py index 0cc88cc..08dfddd 100644 --- a/calculate/templates/format/postfix_format.py +++ b/calculate/templates/format/postfix_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ ZeroOrMore, OneOrMore, ParseException,\ @@ -9,6 +10,7 @@ from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ class PostfixFormat(BaseFormat): FORMAT = 'postfix' + EXECUTABLE = False _initialized = False @@ -19,7 +21,8 @@ class PostfixFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_parameter_line, self._parse_to_delete_line] diff --git a/calculate/templates/format/procmail_format.py b/calculate/templates/format/procmail_format.py index 2503c33..529a1d6 100644 --- a/calculate/templates/format/procmail_format.py +++ b/calculate/templates/format/procmail_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ ZeroOrMore, OneOrMore, ParseException, restOfLine,\ @@ -9,6 +10,7 @@ from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ class ProcmailFormat(BaseFormat): FORMAT = 'procmail' + EXECUTABLE = False _initialized = False @@ -20,7 +22,7 @@ class ProcmailFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, join_before=False, - comment_symbol=''): + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_parameter_line, self._parse_to_delete_line] diff --git a/calculate/templates/format/proftpd_format.py b/calculate/templates/format/proftpd_format.py index a5d82a0..a8c96c3 100644 --- a/calculate/templates/format/proftpd_format.py +++ b/calculate/templates/format/proftpd_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat, FormatError +from ..template_engine import ParametersContainer from jinja2 import Environment, PackageLoader from collections import OrderedDict from pyparsing import originalTextFor, Literal, ZeroOrMore, Word, printables,\ @@ -16,6 +17,7 @@ class ProFTPDFormat(BaseFormat): относятся. ''' FORMAT = 'proftpd' + EXECUTABLE = False _initialized = False @@ -27,7 +29,7 @@ class ProFTPDFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, join_before=False, - comment_symbol=''): + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_section_start_line, self._parse_section_end_line, diff --git a/calculate/templates/format/samba_format.py b/calculate/templates/format/samba_format.py index 77ed35c..b3febc3 100644 --- a/calculate/templates/format/samba_format.py +++ b/calculate/templates/format/samba_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ alphanums, ParseException, Optional, Group, restOfLine @@ -8,6 +9,8 @@ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ class SambaFormat(BaseFormat): FORMAT = 'samba' + EXECUTABLE = False + _initialized = False def __new__(cls, *args, **kwargs): @@ -17,7 +20,8 @@ class SambaFormat(BaseFormat): def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + join_before=False, + parameters=ParametersContainer()): processing_methods = [self._parse_comment_line, self._parse_section_line, self._parse_parameter_line, diff --git a/calculate/templates/format/xml_gconf_format.py b/calculate/templates/format/xml_gconf_format.py index b7b5812..30a4e8b 100644 --- a/calculate/templates/format/xml_gconf_format.py +++ b/calculate/templates/format/xml_gconf_format.py @@ -3,6 +3,7 @@ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ Optional from .base_format import BaseFormat +from ..template_engine import ParametersContainer from collections import OrderedDict try: from lxml.etree import Element, SubElement, ElementTree, tostring @@ -13,6 +14,7 @@ except ImportError: class XMLGConfFormat(BaseFormat): FORMAT = 'xml_gconf' + EXECUTABLE = False _initialized = False @@ -21,7 +23,10 @@ class XMLGConfFormat(BaseFormat): cls._initialize_parser() return super().__new__(cls) - def __init__(self, document_text: str, join_before=False): + def __init__(self, document_text: str, + ignore_comments=False, + join_before=False, + parameters=ParametersContainer()): processing_methods = OrderedDict({'gconf': self._gconf, 'entry': self._entry, 'dir': self._dir, diff --git a/calculate/templates/format/xml_xfce_format.py b/calculate/templates/format/xml_xfce_format.py index 5d9bbec..a08eaa2 100644 --- a/calculate/templates/format/xml_xfce_format.py +++ b/calculate/templates/format/xml_xfce_format.py @@ -1,6 +1,7 @@ # vim: fileencoding=utf-8 # from .base_format import BaseFormat +from ..template_engine import ParametersContainer from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ Optional from collections import OrderedDict @@ -13,6 +14,7 @@ except ImportError: class XMLXfceFormat(BaseFormat): FORMAT = 'xml_xfce' + EXECUTABLE = False _initialized = False @@ -21,8 +23,10 @@ class XMLXfceFormat(BaseFormat): cls._initialize_parser() return super().__new__(cls) - def __init__(self, document_text: str, ignore_comments=False, - join_before=False): + def __init__(self, document_text: str, + ignore_comments=False, + join_before=False, + parameters=ParametersContainer()): processing_methods = OrderedDict({'channel': self._channel, 'property': self._property, 'value': self._value, diff --git a/template_action_draft.py b/template_action_draft.py index 29bcf9e..c5aa8d9 100644 --- a/template_action_draft.py +++ b/template_action_draft.py @@ -13,20 +13,22 @@ import glob import shutil import os -template_text = '''{% calculate append = 'join' -%} -{% calculate package = 'test-category/test-package', format = 'samba' -%} +template_text = '''{% calculate append = 'before', source = '/etc/file' -%} +{% calculate package = 'test-category/test-package', format = 'samba', +unbound -%} [section one] parameter_1 = {{ vars_1.value_1 }} !parameter_2 ''' -template_to_run = '''{% calculate run = "/usr/bin/python" -%} +template_to_run = '''{% calculate run = "python" -%} with open('etc/dir/file.conf', 'r') as input_file: print(input_file.read()) + ''' backup_template_text = '''{% calculate append = 'join', format = 'samba', -package = 'test-category/test-package' -%} +autoupdate, package = 'test-category/test-package' -%} [section one] parameter_1 = value parameter_2 = value_2 @@ -236,6 +238,17 @@ class TemplateWrapper: " 'mirror' parameter is set") self.target_type = None + if self.format_class.EXECUTABLE: + # Если формат исполняемый, но проверяем, существует ли директория, + # из которой будет выполняться шаблон. + if not os.path.exists(self.target_path): + if self.template_type == DIR: + os.makedirs(self.target_path) + else: + self.target_path = os.path.dirname(self.target_path) + os.makedirs(self.target_path) + return + self.check_conflicts() self.check_package_collision() @@ -608,6 +621,11 @@ class TemplateExecutor: self.executor_output['target_path'] =\ template_object.target_path + if self.executor_output['stdout']: + print(self.executor_output['stdout']) + if self.executor_output['stderr']: + print(self.executor_output['stderr']) + return self.executor_output def save_changes(self): @@ -683,47 +701,56 @@ class TemplateExecutor: input_text = input_file.read() else: input_text = '' - parsed_input = template_format(input_text, join_before=join_before) parsed_template = template_format(template_object.template_text, join_before=join_before) - parsed_input.join_template(parsed_template) - - # Результат наложения шаблона. - output_text = parsed_input.document_text - # Удаляем форматный объект входного файла. - del(parsed_input) - output_text_md5 = hashlib.md5(output_text.encode()).hexdigest() - - for save_path in output_paths: - with open(save_path, 'w') as output_file: - output_file.write(output_text) - - if template_object.parameters.chown: - self.chown_file(save_path, - template_object.parameters.chown, - check_existation=False) - - if template_object.parameters.chmod: - self.chmod_file(save_path, - template_object.parameters.chmod, - check_existation=False) - - # Убираем все ._cfg файлы. - if template_object.cfg_list: - for cfg_file_path in template_object.cfg_list: - self._remove_file(cfg_file_path) - - # Убираем целевой файл из CL. - self.calculate_config_file.remove_file(template_object.target_path) - - # Обновляем CONTENTS. - if template_object.protected: - if template_object.parameters.unbound: - template_object.remove_from_contents() - else: - template_object.add_to_contents(file_md5=output_text_md5) + if not template_object.format_class.EXECUTABLE: + parsed_input = template_format(input_text, + join_before=join_before) + parsed_input.join_template(parsed_template) + # Результат наложения шаблона. + output_text = parsed_input.document_text + # Удаляем форматный объект входного файла. + del(parsed_input) + output_text_md5 = hashlib.md5(output_text.encode()).hexdigest() + + for save_path in output_paths: + with open(save_path, 'w') as output_file: + output_file.write(output_text) + + if template_object.parameters.chown: + self.chown_file(save_path, + template_object.parameters.chown, + check_existation=False) + + if template_object.parameters.chmod: + self.chmod_file(save_path, + template_object.parameters.chmod, + check_existation=False) + + # Убираем все ._cfg файлы. + if template_object.cfg_list: + for cfg_file_path in template_object.cfg_list: + self._remove_file(cfg_file_path) + + # Убираем целевой файл из CL. + self.calculate_config_file.remove_file( + template_object.target_path) + + # Обновляем CONTENTS. + if template_object.protected: + if template_object.parameters.unbound: + template_object.remove_from_contents() + else: + template_object.add_to_contents( + file_md5=output_text_md5) + else: + parsed_template.execute_format( + input_text=input_text, + target_path=template_object.target_path) + # Удаляем форматный объект входного файла. + del(parsed_template) else: if template_object.target_type is not None and not replace: with open(input_path, 'r') as input_file: @@ -767,10 +794,10 @@ class TemplateExecutor: template_object.add_to_contents(file_md5=output_text_md5) def _append_after_file(self, template_object: TemplateWrapper): - self._append_join_file(self, template_object, join_before=False) + self._append_join_file(template_object, join_before=False) def _append_before_file(self, template_object: TemplateWrapper): - self._append_join_file(self, template_object, join_before=True) + self._append_join_file(template_object, join_before=True) def _append_skip_file(self, template_object: TemplateWrapper): pass @@ -1000,13 +1027,11 @@ class TemplateExecutor: if run_process.readable: stdout = run_process.read() if stdout: - print("Run output:\n{}".format(stdout)) self.executor_output['stdout'] = stdout if run_process.readable_errors: stderr = run_process.read_error() if stderr: - print("Run errors:\n{}".format(stderr)) self.executor_output['stderr'] = stderr except FilesError as error: @@ -1117,7 +1142,7 @@ template_executor_obj.execute_template(target_path, template_executor_obj.save_changes() input() -template_engine.process_template_from_string(backup_template_text, FILE) +template_engine.process_template_from_string(template_to_run, FILE) template_parameters = template_engine.parameters template_text = template_engine.template_text template_executor_obj = TemplateExecutor( @@ -1131,7 +1156,7 @@ template_executor_obj.execute_template(target_path, template_executor_obj.save_changes() input() -template_engine.process_template_from_string(template_to_run, FILE) +template_engine.process_template_from_string(backup_template_text, FILE) template_parameters = template_engine.parameters template_text = template_engine.template_text template_executor_obj = TemplateExecutor( diff --git a/tests/templates/format/test_bind.py b/tests/templates/format/test_bind.py index bedcd1d..123595f 100644 --- a/tests/templates/format/test_bind.py +++ b/tests/templates/format/test_bind.py @@ -140,70 +140,6 @@ acl "dns_servers" { bind_object = BINDFormat(document_text) assert bind_object._document_dictionary == result - def test_if_comment_parameter_is_set_for_template__format_object_will_parse_comments_with_comment_symbol_from_this_parameter(self): - document_text = ''' -@ Comment 1 -!pid-file "/run/named/named.pid"; -/* -* A very big comment. -* Still here... -* The pure giant of the comment kind. -*/ --disable-empty-zone "10.in-addr.arpa"; - -@ Comment 2 -@ Comment 3 -acl "dns_servers" { - !127.0.0.1; - // Comment 4 - 10.0.1.3; - 10.1.0.3; -}; - --options { - !response-policy { - /* - * This comment is very important. - * And I have no idea, why this - * comment is so important. - */ - zone "rpz.zone"; - }; - !recursion yes; -} - ''' - - acl_section = OrderedDict({'#': ['@ Comment 2', '@ Comment 3'], - ('!', '127.0.0.1'): [''], - ('', '10.0.1.3'): ['// Comment 4', ''], - ('', '10.1.0.3'): ['']}) - response_section = OrderedDict({('', 'zone'): - ['/*', - '* This comment is very important.', - '* And I have no idea, why this', - '* comment is so important.', - '*/', - '"rpz.zone"']}) - options_section = OrderedDict({('!', 'response-policy'): - response_section, - ('!', 'recursion'): ['yes']}) - - result = OrderedDict({('!', 'pid-file'): - ['@ Comment 1', - '"/run/named/named.pid"'], - ('-', 'disable-empty-zone'): - ['/*', - '* A very big comment.', - '* Still here...', - '* The pure giant of the comment kind.', - '*/', - '"10.in-addr.arpa"'], - ('', 'acl', '"dns_servers"'): acl_section, - ('-', 'options'): options_section}) - - bind_object = BINDFormat(document_text, comment_symbol='@') - assert bind_object._document_dictionary == result - def test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary(self): document_text = ''' // Comment 1 diff --git a/tests/templates/format/test_diff.py b/tests/templates/format/test_diff.py index 5c9a931..65a3470 100644 --- a/tests/templates/format/test_diff.py +++ b/tests/templates/format/test_diff.py @@ -9,31 +9,34 @@ import os class TestExecuteMethods: def test_if_diff_patch_used_for_patching_of_several_files__it_changes_patched_file_correctly(self): test_result = True - root_path = path.join(os.getcwd(), 'tests/templates/format/testfiles/') - with open(path.join(root_path, 'diff_1.patch')) as patch_file: + cwd_path = path.join(os.getcwd(), 'tests/templates/format/testfiles/') + with open(path.join(cwd_path, 'diff_1.patch')) as patch_file: patch_text = patch_file.read() diff_patch = DiffFormat(patch_text) - print('Path:', root_path) - output = diff_patch.execute_format(root_path=root_path) + print('Path:', cwd_path) + output = diff_patch.execute_format(target_path=cwd_path) print('Output:') print(output) if output: print('Changed files:') - for changed_file in diff_patch._changed_files_list: - print(changed_file, ':', sep='') - with open(path.join(diff_patch._root_path, changed_file)) as patched_file: + for changed_file, change_type in\ + diff_patch.changed_files.items(): + if changed_file.startswith(cwd_path): + changed_file = changed_file[len(cwd_path):] + # print(changed_file, ':', sep='') + with open(path.join(diff_patch._cwd_path, changed_file)) as patched_file: patched_file_text = patched_file.read() - print(patched_file_text) + # print(patched_file_text) other_file_name = 'b' + changed_file[1:] - with open(path.join(diff_patch._root_path, + with open(path.join(diff_patch._cwd_path, other_file_name)) as other_file: other_file_text = other_file.read() test_result = test_result and (other_file_text == patched_file_text) return_patch_run = Process('patch', '-R', '-p{}'.format(diff_patch._last_level), - cwd=root_path) + cwd=cwd_path) return_patch_run.write(patch_text) output = return_patch_run.read() @@ -47,7 +50,7 @@ class TestExecuteMethods: def test_if_diff_patch_used_for_patching_of_directories__it_changes_files_in_directories_and_adds_ones(self): test_result = True - root_path = path.join(os.getcwd(), + cwd_path = path.join(os.getcwd(), 'tests/templates/format/testfiles/a1') patch_path = path.join(os.getcwd(), 'tests/templates/format/testfiles/diff_2.patch') @@ -55,45 +58,43 @@ class TestExecuteMethods: patch_text = patch_file.read() diff_patch = DiffFormat(patch_text) - print('Path:', root_path) - output = diff_patch.execute_format(root_path=root_path) - print('Output:') - print(output) - if output: - print('Changed files:') - for changed_file in diff_patch._changed_files_list: - print(changed_file, ':', sep='') - file_path = path.join(diff_patch._root_path, changed_file) - with open(file_path) as patched_file: - patched_file_text = patched_file.read() - print(patched_file_text) - other_file_path = os.path.join(path.dirname(root_path), - 'b1', changed_file) - with open(other_file_path) as other_file: - other_file_text = other_file.read() - test_result = test_result and (other_file_text == patched_file_text) - if not test_result: - print('Differences:') - try: - diff_process = Process('diff', '-u', - file_path, - other_file_path) - diff_result = diff_process.read() - print(diff_result) - except Exception as error: - print('diff was not executed.') - print('Reason:', str(error)) + output = diff_patch.execute_format(target_path=cwd_path) - reverse_patch_run = Process('patch', '-R', - '-p{}'.format(diff_patch._last_level), - cwd=root_path) - reverse_patch_run.write(patch_text) - output = reverse_patch_run.read() + for changed_file, change_type in\ + diff_patch.changed_files.items(): + if changed_file.startswith(cwd_path): + changed_file = changed_file[len(cwd_path) + 1:] + print(changed_file, '', sep='') + file_path = path.join(diff_patch._cwd_path, changed_file) + with open(file_path) as patched_file: + patched_file_text = patched_file.read() + # print(patched_file_text) + other_file_path = os.path.join(path.dirname(cwd_path), + 'b1', changed_file) + with open(other_file_path) as other_file: + other_file_text = other_file.read() + test_result = test_result and (other_file_text == patched_file_text) + if not test_result: + # print('Differences:') + try: + diff_process = Process('diff', '-u', + file_path, + other_file_path) + diff_result = diff_process.read() + # print(diff_result) + except Exception as error: + print('diff was not executed.') + print('Reason:', str(error)) - if reverse_patch_run.success(): - print('[*] Changes was returned...') - else: - print('[!] Changes was not returned...') + reverse_patch_run = Process('patch', '-R', + '-p{}'.format(diff_patch._last_level), + cwd=cwd_path) + reverse_patch_run.write(patch_text) + output = reverse_patch_run.read() + + if reverse_patch_run.success(): + print('[*] Changes was returned...') else: - test_result = False + print('[!] Changes was not returned...') assert test_result + assert False diff --git a/tests/templates/format/test_patch.py b/tests/templates/format/test_patch.py index f1693ee..d8faa68 100644 --- a/tests/templates/format/test_patch.py +++ b/tests/templates/format/test_patch.py @@ -1,6 +1,7 @@ import pytest from collections import OrderedDict from calculate.templates.format.patch_format import PatchFormat +from calculate.templates.template_engine import ParametersContainer @pytest.mark.patch @@ -28,10 +29,11 @@ Another line of endless sadness. ParameterName = NewValue ''' - patch = PatchFormat(patch_text) - patch_result = patch.execute_format(input_text) + patch_original = PatchFormat(input_text) + patch_template = PatchFormat(patch_text) + patch_original.join_template(patch_template) - assert patch_result == output_text + assert patch_original.document_text == output_text def test_if_input_patch_document_contains_regular_expressions_with_global_regex_flags_and_flags_as_attributes__it_correctly_patches_input_document_using_regex_flags(self): input_text = ''' @@ -65,16 +67,19 @@ Another line of endless sadness. share modes = no ''' - patch_text = ''' - (\\[netlogon\\].*)writable\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]* - \\1writable = yes - (\\[homes\\].*)browseable\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]* - \\1browseable = who knows - (\\[netlogon\\].*)^\\s*guest ok\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]*\\n - \\1 + patch_text = r''' + (\[netlogon\].*)writable\s*=\s*[a-zA-Z_][a-zA-Z_0-9]* + \1writable = yes + (\[homes\].*)browseable\s*=\s*[a-zA-Z_][a-zA-Z_0-9]* + \1browseable = who knows + (\[netlogon\].*)^\s*guest ok\s*=\s*[a-zA-Z_][a-zA-Z_0-9]*\n + \1 ''' - patch = PatchFormat(patch_text, multiline=True, dotall=True) - patch_result = patch.execute_format(input_text) + parameters = ParametersContainer({'multiline': True, 'dotall': True}) - assert patch_result == output_text + patch_original = PatchFormat(input_text, parameters=parameters) + patch_template = PatchFormat(patch_text, parameters=parameters) + patch_original.join_template(patch_template) + + assert patch_original.document_text == output_text diff --git a/tests/templates/testfiles/test_root/var/db/pkg/test-category/test-package-1.0/CONTENTS b/tests/templates/testfiles/test_root/var/db/pkg/test-category/test-package-1.0/CONTENTS index 553374f..f3222cc 100644 --- a/tests/templates/testfiles/test_root/var/db/pkg/test-category/test-package-1.0/CONTENTS +++ b/tests/templates/testfiles/test_root/var/db/pkg/test-category/test-package-1.0/CONTENTS @@ -1,3 +1,3 @@ dir /etc dir /etc/dir -obj /etc/dir/file.conf 0b87fea7f5b65cac5012baa2bf647e72 1590678156 +obj /etc/dir/file.conf 0b87fea7f5b65cac5012baa2bf647e72 1590764349