diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b24d71e --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..d52f194 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,548 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +jobs=1 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +disable=print-statement, + parameter-unpacking, + unpacking-in-except, + old-raise-syntax, + backtick, + long-suffix, + old-ne-operator, + old-octal-literal, + import-star-module-level, + non-ascii-bytes-literal, + raw-checker-failed, + bad-inline-option, + locally-disabled, + locally-enabled, + file-ignored, + suppressed-message, + useless-suppression, + deprecated-pragma, + apply-builtin, + basestring-builtin, + buffer-builtin, + cmp-builtin, + coerce-builtin, + execfile-builtin, + file-builtin, + long-builtin, + raw_input-builtin, + reduce-builtin, + standarderror-builtin, + unicode-builtin, + xrange-builtin, + coerce-method, + delslice-method, + getslice-method, + setslice-method, + no-absolute-import, + old-division, + dict-iter-method, + dict-view-method, + next-method-called, + metaclass-assignment, + indexing-exception, + raising-string, + reload-builtin, + oct-method, + hex-method, + nonzero-method, + cmp-method, + input-builtin, + round-builtin, + intern-builtin, + unichr-builtin, + map-builtin-not-iterating, + zip-builtin-not-iterating, + range-builtin-not-iterating, + filter-builtin-not-iterating, + using-cmp-argument, + eq-without-hash, + div-method, + idiv-method, + rdiv-method, + exception-message-attribute, + invalid-str-codec, + sys-max-int, + bad-python3-import, + deprecated-string-function, + deprecated-str-translate-call, + deprecated-itertools-function, + deprecated-types-field, + next-method-defined, + dict-items-not-iterating, + dict-keys-not-iterating, + dict-values-not-iterating, + + R0201, R0205, + C0103, C0114, C0326, C0330, C0411, + W0122, W0123, W0201, W0311, W0312, W0603, W0703, W1505, + E0401, E0611, E1101 + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +msg-template='{msg_id}:{line:3d},{column}: {obj}: {msg}' + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=10 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=optparse.Values,sys.exit + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=50 + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + XXX, + TODO + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=300 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +#dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ +dummy-variables-rgx=(_+[a-zA-Z0-9_]*?$)|dummy + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[BASIC] + +# Naming style matching correct argument names +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style +#argument-rgx= + +# Naming style matching correct attribute names +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style +#attr-rgx= + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style +#class-attribute-rgx= + +# Naming style matching correct class names +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming-style +#class-rgx= + +# Naming style matching correct constant names +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style +#const-rgx= + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=1000 + +# Naming style matching correct function names +function-naming-style=camelCase + +# Regular expression matching correct function names. Overrides function- +# naming-style +#function-rgx= + +# Good variable names which should always be accepted, separated by a comma +good-names=i, + j, + k, + ex, + Run, + _ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming style matching correct inline iteration names +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style +#inlinevar-rgx= + +# Naming style matching correct method names +method-naming-style=camelCase + +# Regular expression matching correct method names. Overrides method-naming- +# style +#method-rgx= + +# Naming style matching correct module names +module-naming-style=any + +# Regular expression matching correct module names. Overrides module-naming- +# style +#module-rgx= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style +#variable-rgx= + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub, + TERMIOS, + Bastion, + rexec + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=100 + +# Maximum number of attributes for a class (see R0902). +max-attributes=100 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=100 + +# Maximum number of branch for function / method body +max-branches=100 + +# Maximum number of locals for function / method body +max-locals=100 + +# Maximum number of parents for a class (see R0901). +max-parents=100 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=100 + +# Maximum number of return / yield for function / method body +max-returns=100 + +# Maximum number of statements in function / method body +max-statements=200 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=0 + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/CONTROL/control b/CONTROL/control new file mode 100644 index 0000000..588915b --- /dev/null +++ b/CONTROL/control @@ -0,0 +1,5 @@ +Description: JobCockpit +Maintainer: dream-alpha +Package: enigma2-plugin-systemplugins-jobcockpit +Version: 0.3.16 +Architecture: all diff --git a/CONTROL/postinst b/CONTROL/postinst new file mode 100755 index 0000000..7add5f6 --- /dev/null +++ b/CONTROL/postinst @@ -0,0 +1,16 @@ +#!/bin/sh +if [ ! -f /usr/lib/enigma2/python/Components/Task.py.org ]; then + cp /usr/lib/enigma2/python/Components/Task.py /usr/lib/enigma2/python/Components/Task.py.org +fi +cp /usr/lib/enigma2/python/Plugins/SystemPlugins/JobCockpit/Components/Task.py /usr/lib/enigma2/python/Components/Task.py + +echo "***********************************" +echo "* JobCockpit *" +echo "* by *" +echo "* dream-alpha *" +echo "***********************************" +echo "" +echo "Plugin installed successfully." +echo "Please restart DreamOS now!" +echo "" +exit 0 diff --git a/CONTROL/postrm b/CONTROL/postrm new file mode 100755 index 0000000..39e1389 --- /dev/null +++ b/CONTROL/postrm @@ -0,0 +1,9 @@ +#!/bin/sh +if [ "$1" = "remove" ]; then + rm -rf /usr/lib/enigma2/python/Plugins/SystemPlugins/JobCockpit > /dev/null 2>&1 + cp /usr/lib/enigma2/python/Components/Task.py.org /usr/lib/enigma2/python/Components/Task.py + echo "JobCockpit plugin removed successfully." +else + find /usr/lib/enigma2/python/Plugins/SystemPlugins/JobCockpit -type f -name "*.pyo" -exec rm -f {} \; > /dev/null 2>&1 +fi +exit 0 diff --git a/CONTROL/preinst b/CONTROL/preinst new file mode 100755 index 0000000..9194113 --- /dev/null +++ b/CONTROL/preinst @@ -0,0 +1,5 @@ +#!/bin/sh +if [ ! -f /usr/lib/enigma2/python/Components/Task.py.org ]; then + mv /usr/lib/enigma2/python/Components/Task.py /usr/lib/enigma2/python/Components/Task.py.org +fi +exit 0 diff --git a/Components/Makefile.am b/Components/Makefile.am new file mode 100644 index 0000000..721302f --- /dev/null +++ b/Components/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/SystemPlugins/JobCockpit/Components +install_PYTHON = *.py diff --git a/Components/Task.py b/Components/Task.py new file mode 100644 index 0000000..25a94d2 --- /dev/null +++ b/Components/Task.py @@ -0,0 +1,469 @@ +import os +from enigma import eConsoleAppContainer +from Tools.CList import CList +from Tools import Notifications + + +Notifications.notificationQueue.registerDomain("JobManager", _("Job Manager"), Notifications.ICON_DEFAULT) # pylint: disable=E0602 + + +class Job(object): + NOT_STARTED, IN_PROGRESS, FINISHED, FAILED = range(4) + + def __init__(self, name): + self.tasks = [] + self.resident_tasks = [] + self.workspace = "/tmp" + self.current_task = 0 + self.callback = None + self.name = name + self.finished = False + self.end = 100 + self.__progress = 0 + self.weightScale = 1 + self.afterEvent = None + self.state_changed = CList() + self.status = self.NOT_STARTED + + # description is a dict + def fromDescription(self, description): + pass + + def createDescription(self): + return None + + def getProgress(self): + # if self.current_task == len(self.tasks): + # return self.end + # t = self.tasks[self.current_task] + # jobprogress = t.weighting * t.progress / float(t.end) + sum([task.weighting for task in self.tasks[:self.current_task]]) + jobprogress = sum([task.weighting * task.progress / float(task.end) for task in self.tasks]) + progress = int(jobprogress * self.weightScale) + print("JOB: getProgress: progress: %s" % progress) + return int(jobprogress * self.weightScale) + + progress = property(getProgress) + + def getStatustext(self): + return {self.NOT_STARTED: _("Waiting"), self.IN_PROGRESS: _("In Progress"), self.FINISHED: _("Finished"), self.FAILED: _("Failed")}[self.status] # pylint: disable=E0602 + + def task_progress_changed_CB(self): + self.state_changed() + + def addTask(self, task): + print("JOB: addTask: %s" % task) + task.job = self + task.task_progress_changed = self.task_progress_changed_CB + self.tasks.append(task) + + def start(self, callback): + print("JOB: start: %s" % callback) + assert self.callback is None + self.callback = callback + self.restart() + + def restart(self): + print("JOB: restart") + self.status = self.IN_PROGRESS + self.state_changed() + self.runNext() + sumTaskWeightings = sum([t.weighting for t in self.tasks]) or 1 + self.weightScale = self.end / float(sumTaskWeightings) + + def runNext(self): + print("JOB: runNext: current_task: %s, tasks: %s" % (self.current_task, self.tasks)) + if self.current_task == len(self.tasks): + if len(self.resident_tasks) == 0: + self.status = self.FINISHED + self.state_changed() + self.callback(self, None, []) + self.callback = None + else: + print("JOB: still waiting for %d resident task(s) %s to finish" % (len(self.resident_tasks), str(self.resident_tasks))) + else: + print("JOB: current_task: %s" % self.current_task) + print("JOB: tasks: %s" % self.tasks) + self.tasks[self.current_task].run(self.taskCallback) + self.state_changed() + + def taskCallback(self, task, res, stay_resident=False): + print("JOB: taskCallback: task: %s, res: %s, stay_residents: %s" % (task, res, stay_resident)) + cb_idx = self.tasks.index(task) + if stay_resident: + if cb_idx not in self.resident_tasks: + self.resident_tasks.append(self.current_task) + print("JOB: task going resident:", task) + else: + print("JOB: task keeps staying resident:", task) + return + if len(res) > 0: + print("JOB: >>> Error:", res) + self.status = self.FAILED + self.state_changed() + self.callback(self, task, res) + if cb_idx != self.current_task: + if cb_idx in self.resident_tasks: + print("JOB: resident task finished:", task) + self.resident_tasks.remove(cb_idx) + if res == []: + self.state_changed() + self.current_task += 1 + self.runNext() + + def retry(self): + assert self.status == self.FAILED + self.restart() + + def abort(self, *args): + print("JOB: abort") + if self.current_task < len(self.tasks): + self.tasks[self.current_task].abort(*args) + for i in self.resident_tasks: + self.tasks[i].abort(*args) + + def cancel(self, *args): + print("JOB: cancel") + self.abort(*args) + + def remove(self, callback): + print("JOB: remove: callback: %s" % callback) + if self.status == self.IN_PROGRESS: + self.abort() + else: + callback(self, None, []) + + +class Task(object): + def __init__(self, job, name): + self.name = name + self.immediate_preconditions = [] + self.global_preconditions = [] + self.postconditions = [] + self.returncode = None + self.initial_input = None + self.job = None + self.end = 100 + self.weighting = 100 + self.__progress = 0 + self.cmd = None + self.cwd = "/tmp" + self.args = [] + self.cmdline = None + self.task_progress_changed = None + self.output_line = "" + job.addTask(self) + self.container = None + + def setCommandline(self, cmd, args): + self.cmd = cmd + self.args = args + + def setTool(self, tool): + self.cmd = tool + self.args = [tool] + self.global_preconditions.append(ToolExistsPrecondition()) + self.postconditions.append(ReturncodePostcondition()) + + def setCmdline(self, cmdline): + self.cmdline = cmdline + + def checkPreconditions(self, immediate=False): + not_met = [] + if immediate: + preconditions = self.immediate_preconditions + else: + preconditions = self.global_preconditions + for precondition in preconditions: + if not precondition.check(self): + not_met.append(precondition) + return not_met + + def run(self, callback): + failed_preconditions = self.checkPreconditions(True) + self.checkPreconditions(False) + if len(failed_preconditions) > 0: + callback(self, failed_preconditions) + return + self.prepare() + + self.callback = callback + self.container = eConsoleAppContainer() + self.appClosed_conn = self.container.appClosed.connect(self.processFinished) + self.stdoutAvail_conn = self.container.stdoutAvail.connect(self.processStdout) + self.stderrAvail_conn = self.container.stderrAvail.connect(self.processStderr) + + if self.cwd is not None: + self.container.setCWD(self.cwd) + + if not self.cmd and self.cmdline: + print("TASK: execute:", self.container.execute(self.cmdline), self.cmdline) + else: + assert self.cmd is not None + assert len(self.args) >= 1 + print("TASK: execute:", self.container.execute(self.cmd, *self.args), ' '.join(self.args)) + if self.initial_input: + self.writeInput(self.initial_input) + + def prepare(self): + pass + + def cleanup(self, failed): + pass + + def processStdout(self, data): + self.processOutput(data) + + def processStderr(self, data): + self.processOutput(data) + + def processOutput(self, data): + self.output_line += data + while True: + i = self.output_line.find('\n') + if i == -1: + break + self.processOutputLine(self.output_line[:i + 1]) + self.output_line = self.output_line[i + 1:] + + def processOutputLine(self, line): + pass + + def processFinished(self, returncode): + self.returncode = returncode + self.finish() + + def abort(self): + if self.container: + self.container.kill() + self.finish(aborted=True) + + def finish(self, aborted=False): + self.afterRun() + not_met = [] + if aborted: + not_met.append(AbortedPostcondition()) + else: + for postcondition in self.postconditions: + if not postcondition.check(self): + not_met.append(postcondition) + self.cleanup(not_met) + self.callback(self, not_met) + + def afterRun(self): + pass + + def writeInput(self, ainput): + self.container.write(ainput) + + def getProgress(self): + print("TASK: getProgress: __progress: %s" % self.__progress) + return self.__progress + + def setProgress(self, progress): + print("TASK: setProgress: progress: %s" % progress) + if progress > self.end: + progress = self.end + if progress < 0: + progress = 0 + self.__progress = progress + if self.task_progress_changed: + self.task_progress_changed() # pylint: disable=E1102 + print("TASK: setProgress: __progress: %s" % self.__progress) + + progress = property(getProgress, setProgress) + + +# The jobmanager will execute multiple jobs, each after another. +# later, it will also support suspending jobs (and continuing them after reboot etc) +# It also supports a notification when some error occured, and possibly a retry. + + +class JobManager: + def __init__(self, domain="JobManager"): + self.active_jobs = [] + self.successfull_jobs = [] + self.failed_jobs = [] + self.job_classes = [] + self.in_background = False + self.active_job = None + self.domain = domain + + def AddJob(self, job): + self.active_jobs.append(job) + self.kick() + + def AbortJob(self, job, *args): + if job.status == Job.IN_PROGRESS: + job.abort(*args) + + def RemoveJob(self, job): + if job.status == Job.NOT_STARTED: + if job in self.active_jobs: + self.active_jobs.remove(job) + elif job.status == Job.FINISHED: + if job in self.successfull_jobs: + self.successfull_jobs.remove(job) + elif job.status == Job.FAILED: + if job in self.failed_jobs: + self.failed_jobs.remove(job) + + def CleanupJobs(self): + self.successfull_jobs = [] + self.failed_jobs = [] + + def kick(self): + if self.active_job is None: + if len(self.active_jobs) > 0: + self.active_job = self.active_jobs.pop(0) + self.active_job.start(self.jobDone) + + def jobDone(self, job, task, problems): + print("JOBMGR: job", job, "completed with", problems, "in", task) + if self.in_background: + from Screens.TaskView import JobView # pylint: disable=C0415 + self.in_background = False + Notifications.AddNotification(JobView, self.active_job, domain=self.domain) + if problems: + from Screens.MessageBox import MessageBox # pylint: disable=C0415 + if problems[0].RECOVERABLE: + Notifications.AddNotificationWithCallback(self.errorCB, MessageBox, _("Error: %s\nRetry?") % (problems[0].getErrorMessage(task)), domain=self.domain) # pylint: disable=E0602 + else: + Notifications.AddNotification(MessageBox, _("Error") + (': %s') % (problems[0].getErrorMessage(task)), type=MessageBox.TYPE_ERROR, domain=self.domain) # pylint: disable=E0602 + self.errorCB(False) + if hasattr(self.active_job, "keep") and self.active_job.keep: + self.failed_jobs.append(self.active_job) + return + if hasattr(self.active_job, "keep") and self.active_job.keep: + self.successfull_jobs.append(self.active_job) + + self.active_job = None + self.kick() + + def errorCB(self, answer): + if answer: + print("JOBMGR: retrying job") + self.active_job.retry() + else: + print("JOBMGR: not retrying job.") + self.failed_jobs.append(self.active_job) + self.active_job = None + self.kick() + + def getPendingJobs(self): + jobs = [] + if self.active_job: + jobs.append(self.active_job) + jobs += self.active_jobs + return jobs + + def getSuccessfullJobs(self): + return self.successfull_jobs + + def getFailedJobs(self): + return self.failed_jobs + + +# some examples: +# class PartitionExistsPostcondition: +# def __init__(self, device): +# self.device = device +# +# def check(self, task): +# import os +# return os.access(self.device + "part1", os.F_OK) +# +# class CreatePartitionTask(Task): +# def __init__(self, device): +# Task.__init__(self, _("Create Partition")) +# self.device = device +# self.setTool("/sbin/sfdisk") +# self.args += ["-f", self.device + "disc"] +# self.initial_input = "0,\n;\n;\n;\ny\n" +# self.postconditions.append(PartitionExistsPostcondition(self.device)) +# +# class CreateFilesystemTask(Task): +# def __init__(self, device, partition = 1, largefile = True): +# Task.__init__(self, _("Create Filesystem")) +# self.setTool("/sbin/mkfs.ext") +# if largefile: +# self.args += ["-T", "largefile"] +# self.args.append("-m0") +# self.args.append(device + "part%d" % partition) +# +# class FilesystemMountTask(Task): +# def __init__(self, device, partition = 1, filesystem = "ext3"): +# Task.__init__(self, _("Mounting Filesystem")) +# self.setTool("/bin/mount") +# if filesystem is not None: +# self.args += ["-t", filesystem] +# self.args.append(device + "part%d" % partition) + + +class Condition: + RECOVERABLE = False + + def getErrorMessage(self, task): + return _("An unknown error occured!") + " (%s @ task %s)" % (self.__class__.__name__, task.__class__.__name__) # pylint: disable=E0602 + + +class DiskspacePrecondition(Condition): + def __init__(self, diskspace_required): + self.diskspace_required = diskspace_required + self.diskspace_available = 0 + + def check(self, task): + try: + s = os.statvfs(task.job.workspace) + self.diskspace_available = s.f_bsize * s.f_bavail + return self.diskspace_available >= self.diskspace_required + except OSError: + return False + + def getErrorMessage(self, task): + return _("Not enough diskspace. Please free up some diskspace and try again. (%d MB required, %d MB available)") % (self.diskspace_required / 1024 / 1024, self.diskspace_available / 1024 / 1024) # pylint: disable=E0602 + + +class ToolExistsPrecondition(Condition): + def check(self, task): + if task.cmd[0] == '/': + self.realpath = task.cmd + print("[Task.py][ToolExistsPrecondition] WARNING: usage of absolute paths for tasks should be avoided!") + return os.access(self.realpath, os.X_OK) + self.realpath = task.cmd + path = os.environ.get('PATH', '').split(os.pathsep) + path.append(task.cwd + '/') + absolutes = filter(lambda file: os.access(file, os.X_OK), map(lambda directory, file=task.cmd: os.path.join(directory, file), path)) + if len(absolutes) > 0: + self.realpath = task.cmd[0] + return True + return False + + def getErrorMessage(self, task): + return _("A required tool (%s) was not found.") % (self.realpath) # pylint: disable=E0602 + + +class AbortedPostcondition(Condition): + def getErrorMessage(self, task): + return "Cancelled upon user request" + + +class ReturncodePostcondition(Condition): + def check(self, task): + return task.returncode == 0 + + +# class HDDInitJob(Job): +# def __init__(self, device): +# Job.__init__(self, _("Initialize Harddisk")) +# self.device = device +# self.fromDescription(self.createDescription()) +# +# def fromDescription(self, description): +# self.device = description["device"] +# self.addTask(CreatePartitionTask(self.device)) +# self.addTask(CreateFilesystemTask(self.device)) +# self.addTask(FilesystemMountTask(self.device)) +# +# def createDescription(self): +# return {"device": self.device} + +job_manager = JobManager() diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..f56f3bc --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = Components src po diff --git a/README.md b/README.md new file mode 100755 index 0000000..1373c97 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/92f5ff82cf014812a6383cc8fbac235e)](https://app.codacy.com/gh/dream-alpha/JobCockpit/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![Gemfury](https://badge.fury.io/fp/gemfury.svg)](https://gemfury.com/f/partner) + +# JOBCockpit (JOC) +DreamOS plugin replacing standard job manager + +## Features +- Keeps jobs after completion. +- Adds functions to query successfully completed and failed jobs. +- Provides separate task managers by plugin... that allow parallel execution of jobs. + +## Languages +- n/a + +## Links +- Installation: https://dream-alpha.github.io/JobCockpit +- Support: https://github.com/dream-alpha/JobCockpit/discussions +- Package feed: https://gemfury.com/dream-alpha diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..1c551b4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,15 @@ + + +

JobCockpit Installation

+ To install the JobCockpit plugin execute the following commands in a telnet console on your dreambox: + + The installation script will also install a feed source that enables a convenient upgrade to the latest version with the following commands or automatically as part of a DreamOS upgrade: + + + diff --git a/docs/jobcockpit.sh b/docs/jobcockpit.sh new file mode 100755 index 0000000..b52b8b5 --- /dev/null +++ b/docs/jobcockpit.sh @@ -0,0 +1,8 @@ +#!/bin/sh +rm -f /etc/apt/sources.list.d/cockpit.list +apt-get update +apt-get install -y apt-transport-https +echo deb [trusted=yes] https://apt.fury.io/dream-alpha ./ > /etc/apt/sources.list.d/cockpit.list +apt-get update +apt-get install -y enigma2-plugin-systemplugins-jobcockpit +systemctl restart enigma2 diff --git a/po/JobCockpit.pot b/po/JobCockpit.pot new file mode 100644 index 0000000..dfc967c --- /dev/null +++ b/po/JobCockpit.pot @@ -0,0 +1,35 @@ +msgid "" +msgstr "" +"Project-Id-Version: JobCockpit\n" +"POT-Creation-Date: 2024-09-07 17:56+0200\n" +"PO-Revision-Date: \n" +"Last-Translator: dream-alpha\n" +"Language-Team: \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 3.5\n" +"X-Poedit-Basepath: ../src\n" +"X-Poedit-SearchPath-0: .\n" + +msgid "Job Management" +msgstr "" + +msgid "Abort current job" +msgstr "" + +msgid "Abort all jobs" +msgstr "" + +msgid "Abort all pending jobs" +msgstr "" + +msgid "Cleanup jobs" +msgstr "" + +msgid "Manage Jobs" +msgstr "" + +msgid "Jobs" +msgstr "" diff --git a/po/Makefile.am b/po/Makefile.am new file mode 100644 index 0000000..28156b5 --- /dev/null +++ b/po/Makefile.am @@ -0,0 +1,61 @@ +# +# to use this for the localisation of other plugins, +# just change the DOMAIN to the name of the Plugin. +# It is assumed, that the domain ist the same as +# the directory name of the plugin. +# + +DOMAIN = JobCockpit +installdir = $(libdir)/enigma2/python/Plugins/Extensions/$(DOMAIN) +#GETTEXT=./pygettext.py +GETTEXT=xgettext + +#MSGFMT = ./msgfmt.py +MSGFMT = msgfmt + +LANGS := de +LANGPO := $(foreach LANG, $(LANGS),$(LANG).po) +LANGMO := $(foreach LANG, $(LANGS),$(LANG).mo) + +default: $(DOMAIN).pot $(LANGPO) merge $(LANGMO) + for lang in $(LANGS); do \ + mkdir -p $$lang/LC_MESSAGES; \ + cp $$lang.mo $$lang/LC_MESSAGES/$(DOMAIN).mo; \ + cp $$lang.po $$lang/LC_MESSAGES/$$lang.po; \ + done + +merge: + for lang in $(LANGS); do \ + msgmerge --no-location -s -N -U $$lang.po $(DOMAIN).pot; \ + done + + +# the TRANSLATORS: allows putting translation comments before the to-be-translated line. +$(DOMAIN).pot: + $(GETTEXT) -L python --add-comments="TRANSLATORS:" -d $(DOMAIN) -s -o $(DOMAIN).pot ../*.py + + ../xml2po.py ../ >> $(DOMAIN).pot + + msguniq -o $(DOMAIN)uniq.pot $(DOMAIN).pot + + +.PHONY: $(DOMAIN).pot + + +%.mo: %.po + $(MSGFMT) -o $@ $< + +%.po: + msginit -l $@ -o $@ -i $(DOMAIN).pot --no-translator + +CLEANFILES = $(foreach LANG, $(LANGS),$(LANG).mo) + +clean-local: + $(RM) -r $(LANGS) + +install-data-am: default + for lang in $(LANGS); do \ + mkdir -p $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES; \ + cp $$lang.mo $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES/$(DOMAIN).mo; \ + cp $$lang.po $(DESTDIR)$(installdir)/locale/$$lang/LC_MESSAGES/$$lang.po; \ + done diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000..5dc23b5 --- /dev/null +++ b/po/de.po @@ -0,0 +1,35 @@ +msgid "" +msgstr "" +"Project-Id-Version: JobCockpit\n" +"POT-Creation-Date: 2024-09-07 17:56+0200\n" +"PO-Revision-Date: \n" +"Last-Translator: dream-alpha\n" +"Language-Team: \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 3.5\n" +"X-Poedit-Basepath: ../src\n" +"X-Poedit-SearchPath-0: .\n" + +msgid "Job Management" +msgstr "Job Verwaltung" + +msgid "Abort current job" +msgstr "Ausgewählten Job abbrechen" + +msgid "Abort all jobs" +msgstr "Alle Jobs abbrechen" + +msgid "Abort all pending jobs" +msgstr "Alle wartenden Jobs abbrechen" + +msgid "Cleanup jobs" +msgstr "Jobs bereinigen" + +msgid "Manage Jobs" +msgstr "Jobs verwalten" + +msgid "Jobs" +msgstr "Jobs" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..968fd5c --- /dev/null +++ b/setup.cfg @@ -0,0 +1,9 @@ +[flake8] +ignore = W191, W503, E117, E203, E242, E501 + +[pycodestyle] +count = False +ignore = W191, W503, E117, E203, E242 + +max-line-length = 320 +statistics = True diff --git a/src/Debug.py b/src/Debug.py new file mode 100644 index 0000000..5045d56 --- /dev/null +++ b/src/Debug.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +import sys +import logging +from Components.config import config, ConfigSubsection, ConfigDirectory, ConfigSelection # noqa: F401, pylint: disable=W0611 +from .Version import ID, PLUGIN + + +logger = None +streamer = None +format_string = ID + ": " + "%(levelname)s: %(filename)s: %(funcName)s: %(message)s" +log_levels = {"ERROR": logging.ERROR, "INFO": logging.INFO, "DEBUG": logging.DEBUG} +plugin = PLUGIN.lower() +exec("config.plugins." + plugin + " = ConfigSubsection()") # noqa: F401, pylint: disable=W0122 +exec("config.plugins." + plugin + ".debug_log_level = ConfigSelection(default='INFO', choices=log_levels.keys())") # noqa: F401, pylint: disable=W0122 + + +def initLogging(): + global logger + global streamer + if not logger: + logger = logging.getLogger(ID) + formatter = logging.Formatter(format_string) + streamer = logging.StreamHandler(sys.stdout) + streamer.setFormatter(formatter) + logger.addHandler(streamer) + logger.propagate = False + setLogLevel(log_levels[eval("config.plugins." + plugin + ".debug_log_level").value]) + + +def setLogLevel(level): + logger.setLevel(level) + streamer.setLevel(level) + logger.info("level: %s", level) diff --git a/src/JobCockpit.png b/src/JobCockpit.png new file mode 100644 index 0000000..2a2f8cc Binary files /dev/null and b/src/JobCockpit.png differ diff --git a/src/JobCockpit.py b/src/JobCockpit.py new file mode 100644 index 0000000..8a9d7a0 --- /dev/null +++ b/src/JobCockpit.py @@ -0,0 +1,121 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +from Screens.Screen import Screen +from Components.ActionMap import ActionMap +from Components.Sources.StaticText import StaticText +from Components.Sources.List import List +from Components.Task import Job +from enigma import eTimer +from .__init__ import _ +from .Debug import logger +from .JobSupervisor import JobSupervisor + + +class JobCockpit(Screen): + + def __init__(self, session, plugin_id=""): + logger.info("...") + self.plugin_id = plugin_id + self.job_supervisor = JobSupervisor.getInstance() + Screen.__init__(self, session) + self.skinName = "JobCockpit" + self.setTitle(_("Job Management")) + self['actions'] = ActionMap( + ['JOC_Actions'], + { + 'ok': self.exit, + 'cancel': self.exit, + 'red': self.execRed, + 'green': self.execGreen, + 'yellow': self.execYellow, + 'blue': self.execBlue + } + ) + self['key_red'] = StaticText(_('Abort current job')) + self['key_green'] = StaticText(_('Abort all jobs')) + self['key_yellow'] = StaticText(_('Abort all pending jobs')) + self['key_blue'] = StaticText(_('Cleanup jobs')) + self['list'] = List() + self.update_timer = eTimer() + self.update_timer_conn = self.update_timer.timeout.connect(self.updateList) + self.updateList() + + def updateList(self): + logger.info("...") + self.update_timer.stop() + index = self['list'].index + alist = [] + for plugin, job in self.job_supervisor.getPendingJobs(self.plugin_id, as_tuples=True): + alist.append((job.name, job.getStatustext(), job.getProgress(), "%d%%" % job.getProgress(), job, plugin)) + for plugin, job in self.job_supervisor.getFailedJobs(self.plugin_id, as_tuples=True): + alist.append((job.name, job.getStatustext(), job.getProgress(), "%d%%" % job.getProgress(), job, plugin)) + for plugin, job in self.job_supervisor.getSuccessfullJobs(self.plugin_id, as_tuples=True): + alist.append((job.name, job.getStatustext(), job.getProgress(), "%d%%" % job.getProgress(), job, plugin)) + self['list'].setList(alist) + self['list'].setIndex(index) + self.update_timer.startLongTimer(1) + + @staticmethod + def abortJob(job, plugin_id, force=True): + logger.info("force: %s", force) + if job.status == Job.IN_PROGRESS: + JobSupervisor.getInstance().getJobManager(plugin_id).AbortJob(job, force) + + def execYellow(self): + logger.info("...") + self.update_timer.stop() + for entry in self["list"].list: + _name, _status, _progress, _info, job, plugin_id = entry + if job.status == Job.NOT_STARTED: + self.job_supervisor.getJobManager(plugin_id).RemoveJob(job) + self.updateList() + + def execGreen(self): + logger.info("...") + self.update_timer.stop() + for entry in self["list"].list: + _name, _status, _progress, _info, job, plugin_id = entry + self.job_supervisor.getJobManager(plugin_id).AbortJob(job) + self.updateList() + + def execRed(self): + logger.info("...") + self.update_timer.stop() + entry = self["list"].getCurrent() + if entry: + _name, _status, _progress, _info, job, plugin_id = entry + if job.status == Job.IN_PROGRESS: + self.job_supervisor.getJobManager(plugin_id).AbortJob(job) + else: + self.job_supervisor.getJobManager(plugin_id).RemoveJob(job) + self.updateList() + + def execBlue(self): + logger.info("...") + self.update_timer.stop() + for job_manager in self.job_supervisor.job_managers.values(): + job_manager.CleanupJobs() + self.updateList() + + def exit(self): + self.update_timer.stop() + self.close() diff --git a/src/JobSupervisor.py b/src/JobSupervisor.py new file mode 100644 index 0000000..11e24ea --- /dev/null +++ b/src/JobSupervisor.py @@ -0,0 +1,82 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +from Components.Task import job_manager, JobManager +from .Debug import logger + + +instance = None + + +class JobSupervisor(): + + def __init__(self): + self.job_managers = {} + self.job_managers["DEFAULT"] = job_manager + + @staticmethod + def getInstance(): + global instance + if instance is None: + instance = JobSupervisor() + return instance + + def getJobManager(self, plugin_id): + logger.info("plugin_id: %s", plugin_id) + if plugin_id not in self.job_managers: + self.job_managers[plugin_id] = JobManager() + return self.job_managers[plugin_id] + + def createJobTuples(self, plugin_id, jobs, as_tuples): + job_tuples = [] + if as_tuples: + for job in jobs: + job_tuples.append((plugin_id, job)) + else: + job_tuples = jobs + return job_tuples + + def getJobManagers(self, plugin_id=""): + job_managers = {} + if plugin_id: + if self.job_managers.get(plugin_id, ""): + job_managers = {plugin_id: self.job_managers.get(plugin_id, "")} + else: + job_managers = self.job_managers + return job_managers + + def getPendingJobs(self, plugin_id="", as_tuples=False): + jobs = [] + for plugin, manager in self.getJobManagers(plugin_id).items(): + jobs += self.createJobTuples(plugin, manager.getPendingJobs(), as_tuples) + return jobs + + def getFailedJobs(self, plugin_id="", as_tuples=False): + jobs = [] + for plugin, manager in self.getJobManagers(plugin_id).items(): + jobs += self.createJobTuples(plugin, manager.getFailedJobs(), as_tuples) + return jobs + + def getSuccessfullJobs(self, plugin_id="", as_tuples=False): + jobs = [] + for plugin, manager in self.getJobManagers(plugin_id).items(): + jobs += self.createJobTuples(plugin, manager.getSuccessfullJobs(), as_tuples) + return jobs diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..e546386 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,4 @@ +installdir = $(libdir)/enigma2/python/Plugins/SystemPlugins/JobCockpit +SUBDIRS = skin +install_PYTHON = *.py +install_DATA = *.xml *.png diff --git a/src/PluginUtils.py b/src/PluginUtils.py new file mode 100644 index 0000000..a044a53 --- /dev/null +++ b/src/PluginUtils.py @@ -0,0 +1,39 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +from Components.PluginComponent import plugins + + +WHERE_SEARCH = -99 +WHERE_TMDB_SEARCH = -98 +WHERE_TMDB_MOVIELIST = -97 +WHERE_MEDIATHEK_SEARCH = -96 +WHERE_TVMAGAZINE_SEARCH = -95 +WHERE_COVER_DOWNLOAD = -94 +WHERE_JOBCOCKPIT = -93 + + +def getPlugin(where): + plugin = None + plugins_list = plugins.getPlugins(where=where) + if len(plugins_list) > 0: + plugin = plugins_list[0] + return plugin diff --git a/src/SkinUtils.py b/src/SkinUtils.py new file mode 100644 index 0000000..1228983 --- /dev/null +++ b/src/SkinUtils.py @@ -0,0 +1,96 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +import os +from enigma import getDesktop +from Components.config import config +from Tools.Directories import resolveFilename, SCOPE_PLUGINS +from skin import loadSkin, loadSingleSkinData, dom_skins +from .Debug import logger +from .Version import ID, PLUGIN + + +def getSkinName(skin_name): + return ID + skin_name + + +def getScalingFactor(): + return {"HD": 2.0 / 3.0, "FHD": 1, "WQHD": 4.0 / 3.0}[getResolution()] + + +def getResolution(): + height = getDesktop(0).size().height() + resolution = "SD" + if height > 576: + resolution = "HD" + if height > 720: + resolution = "FHD" + if height > 1080: + resolution = "WQHD" + return resolution + + +def getSkinPath(file_name): + logger.debug(">>> file_name: %s", file_name) + base_skin_dir = "/usr/share/enigma2" + sub_skin_dir = os.path.dirname(config.skin.primary_skin.value) + resolution = getResolution() + logger.debug("resolution: %s, sub_skin_dir: %s", resolution, sub_skin_dir) + if not sub_skin_dir: + sub_skin_dir = "Default-HD" + elif resolution == "FHD": + if sub_skin_dir in ["Shadow-FHD", "Zombi-Shadow-FHD"]: + sub_skin_dir = "Shadow-FHD" + else: + sub_skin_dir = "Default-FHD" + elif resolution == "WQHD": + if sub_skin_dir in ["Shadow-WQHD", "Default-WQHD"]: + sub_skin_dir = "Default-WQHD" + else: + sub_skin_dir = "Other-WQHD" + else: + sub_skin_dir = "Default-HD" + + dirs = [ + os.path.join(resolveFilename(SCOPE_PLUGINS), "Extensions", PLUGIN, "skin", sub_skin_dir), + os.path.join(resolveFilename(SCOPE_PLUGINS), "SystemPlugins", PLUGIN, "skin", sub_skin_dir), + os.path.join(resolveFilename(SCOPE_PLUGINS), "Extensions", PLUGIN, "skin"), + os.path.join(resolveFilename(SCOPE_PLUGINS), "SystemPlugins", PLUGIN, "skin"), + os.path.join(base_skin_dir, sub_skin_dir), + base_skin_dir + ] + logger.debug("dirs: %s", dirs) + + for adir in dirs: + skin_path = os.path.join(adir, file_name) + logger.debug("checking: skin_path: %s", skin_path) + if os.path.exists(skin_path): + break + skin_path = "" + logger.debug("skin_path: %s", skin_path) + return skin_path + + +def loadPluginSkin(skin_file): + logger.info("skin_path: %s", getSkinPath(skin_file)) + loadSkin(getSkinPath(skin_file), "") + path, dom_skin = dom_skins[-1:][0] + loadSingleSkinData(getDesktop(0), dom_skin, path) diff --git a/src/Version.py b/src/Version.py new file mode 100644 index 0000000..521f5e3 --- /dev/null +++ b/src/Version.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +PLUGIN = "JobCockpit" +ID = "JOC" +VERSION = "0.3.16" +COPYRIGHT = "2018-2024 by dream-alpha" +LICENSE = "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..edcc6e0 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,47 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +import os +import gettext +from Components.Language import language +from Tools.Directories import resolveFilename, SCOPE_PLUGINS +from .Version import PLUGIN +from .Debug import initLogging + + +def initLocale(): + lang = language.getLanguage()[:2] + os.environ["LANGUAGE"] = lang + locale = resolveFilename(SCOPE_PLUGINS, "Extensions/" + PLUGIN + "/locale") + if not os.path.exists(locale): + locale = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/" + PLUGIN + "/locale") + if os.path.exists(locale): + gettext.bindtextdomain(PLUGIN, locale) + + +def _(txt): + translation = gettext.dgettext(PLUGIN, txt) + return translation + + +initLogging() +initLocale() +language.addCallback(initLocale) diff --git a/src/keymap.xml b/src/keymap.xml new file mode 100644 index 0000000..734da18 --- /dev/null +++ b/src/keymap.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/locale/de/LC_MESSAGES/JobCockpit.mo b/src/locale/de/LC_MESSAGES/JobCockpit.mo new file mode 100644 index 0000000..7931953 Binary files /dev/null and b/src/locale/de/LC_MESSAGES/JobCockpit.mo differ diff --git a/src/plugin.py b/src/plugin.py new file mode 100644 index 0000000..8fcba52 --- /dev/null +++ b/src/plugin.py @@ -0,0 +1,76 @@ +#!/usr/bin/python +# coding=utf-8 +# +# Copyright (C) 2018-2024 by dream-alpha +# +# In case of reuse of this source code please do not remove this copyright. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# For more information on the GNU General Public License see: +# . + + +from Plugins.Plugin import PluginDescriptor +from .SkinUtils import loadPluginSkin +from .Debug import logger +from .Version import VERSION +from .JobCockpit import JobCockpit +from .PluginUtils import WHERE_JOBCOCKPIT +from . import _ +from .JobSupervisor import JobSupervisor + + +def showJobs(session, plugin_id="", **_kwargs): + logger.info("plugin_id: %s", plugin_id) + session.open(JobCockpit, plugin_id) + + +def main(session, **__kwargs): + logger.info("...") + session.open(JobCockpit) + + +def autoStart(reason, **kwargs): + if reason == 0: # startup + if "session" in kwargs: + logger.info("+++ Version: %s starts...", VERSION) + loadPluginSkin("skin.xml") + JobSupervisor.getInstance() + elif reason == 1: # shutdown + logger.info("--- shutdown") + else: + logger.info("reason not handled: %s", reason) + + +def Plugins(**__kwargs): + return [ + PluginDescriptor( + where=[ + PluginDescriptor.WHERE_AUTOSTART, + PluginDescriptor.WHERE_SESSIONSTART + ], + fnc=autoStart + ), + PluginDescriptor( + name="JobCockpit", + where=PluginDescriptor.WHERE_PLUGINMENU, + icon="JobCockpit.png", + description=_("Manage Jobs"), + fnc=main + ), + PluginDescriptor( + name=_("Jobs"), + description=_("Manage Jobs"), + where=WHERE_JOBCOCKPIT, + fnc=showJobs + ) + ] diff --git a/src/skin/Default-FHD/Makefile.am b/src/skin/Default-FHD/Makefile.am new file mode 100644 index 0000000..116b96d --- /dev/null +++ b/src/skin/Default-FHD/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/Extensions/JobCockpit/skin/Default-FHD +install_DATA = skin.xml diff --git a/src/skin/Default-FHD/colors.xmlinc b/src/skin/Default-FHD/colors.xmlinc new file mode 100644 index 0000000..239e7c9 --- /dev/null +++ b/src/skin/Default-FHD/colors.xmlinc @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/skin/Default-FHD/skin.xml b/src/skin/Default-FHD/skin.xml new file mode 100644 index 0000000..dc6688c --- /dev/null +++ b/src/skin/Default-FHD/skin.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + {"template": [ MultiContentEntryText(pos=(10,0),size=(1160,40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=0), MultiContentEntryText(pos=(10,40),size=(200,40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=1), MultiContentEntryProgress(pos=(250,50),size=(800,20),percent=-2, borderWidth=1), MultiContentEntryText(pos=(1060,40),size=(100,40),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0, text=3), ], "fonts": [gFont("Regular",28)], "itemHeight": 80 } + + + diff --git a/src/skin/Default-HD/Makefile.am b/src/skin/Default-HD/Makefile.am new file mode 100644 index 0000000..acccbb4 --- /dev/null +++ b/src/skin/Default-HD/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/Extensions/JobCockpit/skin/Default-HD +install_DATA = skin.xml diff --git a/src/skin/Default-HD/colors.xmlinc b/src/skin/Default-HD/colors.xmlinc new file mode 100644 index 0000000..239e7c9 --- /dev/null +++ b/src/skin/Default-HD/colors.xmlinc @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/skin/Default-HD/skin.xml b/src/skin/Default-HD/skin.xml new file mode 100644 index 0000000..c749ee6 --- /dev/null +++ b/src/skin/Default-HD/skin.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + {"template":[MultiContentEntryText(pos=(7,0),size=(773,27),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=0),MultiContentEntryText(pos=(7,27),size=(133,27),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=1),MultiContentEntryProgress(pos=(167,33),size=(533,13),percent=-2,borderWidth=1),MultiContentEntryText(pos=(707,27),size=(67,27),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0,text=3),],"fonts":[gFont("Regular",19)],"itemHeight":53} + + + diff --git a/src/skin/Default-WQHD/Makefile.am b/src/skin/Default-WQHD/Makefile.am new file mode 100644 index 0000000..137fb3d --- /dev/null +++ b/src/skin/Default-WQHD/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/Extensions/JobCockpit/skin/Default-WQHD +install_DATA = skin.xml diff --git a/src/skin/Default-WQHD/colors.xmlinc b/src/skin/Default-WQHD/colors.xmlinc new file mode 100644 index 0000000..23b5d66 --- /dev/null +++ b/src/skin/Default-WQHD/colors.xmlinc @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/skin/Default-WQHD/screen_JobCockpit.xmlinc b/src/skin/Default-WQHD/screen_JobCockpit.xmlinc new file mode 100755 index 0000000..6622f38 --- /dev/null +++ b/src/skin/Default-WQHD/screen_JobCockpit.xmlinc @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/skin/Default-WQHD/skin.xml b/src/skin/Default-WQHD/skin.xml new file mode 100644 index 0000000..8b4de64 --- /dev/null +++ b/src/skin/Default-WQHD/skin.xml @@ -0,0 +1,20 @@ + + + + + + + + + {"template":[MultiContentEntryText(pos=(13,0),size=(1547,53),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=0),MultiContentEntryText(pos=(13,53),size=(267,53),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=1),MultiContentEntryProgress(pos=(333,67),size=(1067,27),percent=-2,borderWidth=1),MultiContentEntryText(pos=(1413,53),size=(133,53),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0,text=3),],"fonts":[gFont("Regular",37)],"itemHeight":107} + + + + + + + + + + + diff --git a/src/skin/Makefile.am b/src/skin/Makefile.am new file mode 100644 index 0000000..43f5e1c --- /dev/null +++ b/src/skin/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = Default-HD Default-FHD Default-WQHD Other-WQHD Shadow-FHD diff --git a/src/skin/Other-WQHD/Makefile.am b/src/skin/Other-WQHD/Makefile.am new file mode 100644 index 0000000..137fb3d --- /dev/null +++ b/src/skin/Other-WQHD/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/Extensions/JobCockpit/skin/Default-WQHD +install_DATA = skin.xml diff --git a/src/skin/Other-WQHD/colors.xmlinc b/src/skin/Other-WQHD/colors.xmlinc new file mode 100644 index 0000000..88b18fa --- /dev/null +++ b/src/skin/Other-WQHD/colors.xmlinc @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/skin/Other-WQHD/skin.xml b/src/skin/Other-WQHD/skin.xml new file mode 100644 index 0000000..38a6c0a --- /dev/null +++ b/src/skin/Other-WQHD/skin.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + {"template":[MultiContentEntryText(pos=(13,0),size=(1547,53),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=0),MultiContentEntryText(pos=(13,53),size=(267,53),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0,text=1),MultiContentEntryProgress(pos=(333,67),size=(1067,27),percent=-2,borderWidth=1),MultiContentEntryText(pos=(1413,53),size=(133,53),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0,text=3),],"fonts":[gFont("Regular",37)],"itemHeight":107} + + + diff --git a/src/skin/Shadow-FHD/Makefile.am b/src/skin/Shadow-FHD/Makefile.am new file mode 100644 index 0000000..c91f46e --- /dev/null +++ b/src/skin/Shadow-FHD/Makefile.am @@ -0,0 +1,2 @@ +installdir = $(libdir)/enigma2/python/Plugins/Extensions/JobCockpit/skin/Shadow-FHD +install_DATA = skin.xml diff --git a/src/skin/Shadow-FHD/colors.xmlinc b/src/skin/Shadow-FHD/colors.xmlinc new file mode 100644 index 0000000..218bc31 --- /dev/null +++ b/src/skin/Shadow-FHD/colors.xmlinc @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/skin/Shadow-FHD/screen_JobCockpit.xmlinc b/src/skin/Shadow-FHD/screen_JobCockpit.xmlinc new file mode 100755 index 0000000..a97e581 --- /dev/null +++ b/src/skin/Shadow-FHD/screen_JobCockpit.xmlinc @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/skin/Shadow-FHD/skin.xml b/src/skin/Shadow-FHD/skin.xml new file mode 100644 index 0000000..7f9cef2 --- /dev/null +++ b/src/skin/Shadow-FHD/skin.xml @@ -0,0 +1,20 @@ + + + + + + + + + {"template": [ MultiContentEntryText(pos=(10,0),size=(1160,40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=0), MultiContentEntryText(pos=(10,40),size=(200,40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=1), MultiContentEntryProgress(pos=(250,50),size=(800,20),percent=-2, borderWidth=1), MultiContentEntryText(pos=(1060,40),size=(100,40),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0, text=3), ], "fonts": [gFont("Regular",28)], "itemHeight": 80 } + + + + + + + + + + + diff --git a/src/skin/screen_JobCockpit.xmlinc b/src/skin/screen_JobCockpit.xmlinc new file mode 100755 index 0000000..1c64d40 --- /dev/null +++ b/src/skin/screen_JobCockpit.xmlinc @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/skin/screenpart_1Button_icon.xmlinc b/src/skin/screenpart_1Button_icon.xmlinc new file mode 100644 index 0000000..7fdff5f --- /dev/null +++ b/src/skin/screenpart_1Button_icon.xmlinc @@ -0,0 +1 @@ + diff --git a/src/skin/screenpart_1Button_source_2x.xmlinc b/src/skin/screenpart_1Button_source_2x.xmlinc new file mode 100644 index 0000000..9ce9b2c --- /dev/null +++ b/src/skin/screenpart_1Button_source_2x.xmlinc @@ -0,0 +1 @@ + diff --git a/src/skin/screenpart_4Buttons_icon.xmlinc b/src/skin/screenpart_4Buttons_icon.xmlinc new file mode 100644 index 0000000..3494407 --- /dev/null +++ b/src/skin/screenpart_4Buttons_icon.xmlinc @@ -0,0 +1,4 @@ + + + + diff --git a/src/skin/screenpart_4Buttons_source_2x.xmlinc b/src/skin/screenpart_4Buttons_source_2x.xmlinc new file mode 100644 index 0000000..3fb5b29 --- /dev/null +++ b/src/skin/screenpart_4Buttons_source_2x.xmlinc @@ -0,0 +1,5 @@ + + + + + diff --git a/src/skin/screenpart_Background.xmlinc b/src/skin/screenpart_Background.xmlinc new file mode 100644 index 0000000..73bed6f --- /dev/null +++ b/src/skin/screenpart_Background.xmlinc @@ -0,0 +1,3 @@ + + + diff --git a/src/skin/screenpart_JobCockpitList.xmlinc b/src/skin/screenpart_JobCockpitList.xmlinc new file mode 100755 index 0000000..d1c7b96 --- /dev/null +++ b/src/skin/screenpart_JobCockpitList.xmlinc @@ -0,0 +1,13 @@ + + + {"template": [ + MultiContentEntryText(pos=(10,0),size=(eval($screen_width-40),40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=0), + MultiContentEntryText(pos=(10,40),size=(200,40),flags=RT_HALIGN_LEFT|RT_VALIGN_CENTER,font=0, text=1), + MultiContentEntryProgress(pos=(250,50),size=(800,20),percent=-2, borderWidth=1), + MultiContentEntryText(pos=(1060,40),size=(100,40),flags=RT_HALIGN_RIGHT|RT_VALIGN_CENTER,font=0, text=3), + ], + "fonts": [gFont("Regular",28)], + "itemHeight": 80 + } + + diff --git a/src/skin/screenpart_TitleOnly.xmlinc b/src/skin/screenpart_TitleOnly.xmlinc new file mode 100644 index 0000000..8360b2d --- /dev/null +++ b/src/skin/screenpart_TitleOnly.xmlinc @@ -0,0 +1 @@ + diff --git a/src/skin/skin_src.xml b/src/skin/skin_src.xml new file mode 100755 index 0000000..c8f88e7 --- /dev/null +++ b/src/skin/skin_src.xml @@ -0,0 +1,4 @@ + + + +