From 6e5c28c9c42c0d8799ac4427380a12483fa2982f Mon Sep 17 00:00:00 2001 From: Howland Owl Date: Thu, 9 Apr 2020 19:59:12 +0300 Subject: [PATCH] Refactoring the way we create blank files. --- editor.py | 44 +++++++++++++++++++++++-- sahliEditorPython/sahlifile.py | 59 +++++++++++++++++++++++++++++++--- 2 files changed, 96 insertions(+), 7 deletions(-) diff --git a/editor.py b/editor.py index 6fc2ce9..2ddfa05 100644 --- a/editor.py +++ b/editor.py @@ -8,15 +8,51 @@ import json import argparse -import sahliEditorPython +import os +from sahliEditorPython import sahlifile as SF + + +def getfilesindir(directory): + """return the files in a directory as an array""" + for root, dirs, files, rootfd in os.fwalk(directory): + return files + +# ---------------------------------------------------------------------- + + +def getfilenames(filedata): + """return the file names from a sahli filedata array""" + f = [] + for i in filedata: + f.append(i['file']) + return f + + +def getdata(filedata, name): + """get the filedata entry where file = name""" + for i in filedata: + if i['file'] == name: + return i + return [] def main(args): """maintain a list.sahli file""" if args.new: - mysahli = sahliEditorPython.sahlifile() + mysahli = SF.sahlifile(None) else: - mysahli = sahliEditorPython.sahlifile(args.filename) + mysahli = SF.sahlifile(args.filename) + mysahli.sahli['location'] = args.directory + files = getfilesindir(args.directory) + filedata = mysahli.sahli['filedata'] + filedatanames = getfilenames(filedata) + newdata = [] + for i in files: + if i in filedatanames: + print('found! {}'.format(i)) + newdata.append(getdata(filedata, i)) + else: + print('not found! {}'.format(i)) a = 5 @@ -24,4 +60,6 @@ if __name__ == '__main__': ap = argparse.ArgumentParser() ap.add_argument('-f', '--filename', default='list.sahli') ap.add_argument('-n', '--new', action='store_true') + ap.add_argument('-d', '--directory', type=str, required=True, + help='directory where compo files are') main(ap.parse_args()) diff --git a/sahliEditorPython/sahlifile.py b/sahliEditorPython/sahlifile.py index 8d366bc..0f3e631 100644 --- a/sahliEditorPython/sahlifile.py +++ b/sahliEditorPython/sahlifile.py @@ -37,9 +37,7 @@ class sahlifile: else: location = self.blank_location() slides = self.blank_slides() - filedata = [ - self.blank_filedata() - ] + filedata = [] self.sahli = { 'location': location, 'slides': slides, @@ -55,9 +53,62 @@ class sahlifile: } def blank_location(self): - "blank location structure" + """blank location structure""" return '' + def blank_picture(self): + """Blank picture structure""" + return { + 'file': '', + 'name': '', + 'amiga': False, + 'filetype': 'image', + 'width': '1600', + 'author': '', + 'font': 'Propaz', + 'color': [0, 0, 0, 255], + 'bg': [255, 255, 255, 255], + 'line1': '', + 'line2': '', + 'text': '' + } + # ---------------------------------------------------------------------- + + def blank_amiga_ascii(self): + """blank amiga ascii""" + return { + 'file': '', + 'name': '', + 'amiga': True, + 'filetype': 'plain', + 'width': '80', + 'author': '', + 'font': 'Propaz', + 'color': [250, 250, 250, 255], + 'bg': [0, 0, 0, 255], + 'line1': '', + 'line2': '', + 'text': '' + } + # ---------------------------------------------------------------------- + + def blank_ansi(self): + """blank PC Ansi""" + return { + 'file': '', + 'name': '', + 'amiga': False, + 'filetype': 'ansi', + 'width': '80', + 'author': '', + 'font': 'Propaz', + 'color': [255, 255, 255, 255], + 'bg': [0, 0, 0, 255], + 'line1': '', + 'line2': '', + 'text': '' + } + def blank_filedata(self): """Blank filedata structure"""