Beispiel #1
0
    def make_asset_copy(directory: str) -> file_io.FILE_COPY_ENTRY:
        output_directory = os.path.join(
            project.output_directory,
            directory[len(project.source_directory):].lstrip(os.sep))

        return file_io.FILE_COPY_ENTRY(source=directory,
                                       destination=output_directory)
Beispiel #2
0
    def test_deploy(self, write: MagicMock, copy: MagicMock):
        """Should write and copy given entries according to type."""
        entries = [
            file_io.FILE_COPY_ENTRY('a', 'b'),
            file_io.FILE_WRITE_ENTRY('a', 'b'), None
        ]

        file_io.deploy(entries)
        self.assertEqual(1, write.call_count)
        self.assertEqual(entries[1], write.call_args[0][0])
        self.assertEqual(1, copy.call_count)
        self.assertEqual(entries[0], copy.call_args[0][0])
Beispiel #3
0
def create(project: 'projects.Project') -> COMPONENT:
    """
    :param project:
    :return:
    """

    source_path = get_source_path()
    if not source_path:
        return COMPONENT([], [])

    output_slug = 'components/plotly/plotly.min.js'
    output_path = os.path.join(project.output_directory, output_slug)

    return COMPONENT(
        includes=[WEB_INCLUDE(name='plotly', src='/{}'.format(output_slug))],
        files=[
            file_io.FILE_COPY_ENTRY(source=source_path,
                                    destination=output_path)
        ])
Beispiel #4
0
def stash_source(step_rename: STEP_RENAME) -> STEP_RENAME:
    """

    :param step_rename:
    :return:
    """

    file_io.copy(
        file_io.FILE_COPY_ENTRY(source=step_rename.old_path,
                                destination=step_rename.stash_path))

    if not os.path.exists(step_rename.stash_path):
        raise FileNotFoundError('Unable to stash step file {}'.format(
            step_rename.old_name))

    os.remove(step_rename.old_path)
    if os.path.exists(step_rename.old_path):
        raise FileExistsError('Unable to remove existing step {}'.format(
            step_rename.old_name))

    return step_rename
Beispiel #5
0
def unstash_source(step_rename: STEP_RENAME) -> STEP_RENAME:
    """

    :param step_rename:
    :return:
    """

    file_io.copy(
        file_io.FILE_COPY_ENTRY(source=step_rename.stash_path,
                                destination=step_rename.new_path))

    if not os.path.exists(step_rename.new_path):
        raise FileNotFoundError('Failed to rename step file to {}'.format(
            step_rename.new_path))

    try:
        os.remove(step_rename.stash_path)
    except PermissionError:
        pass

    return step_rename
Beispiel #6
0
def create(
        project: 'projects.Project',
        include_path: str
) -> COMPONENT:
    """
    Creates a COMPONENT instance for the project component specified by the
    include path

    :param project:
        The project in which the component resides
    :param include_path:
        The relative path within the project where the component resides
    :return:
        The created COMPONENT instance
    """

    source_path = environ.paths.clean(
        os.path.join(project.source_directory, include_path)
    )
    if not os.path.exists(source_path):
        return COMPONENT([], [])

    if os.path.isdir(source_path):
        glob_path = os.path.join(source_path, '**', '*')
        include_paths = glob.iglob(glob_path, recursive=True)
    else:
        include_paths = [source_path]

    destination_path = os.path.join(project.output_directory, include_path)

    return COMPONENT(
        includes=filter(
            lambda web_include: web_include is not None,
            map(functools.partial(to_web_include, project), include_paths)
        ),
        files=[file_io.FILE_COPY_ENTRY(
            source=source_path,
            destination=destination_path
        )]
    )
Beispiel #7
0
 def test_copy_retries(self, copy2: MagicMock, sleep: MagicMock):
     """Should fail to copy entry and raise an IOError."""
     copy2.side_effect = ValueError('FAKE')
     with self.assertRaises(IOError):
         file_io.copy(file_io.FILE_COPY_ENTRY(__file__, '/fake'))
     self.assertEqual(3, sleep.call_count)