65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
# coding:utf-8
|
|
"""
|
|
Author: Sir Garbagetruck --<truck@notonfire.somewhere>
|
|
Purpose: make editing the list.sahli file easier
|
|
Created: 2020/04/09
|
|
"""
|
|
|
|
import json
|
|
import argparse
|
|
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 = SF.sahlifile(None)
|
|
else:
|
|
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
|
|
|
|
|
|
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())
|