Exemple #1
0
    def process_remove_tag_from_directory(self, tags: list, directory: str):
        tag_manager = Tag()
        filesystem = FileSystem()

        files = filesystem.get_files(directory)
        for file_path in files:
            tag_manager.remove_tag(tags, file_path)
Exemple #2
0
class FileSystem:
    def __init__(self):
        pass
        self.tag = Tag()

    def get_files(self, dir_path: str) -> list:
        list_files: list = []
        for dirpath, dirnames, files in os.walk(dir_path):
            #print(f'Found directory: {dirpath}')
            for file_name in files:
                list_files.append(os.path.join(dirpath, file_name))
        #print(list_files)
        return list_files

    def get_file_names(self, dir_path: str) -> list:
        list_file_names: list = []
        for i in self.get_files(dir_path):
            #list_file_names.append(os.path.basename(i))
            list_file_names.append(self.tag.prepare_filename(i))
        #print(list_file_names)
        return list_file_names

    def file_exists(self, file_path: str, dir_dest: str) -> bool:
        file_name_source: str = self.tag.prepare_filename(file_path)
        list_file_names_dest: list = self.get_file_names(dir_dest)
        for i in list_file_names_dest:
            if file_name_source == i:
                return True
        return False

    def delete_file(self, file_path: str):
        try:
            os.remove(file_path)
            print(file_path)
        except OSError as err:
            print(f'Error: {file_path} : {err.strerror}')
            return

        dir_name = os.path.dirname(file_path)
        if len(self.get_files(dir_name)) == 0:
            try:
                os.rmdir(dir_name)
                print(dir_name)
            except OSError as err:
                print(f'Error: {dir_name} : {err.strerror}')


#test_path = '/home/kri/Pictures/Favorites/Walpapers/Copy_Top Layers1/00049.jpg'
#a = FileSystem()
#a.delete_file(test_path)
#a.get_files(test_path)
#b=a.get_file_names(test_path)
#print(b)
Exemple #3
0
 def __init__(self):
     pass
     self.tag = Tag()
Exemple #4
0
import pytest

from TagMe.tag import Tag

TAG = Tag()


def test_mod_tag_empty():
    with pytest.raises(Exception, match='TAG_LIST should not be empty'):
        TAG.mod_tag([])


def test_mod_tag_simple():
    assert TAG.mod_tag(['F', 'W']) == '_F_W__'


def test_extract_tag_no_tag():
    assert TAG.extract_tag('koja15.py') == []


def test_extract_tag_simple():
    assert TAG.extract_tag('_F_ZY__koja15.py') == ['F', 'ZY']


def test_check_tag_not_supported():
    with pytest.raises(Exception, match='tag KOJA is not supported'):
        TAG.check_tags(['F', 'KOJA', 'W'])


def test_check_tag_fix_queue():
    assert TAG.check_tags(['ZY', 'F', 'DUM']) == ['F', 'ZY', 'DUM']
Exemple #5
0
 def process_add_tag_to_file(self, tags: list, files: list):
     tag_manager = Tag()
     for file_path in files:
         tag_manager.add_tag(tags, file_path)
Exemple #6
0
 def process_remove_tag_from_file(self, tags: list, files: list):
     tag_manager = Tag()
     for file_path in files:
         tag_manager.remove_tag(tags, file_path)