Adds requirements, streamlines CLI helper procedures
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#! /usr/bin/python3
|
||||
|
||||
import os, click, time, logging, shutil
|
||||
import os, click, time, logging, shutil, subprocess
|
||||
|
||||
from ffx.configuration_controller import ConfigurationController
|
||||
|
||||
@@ -49,6 +49,11 @@ def ffx(ctx, database_file, verbose, dry_run):
|
||||
|
||||
ctx.obj = {}
|
||||
|
||||
if ctx.invoked_subcommand in ('setup_dependencies', 'upgrade'):
|
||||
ctx.obj['dry_run'] = dry_run
|
||||
ctx.obj['verbosity'] = verbose
|
||||
return
|
||||
|
||||
ctx.obj['config'] = ConfigurationController()
|
||||
|
||||
ctx.obj['database'] = databaseContext(databasePath=database_file
|
||||
@@ -97,6 +102,82 @@ def help():
|
||||
click.echo(f"Usage: ffx [input file] [output file] [vp9|av1] [q=[nn[,nn,...]]] [p=nn] [a=nnn[k]] [ac3=nnn[k]] [dts=nnn[k]] [crop]")
|
||||
|
||||
|
||||
def getRepoRootPath():
|
||||
currentFilePath = os.path.abspath(__file__)
|
||||
return os.path.dirname(os.path.dirname(os.path.dirname(currentFilePath)))
|
||||
|
||||
|
||||
def getPrepareScriptPath():
|
||||
return os.path.join(getRepoRootPath(), 'tools', 'prepare.sh')
|
||||
|
||||
|
||||
def getBundleVenvDirectory():
|
||||
return os.path.join(os.path.expanduser('~'), '.local', 'share', 'ffx.venv')
|
||||
|
||||
|
||||
def getBundlePipPath():
|
||||
return os.path.join(getBundleVenvDirectory(), 'bin', 'pip')
|
||||
|
||||
|
||||
def getBundleRepoPath():
|
||||
return getRepoRootPath()
|
||||
|
||||
|
||||
@ffx.command(name='setup_dependencies')
|
||||
@click.pass_context
|
||||
@click.option('--check', is_flag=True, default=False, help='Only verify dependency readiness')
|
||||
@click.argument('prepare_args', nargs=-1, type=click.UNPROCESSED)
|
||||
def setup_dependencies(ctx, check, prepare_args):
|
||||
prepareScriptPath = getPrepareScriptPath()
|
||||
|
||||
if not os.path.isfile(prepareScriptPath):
|
||||
raise click.ClickException(f"Preparation script not found at {prepareScriptPath}")
|
||||
|
||||
commandSequence = ['bash', prepareScriptPath]
|
||||
|
||||
if check:
|
||||
commandSequence.append('--check')
|
||||
|
||||
commandSequence += list(prepare_args)
|
||||
|
||||
if ctx.obj.get('dry_run', False):
|
||||
click.echo(' '.join(commandSequence))
|
||||
return
|
||||
|
||||
completed = subprocess.run(commandSequence)
|
||||
ctx.exit(completed.returncode)
|
||||
|
||||
|
||||
@ffx.command(name='upgrade')
|
||||
@click.pass_context
|
||||
@click.argument('branch', required=False, default='main')
|
||||
def upgrade(ctx, branch):
|
||||
bundleRepoPath = getBundleRepoPath()
|
||||
bundlePipPath = getBundlePipPath()
|
||||
|
||||
if not os.path.isdir(bundleRepoPath):
|
||||
raise click.ClickException(f"Bundle repository not found at {bundleRepoPath}")
|
||||
|
||||
if not os.path.isfile(bundlePipPath):
|
||||
raise click.ClickException(f"Bundle pip not found at {bundlePipPath}")
|
||||
|
||||
commandSequences = [
|
||||
['git', 'checkout', branch],
|
||||
['git', 'pull'],
|
||||
[bundlePipPath, 'install', '--editable', '.'],
|
||||
]
|
||||
|
||||
if ctx.obj.get('dry_run', False):
|
||||
for commandSequence in commandSequences:
|
||||
click.echo(f"(cd {bundleRepoPath} && {' '.join(commandSequence)})")
|
||||
return
|
||||
|
||||
for commandSequence in commandSequences:
|
||||
completed = subprocess.run(commandSequence, cwd=bundleRepoPath)
|
||||
if completed.returncode != 0:
|
||||
ctx.exit(completed.returncode)
|
||||
|
||||
|
||||
@ffx.command()
|
||||
@click.pass_context
|
||||
@click.argument('filename', nargs=1)
|
||||
|
||||
Reference in New Issue
Block a user