From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 4DC3E138ACE for ; Thu, 4 Dec 2014 20:16:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 460B8E093B; Thu, 4 Dec 2014 20:16:18 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E8160E0921 for ; Thu, 4 Dec 2014 20:16:15 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E22E2340598 for ; Thu, 4 Dec 2014 20:16:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0C29BB948 for ; Thu, 4 Dec 2014 20:16:11 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1417722995.c51e517b4dd6b4eb34afa79cb1c0da38fd8291b1.dol-sen@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/emaint/modules/sync/sync.py pym/portage/sync/__init__.py X-VCS-Directories: pym/portage/sync/ pym/portage/emaint/modules/sync/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: c51e517b4dd6b4eb34afa79cb1c0da38fd8291b1 X-VCS-Branch: master Date: Thu, 4 Dec 2014 20:16:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bcded6ef-7db3-443a-9794-97865579fa2e X-Archives-Hash: 4d743a18659e4ae74b046e2cb8a8e8fb Message-ID: <20141204201611.S-pQNPLOpT57rY3Xl9HpywbL578JhokvTfTuEHN6br8@z> commit: c51e517b4dd6b4eb34afa79cb1c0da38fd8291b1 Author: Zac Medico gentoo org> AuthorDate: Tue Oct 21 04:10:36 2014 +0000 Commit: Brian Dolbec gmail com> CommitDate: Thu Dec 4 19:56:35 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c51e517b SyncRepos: manage global variables After calling load_emerge_config, use _reset_legacy_globals to cleanly destroy existing portage.db / settings instances. Then update portage.db and portage.settings to refer to the new instances. Also, instantiate a local instance of SyncManager, so that we can remove the global instance that was previous accessed via get_syncer. There's no reason to have a global instance, and global instances are a maintenance nightmare (see portage.db and portage.settings changes above). --- pym/portage/emaint/modules/sync/sync.py | 24 +++++++++++++++++------- pym/portage/sync/__init__.py | 23 ----------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py index c2847ae..e9f5e0b 100644 --- a/pym/portage/emaint/modules/sync/sync.py +++ b/pym/portage/emaint/modules/sync/sync.py @@ -10,8 +10,8 @@ portage._internal_caller = True portage._sync_mode = True from portage.localization import _ from portage.output import bold, create_color_func -from portage.sync import get_syncer from portage._global_updates import _global_updates +from portage.sync.controller import SyncManager from portage.util import writemsg_level import _emerge @@ -52,13 +52,22 @@ class SyncRepos(object): @param emerge_config: optional an emerge_config instance to use @param emerge_logging: boolean, defaults to False ''' - if emerge_config: - self.emerge_config = emerge_config - else: + if emerge_config is None: # need a basic options instance actions, opts, _files = parse_opts([], silent=True) - self.emerge_config = load_emerge_config( - action='sync', args=_files, trees=[], opts=opts) + emerge_config = load_emerge_config( + action='sync', args=_files, opts=opts) + + if hasattr(portage, 'settings'): + # cleanly destroy global objects + portage._reset_legacy_globals() + # update redundant global variables, for consistency + # and in order to conserve memory + portage.settings = emerge_config.target_config.settings + portage.db = emerge_config.trees + portage.root = portage.db._target_eroot + + self.emerge_config = emerge_config if emerge_logging: _emerge.emergelog._disable = False self.xterm_titles = "notitles" not in \ @@ -176,7 +185,8 @@ class SyncRepos(object): # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22) - sync_manager = get_syncer(self.emerge_config.target_config.settings, emergelog) + sync_manager = SyncManager( + self.emerge_config.target_config.settings, emergelog) retvals = [] for repo in selected_repos: if repo.sync_type is not None: diff --git a/pym/portage/sync/__init__.py b/pym/portage/sync/__init__.py index 58a1298..0f6c566 100644 --- a/pym/portage/sync/__init__.py +++ b/pym/portage/sync/__init__.py @@ -7,8 +7,6 @@ from portage.module import Modules from portage.sync.controller import SyncManager from portage.sync.config_checks import check_type -sync_manager = None - path = os.path.join(os.path.dirname(__file__), "modules") # initial development debug info #print("module path:", path) @@ -20,27 +18,6 @@ module_controller = Modules(path=path, namepath="portage.sync.modules") module_names = module_controller.module_names[:] -def get_syncer(settings=None, logger=None): - '''Initializes and returns the SyncManager instance - to be used for sync operations - - @param settings: emerge.settings instance - @param logger: emerge logger instance - @returns SyncManager instance - ''' - global sync_manager - if sync_manager and not settings and not logger: - return sync_manager - if settings is None: - from _emerge.actions import load_emerge_config - emerge_config = load_emerge_config() - settings = emerge_config.target_config.settings - if logger is None: - from _emerge.emergelog import emergelog as logger - sync_manager = SyncManager(settings, logger) - return sync_manager - - def validate_config(repo, logger): '''Validate the repos.conf settings for the repo''' global module_names, module_controller