Beispiel #1
0
    def load_from_path(path: str):
        if not os.path.exists(path):
            raise FileNotFoundError

        storyboard: Storyboard

        if os.path.isdir(path):
            tmp_storyboard_path = os.path.join(path, "storyboard.json")
            if not os.path.exists(tmp_storyboard_path):
                raise StoryboardFileNotFound(
                    f"No storyboard file found in {tmp_storyboard_path}."
                    f"Please create a new project or try another path.")
            storyboard_path = tmp_storyboard_path
        else:
            storyboard_path = path
            path = get_directory_of_file(path)

        file_type = os.path.splitext(storyboard_path)[1]
        if file_type == ".json":
            file_string = load_file_as_string(storyboard_path)
            file_json = json.loads(file_string)
            if not Storyboard.is_valid_storyboard_dict(file_json):
                raise InvalidStoryboard(
                    f"The chosen storyboard is not valid, please check, that all required attributes are set!"
                )
        else:
            raise StoryboardFileNotFound(
                f"Storyboard file if from type {file_type}, "
                f"instead of .json. Please check that the file has the ending .json and is a valid storyboard file!"
            )

        storyboard: Storyboard = Storyboard.generate_from_file(storyboard_path)
        return Project(path=path, storyboard=storyboard)
Beispiel #2
0
 def generate_file_string(project: Project):
     template = load_file_as_string(EasyLayout.template_path)
     template = template.replace("%*imagepath*", project.images_directory)
     template = template.replace("%*title*", project.storyboard.title)
     template = template.replace("%*author*", project.storyboard.author)
     template = template.replace(
         "%*frames*", EasyLayout._generate_frames_string(project.storyboard.frames)
     )
     return template
Beispiel #3
0
    def test_run_valid(self):
        GenerateTexFileStep.get_file_name = get_tex_file_name
        job = Job(
            layout=LayoutName.EASY_LAYOUT.value, project=generate_sample_project()
        )
        GenerateTexFileStep.run(job)
        expected_tex_file_path = os.path.join(
            job.project.output_directory,
            get_tex_file_name(job.project.storyboard.title),
        )

        self.assertEqual(job.status, Status.VALID)
        self.assertTrue(os.path.exists(job.tex_file_path))

        file_content = load_file_as_string(job.tex_file_path)
        self.assertEqual(job.tex_file_path, expected_tex_file_path)
        self.assertEqual(
            file_content,
            expected_file_content.replace("%*imagepath*", job.project.images_directory),
        )
        clear_output_directory(job)
 def generate_from_file(path: str):
     if os.path.exists(path):
         return Storyboard.generate_from_string(load_file_as_string(path))
     else:
         raise FileNotFoundError
Beispiel #5
0
def load_easy_layout_template():
    return load_file_as_string(EasyLayout.template_path)