Adding interactive shell to main.

This commit is contained in:
Roland 2022-05-18 17:48:44 -06:00
parent dd07236834
commit df72735289
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 31 additions and 1 deletions

30
main.py
View file

@ -43,6 +43,30 @@ def db_main(args):
return 0
INTERACTIVE_BANNER = '''
This is the interactive WROLPi shell. Use this to interact with the WROLPi API library.
Example (get the duration of every video file):
from modules.videos.models import Video
from modules.videos.common import get_video_duration
videos = session.query(Video).filter(Video.video_path != None).all()
videos = list(videos)
for video in videos:
get_video_duration(video.video_path.path)
'''
def launch_interactive_shell():
"""Launches an interactive shell with a DB session."""
import code
from wrolpi.db import get_db_session
modules = import_modules()
with get_db_session() as session:
code.interact(banner=INTERACTIVE_BANNER, local=locals())
async def main(loop):
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='count')
@ -50,6 +74,8 @@ async def main(loop):
parser.add_argument('-c', '--check-media', action='store_true', default=False,
help='Check that the media directory is mounted and has the correct permissions.'
)
parser.add_argument('-i', '--interactive', action='store_true', default=False,
help='Enter an interactive shell with some WROLPi tools')
sub_commands = parser.add_subparsers(title='sub-commands', dest='sub_commands')
@ -63,6 +89,10 @@ async def main(loop):
args = parser.parse_args()
if args.interactive:
launch_interactive_shell()
return 0
if args.version:
# Print out the relevant version information, then exit.
print(get_version_string())

View file

@ -1,4 +1,4 @@
__version__ = '0.4.8-beta'
__version__ = '0.4.9-beta'
import subprocess