diff --git a/blueprint/auth_controller.py b/blueprint/auth_controller.py index eac75ed..53e36b9 100755 --- a/blueprint/auth_controller.py +++ b/blueprint/auth_controller.py @@ -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"], diff --git a/blueprint/collections_controller.py b/blueprint/collections_controller.py index 28a7d43..3ba4be8 100644 --- a/blueprint/collections_controller.py +++ b/blueprint/collections_controller.py @@ -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//fonts//add") def add_font_by_collection_id(collection_id, font_id): diff --git a/blueprint/fonts_controller.py b/blueprint/fonts_controller.py index 520d102..a88714f 100755 --- a/blueprint/fonts_controller.py +++ b/blueprint/fonts_controller.py @@ -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/") def find_by_font_id(font_id): font = FontService().find_by_font_id(font_id).first() @@ -106,7 +86,7 @@ def find_by_font_id(font_id): @fonts_blueprint.route("/fonts//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: @@ -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 diff --git a/consumer/FontsConsumer.py b/consumer/FontsConsumer.py index 185ce3d..95b9251 100755 --- a/consumer/FontsConsumer.py +++ b/consumer/FontsConsumer.py @@ -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( @@ -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) + diff --git a/consumer/TagsConsumer.py b/consumer/TagsConsumer.py new file mode 100644 index 0000000..68a15ed --- /dev/null +++ b/consumer/TagsConsumer.py @@ -0,0 +1,17 @@ +""" Fontman server tags consumer + +Consume and sync with fontman server roles REST API. + +Created by Lahiru Pathirage @ Mooniak 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) diff --git a/consumer/__init__.py b/consumer/__init__.py index bcbe0ad..0d3f151 100755 --- a/consumer/__init__.py +++ b/consumer/__init__.py @@ -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 diff --git a/model/FontType.py b/model/FontType.py new file mode 100644 index 0000000..c9b9bf0 --- /dev/null +++ b/model/FontType.py @@ -0,0 +1,19 @@ +""" Font Type + +Characteristics of a font. eg: serif/sans serif + +Created by Lahiru Pathirage @ Mooniak 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) diff --git a/model/__init__.py b/model/__init__.py index 94930a0..b1bdc32 100755 --- a/model/__init__.py +++ b/model/__init__.py @@ -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 diff --git a/requirements.txt b/requirements.txt index c934bb0..f99fcfa 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ flask==0.12 jinja2==2.8 -python-fontconfig==0.5.1 requests==2.12.4 sqlalchemy==1.1.4 diff --git a/service/FontTypeService.py b/service/FontTypeService.py new file mode 100644 index 0000000..0f0e6a0 --- /dev/null +++ b/service/FontTypeService.py @@ -0,0 +1,35 @@ +""" Font types service + +High level functions to manipulate font types table + +Created by Lahiru Pathirage @ Mooniak 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) diff --git a/utility/FontManager.py b/utility/FontManager.py index 39ecbbb..e7ca683 100755 --- a/utility/FontManager.py +++ b/utility/FontManager.py @@ -6,7 +6,6 @@ """ from consumer import FontsConsumer -from service import FontFaceService from service import FontFileService from service import FontService from service import InstalledFontService @@ -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 ) diff --git a/utility/Initializer.py b/utility/Initializer.py index eadb36a..3e7b086 100755 --- a/utility/Initializer.py +++ b/utility/Initializer.py @@ -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("~")