in-progress peewee rewrite
This commit is contained in:
parent
1b18db3e77
commit
459fd182e5
3 changed files with 88 additions and 45 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
*.bak
|
||||||
|
*.dat
|
||||||
|
*.dir
|
||||||
|
*.pyc
|
86
smoketest.py
86
smoketest.py
|
@ -1,10 +1,10 @@
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
import shelve
|
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Counter, Dict, List, Optional
|
from typing import Counter, Dict, List, Optional
|
||||||
|
|
||||||
|
from peewee import SqliteDatabase
|
||||||
import simfile
|
import simfile
|
||||||
from simfile.notes import NoteData
|
from simfile.notes import NoteData
|
||||||
from simfile.notes.group import group_notes
|
from simfile.notes.group import group_notes
|
||||||
|
@ -13,122 +13,118 @@ from simfile.ssc import SSCChart
|
||||||
from simfile.timing.engine import TimingData
|
from simfile.timing.engine import TimingData
|
||||||
from simfile.timing.displaybpm import displaybpm
|
from simfile.timing.displaybpm import displaybpm
|
||||||
|
|
||||||
|
from .storage import *
|
||||||
|
|
||||||
|
|
||||||
class SimfileError:
|
class SimfileError:
|
||||||
context: str
|
context: str
|
||||||
traceback: Optional[str]
|
traceback: Optional[str]
|
||||||
|
|
||||||
def __init__(self, context: str):
|
def __init__(self, context: str):
|
||||||
self.context = context
|
self.context = context
|
||||||
self.traceback = traceback.format_exc()
|
self.traceback = traceback.format_exc()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.context}: {self.traceback}"
|
return f'{self.context}: {self.traceback}'
|
||||||
|
|
||||||
|
def check_simfile(self, filename: str) -> List[SimfileError]:
|
||||||
def check_simfile(filename: str) -> List[SimfileError]:
|
|
||||||
errors = []
|
errors = []
|
||||||
try:
|
try:
|
||||||
sim = simfile.open(filename)
|
sim = simfile.open(filename)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError("parse"))
|
errors.append(SimfileError('parse'))
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
timing_data = None
|
timing_data = None
|
||||||
try:
|
try:
|
||||||
timing_data = TimingData.from_simfile(sim)
|
timing_data = TimingData.from_simfile(sim)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError("timing"))
|
errors.append(SimfileError('timing'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
displaybpm(sim)
|
displaybpm(sim)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError("displaybpm"))
|
errors.append(SimfileError('displaybpm'))
|
||||||
|
|
||||||
for c, chart in enumerate(sim.charts):
|
for c, chart in enumerate(sim.charts):
|
||||||
try:
|
try:
|
||||||
note_data = NoteData.from_chart(chart)
|
note_data = NoteData.from_chart(chart)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError(f"chart {c} note_data"))
|
errors.append(SimfileError(f'chart {c} note_data'))
|
||||||
try:
|
try:
|
||||||
for _ in group_notes(note_data, join_heads_to_tails=True):
|
for _ in group_notes(note_data, join_heads_to_tails=True):
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError(f"chart {c} group_notes"))
|
errors.append(SimfileError(f'chart {c} group_notes'))
|
||||||
|
|
||||||
if isinstance(chart, SSCChart):
|
if isinstance(chart, SSCChart):
|
||||||
try:
|
try:
|
||||||
displaybpm(sim, chart)
|
displaybpm(sim, chart)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError(f"chart {c} displaybpm"))
|
errors.append(SimfileError(f'chart {c} displaybpm'))
|
||||||
|
|
||||||
# skip the remaining chart tests if timing data parsing failed
|
# skip the remaining chart tests if timing data parsing failed
|
||||||
if timing_data is None:
|
if timing_data is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if isinstance(chart, SSCChart):
|
if isinstance(chart, SSCChart):
|
||||||
try:
|
try:
|
||||||
timing_data = TimingData.from_simfile(sim, chart)
|
timing_data = TimingData.from_simfile(sim, chart)
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError(f"chart {c} timing"))
|
errors.append(SimfileError(f'chart {c} timing'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for _ in time_notes(note_data, timing_data):
|
for _ in time_notes(note_data, timing_data):
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
errors.append(SimfileError(f"chart {c} timed_notes"))
|
errors.append(SimfileError(f'chart {c} timed_notes'))
|
||||||
|
|
||||||
return errors
|
return errors
|
||||||
|
|
||||||
|
|
||||||
def scan_directory(path: str, simfile_errors: Dict[str, List[SimfileError]]):
|
def scan_songs_dir(self, path: str):
|
||||||
stats = Counter()
|
stats = Counter()
|
||||||
for entry in os.scandir(path):
|
for entry in os.scandir(path):
|
||||||
if simfile_errors.get(entry.path) == []:
|
if simfile_errors.get(entry.path) == []:
|
||||||
stats["skipped"] += 1
|
stats['skipped'] += 1
|
||||||
continue
|
continue
|
||||||
if entry.is_dir():
|
if entry.is_dir():
|
||||||
stats.update(scan_directory(entry.path, simfile_errors))
|
stats.update(scan_pack(entry.path))
|
||||||
elif any(entry.name.endswith(ext) for ext in (".sm", ".ssc")):
|
elif any(entry.name.endswith(ext) for ext in ('.sm', '.ssc')):
|
||||||
errors = check_simfile(entry.path)
|
errors = check_simfile(entry.path)
|
||||||
stats["checked"] += 1
|
stats['checked'] += 1
|
||||||
simfile_errors[entry.path] = errors
|
simfile_errors[entry.path] = errors
|
||||||
if errors:
|
if errors:
|
||||||
stats["error"] += 1
|
stats['error'] += 1
|
||||||
pprint.pprint({"path": entry.path, "errors": errors})
|
pprint.pprint({'path': entry.path, 'errors': errors})
|
||||||
else:
|
else:
|
||||||
stats["success"] += 1
|
stats['success'] += 1
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def dir_path(string):
|
def dir_path(string):
|
||||||
if os.path.isdir(string):
|
if os.path.isdir(string):
|
||||||
return string
|
return string
|
||||||
else:
|
else:
|
||||||
raise ValueError("dir_path: not a directory")
|
raise ValueError('dir_path: not a directory')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argparser = argparse.ArgumentParser()
|
argparser = argparse.ArgumentParser()
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"directory",
|
'd',
|
||||||
help="directory of simfiles to scan",
|
'--songs-dir',
|
||||||
|
help='directory of packs to scan',
|
||||||
type=dir_path,
|
type=dir_path,
|
||||||
)
|
)
|
||||||
argparser.add_argument(
|
|
||||||
"-s",
|
|
||||||
"--shelf",
|
|
||||||
help="shelf file to use",
|
|
||||||
default=f"shelf-{simfile.__version__}",
|
|
||||||
)
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
with shelve.open(args.shelf) as simfile_errors:
|
scan_songs_dir(args.songs_dir)
|
||||||
stats = scan_directory(args.directory, simfile_errors)
|
|
||||||
for k, v in stats.items():
|
for k, v in stats.items():
|
||||||
print(k, v)
|
print(k, v)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
43
storage.py
Normal file
43
storage.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from peewee import *
|
||||||
|
|
||||||
|
|
||||||
|
DB = SqliteDatabase("smoketest.db")
|
||||||
|
|
||||||
|
|
||||||
|
class Run(Model):
|
||||||
|
created = DateTimeField()
|
||||||
|
simfile_version = CharField()
|
||||||
|
msdparser_version = CharField()
|
||||||
|
smoketest_version = CharField()
|
||||||
|
success = IntegerField()
|
||||||
|
error = IntegerField()
|
||||||
|
checked = IntegerField()
|
||||||
|
skipped = IntegerField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = DB
|
||||||
|
|
||||||
|
|
||||||
|
class SimfileObject(Model):
|
||||||
|
kind = CharField()
|
||||||
|
path = CharField()
|
||||||
|
simfile_title = CharField(null=True)
|
||||||
|
chart_stepstype = CharField(null=True)
|
||||||
|
chart_meter = CharField(null=True)
|
||||||
|
chart_index = IntegerField(null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = DB
|
||||||
|
|
||||||
|
|
||||||
|
class SimfileError(Model):
|
||||||
|
context = CharField()
|
||||||
|
traceback = CharField(max_length=10000)
|
||||||
|
simfile_object = ForeignKeyField(model=SimfileObject)
|
||||||
|
run = ForeignKeyField(model=Run)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
database = DB
|
||||||
|
|
||||||
|
|
||||||
|
DB.connect()
|
Loading…
Reference in a new issue