FIX forge output paths; improve logging
This commit is contained in:
parent
f12124378f
commit
4100b7b60b
2 changed files with 22 additions and 6 deletions
|
@ -4,13 +4,14 @@ from argparse import ArgumentParser, Action
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger('cli')
|
logger = logging.getLogger('cli')
|
||||||
|
CWD = os.getcwd()
|
||||||
|
|
||||||
import forge
|
import forge
|
||||||
from config_manager import get_config
|
from config_manager import get_config
|
||||||
import server
|
import server
|
||||||
|
|
||||||
|
|
||||||
def pre_check_permissions():
|
def pre_check_permissions():
|
||||||
import sys
|
|
||||||
|
|
||||||
def is_writable(d):
|
def is_writable(d):
|
||||||
return os.access(d, os.W_OK)
|
return os.access(d, os.W_OK)
|
||||||
|
@ -26,6 +27,7 @@ def pre_check_permissions():
|
||||||
yield "Audio output '%s' not writable" % get_config()['AUDIO_OUTPUT']
|
yield "Audio output '%s' not writable" % get_config()['AUDIO_OUTPUT']
|
||||||
sys.exit(10)
|
sys.exit(10)
|
||||||
|
|
||||||
|
|
||||||
def pre_check_user():
|
def pre_check_user():
|
||||||
if os.geteuid() == 0:
|
if os.geteuid() == 0:
|
||||||
yield "You're running as root; this is dangerous"
|
yield "You're running as root; this is dangerous"
|
||||||
|
@ -41,6 +43,7 @@ class DateTimeAction(Action):
|
||||||
raise ValueError("'%s' is not a valid datetime" % values)
|
raise ValueError("'%s' is not a valid datetime" % values)
|
||||||
setattr(namespace, self.dest, parsed_val)
|
setattr(namespace, self.dest, parsed_val)
|
||||||
|
|
||||||
|
|
||||||
def common_pre():
|
def common_pre():
|
||||||
prechecks = [pre_check_user, pre_check_permissions]
|
prechecks = [pre_check_user, pre_check_permissions]
|
||||||
configs = ['default_config.py']
|
configs = ['default_config.py']
|
||||||
|
@ -63,8 +66,9 @@ def common_pre():
|
||||||
logging.warn(warn)
|
logging.warn(warn)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
common_pre()
|
parser = ArgumentParser(description='creates mp3 from live recordings')
|
||||||
parser = ArgumentParser(description='creates mp3 files from live recordings')
|
parser.add_argument('--verbose', '-v', action='count',
|
||||||
|
help='Increase verbosity; can be used multiple times')
|
||||||
sub = parser.add_subparsers(title='subcommands',
|
sub = parser.add_subparsers(title='subcommands',
|
||||||
description='valid subcommands',
|
description='valid subcommands',
|
||||||
help='additional help')
|
help='additional help')
|
||||||
|
@ -78,4 +82,12 @@ if __name__ == "__main__":
|
||||||
forge_p.set_defaults(func=forge.main_cmd)
|
forge_p.set_defaults(func=forge.main_cmd)
|
||||||
|
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
options.cwd = CWD
|
||||||
|
if options.verbose < 1:
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
elif options.verbose == 1:
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
elif options.verbose >= 2:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
common_pre()
|
||||||
options.func(options)
|
options.func(options)
|
||||||
|
|
|
@ -2,6 +2,7 @@ from datetime import datetime, timedelta
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import os
|
import os
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
|
import logging
|
||||||
|
|
||||||
from config_manager import get_config
|
from config_manager import get_config
|
||||||
|
|
||||||
|
@ -94,8 +95,7 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
|
||||||
p.wait()
|
p.wait()
|
||||||
else:
|
else:
|
||||||
start = datetime.now()
|
start = datetime.now()
|
||||||
while (datetime.now() - start).total_seconds() < \
|
while (datetime.now() - start).total_seconds() < get_config()['FORGE_TIMEOUT']:
|
||||||
get_config()['FORGE_TIMEOUT']:
|
|
||||||
p.poll()
|
p.poll()
|
||||||
if p.returncode is None:
|
if p.returncode is None:
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
@ -112,5 +112,9 @@ def create_mp3(start, end, outfile, options={}, **kwargs):
|
||||||
raise OSError("return code was %d" % p.returncode)
|
raise OSError("return code was %d" % p.returncode)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main_cmd(options):
|
def main_cmd(options):
|
||||||
create_mp3(options.starttime, options.endtime, options.outfile)
|
log = logging.getLogger('forge_main')
|
||||||
|
outfile = os.path.abspath(os.path.join(options.cwd, options.outfile))
|
||||||
|
log.debug('will forge an mp3 into %s' % (outfile))
|
||||||
|
create_mp3(options.starttime, options.endtime, outfile)
|
||||||
|
|
Loading…
Reference in a new issue