def get(self, request): ''' return list of all not used folders ''' filter_params = self.get_filter() dataset = False if 'dataset' in filter_params: dataset = Dataset.objects.get(pk=int(filter_params['dataset'])) if not dataset: return Response({'success': False}) data = [] path = os.path.join(settings.DATAFRONTEND['DATA_PATH'], dataset.identifier) files = Folder.files(path, ['.json']) for index, file in enumerate(files): data.append({ 'id': index, 'file_name': file, 'size': os.stat(os.path.join(path, file)).st_size, 'dataset': dataset.id }) return Response(data)
def test_files(self): path = 'datasets/tests/data/tmp/folder1/folder11' result = Folder.files(path, extensions=[]) self.assertEqual( ['testfile11.fake.jpg', 'testfile12.fake.png', 'testfile13.txt'], sorted(result))
def get(self, request): ''' return list of all not used folders ''' folders = Folder.all() dataset_pathes = [d.identifier for d in Dataset.objects.all()] data = [] for folder in folders: if folder in dataset_pathes: continue data.append({'id': folder, 'name': folder}) return Response(data)
def init_folder_task(dataset_id): # print(dataset_id) if not int(dataset_id) > 0: return False dataset = Dataset.objects.get(id=int(dataset_id)) if not dataset: return False path = os.path.join(settings.DATAFRONTEND['DATA_PATH'], dataset.identifier) files = Folder.files(path) for file_name in files: Image.objects.create(name=file_name, path=os.path.join(dataset.identifier, file_name), dataset_id=int(dataset_id))
def test_files_dataset(self): path = 'datasets/tests/data/tmp' result = Folder.files_dataset(path) self.assertEqual([ [ path + '/folder1/folder11/folder111/testfile111.fake.jpg', 'tmp_folder1_folder11_folder111' ], [ path + '/folder1/folder11/testfile11.fake.jpg', 'tmp_folder1_folder11' ], [ path + '/folder1/folder11/testfile12.fake.png', 'tmp_folder1_folder11' ], [path + '/folder1/testfile1.fake.jpg', 'tmp_folder1'], ], sorted(result))
def test_all(self): path = 'datasets/tests/data/tmp/' result = Folder.all(path) self.assertEqual(['folder1'], result)