* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-12-04 20:04 Brian Dolbec
2014-12-04 20:16 ` [gentoo-commits] proj/portage:master " Brian Dolbec
0 siblings, 1 reply; 3+ messages in thread
From: Brian Dolbec @ 2014-12-04 20:04 UTC (permalink / raw
To: gentoo-commits
commit: c51e517b4dd6b4eb34afa79cb1c0da38fd8291b1
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 21 04:10:36 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
2014-12-04 20:04 [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/ Brian Dolbec
@ 2014-12-04 20:16 ` Brian Dolbec
0 siblings, 0 replies; 3+ messages in thread
From: Brian Dolbec @ 2014-12-04 20:16 UTC (permalink / raw
To: gentoo-commits
commit: c51e517b4dd6b4eb34afa79cb1c0da38fd8291b1
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 21 04:10:36 2014 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [gentoo-commits] proj/portage:master commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2017-02-08 8:03 Zac Medico
0 siblings, 0 replies; 3+ messages in thread
From: Zac Medico @ 2017-02-08 8:03 UTC (permalink / raw
To: gentoo-commits
commit: a99414cc781b35d8089472f3c4d7916e4eeb494c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 8 07:49:51 2017 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Feb 8 07:52:21 2017 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a99414cc
SyncManager: rename async method to sync_async (bug 607922)
This fixes the following DeprecationWarning with Python 3.6:
pym/portage/sync/controller.py:117: DeprecationWarning: 'async' and 'await' will become reserved keywords in Python 3.7
def async(self, emerge_config=None, repo=None, master_hooks=True):
X-Gentoo-Bug: 607922
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=607922
pym/portage/emaint/modules/sync/sync.py | 4 ++--
pym/portage/sync/controller.py | 13 +++++++++++--
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 076297a..c8d4ca1 100644
--- a/pym/portage/emaint/modules/sync/sync.py
+++ b/pym/portage/emaint/modules/sync/sync.py
@@ -1,4 +1,4 @@
-# Copyright 2014-2015 Gentoo Foundation
+# Copyright 2014-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import logging
@@ -434,7 +434,7 @@ class SyncScheduler(AsyncScheduler):
self._running_repos.add(node)
self._update_leaf_nodes()
- return self._sync_manager.async(
+ return self._sync_manager.sync_async(
emerge_config=self._emerge_config,
repo=self._repo_map[node],
master_hooks=self._master_hooks(node))
diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 92be3cb..3bccf6f 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -1,4 +1,4 @@
-# Copyright 2014 Gentoo Foundation
+# Copyright 2014-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import print_function
@@ -8,6 +8,7 @@ import sys
import logging
import grp
import pwd
+import warnings
import portage
from portage import os
@@ -107,6 +108,14 @@ class SyncManager(object):
level=logging.WARN, noiselevel=2)
self.hooks[_dir] = hooks
+ def __getattr__(self, name):
+ if name == 'async':
+ warnings.warn("portage.sync.controller.SyncManager.async "
+ "has been renamed to sync_async",
+ DeprecationWarning, stacklevel=2)
+ return self.sync_async
+ else:
+ raise AttributeError(name)
def get_module_descriptions(self, mod):
desc = self.module_controller.get_func_descriptions(mod)
@@ -114,7 +123,7 @@ class SyncManager(object):
return desc
return []
- def async(self, emerge_config=None, repo=None, master_hooks=True):
+ def sync_async(self, emerge_config=None, repo=None, master_hooks=True):
self.emerge_config = emerge_config
self.settings, self.trees, self.mtimedb = emerge_config
self.xterm_titles = "notitles" not in self.settings.features
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-08 8:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-04 20:04 [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/ Brian Dolbec
2014-12-04 20:16 ` [gentoo-commits] proj/portage:master " Brian Dolbec
-- strict thread matches above, loose matches on Subject: below --
2017-02-08 8:03 Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox