kopia lustrzana https://github.com/corrscope/corrscope
Datestamp --profile filenames, add GUI --profile (#104)
rodzic
223e7e2c35
commit
c58140002f
|
@ -161,6 +161,7 @@ fabric.properties
|
|||
|
||||
|
||||
|
||||
*-cprofile-*
|
||||
*.ipynb
|
||||
.directory
|
||||
*.orig
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import datetime
|
||||
from itertools import count
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, Tuple, Union
|
||||
from typing import Optional, List, Tuple, Union, Iterator
|
||||
|
||||
import click
|
||||
|
||||
|
@ -166,8 +167,18 @@ def main(
|
|||
cfg_dir = '.'
|
||||
|
||||
if show_gui:
|
||||
from corrscope import gui
|
||||
gui.gui_main(cfg, cfg_path)
|
||||
def command():
|
||||
from corrscope import gui
|
||||
return gui.gui_main(cfg, cfg_path)
|
||||
|
||||
if profile:
|
||||
import cProfile
|
||||
|
||||
# Pycharm can't load CProfile files with dots in the name.
|
||||
profile_dump_name = get_profile_dump_name('gui')
|
||||
cProfile.runctx('command()', globals(), locals(), profile_dump_name)
|
||||
else:
|
||||
command()
|
||||
|
||||
else:
|
||||
if not files:
|
||||
|
@ -186,24 +197,35 @@ def main(
|
|||
outputs.append(FFmpegOutputConfig(video_path))
|
||||
|
||||
if outputs:
|
||||
assert CorrScope # to prevent PyCharm from deleting the import
|
||||
arg = Arguments(cfg_dir=cfg_dir, outputs=outputs)
|
||||
command = lambda: CorrScope(cfg, arg).play()
|
||||
if profile:
|
||||
import cProfile
|
||||
|
||||
# Pycharm can't load CProfile files with dots in the name.
|
||||
profile_dump_name = Path(files[0]).name.split('.')[0]
|
||||
profile_dump_name += f'-{PROFILE_DUMP_NAME}'
|
||||
|
||||
# Write stats to unused filename
|
||||
for i in count():
|
||||
path = Path(profile_dump_name + str(i))
|
||||
if not path.exists():
|
||||
break
|
||||
|
||||
# noinspection PyUnboundLocalVariable
|
||||
cProfile.runctx('command()', globals(), locals(), str(path))
|
||||
|
||||
first_song_name = Path(files[0]).name.split('.')[0]
|
||||
profile_dump_name = get_profile_dump_name(first_song_name)
|
||||
cProfile.runctx('command()', globals(), locals(), profile_dump_name)
|
||||
else:
|
||||
command()
|
||||
|
||||
|
||||
def get_profile_dump_name(prefix: str) -> str:
|
||||
now = datetime.datetime.now()
|
||||
now = now.strftime('%Y-%m-%d_T%H-%M-%S')
|
||||
|
||||
profile_dump_name = f'{prefix}-{PROFILE_DUMP_NAME}-{now}'
|
||||
|
||||
# Write stats to unused filename
|
||||
for path in add_numeric_suffixes(profile_dump_name):
|
||||
if not Path(path).exists():
|
||||
return path
|
||||
|
||||
|
||||
def add_numeric_suffixes(s: str) -> Iterator[str]:
|
||||
""" f('foo')
|
||||
yields 'foo', 'foo2', 'foo3'...
|
||||
"""
|
||||
yield s
|
||||
for i in count(2):
|
||||
yield s + str(i)
|
||||
|
|
Ładowanie…
Reference in New Issue