Commit 82269ee6 authored by shadMod's avatar shadMod 💬

replaced old copy tree data news with GetNews().init_assets_news()

added debug param
parent 08dafe75
......@@ -85,7 +85,7 @@ def create_app(data_path, debug=False):
return app
def init_data_directory(data_path: str):
def init_data_directory(data_path: str, debug: bool = False):
"""Initialize the data directory"""
src_directory = os.path.dirname(os.path.abspath(__file__))
......@@ -94,23 +94,15 @@ def init_data_directory(data_path: str):
for _dir in dirs:
os.makedirs(os.path.join(data_path, _dir), exist_ok=True)
# Copy news tree dirs and file
ROOT_NEWS = os.path.join(BASE_DIR, "assets/news")
NEWS_PATH = os.path.join(data_path, "news")
if sys.version_info[:2] > (3, 8):
shutil.copytree(ROOT_NEWS, NEWS_PATH, dirs_exist_ok=True)
else:
try:
# if path already exists, remove it before copying with copytree()
if os.path.exists(NEWS_PATH):
shutil.rmtree(NEWS_PATH)
shutil.copytree(ROOT_NEWS, NEWS_PATH)
else:
shutil.copytree(ROOT_NEWS, NEWS_PATH)
except OSError as ex:
shutil.copy(ROOT_NEWS, NEWS_PATH)
except Exception as ex:
print(ex)
news_path = os.path.join(data_path, "news")
os.makedirs(news_path, exist_ok=True) # check if exists
if not os.listdir(news_path) or debug:
# init ROOT_NEWS and NEWS_PATH
ROOT_NEWS = os.path.join(BASE_DIR, "assets/news")
NEWS_PATH = os.path.join(data_path, "news")
# clean and populate news directory with all news and create indexes
nw_cl = GetNews(data_path)
nw_cl.init_assets_news(ROOT_NEWS, NEWS_PATH)
# Initialize the cache
static_dirs = {"static": "+assets"}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment