generated from itdominator/Python-With-Gtk-Template
Added proper folder generation and manifest setup
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
# Python imports
|
||||
import os
|
||||
import json
|
||||
import datetime
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import uuid
|
||||
|
||||
# Lib imports
|
||||
|
||||
@@ -99,6 +101,61 @@ class Settings(StartCheckMixin):
|
||||
|
||||
self._builder.connect_signals(handlers)
|
||||
|
||||
def generate_section_manifest(self):
|
||||
path = self.get_active_notebook()
|
||||
sections = os.listdir(path)
|
||||
|
||||
i = 0
|
||||
if len(sections) == 0:
|
||||
return self._generate_manifest(i, path)
|
||||
|
||||
sections = os.listdir(path)
|
||||
for section in sections:
|
||||
index = section.split("_")[0]
|
||||
try:
|
||||
i = int(index)
|
||||
except Exception:
|
||||
...
|
||||
|
||||
return self._generate_manifest(i, path)
|
||||
|
||||
def generate_page_manifest(self, path):
|
||||
pages = self.clean_pages_list( os.listdir(path) )
|
||||
|
||||
i = 0
|
||||
if len(pages) == 0:
|
||||
return self._generate_manifest(i, path, "New Page")
|
||||
|
||||
pages = self.clean_pages_list( os.listdir(path) )
|
||||
for page in pages:
|
||||
index = page.split("_")[0]
|
||||
try:
|
||||
i = int(index)
|
||||
except Exception:
|
||||
...
|
||||
|
||||
return self._generate_manifest(i, path, "New Page")
|
||||
|
||||
def _generate_manifest(self, i, path, name = "New Section"):
|
||||
i += 1
|
||||
section = os.path.join(path, f"{i}_{uuid.uuid4().hex}")
|
||||
manifest = os.path.join(section, "MANIFEST")
|
||||
|
||||
os.mkdir(section)
|
||||
with open(manifest, "w") as f:
|
||||
f.write(f"name={name}\ndate={datetime.datetime.now()}")
|
||||
f.close()
|
||||
|
||||
return manifest
|
||||
|
||||
def clean_pages_list(self, pages):
|
||||
for i, page in enumerate(pages):
|
||||
if page == "MANIFEST":
|
||||
del pages[i]
|
||||
break
|
||||
|
||||
return pages
|
||||
|
||||
def set_main_window(self, window): self._main_window = window
|
||||
def set_builder(self, builder) -> any: self._builder = builder
|
||||
def set_active_notebook(self, path: str): self._active_notebook = path
|
||||
|
||||
Reference in New Issue
Block a user