# Path: lib/system/busted/Liste.py
# LISTE = Liste()


from threading import Thread
from ..Utils import read_file, file_exists, fn2l, Debug, max_calls
from ..Tss import TSS
from .Liste import LISTE
import sublime
import re
import os

    @max_calls(name='Files.update')
    def update(self, filename, num_lines, content, remove_unused=False):
        """
            updates the references list in LISTE with the used references in the unsaved source file
            Also removes not existing files from LISTE
        """
        self.need_reload = False

        Debug('files', "UPDATE(remove_unused=%s) refs from %s" % (remove_unused, filename) )

        if not LISTE.has(filename):
            return

        tracked_refs = LISTE.get(filename)['refs']
        used_refs = self._get_references(content)

        if remove_unused:
            self._remove_unused_ref(tracked_refs, used_refs)

        self._add_missing_refs(tracked_refs, used_refs, filename, remove_unused)

        self._remove_non_existing_files()

        if self.need_reload:
            self._reload(filename)


    # TODO: should this one remove non existing REFs?
    def _remove_non_existing_files(self):

# Path: lib/system/busted/Liste.py
# LISTE = Liste()


# Path: lib/system/busted/Files.py
from threading import Thread
from ..Utils import read_file, file_exists, fn2l, Debug, max_calls
from ..Tss import TSS
from .Liste import LISTE
import sublime
import re
import os


    @max_calls(name='Files.update')
    def update(self, filename, num_lines, content, remove_unused=False):
        """
            updates the references list in LISTE with the used references in the unsaved source file
            Also removes not existing files from LISTE
        """
        self.need_reload = False

        Debug('files', "UPDATE(remove_unused=%s) refs from %s" % (remove_unused, filename) )

        if not LISTE.has(filename):
            return

        tracked_refs = LISTE.get(filename)['refs']
        used_refs = self._get_references(content)

        if remove_unused:
            self._remove_unused_ref(tracked_refs, used_refs)

        self._add_missing_refs(tracked_refs, used_refs, filename, remove_unused)

        self._remove_non_existing_files()

        if self.need_reload:
            self._reload(filename)


    # TODO: should this one remove non existing REFs?
    def _remove_non_existing_files(self):

        to_delete = [f for f in LISTE.liste if not file_exists(LISTE.get(f)['file'])]