From a5c1b724ab91ae18ccfec2f9ce1185d6327a68d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 25 Jul 2019 11:25:35 +0200 Subject: [PATCH] add drive space check --- delojza.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/delojza.py b/delojza.py index a30e105..1a86dbb 100755 --- a/delojza.py +++ b/delojza.py @@ -219,6 +219,13 @@ class DelojzaBot: self.logger.info("Tagging {} w/ {} - {} [{}]...".format(filepath, title, artist, source)) self._tag_file(filepath, artist, title) + def _get_percent_filled(self): + output = subprocess.check_output(["df", self.out_dir]) + percents_re = re.search(r"[0-9]+%", output.decode('utf-8')) + if not percents_re: + raise RuntimeError + return int(percents_re.group(0)[:-1]) + # noinspection PyUnusedLocal def download_ytdl(self, urls, out_path, date, message, audio=False, filetitle=None): ytdl = { @@ -342,6 +349,14 @@ class DelojzaBot: def handle(self, urls, message, hashtags, download_fn, filetitle=None): self.db.initialize() + try: + if self._get_percent_filled() >= 98: + message.reply("NO! Less than 2% of drive space left :(") + return + except Exception: + message.reply("NO! Couldn't figure out how much space is left???") + return + try: if len(hashtags) == 0: self.logger.info("Ignoring %s due to no hashtag present..." % urls)