photos in config order, always modify config if new files appear

This commit is contained in:
Ville Rantanen
2021-08-19 10:49:35 +03:00
parent fa8798d6b1
commit 69d14b2337
2 changed files with 17 additions and 10 deletions

View File

@@ -24,39 +24,42 @@ class Mirva:
self.create_config() self.create_config()
print("Exiting. Check config.") print("Exiting. Check config.")
return return
self.create_config()
self.get_config() self.get_config()
self.create_posts() self.create_posts()
self.write_index() self.write_index()
self.write_mediums() self.write_mediums()
def create_config(self): def create_config(self):
print("Creating config: {}".format(os.path.join(self.options.folder,self.config_file)))
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(self.config_file) config.read(self.config_file)
config_changed = False
if not "SITE" in config: if not "SITE" in config:
config["SITE"] = { config["SITE"] = {
"title": "", "title": "",
"sub_title": "", "sub_title": "",
"intro": "", "intro": "",
} }
config_changed = True
for f in self.file_list: for f in self.file_list:
if not f in config: if not f in config:
config[f] = {"title": f, "description": ""} config[f] = {"title": f, "description": ""}
config_changed = True
if config_changed:
print("Modified config: {}".format(os.path.join(self.options.folder,self.config_file)))
with open(self.config_file, "wt") as fp: with open(self.config_file, "wt") as fp:
config.write(fp) config.write(fp)
def create_posts(self): def create_posts(self):
self.posts = [] self.posts = []
for f in self.file_list: for c in self.config:
if not f in self.config: if c in self.file_list:
post = self.get_post(f, f, "")
else:
post = self.get_post( post = self.get_post(
f, self.config[f]["title"], self.config[f]["description"] c, self.config[c]["title"], self.config[c]["description"]
) )
self.posts.append(post) self.posts.append(post)
@@ -218,6 +221,8 @@ function create_button(direction, to) {{
pass pass
for f in ("style.css", "arrow_up.png", "arrow_down.png", "banner.jpg", "mirva.ico"): for f in ("style.css", "arrow_up.png", "arrow_down.png", "banner.jpg", "mirva.ico"):
if os.path.exists(os.path.join(self.resource_dir, f)):
continue
shutil.copy( shutil.copy(
os.path.join(self.resource_src, f), os.path.join(self.resource_dir, f) os.path.join(self.resource_src, f), os.path.join(self.resource_dir, f)
) )
@@ -251,6 +256,8 @@ function create_button(direction, to) {{
"85", "85",
outfile, outfile,
] ]
sys.stdout.write(".")
subprocess.call(convargs) subprocess.call(convargs)

View File

@@ -6,7 +6,7 @@ setup(
], ],
package_data={'':['resources/*']}, package_data={'':['resources/*']},
include_package_data=True, include_package_data=True,
version = '20210601', version = '20210819',
description = 'A tool to create a web gallery from a folder of images.', description = 'A tool to create a web gallery from a folder of images.',
author = 'Ville Rantanen', author = 'Ville Rantanen',
author_email = 'ville.q.rantanen@gmail.com', author_email = 'ville.q.rantanen@gmail.com',