<commit_before>"""
This module contains services and commands that may change the state of the system
(i.e. called for their side effects).
"""
from django.db import transaction

from harvardcards.apps.flash.models import Collection, Deck, Card, Decks_Cards, Cards_Fields, Field
from harvardcards.apps.flash import utils
import win32con, win32api,os
from harvardcards.settings.common import MEDIA_ROOT

def delete_collection(collection_id):
    """Deletes a collection and returns true on success, false otherwise."""
    Collection.objects.get(id=collection_id).delete()
    if not Collection.objects.filter(id=collection_id):
        return True
    return False

def delete_deck(deck_id):
    """Deletes a deck and returns true on success, false otherwise."""
    deck = Deck.objects.get(id=deck_id)
    folder_name = str(deck.collection) + '_' + deck.title
    folder_path = os.path.abspath(os.path.join(MEDIA_ROOT, folder_name))
    if os.path.exists(folder_path):
        #to force deletion of a file set it to normal
        win32api.SetFileAttributes(folder_path, win32con.FILE_ATTRIBUTE_NORMAL)
        os.remove(folder_path)
    deck.delete()

    if not Deck.objects.filter(id=deck_id):
        return True
    return False

def delete_card(card_id):
    """Deletes a card and returns true on success, false otherwise."""
    Card.objects.get(id=card_id).delete()
    if not Deck.objects.filter(id=card_id):
        return True
    return False

def handle_uploaded_img_file(file, deck, collection):
    curr_dir = os.getcwd()
    folder_name = 'uploads'<commit_msg>replaced win32con with shutil to delete folders<commit_after>"""
This module contains services and commands that may change the state of the system
(i.e. called for their side effects).
"""
from django.db import transaction

from harvardcards.apps.flash.models import Collection, Deck, Card, Decks_Cards, Cards_Fields, Field
from harvardcards.apps.flash import utils
#import win32con, win32api,os
import os
import shutil
from harvardcards.settings.common import MEDIA_ROOT

def delete_collection(collection_id):
    """Deletes a collection and returns true on success, false otherwise."""
    Collection.objects.get(id=collection_id).delete()
    if not Collection.objects.filter(id=collection_id):
        return True
    return False

def delete_deck(deck_id):
    """Deletes a deck and returns true on success, false otherwise."""
    deck = Deck.objects.get(id=deck_id)
    folder_name = str(deck.collection) + '_' + deck.title
    folder_path = os.path.abspath(os.path.join(MEDIA_ROOT, folder_name))
    if os.path.exists(folder_path):
        #to force deletion of a file set it to normal
        #win32api.SetFileAttributes(folder_path, win32con.FILE_ATTRIBUTE_NORMAL)
        #os.remove(folder_path)
        shutil.rmtree(folder_path)
    deck.delete()

    if not Deck.objects.filter(id=deck_id):
        return True
    return False

def delete_card(card_id):
    """Deletes a card and returns true on success, false otherwise."""
    Card.objects.get(id=card_id).delete()
    if not Deck.objects.filter(id=card_id):
        return True
    return False

def handle_uploaded_img_file(file, deck, collection):
    curr_dir = os.getcwd()
    folder_name = 'uploads'
{'fraction_non_alphanumeric': 0.09415384615384616, 'fraction_numerical': 0.005538461538461538, 'mean_word_length': 4.055987558320373, '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': '1668973', 'n_tokens_mistral': 1000, 'n_tokens_neox': 978, 'n_words': 282}