Skip to content

Commit

Permalink
allow duplicate builds; change banner image name
Browse files Browse the repository at this point in the history
  • Loading branch information
zserhan committed Aug 11, 2022
1 parent 4b94580 commit e66cc3d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions content_management/library_db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def insert_data(self, conn):
except Error as e:
raise Exception("error while inserting data into tables:" + str(e))

def create_library_db(self, version):
database = os.path.join(os.path.abspath(settings.BUILDS_ROOT), version.version_number, 'solarspell.db')
def create_library_db(self, build_path):
database = os.path.join(build_path, 'solarspell.db')
sql_create_metadata_type_table = """CREATE TABLE IF NOT EXISTS metadata_type (
id INTEGER PRIMARY KEY,
type_name TEXT NOT NULL
Expand Down
37 changes: 22 additions & 15 deletions content_management/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os
import shutil
import time
from pathlib import Path

from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -212,9 +213,16 @@ def build_library(self):
db_util = LibraryDbUtil(metadata_types, metadata, folders, modules, contents, contents_metadata,
contents_folder)
try:
self.create_asset_folder(folders.filter(parent_id=None), modules)
db_util.create_library_db(self.version)
self.copy_library_files(contents)
build_path = os.path.join(os.path.abspath(settings.BUILDS_ROOT), self.version.version_number)
if not os.path.isdir(build_path):
os.makedirs(build_path)
else:
build_path = build_path + "_" + str(int(time.time()))
os.makedirs(build_path)
print("Directory '% s' successfully created" % build_path)
self.create_asset_folder(folders.filter(parent_id=None), modules, build_path)
db_util.create_library_db(build_path)
self.copy_library_files(contents, build_path)
print("success creating content folder")
data = {
'result': 'success',
Expand Down Expand Up @@ -264,14 +272,14 @@ def get_modules_names(self, modules):
except Exception as e:
raise e

def copy_library_files(self, files_list):
def copy_library_files(self, files_list, build_path):
"""
This method copy the files of the library to be built into a separate folder to be exported
:param files_list:
:return: boolean value indicating success/failure of operation
"""
dir_path = os.path.join(os.path.abspath(settings.BUILDS_ROOT), self.version.version_number, "content/")
if not os.path.exists(dir_path):
dir_path = os.path.join(build_path, "content/")
if not os.path.isdir(dir_path):
os.makedirs(dir_path)
print("Directory '% s' successfully created" % dir_path)
try:
Expand All @@ -283,17 +291,14 @@ def copy_library_files(self, files_list):
print("file '% s' doesn't exist in content folder: " % src_dir)
os.remove(dir_path)

def create_asset_folder(self, categories, modules):
def create_asset_folder(self, categories, modules, build_path):
"""
This method creates the asset folder that contains the logos, banner image, and a json file that has information
about the library version
"""
logos_path = os.path.join(os.path.abspath(settings.BUILDS_ROOT), self.version.version_number,
"assets/images/logos")
banners_path = os.path.join(os.path.abspath(settings.BUILDS_ROOT), self.version.version_number,
"assets/images/banners")
config_path = os.path.join(os.path.abspath(settings.BUILDS_ROOT), self.version.version_number,
"assets/config.json")
logos_path = os.path.join(build_path, "assets/images/logos")
banners_path = os.path.join(build_path, "assets/images/banners")
config_path = os.path.join(build_path, "assets/config.json")
if not os.path.exists(logos_path):
os.makedirs(logos_path)
print("Directory '% s' successfully created" % logos_path)
Expand All @@ -313,9 +318,11 @@ def create_asset_folder(self, categories, modules):
shutil.copy(src_dir, logos_path)
src_dir = os.path.join(os.path.abspath(settings.MEDIA_ROOT), self.version.library_banner.image_file.path)
shutil.copy(src_dir, banners_path)
# rename banner image to banner.png since since this is what the frontend looks for
os.rename(os.path.join(banners_path, os.path.basename(self.version.library_banner.image_file.path)),
os.path.join(banners_path, "banner.png"))
# create config.json
config = {"version": self.version.version_number,
"banner": "assets/" + self.version.library_banner.image_file.path}
config = {"version": self.version.version_number}
with open(config_path, 'w') as f:
json.dump(config, f)
return True
Expand Down
2 changes: 1 addition & 1 deletion content_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def get(self, request, *args, **kwargs):
version_id = int(kwargs['version_id'])
build_util = LibraryBuildUtil(version_id)
result = build_util.build_library()
if result.get("result") is "success":
if result.get("result") == "success":
return build_response(result)
else:
return build_response(
Expand Down
1 change: 0 additions & 1 deletion frontend/src/js/libraries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ interface LibrariesState {
modals: LibrariesModals
selected_folders: LibraryFolder[]
selected_files: SerializedContent[]

}

interface LibrariesModals {
Expand Down

0 comments on commit e66cc3d

Please sign in to comment.