diff --git a/CHANGELOG.md b/CHANGELOG.md index 679146b..0177037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,25 @@ # Changelog -## [1.2.2a2](https://github.com/NeonGeckoCom/skill-support_helper/tree/1.2.2a2) (2024-04-02) +## [1.2.3a2](https://github.com/NeonGeckoCom/skill-support_helper/tree/1.2.3a2) (2024-07-05) -[Full Changelog](https://github.com/NeonGeckoCom/skill-support_helper/compare/1.2.2a1...1.2.2a2) +[Full Changelog](https://github.com/NeonGeckoCom/skill-support_helper/compare/1.2.3a1...1.2.3a2) + +**Fixed bugs:** + +- \[BUG\] Attachments missing from support email [\#81](https://github.com/NeonGeckoCom/skill-support_helper/issues/81) +- \[BUG\] support email cannot be sent [\#79](https://github.com/NeonGeckoCom/skill-support_helper/issues/79) **Merged pull requests:** -- Update test dependencies [\#76](https://github.com/NeonGeckoCom/skill-support_helper/pull/76) ([NeonDaniel](https://github.com/NeonDaniel)) +- Update attachment truncation to avoid missing attachments [\#80](https://github.com/NeonGeckoCom/skill-support_helper/pull/80) ([NeonDaniel](https://github.com/NeonDaniel)) -## [1.2.2a1](https://github.com/NeonGeckoCom/skill-support_helper/tree/1.2.2a1) (2024-02-05) +## [1.2.3a1](https://github.com/NeonGeckoCom/skill-support_helper/tree/1.2.3a1) (2024-05-20) -[Full Changelog](https://github.com/NeonGeckoCom/skill-support_helper/compare/1.2.1...1.2.2a1) +[Full Changelog](https://github.com/NeonGeckoCom/skill-support_helper/compare/1.2.2...1.2.3a1) **Merged pull requests:** -- Support ovos-utils 0.1 [\#75](https://github.com/NeonGeckoCom/skill-support_helper/pull/75) ([NeonDaniel](https://github.com/NeonDaniel)) +- Remove deprecated calls to `self.translate` [\#78](https://github.com/NeonGeckoCom/skill-support_helper/pull/78) ([NeonDaniel](https://github.com/NeonDaniel)) diff --git a/__init__.py b/__init__.py index e1526c0..778a9f1 100644 --- a/__init__.py +++ b/__init__.py @@ -94,7 +94,7 @@ def handle_contact_support(self, message: Message): diagnostic_info["user_description"] = user_description attachment_files = self._parse_attachments( self._get_attachments(diagnostic_info)) - if self.send_email(self.translate("email_title"), + if self.send_email(self.resources.render_dialog("email_title"), self._format_email_body(diagnostic_info), message, email_addr, attachments=attachment_files): @@ -103,7 +103,7 @@ def handle_contact_support(self, message: Message): private=True) return LOG.error("Email failed to send, retry without attachments") - if self.send_email(self.translate("email_title"), + if self.send_email(self.resources.render_dialog("email_title"), self._format_email_body(diagnostic_info), message, email_addr): self.speak_dialog("complete", @@ -130,12 +130,13 @@ def _parse_attachments(files: list) -> dict: byte_size = getsize(file) if byte_size > 1000000: LOG.info(f"{file} is >1MB, truncating") - with open(file, 'r+') as f: - lines = f.readlines() + with open(file, 'rb+') as f: + content = f.read() + trunc = content[-1000000:].split(b'\n', 1)[1] f.seek(0) - f.writelines(lines[-50000:]) + f.write(trunc) f.truncate() - + LOG.debug(f"{file} is {getsize(file)/1024/1024} MiB") attachments[basename(file).replace('.log', '_log.txt')] = \ encode_file_to_base64_string(file) except Exception as e: @@ -148,11 +149,11 @@ def _format_email_body(self, diagnostics: dict) -> str: :param diagnostics: diagnostic data to format into the email. :returns: email body to send """ - return '\n\n'.join((self.translate("email_intro", - {"email": self.support_email}), + return '\n\n'.join((self.resources.render_dialog("email_intro", + {"email": self.support_email}), diagnostics.get('user_description') or "No Description Provided", - self.translate("email_signature"))) + self.resources.render_dialog("email_signature"))) def _check_service_status(self, message: Message = None) -> dict: """ diff --git a/test/test_skill.py b/test/test_skill.py index 7bc7cd0..61cc879 100644 --- a/test/test_skill.py +++ b/test/test_skill.py @@ -36,6 +36,9 @@ from neon_minerva.tests.skill_unit_test_base import SkillTestCase +os.environ["TEST_SKILL_ENTRYPOINT"] = "skill-support_helper.neongeckocom" + + class TestSkill(SkillTestCase): def test_00_skill_init(self): # Test any parameters expected to be set in init or initialize methods @@ -196,8 +199,11 @@ def test_parse_attachments(self): original = f.readlines() with open(test_outfile, 'r') as f: truncated = f.readlines() - self.assertEqual(truncated, original[-50000:]) - self.assertLess(getsize(test_outfile), input_size) + self.assertTrue(set(truncated) <= set(original)) # truncated is subset + self.assertIsInstance(int(truncated[0].split()[0]), int) + self.assertEqual(truncated[0].split()[1], '-') + self.assertEqual(truncated[-1], original[-1]) + self.assertLess(getsize(test_outfile), 1000000) os.remove(test_outfile) os.remove(test_file) diff --git a/version.py b/version.py index ee2550c..0f9c534 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "1.2.2" +__version__ = "1.2.3"