Fix niceness / executeCommand logger
This commit is contained in:
@@ -168,6 +168,10 @@ def unmux(ctx,
|
|||||||
existingSourcePaths = [p for p in paths if os.path.isfile(p)]
|
existingSourcePaths = [p for p in paths if os.path.isfile(p)]
|
||||||
ctx.obj['logger'].debug(f"\nUnmuxing {len(existingSourcePaths)} files")
|
ctx.obj['logger'].debug(f"\nUnmuxing {len(existingSourcePaths)} files")
|
||||||
|
|
||||||
|
ctx.obj['resource_limits'] = {}
|
||||||
|
ctx.obj['resource_limits']['niceness'] = nice
|
||||||
|
ctx.obj['resource_limits']['cpu_percent'] = cpu
|
||||||
|
|
||||||
for sourcePath in existingSourcePaths:
|
for sourcePath in existingSourcePaths:
|
||||||
|
|
||||||
fp = FileProperties(ctx.obj, sourcePath)
|
fp = FileProperties(ctx.obj, sourcePath)
|
||||||
@@ -200,8 +204,8 @@ def unmux(ctx,
|
|||||||
|
|
||||||
if unmuxSequence:
|
if unmuxSequence:
|
||||||
if not ctx.obj['dry_run']:
|
if not ctx.obj['dry_run']:
|
||||||
ctx.obj['logger'].debug(f"Executing unmuxing sequence: {' '.join(unmuxSequence)}")
|
ctx.obj['logger'].debug(f"Executing unmuxing sequence")
|
||||||
out, err, rc = executeProcess(unmuxSequence, niceness=nice, cpu_percent=cpu)
|
out, err, rc = executeProcess(unmuxSequence, context = ctx.obj)
|
||||||
if rc:
|
if rc:
|
||||||
ctx.obj['logger'].error(f"Unmuxing of stream {trackDescriptor.getIndex()} failed with error ({rc}) {err}")
|
ctx.obj['logger'].error(f"Unmuxing of stream {trackDescriptor.getIndex()} failed with error ({rc}) {err}")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -269,10 +269,10 @@ class FfxController():
|
|||||||
commandSequence += self.generateOutputTokens(targetPath,
|
commandSequence += self.generateOutputTokens(targetPath,
|
||||||
targetFormat)
|
targetFormat)
|
||||||
|
|
||||||
self.__logger.debug(f"FfxController.runJob() commandSequence:{' '.join(commandSequence)}")
|
self.__logger.debug(f"FfxController.runJob(): Running command sequence")
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
if not self.__context['dry_run']:
|
||||||
executeProcess(commandSequence, niceness=self.__niceness, cpu_percent=self.__cpuPercent)
|
executeProcess(commandSequence, context = self.__context)
|
||||||
|
|
||||||
|
|
||||||
if videoEncoder == VideoEncoder.VP9:
|
if videoEncoder == VideoEncoder.VP9:
|
||||||
@@ -294,13 +294,13 @@ class FfxController():
|
|||||||
|
|
||||||
commandSequence1 += FfxController.NULL_TOKENS
|
commandSequence1 += FfxController.NULL_TOKENS
|
||||||
|
|
||||||
self.__logger.debug(f"FfxController.runJob() commandSequence1:{' '.join(commandSequence1)}")
|
|
||||||
|
|
||||||
if os.path.exists(FfxController.TEMP_FILE_NAME):
|
if os.path.exists(FfxController.TEMP_FILE_NAME):
|
||||||
os.remove(FfxController.TEMP_FILE_NAME)
|
os.remove(FfxController.TEMP_FILE_NAME)
|
||||||
|
|
||||||
|
self.__logger.debug(f"FfxController.runJob(): Running command sequence 1")
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
if not self.__context['dry_run']:
|
||||||
executeProcess(commandSequence1, niceness=self.__niceness, cpu_percent=self.__cpuPercent)
|
executeProcess(commandSequence1, context = self.__context)
|
||||||
|
|
||||||
commandSequence2 = (commandTokens
|
commandSequence2 = (commandTokens
|
||||||
+ self.__targetMediaDescriptor.getImportFileTokens()
|
+ self.__targetMediaDescriptor.getImportFileTokens()
|
||||||
@@ -319,10 +319,10 @@ class FfxController():
|
|||||||
commandSequence2 += self.generateOutputTokens(targetPath,
|
commandSequence2 += self.generateOutputTokens(targetPath,
|
||||||
targetFormat)
|
targetFormat)
|
||||||
|
|
||||||
self.__logger.debug(f"FfxController.runJob() commandSequence2:{' '.join(commandSequence2)}")
|
self.__logger.debug(f"FfxController.runJob(): Running command sequence 2")
|
||||||
|
|
||||||
if not self.__context['dry_run']:
|
if not self.__context['dry_run']:
|
||||||
out, err, rc = executeProcess(commandSequence2, niceness=self.__niceness, cpu_percent=self.__cpuPercent)
|
out, err, rc = executeProcess(commandSequence2, context = self.__context)
|
||||||
if rc:
|
if rc:
|
||||||
raise click.ClickException(f"Command resulted in error: rc={rc} error={err}")
|
raise click.ClickException(f"Command resulted in error: rc={rc} error={err}")
|
||||||
|
|
||||||
@@ -349,4 +349,4 @@ class FfxController():
|
|||||||
str(length),
|
str(length),
|
||||||
path]
|
path]
|
||||||
|
|
||||||
out, err, rc = executeProcess(commandTokens, niceness=self.__niceness, cpu_percent=self.__cpuPercent)
|
out, err, rc = executeProcess(commandTokens, context = self.__context)
|
||||||
|
|||||||
@@ -101,7 +101,8 @@ class FileProperties():
|
|||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-show_format",
|
"-show_format",
|
||||||
"-of", "json",
|
"-of", "json",
|
||||||
self.__sourcePath])
|
self.__sourcePath],
|
||||||
|
context = self.context)
|
||||||
|
|
||||||
if 'Invalid data found when processing input' in ffprobeError:
|
if 'Invalid data found when processing input' in ffprobeError:
|
||||||
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
||||||
@@ -160,7 +161,8 @@ class FileProperties():
|
|||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-show_streams",
|
"-show_streams",
|
||||||
"-of", "json",
|
"-of", "json",
|
||||||
self.__sourcePath])
|
self.__sourcePath],
|
||||||
|
context = self.context)
|
||||||
|
|
||||||
if 'Invalid data found when processing input' in ffprobeError:
|
if 'Invalid data found when processing input' in ffprobeError:
|
||||||
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
raise Exception(f"File {self.__sourcePath} does not contain valid stream data")
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
import subprocess, click
|
import subprocess, logging
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
def executeProcess(commandSequence: List[str], directory: str = None, niceness: int = 99, cpu_percent: int = 0):
|
def executeProcess(commandSequence: List[str], directory: str = None, context: dict = None):
|
||||||
"""
|
"""
|
||||||
niceness -20 bis +19
|
niceness -20 bis +19
|
||||||
cpu_percent: 1 bis 99
|
cpu_percent: 1 bis 99
|
||||||
"""
|
"""
|
||||||
|
|
||||||
nice = int(niceness)
|
logger = (context['logger'] if not context is None
|
||||||
cpu = int(cpu_percent)
|
else logging.getLogger('FFX').addHandler(logging.NullHandler()))
|
||||||
|
|
||||||
click.echo(f"nice {nice} cpu {cpu}")
|
|
||||||
|
|
||||||
niceSequence = []
|
niceSequence = []
|
||||||
|
|
||||||
if nice >= -20 and nice <= 19:
|
niceness = (int(context['resource_limits']['niceness'])
|
||||||
niceSequence += ['nice', '-n', str(nice)]
|
if 'resource_limits' in context.keys() and 'niceness' in context['resource_limits'].keys() else 99)
|
||||||
if cpu >= 1 and cpu <= 99:
|
cpu_percent = (int(context['resource_limits']['cpu_percent'])
|
||||||
niceSequence += ['cpulimit', '-l', str(cpu), '--']
|
if 'resource_limits' in context.keys() and 'cpu_percent' in context['resource_limits'].keys() else 0)
|
||||||
|
|
||||||
|
if niceness >= -20 and niceness <= 19:
|
||||||
|
niceSequence += ['nice', '-n', str(niceness)]
|
||||||
|
if cpu_percent >= 1:
|
||||||
|
niceSequence += ['cpulimit', '-l', str(cpu_percent), '--']
|
||||||
|
|
||||||
niceCommand = niceSequence + commandSequence
|
niceCommand = niceSequence + commandSequence
|
||||||
|
|
||||||
click.echo(f"executeProcess(): {' '.join(niceCommand)}")
|
logger.debug(f"executeProcess() command sequence: {' '.join(niceCommand)}")
|
||||||
|
|
||||||
process = subprocess.Popen(niceCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', cwd = directory)
|
process = subprocess.Popen(niceCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf-8', cwd = directory)
|
||||||
output, error = process.communicate()
|
output, error = process.communicate()
|
||||||
|
|||||||
@@ -255,10 +255,9 @@ def createMediaTestFile(mediaDescriptor: MediaDescriptor,
|
|||||||
commandTokens += [outputPath]
|
commandTokens += [outputPath]
|
||||||
|
|
||||||
|
|
||||||
if not logger is None:
|
ctx = {'logger': logger}
|
||||||
logger.debug(f"createMediaTestFile(): Command sequence: {commandTokens}")
|
|
||||||
|
|
||||||
out, err, rc = executeProcess(commandTokens)
|
out, err, rc = executeProcess(commandTokens, context = ctx)
|
||||||
|
|
||||||
if not logger is None:
|
if not logger is None:
|
||||||
if out:
|
if out:
|
||||||
|
|||||||
@@ -109,16 +109,10 @@ class Scenario1(Scenario):
|
|||||||
commandSequence += ['--label', variantFilenameLabel]
|
commandSequence += ['--label', variantFilenameLabel]
|
||||||
|
|
||||||
|
|
||||||
# if not testContext['use_jellyfin']:
|
|
||||||
# commandSequence += ['--no-jellyfin']
|
|
||||||
|
|
||||||
commandSequence += ['--no-pattern']
|
commandSequence += ['--no-pattern']
|
||||||
commandSequence += ['--no-tmdb']
|
commandSequence += ['--no-tmdb']
|
||||||
|
|
||||||
|
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, context = self._context)
|
||||||
self._logger.debug(f"{variantLabel}: Test sequence: {commandSequence}")
|
|
||||||
|
|
||||||
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, niceness=self._niceness, cpu_percent=self._cpuPercent)
|
|
||||||
|
|
||||||
if out and self._context['verbosity'] >= 9:
|
if out and self._context['verbosity'] >= 9:
|
||||||
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
||||||
|
|||||||
@@ -97,13 +97,7 @@ class Scenario2(Scenario):
|
|||||||
'--no-prompt',
|
'--no-prompt',
|
||||||
'--no-signature']
|
'--no-signature']
|
||||||
|
|
||||||
# if not testContext['use_jellyfin']:
|
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, context = self._context)
|
||||||
# commandSequence += ['--no-jellyfin']
|
|
||||||
|
|
||||||
|
|
||||||
self._logger.debug(f"{variantLabel}: Test sequence: {commandSequence}")
|
|
||||||
|
|
||||||
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, niceness=self._niceness, cpu_percent=self._cpuPercent)
|
|
||||||
|
|
||||||
if out and self._context['verbosity'] >= 9:
|
if out and self._context['verbosity'] >= 9:
|
||||||
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
||||||
|
|||||||
@@ -182,12 +182,7 @@ class Scenario4(Scenario):
|
|||||||
|
|
||||||
commandSequence += ['--no-prompt', '--no-signature']
|
commandSequence += ['--no-prompt', '--no-signature']
|
||||||
|
|
||||||
# if not testContext['use_jellyfin']:
|
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, context = self._context)
|
||||||
# commandSequence += ['--no-jellyfin']
|
|
||||||
|
|
||||||
self._logger.debug(f"{variantLabel}: Test sequence: {commandSequence}")
|
|
||||||
|
|
||||||
out, err, rc = executeProcess(commandSequence, directory = self._testDirectory, niceness=self._niceness, cpu_percent=self._cpuPercent)
|
|
||||||
|
|
||||||
if out and self._context['verbosity'] >= 9:
|
if out and self._context['verbosity'] >= 9:
|
||||||
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
self._logger.debug(f"{variantLabel}: Process output: {out}")
|
||||||
|
|||||||
Reference in New Issue
Block a user