add drive space check
This commit is contained in:
parent
9fe9c81586
commit
a5c1b724ab
1 changed files with 15 additions and 0 deletions
15
delojza.py
15
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)
|
||||
|
|
Loading…
Reference in a new issue