added support for custom config file paths

This commit is contained in:
deadvey 2025-04-12 14:36:12 +01:00
parent d54da0ac66
commit 66efd0c696
7 changed files with 80 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
config.py config.py
htmlconfig.py
__pycache__ __pycache__
*.swp *.swp
log log

View File

@ -1,10 +1,8 @@
import users
import posts
import rebuild import rebuild
import click import click
def editpost(userID, datetime): def editpost(userID, datetime, config, posts, users):
post_counter = 0 post_counter = 0
user_posts = [] user_posts = []
print("Which post do you want to edit?") print("Which post do you want to edit?")

View File

@ -1,4 +1,17 @@
import sys # Command line arguments
from importlib.machinery import SourceFileLoader
from datetime import datetime
import newpost
import editpost
import rebuild
import initialise import initialise
config_file_path = "config.py"
if len(sys.argv) > 1:
for argument in sys.argv:
if argument[:9] == "--config=":
config_file_path = argument[9:]
try: try:
import posts import posts
except: except:
@ -10,19 +23,13 @@ except:
print("No users database") print("No users database")
initialise.initialise() initialise.initialise()
try: try:
import config config = SourceFileLoader("config", config_file_path).load_module()
if config.autogenerated == True: if config.autogenerated == True:
print("Error: autogenerated = True") print("Error: autogenerated = True")
exit() exit()
except: except:
print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False") print("Please move example.config.py to config.py and edit the options to your case and then set autogenerated=False")
exit() exit()
import newpost
import editpost
import rebuild
import sys # Command line arguments
from datetime import datetime
if len(sys.argv) > 1: if len(sys.argv) > 1:
for argument in sys.argv: for argument in sys.argv:
@ -53,8 +60,8 @@ if user_present == True:
answer = input() answer = input()
if answer == 'N' or answer == '0': if answer == 'N' or answer == '0':
newpost.newpost(userID, username, datetime) newpost.newpost(userID, username, datetime, config, posts, users)
if answer == 'E' or answer == '1': if answer == 'E' or answer == '1':
editpost.editpost(userID, datetime) editpost.editpost(userID, datetime, config, posts, users)
else: else:
print('Sorry, that account does not exist, If it should, please ask the webadmin to add this account') print('Sorry, that account does not exist, If it should, please ask the webadmin to add this account')

59
htmlconfig.py Normal file
View File

@ -0,0 +1,59 @@
### General ###
site_url = "https://deadvey.com/blog/"
site_name = "DeaDvey's Blog"
site_description = "Linux, tech and reviews"
webroot = "/var/www/deadvey.com/blog/"
date_format = "%d/%m/%Y at %H:%M" # The date that is displayed on the page
post_seperator = "---------------------------------------------"
posts_in_timeline = 100
file_extension = "html"
### Feeds ###
atom = False
rss = True
### Logging ###
logfile = "/home/max/glogger/log"
verbose = False
### Format ###
# The syntax for this is pretty simple
# %S - post seperator as defined by post_seperator
# %T - Title
# %D - Published date in the format specified by date_format
# %E - Edited date in the format specified by date_format
# %C - Post content
# %L - URL Permanent link to the post
# %U - URL the the user (poster)
# %H - URL to the site home page /
# %N - the username of the user (poster)
# %R - Site wide RSS feed
# %Y - Site Name as defined by site_name
# %y - Site Descriptin as defined by site_description
site_header = '''
<h1>%Y</h1>
<b>%y</b>
<a href="%R">RSS Feed</a>
'''
user_page_post_format = '''
<h2>%T</h2>
<pre style="white-space: pre-wrap;">%C</pre>
<a href="%L">permalink</a>
<hr/>
'''
post_page_post_format = '''
<h1>Posted by %N</h1>
<h2>%T</h2>
<i>Published: %D</i>
<pre style="white-space: pre-wrap;">%C</pre>
<a href="%U">%N</a>
<i>Published: %D</i>
<i>Last Edited: %E</i>
'''
timeline_post_format = '''
<h3>%T</h3>
<pre style="white-space: pre-wrap;">%C</pre>
<a href="%L">permalink</a>
<hr/>
'''
autogenerated = False

View File

@ -15,7 +15,7 @@ except:
print("No users database") print("No users database")
import output import output
def newpost(userID, username, datetime): def newpost(userID, username, datetime, config, posts, users):
title = input("Title: ") title = input("Title: ")
content = click.edit() content = click.edit()
content = content.replace("'", "\'") content = content.replace("'", "\'")

View File

@ -11,6 +11,7 @@ def parse_post_format(post, post_index, username):
post = post.replace("%C", post_data["content"]) post = post.replace("%C", post_data["content"])
post = post.replace("%L", f"{config.site_url}/post/{post_index}.{config.file_extension}") post = post.replace("%L", f"{config.site_url}/post/{post_index}.{config.file_extension}")
post = post.replace("%U", f"{config.site_url}/user/{username}.{config.file_extension}") post = post.replace("%U", f"{config.site_url}/user/{username}.{config.file_extension}")
post = post.replace("%H", f"{config.site_url}/")
post = post.replace("%N", username) post = post.replace("%N", username)
return post return post

1
posts.py.back Normal file

File diff suppressed because one or more lines are too long