<commit_before>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from sys import argv, exit
from dbclient import dbclient
from os.path import exists
from os import unlink

def rmthumbs(post):
	m = post["md5"]
	sizes = map(int, client.cfg.thumb_sizes.split()) + ["normal", "large"]
	for z in sizes:
		if isinstance(z, int):
			path = client.thumb_path(m, z)
		else:
			path = client.pngthumb_path(m, post["ext"], z)
		if exists(path):
			unlink(path)

def rmimg(m):
	path = client.image_path(m)
	if exists(path):
		unlink(path)

def delete_post(m, force):
	post = client.get_post(m, True, ["tagguid", "ext"])
	if not post:
		print m, "post not found"
		return 1
	tags = post["tagguid"]
	if tags:
		if force:
			client.tag_post(m, remove_tags = tags)
		else:
			print m, "post has tags"
			return 1
	rels = client.post_rels(m)
	if rels:
		if force:
			client.remove_rels(m, rels)
		else:
			print m, "post has related posts"
			return 1
	client.delete_post(m)<commit_msg>[db_rmpost] Fix to remove image symlink even if destination doesn't exist.<commit_after>#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

from sys import argv, exit
from dbclient import dbclient
from os.path import exists, lexists
from os import unlink

def rmthumbs(post):
	m = post["md5"]
	sizes = map(int, client.cfg.thumb_sizes.split()) + ["normal", "large"]
	for z in sizes:
		if isinstance(z, int):
			path = client.thumb_path(m, z)
		else:
			path = client.pngthumb_path(m, post["ext"], z)
		if exists(path):
			unlink(path)

def rmimg(m):
	path = client.image_path(m)
	if lexists(path):
		unlink(path)

def delete_post(m, force):
	post = client.get_post(m, True, ["tagguid", "ext"])
	if not post:
		print m, "post not found"
		return 1
	tags = post["tagguid"]
	if tags:
		if force:
			client.tag_post(m, remove_tags = tags)
		else:
			print m, "post has tags"
			return 1
	rels = client.post_rels(m)
	if rels:
		if force:
			client.remove_rels(m, rels)
		else:
			print m, "post has related posts"
			return 1
	client.delete_post(m)
{'fraction_non_alphanumeric': 0.13859910581222057, 'fraction_numerical': 0.00894187779433681, 'mean_word_length': 3.7838479809976246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5341858', 'n_tokens_mistral': 846, 'n_tokens_neox': 762, 'n_words': 226}