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,41 +24,44 @@ class Mirva:
self.create_config()
print("Exiting. Check config.")
return
self.create_config()
self.get_config()
self.create_posts()
self.write_index()
self.write_mediums()
def create_config(self):
print("Creating config: {}".format(os.path.join(self.options.folder,self.config_file)))
config = configparser.ConfigParser()
config.read(self.config_file)
config_changed = False
if not "SITE" in config:
config["SITE"] = {
"title": "",
"sub_title": "",
"intro": "",
}
config_changed = True
for f in self.file_list:
if not f in config:
config[f] = {"title": f, "description": ""}
config_changed = True
with open(self.config_file, "wt") as fp:
config.write(fp)
if config_changed:
print("Modified config: {}".format(os.path.join(self.options.folder,self.config_file)))
with open(self.config_file, "wt") as fp:
config.write(fp)
def create_posts(self):
self.posts = []
for f in self.file_list:
if not f in self.config:
post = self.get_post(f, f, "")
else:
for c in self.config:
if c in self.file_list:
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)
def get_config(self):
self.config = configparser.ConfigParser()
@@ -218,6 +221,8 @@ function create_button(direction, to) {{
pass
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(
os.path.join(self.resource_src, f), os.path.join(self.resource_dir, f)
)
@@ -251,6 +256,8 @@ function create_button(direction, to) {{
"85",
outfile,
]
sys.stdout.write(".")
subprocess.call(convargs)