Skip to content

Commit

Permalink
devel font installtion deprecated. fontman/fontmanpkg-spec#2
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsandaruwan committed Feb 10, 2017
1 parent a3625aa commit fbae05c
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 174 deletions.
18 changes: 0 additions & 18 deletions blueprint/auth_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@ def login():
auth_response["token"]
)

# sync other user settings from server
user_roles = RolesConsumer().consume_by_user_id(
new_profile.user_id,
{
"token": new_profile.token
}
)

for role in user_roles:
RoleService().add_new(
role["role_id"],
role["entity_id"],
role["entity"],
role["role"]
)

return jsonify(True)

else:
ProfileService().update_by_user_id(
auth_response["user_id"],
Expand Down
2 changes: 2 additions & 0 deletions blueprint/collections_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def find_fonts_by_collection_id(collection_id):
def install_fonts_by_collection_id(collection_id):
fonts = FontCollectionService().find_by_collection_id(collection_id)

return jsonify(True)


@collections_blueprint.route("/collections/<collection_id>/fonts/<font_id>/add")
def add_font_by_collection_id(collection_id, font_id):
Expand Down
74 changes: 1 addition & 73 deletions blueprint/fonts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ def find_chosen_fonts_status():
return jsonify(True)


@fonts_blueprint.route("/fonts/admin")
def find_all_user_fonts():
response_data = []
font_privileges = RoleService().find_by_entity("font")

for privilege in font_privileges:
if privilege.role in "admin":
font = FontService().find_by_font_id(privilege.entity_id).first()

response_data.append(
{
"font_id": font.font_id,
"name": font.name,
"type": font.type
}
)

return jsonify(response_data)


@fonts_blueprint.route("/fonts/<font_id>")
def find_by_font_id(font_id):
font = FontService().find_by_font_id(font_id).first()
Expand All @@ -106,7 +86,7 @@ def find_by_font_id(font_id):

@fonts_blueprint.route("/fonts/<font_id>/releases")
def find_tags_by_font_id(font_id):
response = [{"id": "devel", "tag_name": "devel"}]
response = []
rel_info = FontsConsumer().consume_releases(font_id)

for release in rel_info:
Expand Down Expand Up @@ -197,58 +177,6 @@ def find_metadata_by_font_id(font_id):
}
)


@fonts_blueprint.route("/fonts/new", methods=["POST"])
def add_new_font():
json_data = request.json
profile = ProfileService().find_logged_user()

json_data["user_id"] = profile.user_id
json_data["token"] = profile.token

response = FontsConsumer().consume_new_font(json_data)

if "error" in response:
return jsonify(response)

else:
FontService().add_new(
response["font_id"],
response["channel_id"],
response["name"],
response["type"]
)
tags_info = FontsConsumer().consume_metadata_by_font_id(
response["font_id"]
)

MetadataService().add_new(
tags_info["font_id"],
"https://api.github.com/repos/"
+ json_data["gitUser"] + "/"
+ json_data["gitRepository"] + "/releases/latest",
tags_info["tags_url"]
)

for fontface in response["fontfaces"]:
FontFaceService().add_new(
fontface["fontface_id"],
fontface["download_url"],
response["font_id"],
fontface["fontface"],
fontface["resource_path"]
)

RoleService().add_new(
response["role_id"],
response["font_id"],
"font",
"admin"
)

return jsonify(True)


@fonts_blueprint.route("/fonts/update", methods=["POST"])
def update_all_fonts():
json_data = request.json
Expand Down
19 changes: 1 addition & 18 deletions consumer/FontsConsumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,11 @@ def consume_by_query(self, team_id="", type=""):
)
return json.loads(response.text)

def consume_delete_font(self, font_id, json_data):
response = requests.post(
api_base_url + "/fonts/" + str(font_id) + "/delete",
json=json_data
)
return json.loads(response.text)

def consume_metadata_by_font_id(self, font_id):
response = requests.get(
api_base_url + "/fonts/" + str(font_id) + "/metadata"
)
return json.loads(response.text)

def consume_new_font(self, json_data):
response = requests.post(api_base_url + "/fonts/new", json=json_data)
return json.loads(response.text)

def consume_latest_rel_info(self, font_id):
response = json.loads(requests.get(
Expand All @@ -69,10 +58,4 @@ def consume_releases(self, font_id):
MetadataService().find_by_font_id(font_id).first().tags_url
).text)
return response

def consume_update_font(self, font_id, json_data):
response = requests.post(
api_base_url + "/fonts/" + str(font_id) + "/update",
json=json_data
)
return json.loads(response.text)

17 changes: 17 additions & 0 deletions consumer/TagsConsumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
""" Fontman server tags consumer
Consume and sync with fontman server roles REST API.
Created by Lahiru Pathirage @ Mooniak<lpsandaruwan@gmail.com> on 5/1/2017
"""

from session import api_base_url

import json, requests


class TagsConsumer:

def consume_tags_by_font_id(self, font_id):
response = requests.get(api_base_url + "/tags/" + str(font_id))
return json.loads(response)
1 change: 1 addition & 0 deletions consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
from consumer.FontsConsumer import FontsConsumer
from consumer.RatingsConsumer import RatingsConsumer
from consumer.RolesConsumer import RolesConsumer
from consumer.TagsConsumer import TagsConsumer
from consumer.TeamsConsumer import TeamsConsumer
from consumer.UsersConsumer import UsersConsumer
19 changes: 19 additions & 0 deletions model/FontType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
""" Font Type
Characteristics of a font. eg: serif/sans serif
Created by Lahiru Pathirage @ Mooniak <lpsandaruwan@gmail.com> on 8/2/2017
"""

from sqlalchemy import Boolean, Column, ForeignKey, Integer, String

from session import Base


class FontType(Base):

__tablename__ = "fonttype"

type_id = Column(Integer, primary_key=True)
font_id = Column(Integer, ForeignKey("font.font_id"))
tag = Column(String(20), nullable=False)
1 change: 1 addition & 0 deletions model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from model.FontCollection import FontCollection
from model.FontFace import FontFace
from model.FontFile import FontFile
from model.FontType import FontType
from model.InstalledFont import InstalledFont
from model.Metadata import Metadata
from model.Profile import Profile
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
flask==0.12
jinja2==2.8
python-fontconfig==0.5.1
requests==2.12.4
sqlalchemy==1.1.4
35 changes: 35 additions & 0 deletions service/FontTypeService.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
""" Font types service
High level functions to manipulate font types table
Created by Lahiru Pathirage @ Mooniak<lpsandaruwan@gmail.com> on 8/2/2017
"""

from model import FontType
from session import db_session


class FontTypeService:

def add_new(self, font_id, tag):
new_tag = FontType(
font_id=font_id,
tag=tag
)

db_session.add(new_tag)
db_session.commit()

return new_tag

def find_all(self):
return db_session.query(FontType).all()

def find_by_font_id(self, font_id):
return db_session.query(FontType).filter_by(font_id=font_id)

def find_by_tag(self, tag):
return db_session.query(FontType).filter_by(tag=tag)

def find_by_type_id(self, type_id):
return db_session.query(FontType).filter_by(type_id=type_id)
63 changes: 0 additions & 63 deletions utility/FontManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

from consumer import FontsConsumer
from service import FontFaceService
from service import FontFileService
from service import FontService
from service import InstalledFontService
Expand Down Expand Up @@ -117,70 +116,8 @@ def install_font(self, font_id, rel_id):
font_dir = "./data/" + font_id
sys_font_dir = self.__system.font_directory
artifacts_dir = "./data/" + font_id + "/extracted"

FileManager().create_directory(artifacts_dir)

requested_font = FontService().find_by_font_id(font_id).first()

if rel_id in "devel":
try:
fontfaces = FontFaceService().find_by_font_id(font_id)

for fontface in fontfaces:
fontfile_name = requested_font.name + "-"\
+ fontface.fontface

if fontface.download_url.endswith(".otf"):
fontfile_name += ".otf"
elif fontface.download_url.endswith(".ttf"):
fontfile_name += ".ttf"

FileManager().download_file(
artifacts_dir + "/" + fontfile_name,
fontface.download_url
)

fontfiles = find_files_by_extension(font_dir, ".ttf")

if len(fontfiles) == 0:
fontfiles = find_files_by_extension(
font_dir, ".otf"
)

if len(fontfiles) == 0:
fontfiles = find_files_by_extension(
font_dir, ".ufo"
)

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

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

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

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

InstalledFontService().add_new(
font_id, "devel"
)
FileManager().remove_directory(font_dir)

return True

except:
# raise
return {"error": "Error while installing devel version."}

release_data = FontsConsumer().consume_rel_info(
font_id, rel_id
)
Expand Down
2 changes: 1 addition & 1 deletion utility/Initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def initialize():
engine = create_engine(
"sqlite:///./data/fontman.db"
)
Base.metadata.create_all(engine)
Base.metadata.create_all(engine, checkfirst=True)

# gather and save system data
user_home_dir = expanduser("~")
Expand Down

0 comments on commit fbae05c

Please sign in to comment.