From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 9CEB08194D; Mon, 19 Dec 2022 23:52:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671493975; bh=mo9MtstksaPutuc/ASQBiCReNPtUH3d4HyiMHRH5xjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KpuBYwM68GawKuYqfFLX1u9k+pTHGgVxgC/ndLgDWNmQmpvK1sZQjz5Z11p7Y0tDU jrntSZGmhdaAsTs86QritC/mrzLMUw/A2I9uuHLdkbeJHVvcj6vNSZbtrQBlPj+McG SfLAzOVAf0K35DbHiWVp9ieIoCyJCoekTqiDGa9odS0Att5gddug/Q95g5aREzwWih KQ80UQ1jWc4xwF8qIsirsyRqHM6EtzwzgZvw+9CWA8/ECNTfvT8SjbvKR06MoNmlLJ 2CfrtrVCR2MNo7Bl6cuc2Lh8k45TdOCCTBkkS62imWfQgZs3b1QLNvDaBKfqwid6ju Qc6aDWLFLraiQ== From: Muhammad Rizki To: Cc: Muhammad Rizki , Alviro Iskandar Setiawan , Ammar Faizi , GNU/Weeb Mailing List Subject: [PATCH 04/28] atom: Improve remove_patch() Date: Tue, 20 Dec 2022 06:52:02 +0700 Message-Id: <20221219235226.1567-4-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221219235226.1567-1-kiizuha@gnuweeb.org> References: <20221219235226.1567-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Improvement on remove_patch(). So, after send all the email attachments then remove them. On the previous patch, this function can't remove them properly. Signed-off-by: Muhammad Rizki Link: https://lore.gnuweeb.org/gwml/20221022065149.865-5-kiizuha@gnuweeb.org Cc: Alviro Iskandar Setiawan Cc: Ammar Faizi Cc: GNU/Weeb Mailing List Signed-off-by: Ammar Faizi --- daemon/atom/utils.py | 10 +++++++--- daemon/dscord/mailer/listener.py | 4 ++-- daemon/telegram/mailer/listener.py | 3 +-- daemon/telegram/packages/plugins/commands/scrape.py | 3 +-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index a30d5cb..f554f6f 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -6,7 +6,7 @@ from pyrogram.types import Chat, InlineKeyboardMarkup, InlineKeyboardButton from email.message import Message -from typing import Dict +from typing import Dict, Union from slugify import slugify import hashlib import uuid @@ -238,8 +238,12 @@ def prepare_patch(mail, text, url, platform: str): return tmp, file, caption, url -def remove_patch(tmp): - shutil.rmtree(tmp) +def remove_patch(tmp: Union[str, list]): + if isinstance(tmp, str): + return shutil.rmtree(tmp) + + for d,_ in tmp: + shutil.rmtree(d) def fix_utf8_char(text: str, html_escape: bool = True): diff --git a/daemon/dscord/mailer/listener.py b/daemon/dscord/mailer/listener.py index a280a58..cc0a9f7 100644 --- a/daemon/dscord/mailer/listener.py +++ b/daemon/dscord/mailer/listener.py @@ -125,10 +125,10 @@ class Listener: for d, f in files: await m.reply(file=File(f"{d}/{f}")) - if files.index((d,f)) == len(files)-1: - utils.remove_patch(d) await asyncio.sleep(1) + utils.remove_patch(files) + return True diff --git a/daemon/telegram/mailer/listener.py b/daemon/telegram/mailer/listener.py index 208aed0..08feddd 100644 --- a/daemon/telegram/mailer/listener.py +++ b/daemon/telegram/mailer/listener.py @@ -118,8 +118,7 @@ class Bot(): await m.reply_document(f"{d}/{f}", file_name=f) await asyncio.sleep(1) - if files: - shutil.rmtree(str(files[0][0])) + utils.remove_patch(files) return True diff --git a/daemon/telegram/packages/plugins/commands/scrape.py b/daemon/telegram/packages/plugins/commands/scrape.py index d4d10a9..52ddb0b 100644 --- a/daemon/telegram/packages/plugins/commands/scrape.py +++ b/daemon/telegram/packages/plugins/commands/scrape.py @@ -53,5 +53,4 @@ async def scrap_email(c: DaemonClient, m: Message): await m.reply_document(f"{d}/{f}", file_name=f) await asyncio.sleep(1) - if files: - shutil.rmtree(str(files[0][0])) + utils.remove_patch(files) -- 2.34.1.windows.1