Refactoring the way we create blank files.
This commit is contained in:
parent
97d1b1ebe5
commit
6e5c28c9c4
2 changed files with 96 additions and 7 deletions
44
editor.py
44
editor.py
|
|
@ -8,15 +8,51 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import argparse
|
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):
|
def main(args):
|
||||||
"""maintain a list.sahli file"""
|
"""maintain a list.sahli file"""
|
||||||
if args.new:
|
if args.new:
|
||||||
mysahli = sahliEditorPython.sahlifile()
|
mysahli = SF.sahlifile(None)
|
||||||
else:
|
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
|
a = 5
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,4 +60,6 @@ if __name__ == '__main__':
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument('-f', '--filename', default='list.sahli')
|
ap.add_argument('-f', '--filename', default='list.sahli')
|
||||||
ap.add_argument('-n', '--new', action='store_true')
|
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())
|
main(ap.parse_args())
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,7 @@ class sahlifile:
|
||||||
else:
|
else:
|
||||||
location = self.blank_location()
|
location = self.blank_location()
|
||||||
slides = self.blank_slides()
|
slides = self.blank_slides()
|
||||||
filedata = [
|
filedata = []
|
||||||
self.blank_filedata()
|
|
||||||
]
|
|
||||||
self.sahli = {
|
self.sahli = {
|
||||||
'location': location,
|
'location': location,
|
||||||
'slides': slides,
|
'slides': slides,
|
||||||
|
|
@ -55,9 +53,62 @@ class sahlifile:
|
||||||
}
|
}
|
||||||
|
|
||||||
def blank_location(self):
|
def blank_location(self):
|
||||||
"blank location structure"
|
"""blank location structure"""
|
||||||
return ''
|
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):
|
def blank_filedata(self):
|
||||||
"""Blank filedata structure"""
|
"""Blank filedata structure"""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue