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 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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue