def get_package_manager(): if get_package_manager._package_manager is None: package_manager = PackageManager(lock=False) package_manager.set_finished( ) # currently not working. accepting new tasks package_manager.logger.parent = get_base_logger() log_filter = _PackageManagerLogHandler() package_manager.logger.addHandler(log_filter) get_package_manager._package_manager = package_manager return get_package_manager._package_manager
def init(self): os.umask( 0o022 ) # umc umask is too restrictive for app center as it creates a lot of files in docker containers self.ucr = ucr_instance() self.update_applications_done = False install_opener(self.ucr) self._is_working = False try: self.package_manager = PackageManager( info_handler=MODULE.process, step_handler=None, error_handler=MODULE.warn, lock=False, ) except SystemError as exc: MODULE.error(str(exc)) raise umcm.UMC_Error(str(exc), status=500) self.package_manager.set_finished( ) # currently not working. accepting new tasks get_package_manager._package_manager = self.package_manager # build cache _update_modules() get_action('list').get_apps() # not initialize here: error prone due to network errors and also kinda slow self._uu = None self._cm = None # in order to set the correct locale locale.setlocale(locale.LC_ALL, str(self.locale)) try: log_to_logfile() except IOError: pass # connect univention.appcenter.log to the progress-method handler = ProgressInfoHandler(self.package_manager) handler.setLevel(logging.INFO) get_base_logger().addHandler(handler) percentage = ProgressPercentageHandler(self.package_manager) percentage.setLevel(logging.DEBUG) get_base_logger().getChild('actions.install.progress').addHandler( percentage) get_base_logger().getChild('actions.upgrade.progress').addHandler( percentage) get_base_logger().getChild('actions.remove.progress').addHandler( percentage)
def init(self): os.umask(0o022) # umc umask is too restrictive for app center as it creates a lot of files in docker containers self.ucr = ucr_instance() self.update_applications_done = False util.install_opener(self.ucr) self._remote_progress = {} try: self.package_manager = PackageManager( info_handler=MODULE.process, step_handler=None, error_handler=MODULE.warn, lock=False, ) except SystemError as exc: MODULE.error(str(exc)) raise umcm.UMC_Error(str(exc), status=500) self.package_manager.set_finished() # currently not working. accepting new tasks self.uu = UniventionUpdater(False) self.component_manager = util.ComponentManager(self.ucr, self.uu) get_package_manager._package_manager = self.package_manager # in order to set the correct locale for Application locale.setlocale(locale.LC_ALL, str(self.locale)) try: log_to_logfile() except IOError: pass # connect univention.appcenter.log to the progress-method handler = ProgressInfoHandler(self.package_manager) handler.setLevel(logging.INFO) get_base_logger().addHandler(handler) percentage = ProgressPercentageHandler(self.package_manager) percentage.setLevel(logging.DEBUG) get_base_logger().getChild('actions.install.progress').addHandler(percentage) get_base_logger().getChild('actions.upgrade.progress').addHandler(percentage) get_base_logger().getChild('actions.remove.progress').addHandler(percentage)
# License with the Debian GNU/Linux or Univention distribution in file # /usr/share/common-licenses/AGPL-3; if not, see # <http://www.gnu.org/licenses/>. # import os import MySQLdb as mysql from ipaddr import IPv4Network, AddressValueError from univention.appcenter.utils import generate_password, call_process, call_process_as, container_mode from univention.appcenter.packages import packages_are_installed, install_packages, update_packages, mark_packages_as_manually_installed from univention.appcenter.log import get_base_logger, LogCatcher from univention.appcenter.ucr import ucr_get database_logger = get_base_logger().getChild('database') class DatabaseError(Exception): pass class DatabaseCreationFailed(DatabaseError): pass class DatabaseConnectionFailed(DatabaseError): pass class DatabaseInfoError(DatabaseError):
# License with the Debian GNU/Linux or Univention distribution in file # /usr/share/common-licenses/AGPL-3; if not, see # <https://www.gnu.org/licenses/>. # import os import os.path from six import string_types from univention.appcenter.utils import app_is_running, container_mode, mkdir, _ from univention.appcenter.log import get_base_logger from univention.appcenter.ucr import ucr_get, ucr_is_true, ucr_run_filter from univention.appcenter.ini_parser import TypedIniSectionObject, IniSectionBooleanAttribute, IniSectionListAttribute, IniSectionAttribute settings_logger = get_base_logger().getChild('settings') class SettingValueError(Exception): pass class Setting(TypedIniSectionObject): '''Based on the .settings file, models additional settings for Apps that can be configured before installation, during run-time, etc.''' type = IniSectionAttribute(default='String', choices=[ 'String', 'Int', 'Bool', 'List', 'Password', 'File', 'PasswordFile', 'Status' ])
# <https://www.gnu.org/licenses/>. # import os import fcntl import time import re from logging import Handler from contextlib import contextmanager from univention.lib.package_manager import PackageManager, LockError # LockError is actually imported from other files! from univention.appcenter.log import get_base_logger, LogCatcher from univention.appcenter.utils import call_process package_logger = get_base_logger().getChild('packages') LOCK_FILE = '/var/run/univention-appcenter.lock' class _PackageManagerLogHandler(Handler): def emit(self, record): if record.name.startswith('packagemanager.dpkg'): if isinstance(record.msg, basestring): record.msg = record.msg.rstrip() + '\r' if record.name.startswith('packagemanager.dpkg.percentage'): record.levelname = 'DEBUG' record.levelno = 10 def get_package_manager():
# License with the Debian GNU/Linux or Univention distribution in file # /usr/share/common-licenses/AGPL-3; if not, see # <https://www.gnu.org/licenses/>. # import os import re from univention.appcenter.app import CaseSensitiveConfigParser from univention.appcenter.log import get_base_logger from univention.appcenter.meta import UniventionMetaClass, UniventionMetaInfo from univention.appcenter.ucr import ucr_get, ucr_run_filter from univention.appcenter.udm import create_object_if_not_exists, create_recursive_container, remove_object_if_exists, modify_object from univention.appcenter.utils import underscore, get_md5, read_ini_file attribute_logger = get_base_logger().getChild('attributes') class Attribute(UniventionMetaInfo): pop = True save_as_list = '_attrs' auto_set_name = True def __init__(self, default_value=None): self.default_value = default_value super(Attribute, self).__init__() def ldap_name(self): return self.name.upper().replace('_', '-') def escape_value(self, value):
class UniventionAppAction(with_metaclass(UniventionAppActionMeta, object)): parent_logger = get_base_logger().getChild('actions') def __init__(self): self._progress_percentage = 0 @classmethod def get_action_name(cls): return underscore(cls.__name__).replace('_', '-') @classmethod def _log(cls, logger, level, msg, *args, **kwargs): if logger is not None: logger = cls.logger.getChild(logger) else: logger = cls.logger logger.log(level, msg, *args, **kwargs) @classmethod def debug(cls, msg, logger=None): cls._log(logger, logging.DEBUG, str(msg)) @classmethod def log(cls, msg, logger=None): cls._log(logger, logging.INFO, str(msg)) @classmethod def warn(cls, msg, logger=None): cls._log(logger, logging.WARN, str(msg)) @classmethod def fatal(cls, msg, logger=None): cls._log(logger, logging.FATAL, str(msg)) @classmethod def log_exception(cls, exc, logger=None): cls._log(logger, logging.ERROR, exc, exc_info=1) def setup_parser(self, parser): pass @property def percentage(self): return self._progress_percentage @percentage.setter def percentage(self, percentage): self._progress_percentage = percentage self.progress.debug(str(percentage)) def _build_namespace(self, _namespace=None, **kwargs): parser = ArgumentParser() self.setup_parser(parser) namespace = Namespace() args = {} for action in parser._actions: default = parser._defaults.get(action.dest) if action.default is not None: default = action.default if hasattr(_namespace, action.dest): default = getattr(_namespace, action.dest) args[action.dest] = default args.update(kwargs) for key, value in args.items(): setattr(namespace, key, value) return namespace @classmethod def call_safe(cls, **kwargs): try: return cls.call(**kwargs) except Abort: return None @classmethod def call(cls, **kwargs): obj = cls() namespace = obj._build_namespace(**kwargs) return obj.call_with_namespace(namespace) def call_with_namespace(self, namespace): self.debug('Calling %s' % self.get_action_name()) self.percentage = 0 try: result = self.main(namespace) except Abort as exc: msg = str(exc) if msg: self.fatal(msg) self.percentage = 100 raise except Exception as exc: self.log_exception(exc) raise else: self.percentage = 100 return result def _get_joinscript_path(self, app, unjoin=False): number = 50 suffix = '' ext = 'inst' if unjoin: number = 51 ext = 'uinst' suffix = '-uninstall' return os.path.join(JOINSCRIPT_DIR, '%d%s%s.%s' % (number, app.id, suffix, ext)) def _call_cache_script(self, _app, _ext, *args, **kwargs): fname = _app.get_cache_file(_ext) # change to UCS umask + u+x: -rwxr--r-- if os.path.exists(fname): os.chmod(fname, 0o744) return self._call_script(fname, *args, **kwargs) def _call_script(self, _script, *args, **kwargs): if not os.path.exists(_script): self.debug('%s does not exist' % _script) return None subprocess_args = [_script] + list(args) for key, value in kwargs.items(): if value is None or value is False: continue key = '--%s' % key.replace('_', '-') subprocess_args.append(key) if value is not True: subprocess_args.append(value) process = self._subprocess(subprocess_args) self.debug('%s returned with %s' % (_script, process.returncode)) return process.returncode == 0 def _subprocess(self, args, logger=None, env=None): if logger is None: logger = self.logger elif isinstance(logger, string_types): logger = self.logger.getChild(logger) return call_process(args, logger, env) @possible_network_error def _send_information(self, app, status, value=None): action = self.get_action_name() send_information(action, app, status, value)
from six.moves.configparser import RawConfigParser, ParsingError from six.moves import urllib_request, http_client from six.moves.urllib_parse import urlencode from univention.lib.i18n import Translation from univention.config_registry.misc import key_shell_escape from univention.config_registry import interfaces from univention.appcenter.log import get_base_logger from univention.appcenter.ucr import ucr_get, ucr_keys # "global" translation for univention-appcenter # also provides translation for univention-appcenter-docker etc _ = Translation('univention-appcenter').translate utils_logger = get_base_logger().getChild('utils') def read_ini_file(filename, parser_class=RawConfigParser): parser = parser_class() try: with open(filename, 'rb') as f: parser.readfp(f) except TypeError: pass except EnvironmentError: pass except ParsingError as exc: utils_logger.warn('Could not parse %s' % filename) utils_logger.warn(str(exc)) else:
from glob import glob from json import dump, load from distutils.version import LooseVersion from six.moves.configparser import NoSectionError from six.moves.urllib_parse import urlsplit from univention.appcenter.app import App from univention.appcenter.log import get_base_logger from univention.appcenter.utils import mkdir, get_locale from univention.appcenter.ini_parser import read_ini_file, IniSectionListAttribute, IniSectionAttribute, IniSectionObject from univention.appcenter.ucr import ucr_load, ucr_get, ucr_is_true CACHE_DIR = '/var/cache/univention-appcenter' cache_logger = get_base_logger().getChild('cache') def _cmp_mtimes(mtime1, mtime2): if mtime1 is None or mtime2 is None: return cmp(mtime1, mtime2) return cmp(float('{:.3f}'.format(mtime1)), float('{:.3f}'.format(mtime2))) class _AppCache(object): def get_every_single_app(self): raise NotImplementedError() def get_all_apps_with_id(self, app_id): ret = [] for app in self.get_every_single_app():
import sys from subprocess import check_output, call, CalledProcessError import os import os.path import shlex from json import loads import requests from tempfile import NamedTemporaryFile from contextlib import contextmanager from univention.appcenter.utils import app_ports_with_protocol, call_process, call_process2, shell_safe, get_sha256, _ from univention.appcenter.log import get_base_logger from univention.appcenter.exceptions import DockerVerificationFailed from univention.appcenter.ucr import ucr_save, ucr_is_false, ucr_get, ucr_run_filter, ucr_is_true _logger = get_base_logger().getChild('docker') DOCKER_READ_USER_CRED = { 'username': '******', 'password': '******', } class DockerImageVerificationFailedRegistryContact(Exception): def __init__(self, app_name, docker_image_manifest_url): reason_en_US = 'Error while contacting Docker registry server %s' % ( docker_image_manifest_url, ) reason_message = _('Error while contacting Docker registry server %s' ) % (docker_image_manifest_url, ) _logger.error(reason_en_US)
function(app_center, function.__name__.replace("_", "-")) except Exception: print("Error in {}{}".format(function.__name__, function.__doc__)) raise print("Ok - {}{}".format(function.__name__, function.__doc__)) return wrapper def fail(message): raise AppCenterTestFailure(message) if __name__ == "__main__": app_logger.log_to_stream() app_logger.get_base_logger().setLevel(logging.WARNING) with local_appcenter(): app_center = AppCenterOperations() package = AppPackage.with_package(name="my-test-app", app_version="1.0") package.build_and_publish() test = TestOperations(app_center, package.app_id) test.test_install_remove_cycle() with test.test_install_safe(): dependency = DebianPackage("my-dependency") dependency.build()
# # You should have received a copy of the GNU Affero General Public # License with the Debian GNU/Linux or Univention distribution in file # /usr/share/common-licenses/AGPL-3; if not, see # <http://www.gnu.org/licenses/>. # from ConfigParser import RawConfigParser, ParsingError, NoSectionError, NoOptionError import re from copy import deepcopy from univention.appcenter.utils import get_locale from univention.appcenter.meta import UniventionMetaClass, UniventionMetaInfo from univention.appcenter.log import get_base_logger ini_logger = get_base_logger().getChild('ini') class NoValueError(Exception): def __init__(self, name, section): self.name = name self.section = section def __str__(self): return 'Missing %s in %s' % (self.name, self.section) class ParseError(Exception): def __init__(self, name, section, message): self.name = name self.section = section
import re from base64 import b64encode from copy import copy from ldap.dn import escape_dn_chars from ldap import SERVER_DOWN from six.moves.urllib_parse import urlsplit from univention.config_registry.interfaces import Interfaces import univention.admin.uexceptions as udm_errors from univention.appcenter.log import log_to_logfile, get_base_logger from univention.appcenter.udm import create_object_if_not_exists, remove_object_if_exists, get_machine_connection, modify_object, init_object, position log_to_logfile() portal_logger = get_base_logger().getChild('portalentries') class _Link(object): def __init__(self, protocol=None, host=None, port=None, path=None, full=None): self.protocol = protocol self.host = host self.port = port self.path = path self.full = full