def save(self, data={}, project_path=None): project_path = str( project_path) if project_path is not None else self.directory if project_path is None: raise Exception('The project path is not defined') self._directory = str(project_path) videos_path = os.path.join(project_path, 'videos') if not os.path.exists(videos_path): os.makedirs(videos_path) data['videos'] = [] ## Save videos ################################# videos_paths = [] for video in self.videos: data['videos'].append(video.save({}, videos_path)) videos_paths.append(video.directory) ## Check if there are videos in the videos folder that should be removed for video_path in tools.list_folders_in_path(videos_path): if video_path not in videos_paths: send2trash(video_path) #Save the project file ###################################### project_filename = os.path.join(self.directory, 'project.json') with open(project_filename, 'w') as outfile: json.dump(data, outfile) return data
def save(self, data, videos_path=None): video_path = os.path.join(videos_path, self.name) if not os.path.exists(video_path): os.makedirs(video_path) ############## save objects ############# objects_path = os.path.join(video_path, 'objects') if not os.path.exists(objects_path): os.makedirs(objects_path) for obj in self._children: obj_path = os.path.join(objects_path, obj.name) if not os.path.exists(obj_path): os.makedirs(obj_path) obj.save({}, obj_path) # remove not used objects ############### objects_paths = [ os.path.join(objects_path, obj.name) for obj in self._children ] for obj_path in tools.list_folders_in_path(objects_path): if obj_path not in objects_paths: send2trash(obj_path) ######################################### videoconf = os.path.join(video_path, 'video.json') data['video-filepath'] = os.path.relpath(self.filepath, start=self.project.directory) data['multiple-files'] = self.multiple_files with open(videoconf, 'w') as outfile: json.dump(data, outfile) return data
def save(self, data={}, project_path=None): project_path = str( project_path) if project_path is not None else self.directory if project_path is None: raise Exception('The project path is not defined') self._directory = str(project_path) videos_path = os.path.join(project_path, 'videos') if not os.path.exists(videos_path): os.makedirs(videos_path) data['videos'] = [] #Check Repo try: _ = git.Repo(self.directory).git_dir repo = git.Repo(self.directory) except git.exc.InvalidGitRepositoryError: repo = git.Repo.init(self.directory) ## Save videos ################################# videos_paths = [] for video in self.videos: data['videos'].append(video.save({}, videos_path)) videos_paths.append(video.directory) ## Check if there are videos in the videos folder that should be removed for video_path in tools.list_folders_in_path(videos_path): if video_path not in videos_paths: send2trash(video_path) #Save the project file ###################################### project_filename = os.path.join(self.directory, 'project.json') with open(project_filename, 'w') as outfile: json.dump(data, outfile) # Commit path_c = Path(self.directory).glob('**/*.csv') path_j = Path(self.directory).glob('**/*.json') pathlist = chain(path_j, path_c) for path in pathlist: path_in_str = str(path) repo.index.add([path_in_str]) committer = git.Actor('Test', '*****@*****.**') repo.index.commit(str(datetime.datetime.now()), author=committer, committer=committer) return data
def load(self, data, object2d_path=None): data = super(Object2dIO, self).load(data, object2d_path) dirname = os.path.basename(object2d_path) datasets_path = os.path.join(object2d_path, 'datasets') for dataset_path in list_folders_in_path(datasets_path): name = os.path.basename(dataset_path) conf_path = os.path.join(dataset_path, 'dataset.json') with open(conf_path, 'r') as infile: dataset_conf = json.load(infile) func = getattr(self, dataset_conf['factory-function']) dataset = func() dataset.name = name dataset.load(dataset_conf, dataset_path)
def save(self, data, object2d_path=None): data = super(Object2dIO, self).save(data, object2d_path) datasets_path = os.path.join(object2d_path, 'datasets') if not os.path.exists(datasets_path): os.makedirs(datasets_path) datasets = [] for dataset in self._datasets: dataset_path = os.path.join(datasets_path, dataset.name) if not os.path.exists(dataset_path): os.makedirs(dataset_path) dataset.save({}, dataset_path) datasets.append(dataset.directory) for dataset_path in list_folders_in_path(datasets_path): if dataset_path not in datasets: if os.path.exists(dataset_path): send2trash(dataset_path) return data
def load(self, data, project_path=None): project_path = str( project_path) if project_path is not None else self.directory if project_path is None: raise Exception('The project path was not defined') self._directory = os.path.abspath(project_path) project_filename = os.path.join(str(project_path), 'project.json') with open(project_filename, 'r') as outfile: data.update(json.load(outfile)) videos_path = os.path.join(project_path, 'videos') videos_paths = tools.list_folders_in_path(videos_path) for video_path in videos_paths: video = self.create_video() video.load(data, video_path) return data
def load(self, data, video_path=None): videoconf = os.path.join(video_path, 'video.json') with open(videoconf, 'r') as outfile: data = json.load(outfile) self.multiple_files = data.get('multiple-files', False) self.filepath = os.path.join(self.project.directory, data['video-filepath']) objects_path = os.path.join(video_path, 'objects') objects_dirs = tools.list_folders_in_path(objects_path) for obj_dir in objects_dirs: name = os.path.basename(obj_dir) conf_path = os.path.join(obj_dir, 'dataset.json') with open(conf_path, 'r') as infile: dataset_conf = json.load(infile) func = getattr(self, dataset_conf['factory-function']) dataset = func() dataset.load(dataset_conf, obj_dir) dataset.name = name super(VideoIO, self).load(data, video_path)