public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-09-05 21:15 Brian Dolbec
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Dolbec @ 2014-09-05 21:15 UTC (permalink / raw
  To: gentoo-commits

commit:     0e4a4ccb41342813c6374ecd3777d7f3668addec
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Sep  5 20:08:36 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Sep  5 20:26:15 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0e4a4ccb

portage/sync/controller.sync(): Migrate writemsg() call to return the error message to caller

Highlight the "ERROR" string portion usig bad(), remove 1 linefeed.
This puts the error in the emaint sync message list.

---
 pym/portage/emaint/modules/sync/sync.py |  6 +++---
 pym/portage/sync/controller.py          | 13 ++++++-------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 9b0d82c..4369a2a 100644
--- a/pym/portage/emaint/modules/sync/sync.py
+++ b/pym/portage/emaint/modules/sync/sync.py
@@ -179,11 +179,11 @@ class SyncRepos(object):
 		sync_manager = get_syncer(self.emerge_config.target_config.settings, emergelog)
 		retvals = []
 		for repo in selected_repos:
-			#print("syncing repo:", repo.name)
 			if repo.sync_type is not None:
-				returncode = sync_manager.sync(self.emerge_config, repo)
-				#if returncode != os.EX_OK:
+				returncode, message = sync_manager.sync(self.emerge_config, repo)
 				retvals.append((repo.name, returncode))
+				if message:
+					msgs.append(message)
 
 		# Reload the whole config.
 		portage._sync_mode = False

diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 2b3dbad..e8fe291 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -103,14 +103,13 @@ class SyncManager(object):
 		if repo.sync_type in self.module_names[1:]:
 			tasks = [self.module_controller.get_class(repo.sync_type)]
 		else:
-			portage.util.writemsg(
-				"\nERROR: Sync module '%s' is not an installed/known type'\n\n"
-				% (repo.sync_type), noiselevel=-1)
-			return self.exitcode
+			msg = "\n%s: Sync module '%s' is not an installed/known type'\n" \
+				% (bad("ERROR"), repo.sync_type)
+			return self.exitcode, msg
 
 		rval = self.pre_sync(repo)
 		if rval != os.EX_OK:
-			return rval
+			return rval, None
 
 		# need to pass the kwargs dict to the modules
 		# so they are available if needed.
@@ -131,7 +130,7 @@ class SyncManager(object):
 
 		self.perform_post_sync_hook(repo.sync_uri)
 
-		return self.exitcode
+		return self.exitcode, None
 
 
 	def do_callback(self, result):
@@ -167,7 +166,7 @@ class SyncManager(object):
 		except OSError:
 			st = None
 		if st is None:
-			print(">>> '%s' not found, creating it." % repo.location)
+			writemsg_level(">>> '%s' not found, creating it." % repo.location)
 			portage.util.ensure_dirs(repo.location, mode=0o755)
 			st = os.stat(repo.location)
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-09-27  2:20 Brian Dolbec
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Dolbec @ 2014-09-27  2:20 UTC (permalink / raw
  To: gentoo-commits

commit:     0a8c1e2ec672ccfbf7064e89c9a182155308a0c1
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Sep  5 20:08:36 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sat Sep 27 01:40:45 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0a8c1e2e

portage/sync/controller.sync(): Migrate writemsg() call to return the error message to caller

Highlight the "ERROR" string portion usig bad(), remove 1 linefeed.
This puts the error in the emaint sync message list.

---
 pym/portage/emaint/modules/sync/sync.py |  6 +++---
 pym/portage/sync/controller.py          | 13 ++++++-------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 9b0d82c..4369a2a 100644
--- a/pym/portage/emaint/modules/sync/sync.py
+++ b/pym/portage/emaint/modules/sync/sync.py
@@ -179,11 +179,11 @@ class SyncRepos(object):
 		sync_manager = get_syncer(self.emerge_config.target_config.settings, emergelog)
 		retvals = []
 		for repo in selected_repos:
-			#print("syncing repo:", repo.name)
 			if repo.sync_type is not None:
-				returncode = sync_manager.sync(self.emerge_config, repo)
-				#if returncode != os.EX_OK:
+				returncode, message = sync_manager.sync(self.emerge_config, repo)
 				retvals.append((repo.name, returncode))
+				if message:
+					msgs.append(message)
 
 		# Reload the whole config.
 		portage._sync_mode = False

diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 2b3dbad..e8fe291 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -103,14 +103,13 @@ class SyncManager(object):
 		if repo.sync_type in self.module_names[1:]:
 			tasks = [self.module_controller.get_class(repo.sync_type)]
 		else:
-			portage.util.writemsg(
-				"\nERROR: Sync module '%s' is not an installed/known type'\n\n"
-				% (repo.sync_type), noiselevel=-1)
-			return self.exitcode
+			msg = "\n%s: Sync module '%s' is not an installed/known type'\n" \
+				% (bad("ERROR"), repo.sync_type)
+			return self.exitcode, msg
 
 		rval = self.pre_sync(repo)
 		if rval != os.EX_OK:
-			return rval
+			return rval, None
 
 		# need to pass the kwargs dict to the modules
 		# so they are available if needed.
@@ -131,7 +130,7 @@ class SyncManager(object):
 
 		self.perform_post_sync_hook(repo.sync_uri)
 
-		return self.exitcode
+		return self.exitcode, None
 
 
 	def do_callback(self, result):
@@ -167,7 +166,7 @@ class SyncManager(object):
 		except OSError:
 			st = None
 		if st is None:
-			print(">>> '%s' not found, creating it." % repo.location)
+			writemsg_level(">>> '%s' not found, creating it." % repo.location)
 			portage.util.ensure_dirs(repo.location, mode=0o755)
 			st = os.stat(repo.location)
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-09-30  0:46 Brian Dolbec
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Dolbec @ 2014-09-30  0:46 UTC (permalink / raw
  To: gentoo-commits

commit:     264c4a0c2a855a35d634851abd189302e6f87280
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Sep  5 20:08:36 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue Sep 30 00:42:27 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=264c4a0c

portage/sync/controller.sync(): Migrate writemsg() call to return the error message to caller

Highlight the "ERROR" string portion usig bad(), remove 1 linefeed.
This puts the error in the emaint sync message list.

---
 pym/portage/emaint/modules/sync/sync.py |  6 +++---
 pym/portage/sync/controller.py          | 13 ++++++-------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 9b0d82c..4369a2a 100644
--- a/pym/portage/emaint/modules/sync/sync.py
+++ b/pym/portage/emaint/modules/sync/sync.py
@@ -179,11 +179,11 @@ class SyncRepos(object):
 		sync_manager = get_syncer(self.emerge_config.target_config.settings, emergelog)
 		retvals = []
 		for repo in selected_repos:
-			#print("syncing repo:", repo.name)
 			if repo.sync_type is not None:
-				returncode = sync_manager.sync(self.emerge_config, repo)
-				#if returncode != os.EX_OK:
+				returncode, message = sync_manager.sync(self.emerge_config, repo)
 				retvals.append((repo.name, returncode))
+				if message:
+					msgs.append(message)
 
 		# Reload the whole config.
 		portage._sync_mode = False

diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 2b3dbad..e8fe291 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -103,14 +103,13 @@ class SyncManager(object):
 		if repo.sync_type in self.module_names[1:]:
 			tasks = [self.module_controller.get_class(repo.sync_type)]
 		else:
-			portage.util.writemsg(
-				"\nERROR: Sync module '%s' is not an installed/known type'\n\n"
-				% (repo.sync_type), noiselevel=-1)
-			return self.exitcode
+			msg = "\n%s: Sync module '%s' is not an installed/known type'\n" \
+				% (bad("ERROR"), repo.sync_type)
+			return self.exitcode, msg
 
 		rval = self.pre_sync(repo)
 		if rval != os.EX_OK:
-			return rval
+			return rval, None
 
 		# need to pass the kwargs dict to the modules
 		# so they are available if needed.
@@ -131,7 +130,7 @@ class SyncManager(object):
 
 		self.perform_post_sync_hook(repo.sync_uri)
 
-		return self.exitcode
+		return self.exitcode, None
 
 
 	def do_callback(self, result):
@@ -167,7 +166,7 @@ class SyncManager(object):
 		except OSError:
 			st = None
 		if st is None:
-			print(">>> '%s' not found, creating it." % repo.location)
+			writemsg_level(">>> '%s' not found, creating it." % repo.location)
 			portage.util.ensure_dirs(repo.location, mode=0o755)
 			st = os.stat(repo.location)
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-10-21  5:05 Zac Medico
  0 siblings, 0 replies; 7+ messages in thread
From: Zac Medico @ 2014-10-21  5:05 UTC (permalink / raw
  To: gentoo-commits

commit:     739b01280b3e94f3527af1764062d76629aeae5d
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 21 04:10:36 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Oct 21 05:04:08 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=739b0128

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 | 23 ++++++++++++++++-------
 pym/portage/sync/__init__.py            | 23 -----------------------
 2 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 4369a2a..4a17c9e 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,21 @@ 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
+
+		self.emerge_config = emerge_config
 		if emerge_logging:
 			_emerge.emergelog._disable = False
 		self.xterm_titles = "notitles" not in \
@@ -176,7 +184,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] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-12-01 21:50 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2014-12-01 21:50 UTC (permalink / raw
  To: gentoo-commits

commit:     28d6ae3cf4f7853cab8b68457ef171ce15747242
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Sep  5 20:08:36 2014 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec  1 21:49:41 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=28d6ae3c

portage/sync/controller.sync(): Migrate writemsg() call to return the error message to caller

Highlight the "ERROR" string portion usig bad(), remove 1 linefeed.
This puts the error in the emaint sync message list.

---
 pym/portage/emaint/modules/sync/sync.py |  6 +++---
 pym/portage/sync/controller.py          | 13 ++++++-------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py
index 9b0d82c..4369a2a 100644
--- a/pym/portage/emaint/modules/sync/sync.py
+++ b/pym/portage/emaint/modules/sync/sync.py
@@ -179,11 +179,11 @@ class SyncRepos(object):
 		sync_manager = get_syncer(self.emerge_config.target_config.settings, emergelog)
 		retvals = []
 		for repo in selected_repos:
-			#print("syncing repo:", repo.name)
 			if repo.sync_type is not None:
-				returncode = sync_manager.sync(self.emerge_config, repo)
-				#if returncode != os.EX_OK:
+				returncode, message = sync_manager.sync(self.emerge_config, repo)
 				retvals.append((repo.name, returncode))
+				if message:
+					msgs.append(message)
 
 		# Reload the whole config.
 		portage._sync_mode = False

diff --git a/pym/portage/sync/controller.py b/pym/portage/sync/controller.py
index 2b3dbad..e8fe291 100644
--- a/pym/portage/sync/controller.py
+++ b/pym/portage/sync/controller.py
@@ -103,14 +103,13 @@ class SyncManager(object):
 		if repo.sync_type in self.module_names[1:]:
 			tasks = [self.module_controller.get_class(repo.sync_type)]
 		else:
-			portage.util.writemsg(
-				"\nERROR: Sync module '%s' is not an installed/known type'\n\n"
-				% (repo.sync_type), noiselevel=-1)
-			return self.exitcode
+			msg = "\n%s: Sync module '%s' is not an installed/known type'\n" \
+				% (bad("ERROR"), repo.sync_type)
+			return self.exitcode, msg
 
 		rval = self.pre_sync(repo)
 		if rval != os.EX_OK:
-			return rval
+			return rval, None
 
 		# need to pass the kwargs dict to the modules
 		# so they are available if needed.
@@ -131,7 +130,7 @@ class SyncManager(object):
 
 		self.perform_post_sync_hook(repo.sync_uri)
 
-		return self.exitcode
+		return self.exitcode, None
 
 
 	def do_callback(self, result):
@@ -167,7 +166,7 @@ class SyncManager(object):
 		except OSError:
 			st = None
 		if st is None:
-			print(">>> '%s' not found, creating it." % repo.location)
+			writemsg_level(">>> '%s' not found, creating it." % repo.location)
 			portage.util.ensure_dirs(repo.location, mode=0o755)
 			st = os.stat(repo.location)
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-12-01 21:50 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2014-12-01 21:50 UTC (permalink / raw
  To: gentoo-commits

commit:     9b158cd215d94b7acf65fd254061a9227b99d813
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Oct 21 04:10:36 2014 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec  1 21:49:42 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=9b158cd2

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 4369a2a..1316eaa 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] 7+ messages in thread

* [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/
@ 2014-12-04 20:04 Brian Dolbec
  0 siblings, 0 replies; 7+ 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] 7+ messages in thread

end of thread, other threads:[~2014-12-04 20:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-21  5:05 [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/, pym/portage/emaint/modules/sync/ Zac Medico
  -- strict thread matches above, loose matches on Subject: below --
2014-12-04 20:04 Brian Dolbec
2014-12-01 21:50 Michał Górny
2014-12-01 21:50 Michał Górny
2014-09-30  0:46 Brian Dolbec
2014-09-27  2:20 Brian Dolbec
2014-09-05 21:15 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox