moved dependency checking to utility module

This commit is contained in:
Kjistóf 2017-10-30 11:47:41 +01:00
parent 71ec1f778f
commit a881bdaaf6
2 changed files with 17 additions and 19 deletions

View File

@ -5,7 +5,7 @@
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
from subprocess import call, Popen, PIPE, check_output, DEVNULL, CalledProcessError
from subprocess import call, Popen, PIPE, DEVNULL
from os import listdir, remove
from os.path import splitext, exists, join
from re import match
@ -17,7 +17,7 @@ from signal import signal, SIGINT
from sys import exit
from copy import deepcopy
import utility
from utility import call_verbose, print_opt, get_output, temporary_directory, yes_no_question
from utility import call_verbose, print_opt, get_output, temporary_directory, yes_no_question, check_dependencies
class Stream(Enum):
@ -168,20 +168,6 @@ class coub_dl:
return get_output(('youtube-dl', '--get-title', url))
@staticmethod
@call_verbose(before_message='Checking your system for dependencies... ', after_message='Found all!')
def check_for_dependencies():
check_for = (('youtube-dl', '--version'), ('ffmpeg', '-version'))
error_str = '\nMissing dependencies: {}'
missing = []
for command in check_for:
try: check_output(command)
except (CalledProcessError, FileNotFoundError): missing.append(command[0])
if missing: exit(error_str.format(', '.join(missing)))
def run(URL, output, extension):
# create dict that contains files used
FILES = deepcopy(coub_dl.default_files)
@ -232,7 +218,7 @@ if __name__ == '__main__':
args = parse_cmd_arguments()
utility.VERBOSE = False if args.nonverbose else True
coub_dl.check_for_dependencies()
check_dependencies((('youtube-dl', '--version'), ('ffmpeg', '-version')))
for url in set(args.URLs):
print_opt('\nCreating video from {}'.format(url))

View File

@ -1,7 +1,7 @@
from functools import wraps
from tempfile import mkdtemp
from shutil import rmtree
from subprocess import check_output
from subprocess import check_output, CalledProcessError
VERBOSE = True
@ -56,3 +56,15 @@ class temporary_directory:
def get_output(*args, **kwargs):
return check_output(*args, **kwargs).decode().rstrip('\n')
@call_verbose(before_message='Checking your system for dependencies... ', after_message='Found all!')
def check_dependencies(check_for):
error_str = '\nMissing dependencies: {}'
missing = []
for command in check_for:
try: check_output(command)
except (CalledProcessError, FileNotFoundError): missing.append(command[0])
if missing: exit(error_str.format(', '.join(missing)))