コード例 #1
0
ファイル: build.py プロジェクト: pvinis/incontext
    def inner(path):
        root, dirname, basename = utils.tripple(from_directory, path)
        document = converters.frontmatter_document(
            root,
            os.path.join(dirname, basename),
            default_category=default_category)

        files = []

        # Thumbnail.
        try:
            if isinstance(document["thumbnail"],
                          str):  # work-around for legacy photo handling
                thumbnail_src = os.path.normpath(
                    os.path.join(from_directory, dirname,
                                 document["thumbnail"]))
                name, ext = os.path.splitext(basename)
                thumbnail_basename = "%s-thumbnail.jpg" % (name, )

                # Ensure the destination directory exists.
                # This is designed to fail if the destination path exists, but is not a directory.
                target_directory = os.path.join(to_directory, dirname)
                utils.makedirs(target_directory)

                document.metadata['thumbnail'] = gallery.resize(
                    thumbnail_src, to_directory, dirname, thumbnail_basename,
                    (None, 500), 2)
                files.append(
                    os.path.join(to_directory, dirname, thumbnail_basename))
        except KeyError:
            pass

        incontext.environment[DOCUMENT_STORE].add(document)
        return {'files': files, 'urls': [document.url]}
コード例 #2
0
 def inner(path):
     root, dirname, basename = utils.tripple(from_directory, path)
     return process_image(incontext,
                          from_directory,
                          to_directory,
                          dirname,
                          basename,
                          category=category,
                          title_from_filename=title_from_filename)
コード例 #3
0
 def inner(source):
     if path is not None:
         source = path
     root, dirname, basename = utils.tripple(from_directory, source)
     destination = os.path.join(to_directory, dirname,
                                os.path.splitext(basename)[0] + ".css")
     if path is not None:
         destination = os.path.join(to_directory,
                                    os.path.splitext(path)[0] + ".css")
     utils.makedirs(os.path.dirname(destination))
     utils.sass(os.path.join(from_directory, source), destination)
     return {'files': [destination]}
コード例 #4
0
ファイル: video.py プロジェクト: inseven/incontext
    def inner(path):

        root, dirname, basename = utils.tripple(from_directory, path)
        destination = os.path.join(to_directory, dirname, basename)
        utils.makedirs(os.path.join(to_directory, dirname))

        data = gallery.metadata_for_media_file(
            root,
            os.path.join(dirname, basename),
            title_from_filename=title_from_filename)
        data["category"] = category
        data[
            "template"] = "photo.html"  # TODO: Change this to be part of the configuration.

        name, _ = os.path.splitext(basename)
        mp4_name = "%s.mp4" % name
        mp4_path = os.path.join(to_directory, dirname, mp4_name)
        if not os.path.exists(mp4_path):
            subprocess.check_call([
                "ffmpeg", "-y", "-i", path, "-vcodec", "h264", "-acodec",
                "aac", "-strict", "-2", "-vf", "scale=1080:trunc(ow/a/2)*2",
                "-loglevel", LOG_LEVEL_PANIC, mp4_path
            ])

        thumbnail_name = "%s-thumbnail.jpg" % name
        thumbnail_path = os.path.join(to_directory, dirname, thumbnail_name)
        if not os.path.exists(thumbnail_path):
            subprocess.check_call([
                "ffmpeg", "-y", "-i", path, "-ss", "00:00:1.000", "-vframes",
                "1", "-loglevel", LOG_LEVEL_PANIC, thumbnail_path
            ])

        size = gallery.get_size(thumbnail_path, 1)
        data["thumbnail"] = utils.merge_dictionaries(
            {
                'filename': thumbnail_name,
                'url': os.path.join("/", dirname, thumbnail_name)
            }, size)
        data["video"] = utils.merge_dictionaries(
            {
                'filename': mp4_name,
                'url': os.path.join("/", dirname, mp4_name)
            }, size)

        data["path"] = converters.ensure_leading_slash(path)

        document = store.Document(data["url"], data, os.path.getmtime(path))
        incontext.environment["DOCUMENT_STORE"].add(document)

        return {'files': [mp4_path, thumbnail_path], 'urls': [document.url]}
コード例 #5
0
 def inner(path):
     root, dirname, basename = utils.tripple(from_directory, path)
     destination = os.path.join(to_directory, dirname, basename)
     utils.makedirs(os.path.join(to_directory, dirname))
     shutil.copy(path, destination)
     return {'files': [destination]}