Commit eb701d6e by Denis Salem

progress on datastore and entries

parent 04fbbb21
......@@ -86,9 +86,8 @@
WIP | No more awkward silence when something is successfully done.
WIP | Add more coloration for message!
WIP | Speed up blog exportation
WIP | Massive refactorisation and code cleaning.
WIP | Massive refactorisation, code cleaning and optimisation.
TODO | Auto include CSS
TODO | Change nomenclature entry_name -> title. Fix doc.
TODO | warn about missing mandatory field in entry
TODO | Add GetIfExist
TODO | Fix vertical scroll bar in code snippet.
......@@ -96,3 +95,5 @@
TODO | Clean up installation
TODO | Client-side search engine.
TODO | Add translation for Deutsch and Spanish
TODO | Change nomenclature: entry_name -> title. Fix doc.
TODO | Change nomenclature: thread_order must become a boolean known as reverse
File mode changed
#! /usr/bin/python
from VenC.configuration import GetBlogConfiguration
from VenC.entry import GetEntriesList
from VenC.entry import YieldEntriesContent
from VenC.entry import GetEntry
class DataStore:
def __init__(self):
self.blogConfiguration = GetBlogConfiguration
self.entries = dict()
for entry in GetEntriesList():
self.entries[entry] = GetEntry()
self.blogConfiguration = GetBlogConfiguration()
self.entries = list()
''' Entry index is different from entry id.'''
for entryIndex, filename in YieldEntriesContent():
self.entries.append(GetEntry(filename))
entryIndex+=1
def GetEntries(reverse=False):
for entry in (self.entries[::-1] if reverse else self.entries):
yield entry
'''
self.entriesPerDates = GetEntriesPerDates(self.entriesList, self.blogConfiguration["path"]["dates_directory_name"])
self.entriesPerCategories = GetEntriesPerCategories(self.entriesList)
......
......@@ -5,6 +5,12 @@ import os
import time
import yaml
from VenC.helpers import Die
from VenC.helpers import Notify
from VenC.l10n.auto import Messages
from VenC.datastore.metadata import
class Entry:
def __init__(self, filename):
''' Loading '''
......@@ -68,40 +74,42 @@ class Entry:
except KeyError:
Die(Messages.missingMandatoryFieldInEntry.format("tags", self.id))
def GetSortedEntriesList(inputEntries, threadOrder):
return sorted(inputEntries, key = lambda e : int(e.split("__")[0]), reverse=(threadOrder.strip() == "latest first"))
def GetEntriesList():
def YieldEntriesContent():
try:
files = os.listdir(os.getcwd()+"/entries")
except FileNotFoundError as e:
Die(Messages.fileNotFound.format(os.getcwd()+"/entries"))
entryIndex = 0
for filename in sorted(
os.listdir(os.getcwd()+"/entries"),
key = lambda e : int(e.split("__")[0]),
reverse=(threadOrder.strip() == "latest first")
):
explodedFilename = filename.split("__")
try:
date = explodedFilename[1].split('-')
entryID = int(explodedFilename[0])
datetime.datetime(
year=int(date[2]),
month=int(date[0]),
day=int(date[1]),
hour=int(date[3]),
minute=int(date[4])
)
if entryID > 0:
yield entryIndex, filename
entryIndex+=1
else:
raise ValueError
except ValueError:
Notify(Messages.invalidEntryFilename.format(filename), "YELLOW")
except IndexError:
Notify(Messages.invalidEntryFilename.format(filename), "YELLOW")
entries = list()
for filename in files:
explodedFilename = filename.split("__")
try:
date = explodedFilename[1].split('-')
entryID = int(explodedFilename[0])
datetime.datetime(
year=int(date[2]),
month=int(date[0]),
day=int(date[1]),
hour=int(date[3]),
minute=int(date[4])
)
if entryID > 0:
entries.append(filename)
except ValueError:
Notify(Messages.invalidEntryFilename.format(filename), "YELLOW")
except IndexError:
Notify(Messages.invalidEntryFilename.format(filename), "YELLOW")
return entries
'''
except FileNotFoundError:
Die(Messages.fileNotFound.format(os.getcwd()+"/entries"))
def GetLatestEntryID():
entriesList = sorted(GetEntriesList(), key = lambda entry : int(entry.split("__")[0]))
......@@ -109,7 +117,7 @@ def GetLatestEntryID():
return int(entriesList[-1].split("__")[0])
else:
return 0
'''
def SetNewEntryMetadata(entryDate, entryName, blogConfiguration):
entry = dict()
entry["EntryID"] = GetLatestEntryID()+1
......
#! /usr/bin/python3
def PrintCategoriesTree(tree,indentation=""):
for node in tree:
print(indentation+node.value, "->", node.relatedTo)
PrintCategoriesTree(node.childs,indentation+"\t")
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment