From e51bec49095026d4174ff010f6405e44c9029fa1 Mon Sep 17 00:00:00 2001 From: Howland Owl Date: Fri, 10 Apr 2020 02:10:56 +0300 Subject: [PATCH] Actually handle a new file, and create a sahli file - just ansi for now --- editor.py | 27 ++++++++++++++++++++++++--- sahliEditorPython/sahlifile.py | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/editor.py b/editor.py index d7c5a27..d5640e4 100644 --- a/editor.py +++ b/editor.py @@ -48,7 +48,9 @@ def getansidata(filename): 'group': saucedata.group, 'title': saucedata.title, 'filesize': saucedata.filesize, - 'comments': saucedata.comments + 'comments': saucedata.comments, + 'width': None, + 'height': None } tinfonames = [saucedata.tinfo1_name, saucedata.tinfo2_name, @@ -87,6 +89,7 @@ def main(args): dirfile = '{}/{}'.format(args.directory, i) if i in filedatanames: print('found! {}'.format(i)) + # todo: _if_ I ever make this a non-preparser, then... futz with a = getansidata(dirfile) newdata.append(getdata(filedata, i)) else: @@ -95,21 +98,39 @@ def main(args): if suf in ['png', 'jpg', 'jpeg', 'gif', 'PNG', 'JPG', 'JPEG', 'GIF']: stuff = getpicdata(dirfile) + a = 5 elif suf in ['ans', 'ANS', 'BIN', 'bin', 'XB', 'xb']: stuff = getansidata(dirfile) - a = 5 + entry = mysahli.blank_ansi() + entry['file'] = i + entry['name'] = stuff['title'] + entry['author'] = '{}/{}'.format( + stuff['author'], stuff['group']) + entry['text'] = stuff['comments'] + if stuff['height'] is not None: + entry['height'] = stuff['height'] + if stuff['width'] is not None: + entry['width'] = stuff['width'] + newdata.append(entry) elif suf in ['TXT', 'ASC', 'txt', 'asc', 'NFO', 'nfo', 'diz', 'DIZ']: stuff = getamigadata(dirfile) else: print("dunno what type of file this is...") - a = 5 + mysahli.sahli['filedata'] = newdata + out = json.dumps(mysahli.sahli, sort_keys=False, indent=4) + if args.outfile == '>stdout': + print(out) + else: + with open(args.outfile, 'w') as f: + json.dump(mysahli.sahli, f, sort_keys=False, indent=4) 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('-o', '--outfile', type=str, default='>stdout') 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 0f3e631..598614e 100644 --- a/sahliEditorPython/sahlifile.py +++ b/sahliEditorPython/sahlifile.py @@ -51,6 +51,7 @@ class sahlifile: 'template': '', 'css': '' } + return slides def blank_location(self): """blank location structure"""