コード例 #1
0
def add_new_font():
    font_data = request.json

    FontService().add_new(channel_id=font_data["channel_id"],
                          name=font_data["name"],
                          preview_cdn=font_data["preview_cdn"],
                          sample=font_data["sample"],
                          type=font_data["type"],
                          version=font_data["version"],
                          url=font_data["url"])

    font = FontService().find_by_name(font_data["channel_id"],
                                      font_data["name"], font_data["url"])

    return jsonify({
        "font_id": font.id,
        "channel_id": font.channel_id,
        "name": font.name,
        "preview_cdn": font.preview_cdn,
        "sample": font.sample,
        "type": font.type,
        "url": font.url,
        "upgradable": font.upgradable,
        "version": font.version
    })
コード例 #2
0
    def install_font(self, font_id):
        font_dir = "./data/" + font_id
        sys_font_dir = self.__system.font_directory
        artifacts_dir = "./data/" + font_id + "/extracted"
        FileManager().create_directory(artifacts_dir)

        font_data = FontService().find_by_font_id(font_id).first()
        metadata = MetadataService().find_by_font_id(font_id).first()

        FileManager().download_file(
            font_dir + "/" + font_data.name + ".zip",
            metadata.download_url
        )

        FileManager().extract_file(
            font_dir + "/" + font_data.name + ".zip",
            artifacts_dir
        )

        fontfaces = find_files_by_extension(artifacts_dir, ".otf")

        if fontfaces is []:
            fontfaces = find_files_by_extension(
                artifacts_dir, ".ttf"
            )

        print(fontfaces)

        for fontface in fontfaces:
            if "Windows" in self.__system.platform:
                fixed_install_font(fontface["file_path"])

            else:
                FileManager().move_file(
                    fontface["name"],
                    sys_font_dir,
                    fontface["file_path"]
                )

            FontFileService().add_new(fontface["name"], font_id)

        FontService().update_by_font_id(
            font_id,
            {
                "is_installed": True
            }
        )

        InstalledFontService().add_new(
            font_id, metadata.version
        )

        FileManager().remove_directory(font_dir)

        return True
コード例 #3
0
def update_font():
    font_data = request.json

    FontService().update_by_id(font_data["font_id"], font_data["update_data"])

    updated_font = FontService().find_by_id(font_data["id"])

    return jsonify({
        "font_id": updated_font.id,
        "url": updated_font.url,
        "version": updated_font.version
    })
コード例 #4
0
    def update_font_cache(self):
        print(self.__font_index)
        for __font in self.__font_index:
            if FontService().is_exists_by_font_id(__font["font_id"]):
                MetadataService().update_by_font_id(
                    __font["font_id"], {
                        "download_url": __font["download_url"],
                        "version": __font["version"]
                    })

                installed_font = InstalledFontService().find_by_font_id(
                    __font["font_id"]).first()

                if installed_font is not None:
                    if installed_font.version != __font["version"]:
                        FontService().update_by_font_id(
                            __font["font_id"], {"is_upgradable": True})
                continue

            self.add_new_font(__font)
コード例 #5
0
    def add_new_font(self, __font):
        FontService().add_new(__font["font_id"], __font["name"])

        MetadataService().add_new(__font["font_id"],
                                  __font["default_fontface"],
                                  __font["download_url"], __font["license"],
                                  __font["version"])

        for key, value in __font["fontfaces"].items():
            FontFaceService().add_new(__font["font_id"], key, value)

        for __language in __font["languages"]:
            LanguageService().add_new(__font["font_id"], __language)
コード例 #6
0
    def add_new_font(self, font_id):
        new_font = FontsConsumer().consume_by_font_id(font_id)
        new_fontfaces = FontFacesConsumer().consume_by_query(font_id)

        FontService().add_new(new_font["font_id"], new_font["name"])

        MetadataService().add_new(new_font["metadata_id"], new_font["font_id"],
                                  new_font["default_fontface"],
                                  new_font["download_url"],
                                  new_font["license"], new_font["version"])

        self.add_new_fontfaces(new_fontfaces)
        self.add_tags(font_id)
コード例 #7
0
def find_by_query():
    try:
        if request.args.get("upgradable"):
            upgradable_fonts = FontService().find_all_upgradable()
            response_data = []

            if upgradable_fonts.first() is None:
                return jsonify(False)

            for font in upgradable_fonts:
                fontfaces = FontFaceService().find_by_font_id(font.font_id)
                languages = LanguageService().find_by_font_id(font.font_id)
                metadata = MetadataService().find_by_font_id(font.font_id).first()

                default_resource = ""
                languages_list = []

                for fontface in fontfaces:
                    if "Regular" in fontface.fontface:
                        default_resource = fontface.resource_path

                for language in languages:
                    languages_list.append(language.language)

                response_data.append(
                    {
                        "fontId": font.font_id,
                        "defaultFontface": font.name + "-" + metadata.default_fontface,
                        "defaultResource": default_resource,
                        "installedVersion": InstalledFontService().find_by_font_id(font.font_id).first().version,
                        "latestVersion": metadata.version,
                        "name": font.name
                    }
                )

            return jsonify(response_data)

    except:
        return jsonify({"error": "Invalid request"})
コード例 #8
0
    def update_font_cache(self):
        update_list = FontsConsumer().consume_all_fonts()

        for font_id in update_list:
            font_data = FontsConsumer().consume_by_font_id(font_id)

            if FontService().is_exists_by_font_id(font_id):
                MetadataService().update_by_font_id(
                    font_id, {
                        "download_url": font_data["download_url"],
                        "version": font_data["version"]
                    })

                installed_font = InstalledFontService().find_by_font_id(
                    font_id).first()
                if installed_font is not None:
                    if installed_font.version != font_data["version"]:
                        FontService().update_by_font_id(
                            font_id, {"is_upgradable": True})

                continue

            self.add_new_font(font_id)
コード例 #9
0
def find_all_fonts():
    display_texts = [
        "Nymphs blitz quick vex dwarf jog.",
        "DJs flock by when MTV ax quiz prog.",
        "Big fjords vex quick waltz nymph.",
        "Junk MTV quiz graced by fox whelps.",
        "Vamp fox held quartz duck just by wing."
    ]
    response_data = []
    fonts = FontService().find_all()

    for font in fonts:
        metadata = MetadataService().find_by_font_id(font.font_id).first()
        fontfaces = FontFaceService().find_by_font_id(font.font_id)
        languages = LanguageService().find_by_font_id(font.font_id)

        fontfaces_list = []
        languages_list = []

        print(fontfaces.first())

        for fontface in fontfaces:
            fontfaces_list.append(
                {
                    "fontface": fontface.fontface,
                    "resource_path": fontface.resource_path
                }
            )

        for language in languages:
            languages_list.append(language.language)

        response_data.append(
            {
                "fontId": font.font_id,
                "defaultFontface": metadata.default_fontface,
                "displayText": display_texts[font.font_id // 5],
                "fontfaces": fontfaces_list,
                "isInstalled": font.is_installed,
                "isUpgradable": font.is_upgradable,
                "license": metadata.license,
                "name": font.name,
                "textSize": 25,
                "version": metadata.version,
                "viewId": {"id": 2}
            }
        )

    return jsonify(response_data)
コード例 #10
0
def find_fonts_by_channel_id(id):
    fonts_list = []

    for font in FontService().find_all_by_channel_id(id):
        fonts_list.append(
            {
                "id": font.id,
                "cdn": font.preview_cdn,
                "channel_id": font.channel_id,
                "name": font.name,
                "version": font.version
            }
        )

    return jsonify(fonts_list)
コード例 #11
0
def find_all_fonts():
    fonts_list = []

    for font in FontService().find_all():
        fonts_list.append({
            "id": font.id,
            "channel_id": font.channel_id,
            "name": font.name,
            "preview_cdn": font.preview_cdn,
            "sample": font.sample,
            "type": font.type,
            "version": font.version,
            "url": font.url
        })

    return jsonify(fonts_list)
コード例 #12
0
    def remove_font(self, font_id):
        font_files = FontFileService().find_all_by_font_id(font_id)
        sys_font_dir = SystemService().find_system_info().font_directory

        try:
            for file in font_files:
                FileManager().remove_file(sys_font_dir + "/" + file.file_name)

            FontFileService().delete_by_font_id(font_id)
            InstalledFontService().delete_by_font_id(font_id)

            FontService().update_by_font_id(font_id, {
                "is_installed": False,
                "is_upgradable": False
            })

            return True

        except:
            return {"error": "Error while removing font"}
コード例 #13
0
def update_font_by_font_id(font_id):
    json_data = request.json
    FontService().update_by_font_id(font_id, json_data)

    return jsonify(True)
コード例 #14
0
def find_chosen_fonts_status():
    if FontService().find_all_chosen().first() is None:
        return jsonify(False)
    else:
        return jsonify(True)
コード例 #15
0
def update_all_fonts():
    json_data = request.json
    FontService().update_all(json_data)

    return jsonify(json_data)