From 4100b7b60b99d3b83097b2b22b4a52fbd6beb5dd Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 27 Dec 2013 00:56:46 +0100 Subject: [PATCH] FIX forge output paths; improve logging --- server/cli.py | 18 +++++++++++++++--- server/forge.py | 10 +++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/server/cli.py b/server/cli.py index 31cb5f0..d5445f4 100644 --- a/server/cli.py +++ b/server/cli.py @@ -4,13 +4,14 @@ from argparse import ArgumentParser, Action from datetime import datetime import logging logger = logging.getLogger('cli') +CWD = os.getcwd() import forge from config_manager import get_config import server + def pre_check_permissions(): - import sys def is_writable(d): 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'] sys.exit(10) + def pre_check_user(): if os.geteuid() == 0: 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) setattr(namespace, self.dest, parsed_val) + def common_pre(): prechecks = [pre_check_user, pre_check_permissions] configs = ['default_config.py'] @@ -63,8 +66,9 @@ def common_pre(): logging.warn(warn) if __name__ == "__main__": - common_pre() - parser = ArgumentParser(description='creates mp3 files from live recordings') + parser = ArgumentParser(description='creates mp3 from live recordings') + parser.add_argument('--verbose', '-v', action='count', + help='Increase verbosity; can be used multiple times') sub = parser.add_subparsers(title='subcommands', description='valid subcommands', help='additional help') @@ -78,4 +82,12 @@ if __name__ == "__main__": forge_p.set_defaults(func=forge.main_cmd) 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) diff --git a/server/forge.py b/server/forge.py index 712b93e..d81026e 100644 --- a/server/forge.py +++ b/server/forge.py @@ -2,6 +2,7 @@ from datetime import datetime, timedelta from time import sleep import os from subprocess import Popen +import logging from config_manager import get_config @@ -94,8 +95,7 @@ def create_mp3(start, end, outfile, options={}, **kwargs): p.wait() else: start = datetime.now() - while (datetime.now() - start).total_seconds() < \ - get_config()['FORGE_TIMEOUT']: + while (datetime.now() - start).total_seconds() < get_config()['FORGE_TIMEOUT']: p.poll() if p.returncode is None: sleep(1) @@ -112,5 +112,9 @@ def create_mp3(start, end, outfile, options={}, **kwargs): raise OSError("return code was %d" % p.returncode) return True + 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)