Skip to content

Commit

Permalink
Merge pull request #144 from vindevoy/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
vindevoy authored Apr 17, 2020
2 parents 1d4d9cc + f4a0f4e commit 65e73a4
Show file tree
Hide file tree
Showing 63 changed files with 1,994 additions and 788 deletions.
26 changes: 26 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@

# VERSION 1.2.0

## Release info

- author: Yves Vindevogel (vindevoy)
- date: 2020-04-17

## Enhancements

- Code is now following the Model-View-Controller pattern
- Logging updated for CherryPy and added for CherryBlog
- Updated the caching system, all data is stored in memory
- Server can now run in daemon mode, including user privileges
- Try Except added when reading configuration and content
- Texts are now in I8N directory, for future translations
- Static directories and static files can be served
- Separator is now a setting
- Minor bug fixes


### Github

For more information on this release, see the issues for this milestone:

- [https://github.com/vindevoy/cherryblog/milestone/6](https://github.com/vindevoy/cherryblog/milestone/6)

# VERSION 1.1.1

## Release info
Expand Down
19 changes: 7 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@

clean:
@find . -name '__pycache__' -type d -delete
@find . -name '*.log' -type f -delete
@rm -rf ./tmp ./log ./download

@echo '[OK] Cleaned'

setup:
@mkdir -p ./src/application
@mkdir -p ./src/theme/default
@mkdir -p ./src/data/pages
@mkdir -p ./src/data/blog
@mkdir -p ./src/data/site
@touch ./src/data/site/settings.yml

@echo '[OK] Setup has created the /src directory and sub-directories'

download: clean
@mkdir -p ./tmp
@wget -O ./tmp/startbootstrap-blog-home.zip https://github.com/BlackrockDigital/startbootstrap-blog-home/archive/gh-pages.zip
Expand Down Expand Up @@ -66,6 +57,10 @@ readme:

history:
@echo '' > ./HISTORY.md
@echo '# VERSION 1.2.0' >> ./HISTORY.md
@echo '' >> ./HISTORY.md
@sed -n '/##/,$$p' ./src/data/posts/0007_version_1_2_0.md >> ./HISTORY.md
@echo '' >> ./HISTORY.md
@echo '# VERSION 1.1.1' >> ./HISTORY.md
@echo '' >> ./HISTORY.md
@sed -n '/##/,$$p' ./src/data/posts/0006_version_1_1_1.md >> ./HISTORY.md
Expand Down Expand Up @@ -108,11 +103,11 @@ history:

develop:
@mkdir -p ./log
@python3 ./src/application/serve.py 2>&1 | tee ./log/develop.log
@python3 ./src/application/main.py 2>&1 | tee ./log/develop.log

production:
@mkdir -p /var/log/cherryblog
@python3 ./src/application/serve.py --env production 2>&1 | tee /var/log/cherryblog/production.log &
@python3 ./src/application/main.py --env production 2>&1 | tee /var/log/cherryblog/production.log &

###
#
Expand Down
117 changes: 117 additions & 0 deletions src/application/common/content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
###
#
# Full history: see below
#
# Version: 1.1.0
# Date: 2020-04-15
# Author: Yves Vindevogel (vindevoy)
#
# Changes:
# - Added logging
# - Added try except on read of the files in case they don't exist
#
###

import logging
import markdown
import os
import yaml

from common.options import Options
from common.singleton import Singleton


class Content(metaclass=Singleton):
__logger = None
__meta_content_separator = None

def __init__(self):
self.__logger = logging.getLogger('COMMON.CONTENT')
self.__logger.setLevel(Options().default_logging_level)

def load_data_settings_yaml(self, directory):
self.__logger.debug('load_data_settings_yaml - '
'Loading settings.yml from data sub-directory {0}.'.format(directory))

return self.load_settings_yaml(os.path.join(Options().data_dir, directory))

def load_settings_yaml(self, directory):
self.__logger.debug('load_settings_yaml - Loading settings.yml from directory {0}.'.format(directory))

return self.load_yaml(directory, 'settings.yml')

def load_data_yaml(self, directory, file):
self.__logger.debug('load_data_yaml - Loading {0} from directory {1}.'.format(file, directory))

return self.load_yaml(os.path.join(Options().data_dir, directory), file)

def load_yaml(self, directory, file):
self.__logger.debug('load_yaml - Loading {0} from directory {0}.'.format(file, directory))

# If the file cannot be read (for instance when the user deleted the directory in data)
# don't care, return blanks
try:
yaml_file = open(os.path.join(directory, file), 'r')
except FileNotFoundError:
self.__logger.warning('COULD NOT FIND THE YAML FILE {0}/{1}'.format(directory, file))
return {}

content = yaml.load(yaml_file, Loader=yaml.SafeLoader)

# In case there's an empty file, yaml returns a None instead of a empty structure
if content is None:
content = {}

self.__logger.debug('load_yaml - Content of yaml:\n{0}'.format(content))

return content

def read_content(self, directory, file):
content_dir = os.path.join(Options().data_dir, directory)
self.__logger.debug('read_content - Reading content file {0} from directory {0}.'.format(file, content_dir))

try:
content_file = open(os.path.join(content_dir, file), 'r')
except FileNotFoundError:
self.__logger.warning('COULD NOT FIND THE YAML FILE {0}/{1}'.format(directory, file))
return {}, ''

meta, raw, html = self.__split_file(content_file.read())
# No logging, already logged

return meta, raw, html

def __split_file(self, data):
if self.__meta_content_separator is None:
self.__meta_content_separator = Options().meta_content_separator

self.__logger.debug('__split_file - Split file separator is {0}'.format(self.__meta_content_separator))

split = data.split(self.__meta_content_separator)

meta = split[0]
content_raw = ""

if len(split) == 2:
content_raw = split[1]
else:
self.__logger.debug('__split_file - No content found.')

meta_data = yaml.load(meta, Loader=yaml.SafeLoader)
self.__logger.debug('__split_file - Meta data:\n{0}'.format(meta_data))

self.__logger.debug('__split_file - Markdown data:\n{0}'.format(content_raw))
content_html = markdown.markdown(content_raw)
self.__logger.debug('__split_file - HTML:\n{0}'.format(content_html))

return meta_data, content_raw, content_html

###
#
# Version: 1.0.0
# Date: 2020-04-13
# Author: Yves Vindevogel (vindevoy)
#
# This class was split of the DataLoader class
#
###
57 changes: 57 additions & 0 deletions src/application/common/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
###
#
# Full history: see below
#
# Version: 2.0.0
# Date: 2020-04-13
# Author: Yves Vindevogel (vindevoy)
#
# Renamed class from OptionsLoader to Options (as it's not loading anything)
#
###

from common.singleton import Singleton


class Options(metaclass=Singleton):
# Will be used for loading the correct file
environment = ''

# Directories set through the command line
data_dir = ''

# Directories set from the settings file (environment.yml)
theme_dir = ''
log_dir = ''
run_dir = ''

# Properties set from the settings file (environment.yml)
daemon = False
meta_content_separator = ''

# User privileges can be used to start as root and run on port 80 (privileged port)
# and then run with a user with less rights
privileges = False
uid = 0
gid = 0

default_logging_level = ''

###
#
# Version: 1.1.0
# Date: 2020-04-13
# Author: Yves Vindevogel (vindevoy)
#
# Features:
# - Extra properties for
# - Daemon
# - Extra directories
# - privileges (starting as root, lower to other user and group)
#
# Version: 1.0.0
# Date: 2020-04-09
# Author: Yves Vindevogel (vindevoy)
#
# Original code
###
File renamed without changes.
Loading

0 comments on commit 65e73a4

Please sign in to comment.