コード例 #1
0
ファイル: qa.py プロジェクト: skwerlman/entropy
    def __init__(self, repository_id):
        """
        object constructor, repository_id must be a valid repository
        identifier.

        @param repository_id: valid repository identifier
        @type repository_id: string
        """
        super(UGCErrorReport, self).__init__("#fake#")

        self.__system_settings = SystemSettings()
        self._entropy = Client()
        if repository_id not in self.__system_settings['repositories']['order']:
            raise AttributeError('invalid repository_id provided')
        self.__repository_id = repository_id

        self._factory = self._entropy.WebServices()
        try:
            self._webserv = self._factory.new(self.__repository_id)
        except WebService.UnsupportedService:
            raise AttributeError('Web Services not supported by %s' % (
                self.__repository_id,))

        try:
            available = self._webserv.service_available()
        except WebService.WebServiceException:
            available = False

        if not available:
            raise AttributeError('Web Services not supported by %s (2)' % (
                self.__repository_id,))
コード例 #2
0
ファイル: client.py プロジェクト: skwerlman/entropy
 def _settings(self):
     """
     Get SystemSettings instance
     """
     if self.__settings is None:
         self.__settings = SystemSettings()
     return self.__settings
コード例 #3
0
    def __init__(self, repository_id):
        """
        Object constructor.

        @param repository_id: the repository identifier
        @type repository_id: string
        """
        self._repository_id = repository_id
        self._settings = SystemSettings()
コード例 #4
0
ファイル: skel.py プロジェクト: skwerlman/entropy
    def log_message(self, message):
        """
        Log message string to logfile.

        @param message: message string to log
        @type message: string
        """
        with LogFile(level=SystemSettings()['system']['log_level'],
                     filename=etpConst['entropylogfile'],
                     header="[spm]") as log:
            log.write(message)
コード例 #5
0
    def _settings(self):
        """
        Return a SystemSettings object instance.
        """
        with self._real_settings_lock:
            if self._real_settings is None:
                self._real_settings = SystemSettings()
                const_debug_write(__name__, "SystemSettings loaded")

                # add our SystemSettings plugin
                # Make sure we connect Entropy Client plugin
                # AFTER client db init
                self._real_settings.add_plugin(self._settings_client_plugin)

        return self._real_settings
コード例 #6
0
ファイル: utils.py プロジェクト: jgarte/entropy
def build_application_store_url(app, sub_page):
    """
    take rigo.models.application.Application object
    and build up HTTP Entropy Application Store URL
    pointing to exact Application page.
    sub_page is used to load a specific part of the page,
    for example "ugc" can be passed to load URL/ugc page.
    """
    settings = SystemSettings()
    details = app.get_details()
    pkg_id, pkg_repo = details.pkg
    branch = settings['repositories']['branch']
    product = settings['repositories']['product']
    url = "%s/show/%s,%s,%s,%s,%s,%s/%s" % (
        etpConst['packages_website_url'], details.pkgname, pkg_id, pkg_repo,
        etpConst['currentarch'], branch, product, sub_page)
    return url
コード例 #7
0
ファイル: locks.py プロジェクト: skwerlman/entropy
    def _clear_resources_after_lock(self):
        """
        Clear resources that could have become stale after
        the Entropy Lock acquisition.
        """
        cacher = EntropyCacher()
        with cacher:

            SystemSettings().clear()
            cacher.discard()

            with EntropyResourcesLock._POST_ACQUIRE_HOOK_LOCK:
                callables = list(
                    EntropyResourcesLock._POST_ACQUIRE_HOOKS.values())

            for callab in callables:
                callab()

        cacher.sync()
コード例 #8
0
    def update_entropy_repositories(self):

        progressQ.send_message(_("Downloading software repositories..."))

        settings = SystemSettings()
        chroot = ROOT_PATH
        root = etpSys['rootdir']
        if chroot != root:
            self._change_entropy_chroot(chroot)

        repos = list(settings['repositories']['available'].keys())

        try:
            # fetch_security = False => avoid spamming stdout
            try:
                repo_intf = self._backend.entropy.Repositories(
                    repos, fetch_security=False)
            except AttributeError as err:
                log.error("No repositories in repositories.conf")
                return False
            except Exception as err:
                log.error("Unhandled exception: %s" % (err, ))
                return False

            try:
                update_rc = repo_intf.sync()
            except Exception as err:
                log.error("Sync error: %s" % (err, ))
                return False

            if repo_intf.sync_errors or (update_rc != 0):
                log.error("Cannot download repositories atm")
                return False

            return update_rc == 0

        finally:

            self._backend.entropy.close_repositories()
            settings.clear()
            if chroot != root:
                self._change_entropy_chroot(root)
コード例 #9
0
    def __init__(self, entropy_client, repo_identifiers = None,
        force = False, fetch_security = True, gpg = True):
        """
        Entropy Client Repositories management interface constructor.

        @param entropy_client: a valid entropy.client.interfaces.client.Client
            instance
        @type entropy_client: entropy.client.interfaces.client.Client
        @keyword repo_identifiers: list of repository identifiers you want to
            take into consideration
        @type repo_identifiers: list
        @
        """

        if repo_identifiers is None:
            repo_identifiers = []
        self._entropy = entropy_client
        self._settings = SystemSettings()
        self._pkg_size_warning_th = 512*1024000 # 500mb
        repo_ids = repo_identifiers
        self.force = force
        self.sync_errors = False
        self.updated = False
        self.new_entropy = False
        self.need_packages_cleanup = False
        self.updated_repos = set()
        self.fetch_security = fetch_security
        self.already_updated = 0
        self.not_available = 0
        self._gpg_feature = gpg
        env_gpg = os.getenv('ETP_DISBLE_GPG')
        if env_gpg is not None:
            self._gpg_feature = False

        if not repo_ids:
            avail_repos = self._settings['repositories']['available'].keys()
            repo_ids.extend(list(avail_repos))
        # filter out package repositories
        self.repo_ids = self._entropy.filter_repositories(repo_ids)
コード例 #10
0
ファイル: client.py プロジェクト: skwerlman/entropy
    def config(cls, repository_id):
        """
        Return the WebService configuration for the given repository.
        The object returned is a dictionary containing the following
        items:
          - url: the Entropy WebService base URL (or None, if not supported)
          - update_eapi: the maximum supported EAPI for repository updates.
          - repo_eapi: the maximum supported EAPI for User Generate Content.

        @param repository_id: repository identifier
        @type repository_id: string
        """
        settings = SystemSettings()
        _repository_data = settings['repositories']['available'].get(
            repository_id)
        if _repository_data is None:
            const_debug_write(__name__, "WebService.config error: no repo")
            return None

        web_services_conf = _repository_data.get('webservices_config')
        if web_services_conf is None:
            const_debug_write(__name__, "WebService.config error: no metadata")
            return None

        data = {
            'url': None,
            '_url_obj': None,
            'update_eapi': None,
            'repo_eapi': None,
        }

        content = []
        try:
            content += entropy.tools.generic_file_content_parser(
                web_services_conf, encoding=etpConst['conf_encoding'])
        except (OSError, IOError) as err:
            const_debug_write(__name__,
                              "WebService.config error: %s" % (err, ))
            return None

        if not content:
            const_debug_write(__name__,
                              "WebService.config error: empty config")
            return None

        remote_url = content.pop(0)
        if remote_url == "-":  # as per specs
            remote_url = None
        elif not remote_url:
            remote_url = None
        data['url'] = remote_url

        if data['url']:
            url_obj = entropy.tools.spliturl(data['url'])
            if url_obj.scheme in WebService.SUPPORTED_URL_SCHEMAS:
                data['_url_obj'] = url_obj
            else:
                data['url'] = None

        for line in content:
            for k in ("UPDATE_EAPI", "REPO_EAPI"):
                if line.startswith(k + "="):
                    try:
                        data[k.lower()] = int(line.split("=", 1)[-1])
                    except (IndexError, ValueError):
                        pass

        return data
コード例 #11
0
    def __init__(self, url_path_list, checksum = True,
                 show_speed = True, resume = True,
                 abort_check_func = None, disallow_redirect = False,
                 url_fetcher_class = None, timeout = None,
                 download_context_func = None,
                 pre_download_hook = None, post_download_hook = None):
        """
        @param url_path_list: list of tuples composed by url and
            path to save, for eg. [(url,path_to_save,),...]
        @type url_path_list: list
        @keyword checksum: return md5 hash instead of status code
        @type checksum: bool
        @keyword show_speed: show download speed
        @type show_speed: bool
        @keyword resume: enable resume support
        @type resume: bool
        @keyword abort_check_func: callback used to stop download, it has to
            raise an exception that has to be caught by provider application.
            This exception will be considered an "abort" request.
        @type abort_check_func: callable
        @keyword disallow_redirect: disallow automatic HTTP redirects
        @type disallow_redirect: bool
        @keyword thread_stop_func: callback used to stop download, it has to
            raise an exception that has to be caught by provider application.
            This exception will be considered a "stop" request.
        @type thread_stop_func: callable
        @param url_fetcher_class: UrlFetcher based class to use
        @type url_fetcher_class: subclass of UrlFetcher
        @keyword timeout: custom request timeout value (in seconds), if None
            the value is read from Entropy configuration files.
        @type timeout: int
        @keyword download_context_func: if not None, it must be a function
            exposing a context manager and taking a path (the download path)
            as argument. This can be used to implement locking on files to be
            downloaded.
        @type download_context_func: callable
        @keyword pre_download_hook: hook called before starting the download
            process, inside the download_context_func context. This can be
            used to verify if the download is actually needed or just return.
            If the returned value is not None, the download method will return
            that value. The function takes a path (the download path) and the
            download id as arguments.
        @type pre_download_hook: callable
        @keyword post_download_hook: hook called after the download is complete,
            inside the download_context_func context. This can be used to verify
            the integrity of the downloaded data.
            The function takes a path (the download path) and the download
            status and the download id as arguments.
        @type post_download_hook: callable
        """
        self._progress_data = {}
        self._url_path_list = url_path_list

        self.__system_settings = SystemSettings()
        self.__resume = resume
        self.__checksum = checksum
        self.__show_speed = show_speed
        self.__abort_check_func = abort_check_func
        self.__disallow_redirect = disallow_redirect
        self.__timeout = timeout
        self.__download_context_func = download_context_func
        self.__pre_download_hook = pre_download_hook
        self.__post_download_hook = post_download_hook

        # important to have a declaration here
        self.__data_transfer = 0
        self.__average = 0
        self.__old_average = 0
        self.__time_remaining_secs = 0

        self.__url_fetcher = url_fetcher_class
        if self.__url_fetcher == None:
            self.__url_fetcher = UrlFetcher
コード例 #12
0
 def __init__(self, entropy_client, quiet=False):
     self._quiet = quiet
     self._entropy = entropy_client
     self._settings = SystemSettings()
     dict.__init__(self)
     self._load()
コード例 #13
0
ファイル: factory.py プロジェクト: skwerlman/entropy
"""

    @author: Fabio Erculiani <*****@*****.**>
    @contact: [email protected]
    @copyright: Fabio Erculiani
    @license: GPL-2

    B{Entropy Source Package Manager Plugins factory module}.

"""
from entropy.core import EntropyPluginFactory
from entropy.core.settings.base import SystemSettings
from entropy.spm.plugins.skel import SpmPlugin
import entropy.spm.plugins.interfaces as plugs

_settings = SystemSettings()
_USER_PLUG = _settings['system'].get('spm_backend')

FACTORY = EntropyPluginFactory(SpmPlugin, plugs,
    default_plugin_name = _USER_PLUG)

get_available_plugins = FACTORY.get_available_plugins

def get_default_class():
    """
    Return default Source Package Manager plugin class.

    @return: default Source Package Manager plugin class
    @raise SystemError: if no default plugin class has been specified.
        This usually means a programming error.
    """
コード例 #14
0
ファイル: sets.py プロジェクト: skwerlman/entropy
 def __init__(self, entropy_client):
     self._entropy = entropy_client
     self._settings = SystemSettings()
コード例 #15
0
def handle_exception(exc_class, exc_instance, exc_tb):

    # restore original exception handler, to avoid loops
    uninstall_exception_handler()

    _text = TextInterface()

    if exc_class is SystemDatabaseError:
        _text.output(darkred(
            _("Installed packages repository corrupted. "
              "Please re-generate it")),
                     importance=1,
                     level="error")
        os._exit(101)

    generic_exc_classes = (OnlineMirrorError, RepositoryError,
                           PermissionDenied, FileNotFound, SPMError,
                           SystemError)
    if exc_class in generic_exc_classes:
        _text.output("%s: %s" % (
            exc_instance,
            darkred(_("Cannot continue")),
        ),
                     importance=1,
                     level="error")
        os._exit(1)

    if exc_class is SystemExit:
        return

    if issubclass(exc_class, IOError):  # in Python 3.3+ it's BrokenPipeError
        if exc_instance.errno == errno.EPIPE:
            return

    if exc_class is KeyboardInterrupt:
        os._exit(1)

    t_back = entropy.tools.get_traceback(tb_obj=exc_tb)
    if const_debug_enabled():
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
        sys.stdin = sys.__stdin__
        entropy.tools.print_exception(tb_data=exc_tb)
        pdb.set_trace()

    if exc_class in (IOError, OSError):
        if exc_instance.errno == errno.ENOSPC:
            print_generic(t_back)
            _text.output("%s: %s" % (
                exc_instance,
                darkred(_("Your hard drive is full! Your fault!")),
            ),
                         importance=1,
                         level="error")
            os._exit(5)
        elif exc_instance.errno == errno.ENOMEM:
            print_generic(t_back)
            _text.output("%s: %s" % (
                exc_instance,
                darkred(_("No more memory dude! Your fault!")),
            ),
                         importance=1,
                         level="error")
            os._exit(5)

    _text.output(darkred(
        _("Hi. My name is Bug Reporter. "
          "I am sorry to inform you that the program crashed. "
          "Well, you know, shit happens.")),
                 importance=1,
                 level="error")
    _text.output(darkred(
        _("But there's something you could "
          "do to help me to be a better application.")),
                 importance=1,
                 level="error")
    _text.output(darkred(
        _("-- BUT, DO NOT SUBMIT THE SAME REPORT MORE THAN ONCE --")),
                 importance=1,
                 level="error")
    _text.output(darkred(
        _("Now I am showing you what happened. "
          "Don't panic, I'm here to help you.")),
                 importance=1,
                 level="error")

    entropy.tools.print_exception(tb_data=exc_tb)

    exception_data = entropy.tools.print_exception(silent=True,
                                                   tb_data=exc_tb,
                                                   all_frame_data=True)
    exception_tback_raw = const_convert_to_rawstring(t_back)

    error_fd, error_file = None, None
    try:
        error_fd, error_file = const_mkstemp(prefix="entropy.error.report.",
                                             suffix=".txt")

        with os.fdopen(error_fd, "wb") as ferror:
            ferror.write(
                const_convert_to_rawstring("\nRevision: %s\n\n" %
                                           (etpConst['entropyversion'], )))
            ferror.write(exception_tback_raw)
            ferror.write(const_convert_to_rawstring("\n\n"))
            ferror.write(const_convert_to_rawstring(''.join(exception_data)))
            ferror.write(const_convert_to_rawstring("\n"))

    except (OSError, IOError) as err:
        _text.output("%s: %s" %
                     (err,
                      darkred(
                          _("Oh well, I cannot even write to TMPDIR. "
                            "So, please copy the error and "
                            "mail [email protected]."))),
                     importance=1,
                     level="error")
        os._exit(1)
    finally:
        if error_fd is not None:
            try:
                os.close(error_fd)
            except OSError:
                pass

    _text.output("", level="error")

    ask_msg = _("Erm... Can I send the error, "
                "along with some other information\nabout your "
                "hardware to my creators so they can fix me? "
                "(Your IP will be logged)")
    rc = _text.ask_question(ask_msg)
    if rc == _("No"):
        _text.output(darkgreen(_("Ok, ok ok ok... Sorry!")), level="error")
        os._exit(2)

    _text.output(darkgreen(
        _("If you want to be contacted back "
          "(and actively supported), also answer "
          "the questions below:")),
                 level="error")

    try:
        name = readtext(_("Your Full name:"))
        email = readtext(_("Your E-Mail address:"))
        description = readtext(_("What you were doing:"))
    except EOFError:
        os._exit(2)

    try:
        from entropy.client.interfaces.qa import UGCErrorReport
        from entropy.core.settings.base import SystemSettings
        _settings = SystemSettings()
        repository_id = _settings['repositories']['default_repository']
        error = UGCErrorReport(repository_id)
    except (
            OnlineMirrorError,
            AttributeError,
            ImportError,
    ):
        error = None

    result = None
    if error is not None:
        error.prepare(exception_tback_raw, name, email,
                      '\n'.join([x for x in exception_data]), description)
        result = error.submit()

    if result:
        _text.output(darkgreen(
            _("Thank you very much. The error has been "
              "reported and hopefully, the problem will "
              "be solved as soon as possible.")),
                     level="error")
    else:
        _text.output(darkred(
            _("Ugh. Cannot send the report. "
              "Please mail the file below "
              "to [email protected].")),
                     level="error")
        _text.output("", level="error")
        _text.output("==> %s" % (error_file, ), level="error")
        _text.output("", level="error")
コード例 #16
0
    def __init__(self, url, path_to_save, checksum = True,
                 show_speed = True, resume = True,
                 abort_check_func = None, disallow_redirect = False,
                 thread_stop_func = None, speed_limit = None,
                 timeout = None, download_context_func = None,
                 pre_download_hook = None, post_download_hook = None):
        """
        Entropy URL downloader constructor.

        @param url: download URL (do not URL-encode it!)
        @type url: string
        @param path_to_save: file path where to save downloaded data
        @type path_to_save: string
        @keyword checksum: return md5 hash instead of status code
        @type checksum: bool
        @keyword show_speed: show download speed
        @type show_speed: bool
        @keyword resume: enable resume support
        @type resume: bool
        @keyword abort_check_func: callback used to stop download, it has to
            raise an exception that has to be caught by provider application.
            This exception will be considered an "abort" request.
        @type abort_check_func: callable
        @keyword disallow_redirect: disallow automatic HTTP redirects
        @type disallow_redirect: bool
        @keyword thread_stop_func: callback used to stop download, it has to
            raise an exception that has to be caught by provider application.
            This exception will be considered a "stop" request.
        @type thread_stop_func: callable
        @keyword speed_limit: speed limit in kb/sec
        @type speed_limit: int
        @keyword timeout: custom request timeout value (in seconds), if None
            the value is read from Entropy configuration files.
        @type timeout: int
        @keyword download_context_func: if not None, it must be a function
            exposing a context manager and taking a path (the download path)
            as argument. This can be used to implement locking on files to be
            downloaded.
        @type download_context_func: callable
        @keyword pre_download_hook: hook called before starting the download
            process, inside the download_context_func context. This can be
            used to verify if the download is actually needed or just return.
            If the returned value is not None, the download method will return
            that value. The function takes a path (the download path) and the
            download id as arguments.
        @type pre_download_hook: callable
        @keyword post_download_hook: hook called after the download is complete,
            inside the download_context_func context. This can be used to verify
            the integrity of the downloaded data.
            The function takes a path (the download path) and the download
            status and the download id as arguments.
        @type post_download_hook: callable
        """
        self.__supported_uris = {
            'file': self._urllib_download,
            'http': self._urllib_download,
            'https': self._urllib_download,
            'ftp': self._urllib_download,
            'ftps': self._urllib_download,
            'rsync': self._rsync_download,
            'ssh': self._rsync_download,
        }

        self.__system_settings = SystemSettings()
        if speed_limit == None:
            speed_limit = \
                self.__system_settings['repositories']['transfer_limit']

        if timeout is None:
            self.__timeout = \
                self.__system_settings['repositories']['timeout']
        else:
            self.__timeout = timeout
        self.__th_id = 0

        if download_context_func is None:
            @contextlib.contextmanager
            def download_context_func(path):
                yield

        self.__download_context_func = download_context_func
        self.__pre_download_hook = pre_download_hook
        self.__post_download_hook = post_download_hook

        self.__resume = resume
        self.__url = url
        self.__path_to_save = path_to_save
        self.__checksum = checksum
        self.__show_speed = show_speed
        self.__abort_check_func = abort_check_func
        self.__thread_stop_func = thread_stop_func
        self.__disallow_redirect = disallow_redirect
        self.__speedlimit = speed_limit # kbytes/sec

        self._init_vars()
        self.__init_urllib()
コード例 #17
0
ファイル: command.py プロジェクト: skwerlman/entropy
 def _settings(self):
     """
     Return a SystemSettings instance.
     """
     return SystemSettings()
コード例 #18
0
ファイル: transceivers.py プロジェクト: skwerlman/entropy
    def __init__(self,
                 entropy_interface,
                 uris,
                 files_to_upload,
                 download=False,
                 remove=False,
                 txc_basedir=None,
                 local_basedir=None,
                 critical_files=None,
                 handlers_data=None,
                 repo=None,
                 copy_herustic_support=False):

        if critical_files is None:
            critical_files = []
        if handlers_data is None:
            handlers_data = {}

        self._entropy = entropy_interface
        if not isinstance(uris, list):
            raise AttributeError("uris must be a list instance")
        if not isinstance(files_to_upload, (list, dict)):
            raise AttributeError(
                "files_to_upload must be a list or dict instance")
        self.uris = uris
        if isinstance(files_to_upload, list):
            self.myfiles = files_to_upload[:]
        else:
            self.myfiles = sorted([x for x in files_to_upload])

        self._settings = SystemSettings()
        self.sys_settings_plugin_id = \
            etpConst['system_settings_plugins_ids']['server_plugin']
        srv_set = self._settings[self.sys_settings_plugin_id]['server']

        # server-side speed limit
        self.speed_limit = srv_set['sync_speed_limit']
        self.download = download
        self.remove = remove
        self.repo = repo
        if self.repo == None:
            self.repo = self._entropy.repository()
        if self.remove:
            self.download = False
        self._copy_herustic = copy_herustic_support
        if self._copy_herustic and (self.download or self.remove):
            raise AttributeError(
                "copy_herustic_support can be enabled only for uploads")

        if not txc_basedir:
            raise AttributeError("invalid txc_basedir passed")
        self.txc_basedir = txc_basedir

        if not local_basedir:
            # default to database directory
            self.local_basedir = os.path.dirname(
                self._entropy._get_local_repository_file(self.repo))
        else:
            self.local_basedir = local_basedir

        self.critical_files = critical_files
        self.handlers_data = handlers_data.copy()