Refactoring the way we create blank files.

This commit is contained in:
Howland Owl 2020-04-09 19:59:12 +03:00
parent 97d1b1ebe5
commit 6e5c28c9c4
2 changed files with 96 additions and 7 deletions

View file

@ -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())

View file

@ -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"""