public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2011-02-20  0:00 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-02-20  0:00 UTC (permalink / raw
  To: gentoo-commits

commit:     ed5aa31ee605fe6efbdcb0c0ab7deabcb12f4b77
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 20 00:00:16 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 20 00:00:16 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ed5aa31e

Update date headers in modified files.

---
 bin/ebuild.sh         |    2 +-
 bin/misc-functions.sh |    2 +-
 pym/portage/mail.py   |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 8abdec9..1764da1 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 PORTAGE_BIN_PATH="${PORTAGE_BIN_PATH:-/usr/lib/portage/bin}"

diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index e1e5df1..ae4cc9e 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright 1999-2010 Gentoo Foundation
+# Copyright 1999-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 #
 # Miscellaneous shell functions that make use of the ebuild env but don't need

diff --git a/pym/portage/mail.py b/pym/portage/mail.py
index 7268398..aa41854 100644
--- a/pym/portage/mail.py
+++ b/pym/portage/mail.py
@@ -1,5 +1,5 @@
 # portage.py -- core Portage functionality
-# Copyright 1998-2004 Gentoo Foundation
+# Copyright 1998-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 # Since python ebuilds remove the 'email' module when USE=build



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2011-06-04  1:39 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-06-04  1:39 UTC (permalink / raw
  To: gentoo-commits

commit:     eb8325c739fdafbff6652e43f6fe8074f1f0aa28
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Jun  4 01:38:40 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jun  4 01:38:40 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=eb8325c7

portdbapi: cleanup when base module is reloaded

This prevents memory leaks via portdbapi.portdbapi_instances when the
module is reloaded. Also, there's no need for ebuild(1) to call
close_portdbapi_caches() since it's now handled automatically during
the reload.

---
 bin/ebuild              |    1 -
 pym/portage/__init__.py |   29 +++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/bin/ebuild b/bin/ebuild
index e3e8c6b..9ad17e8 100755
--- a/bin/ebuild
+++ b/bin/ebuild
@@ -147,7 +147,6 @@ if ebuild_portdir != vdb_path and \
 			encoding=_encodings['content'], errors='strict')
 
 	print("Appending %s to PORTDIR_OVERLAY..." % ebuild_portdir)
-	portage.close_portdbapi_caches()
 	imp.reload(portage)
 
 # Constrain eclass resolution to the master(s)

diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 9e8298e..515a9a7 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -576,6 +576,35 @@ if VERSION == 'HEAD':
 			return VERSION
 	VERSION = _LazyVersion()
 
+if "_legacy_globals_constructed" in globals():
+	# The module has been reloaded, so perform any relevant cleanup
+	# and prevent memory leaks.
+	if "db" in _legacy_globals_constructed:
+		try:
+			db
+		except NameError:
+			pass
+		else:
+			if isinstance(db, dict) and db:
+				for _x in db.values():
+					try:
+						if "porttree" in _x.lazy_items:
+							continue
+					except (AttributeError, TypeError):
+						continue
+					try:
+						_x = _x["porttree"].dbapi
+					except (AttributeError, KeyError):
+						continue
+					if not isinstance(_x, portdbapi):
+						continue
+					_x.close_caches()
+					try:
+						portdbapi.portdbapi_instances.remove(_x)
+					except ValueError:
+						pass
+				del _x
+
 class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
 
 	__slots__ = ('_name',)



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2011-06-17 22:35 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-06-17 22:35 UTC (permalink / raw
  To: gentoo-commits

commit:     d3d1aee93c9c5f04612c9237d452e9885c10af6d
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 17 22:35:29 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Jun 17 22:35:29 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d3d1aee9

repoman: handle PermissionDenied from digestgen

This will fix bug #371987.

---
 bin/repoman             |    9 +++++++--
 pym/portage/checksum.py |   15 +++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/bin/repoman b/bin/repoman
index 164a127..487cc67 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -1095,8 +1095,13 @@ for x in scanlist:
 				portage._doebuild_manifest_exempt_depend -= 1
 
 		repoman_settings["O"] = checkdir
-		generated_manifest = digestgen(
-			mysettings=repoman_settings, myportdb=portdb)
+		try:
+			generated_manifest = digestgen(
+				mysettings=repoman_settings, myportdb=portdb)
+		except portage.exception.PermissionDenied as e:
+			generated_manifest = False
+			writemsg_level("!!! Permission denied: '%s'\n" % (e,),
+				level=logging.ERROR, noiselevel=-1)
 
 		if not generated_manifest:
 			print("Unable to generate manifest.")

diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index f640fd9..eeb5995 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -29,8 +29,19 @@ def _generate_hash_function(hashtype, hashobject, origin="unknown"):
 		@type filename: String
 		@return: The hash and size of the data
 		"""
-		f = open(_unicode_encode(filename,
-			encoding=_encodings['fs'], errors='strict'), 'rb')
+		try:
+			f = open(_unicode_encode(filename,
+				encoding=_encodings['fs'], errors='strict'), 'rb')
+		except IOError as e:
+			func_call = "open('%s')" % filename
+			if e.errno == errno.EPERM:
+				raise portage.exception.OperationNotPermitted(func_call)
+			elif e.errno == errno.EACCES:
+				raise portage.exception.PermissionDenied(func_call)
+			elif e.errno == errno.ENOENT:
+				raise portage.exception.FileNotFound(filename)
+			else:
+				raise
 		blocksize = HASHING_BLOCKSIZE
 		data = f.read(blocksize)
 		size = 0



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2011-12-08  7:26 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2011-12-08  7:26 UTC (permalink / raw
  To: gentoo-commits

commit:     c281c323adf14ece439b98dcf35531666266a0a5
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Dec  8 07:26:02 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Dec  8 07:26:02 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c281c323

dispatch-conf: experimental prefix support

---
 bin/dispatch-conf            |    5 +++--
 pym/portage/dispatch_conf.py |    5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index 3089329..1cad9e0 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -85,7 +85,7 @@ class dispatch:
         confs = []
         count = 0
 
-        config_root = '/'
+        config_root = os.environ.get("__PORTAGE_TEST_EPREFIX", "/")
         self.options = portage.dispatch_conf.read_config(MANDATORY_OPTS)
 
         if "log-file" in self.options:
@@ -120,7 +120,8 @@ class dispatch:
         #
 
         for path in config_paths:
-            path = portage.normalize_path(path)
+            path = portage.normalize_path(
+                 os.path.join(config_root, path.lstrip(os.sep)))
             try:
                 mymode = os.stat(path).st_mode
             except OSError:

diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
index 4991020..f5beba5 100644
--- a/pym/portage/dispatch_conf.py
+++ b/pym/portage/dispatch_conf.py
@@ -38,8 +38,9 @@ def diffstatusoutput_len(cmd):
         return (1, 1)
 
 def read_config(mandatory_opts):
-    loader = KeyValuePairFileLoader(
-        '/etc/dispatch-conf.conf', None)
+    eprefix = os.environ.get("__PORTAGE_TEST_EPREFIX", "/")
+    config_path = os.path.join(eprefix, "etc/dispatch-conf.conf")
+    loader = KeyValuePairFileLoader(config_path, None)
     opts, errors = loader.load()
     if not opts:
         print(_('dispatch-conf: Error reading /etc/dispatch-conf.conf; fatal'), file=sys.stderr)



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2012-03-11  1:40 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2012-03-11  1:40 UTC (permalink / raw
  To: gentoo-commits

commit:     3467a10ba5eb37f67899e772c2951992dc28f46c
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Mar  8 21:47:16 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Mar 11 01:40:29 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3467a10b

dispatch-conf: do regex matching ourselves

This avoids having to pipe through multiple greps, as well as running
diff multiple times on the same set of files.

Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 bin/dispatch-conf            |   37 ++++++++++++++++++++++++-------------
 pym/portage/dispatch_conf.py |    8 ++++----
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/bin/dispatch-conf b/bin/dispatch-conf
index a778118..139a001 100755
--- a/bin/dispatch-conf
+++ b/bin/dispatch-conf
@@ -27,13 +27,11 @@ except ImportError:
 from portage import os
 from portage import dispatch_conf
 from portage import _unicode_decode
-from portage.dispatch_conf import diffstatusoutput_len
+from portage.dispatch_conf import diffstatusoutput
 from portage.process import find_binary
 
 FIND_EXTANT_CONFIGS  = "find '%s' %s -name '._cfg????_%s' ! -name '.*~' ! -iname '.*.bak' -print"
 DIFF_CONTENTS        = "diff -Nu '%s' '%s'"
-DIFF_CVS_INTERP      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '# .Header:.*'"
-DIFF_WSCOMMENTS      = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '^[-+]#' | grep -v '^[-+][[:space:]]*$'"
 
 # We need a secure scratch dir and python does silly verbose errors on the use of tempnam
 oldmask = os.umask(0o077)
@@ -62,7 +60,7 @@ def cleanup(mydir=SCRATCH_DIR):
     shutil.rmtree(mydir)
 atexit.register(cleanup)
 
-MANDATORY_OPTS  = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ]
+MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ]
 
 def cmd_var_is_valid(cmd):
     """
@@ -152,6 +150,9 @@ class dispatch:
             portage.util.shlex_split(
             portage.settings.get('CONFIG_PROTECT_MASK', '')))
 
+        def diff(file1, file2):
+            return diffstatusoutput(DIFF_CONTENTS, file1, file2)
+
         #
         # Remove new configs identical to current
         #                  and
@@ -168,11 +169,11 @@ class dispatch:
             else:
                 mrgfail = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf)
             if os.path.exists(archive + '.dist'):
-                unmodified = diffstatusoutput_len(DIFF_CONTENTS % (conf['current'], archive + '.dist'))[1] == 0
+                unmodified = len(diff(conf['current'], archive + '.dist')[1]) == 0
             else:
                 unmodified = 0
             if os.path.exists(mrgconf):
-                if mrgfail or diffstatusoutput_len(DIFF_CONTENTS % (conf['new'], mrgconf))[1] == 0:
+                if mrgfail or len(diff(conf['new'], mrgconf)[1]) == 0:
                     os.unlink(mrgconf)
                     newconf = conf['new']
                 else:
@@ -183,24 +184,34 @@ class dispatch:
             if newconf == mrgconf and \
                 self.options.get('ignore-previously-merged') != 'yes' and \
                 os.path.exists(archive+'.dist') and \
-                diffstatusoutput_len(DIFF_CONTENTS % (archive+'.dist', conf['new']))[1] == 0:
+                len(diff(archive+'.dist', conf['new'])[1]) == 0:
                 # The current update is identical to the archived .dist
                 # version that has previously been merged.
                 os.unlink(mrgconf)
                 newconf = conf['new']
 
-            mystatus, myoutput_len = diffstatusoutput_len(
-                DIFF_CONTENTS  % (conf ['current'], newconf))
+            mystatus, myoutput = diff(conf['current'], newconf)
+            myoutput_len = len(myoutput)
             same_file = 0 == myoutput_len
             if mystatus >> 8 == 2:
                 # Binary files differ
                 same_cvs = False
                 same_wsc = False
             else:
-                same_cvs = 0 == diffstatusoutput_len(
-                    DIFF_CVS_INTERP % (conf ['current'], newconf))[1]
-                same_wsc = 0 == diffstatusoutput_len(
-                    DIFF_WSCOMMENTS % (conf ['current'], newconf))[1]
+                # Extract all the normal diff lines (ignore the headers).
+                mylines = re.findall('^[+-][^\n+-].*$', myoutput, re.MULTILINE)
+
+                # Filter out all the cvs headers
+                cvs_header = re.compile('# [$]Header:')
+                cvs_lines = list(filter(cvs_header.search, mylines))
+                same_cvs = len(mylines) == len(cvs_lines)
+
+                # Filter out comments and whitespace-only changes.
+                # Note: be nice to also ignore lines that only differ in whitespace...
+                wsc_lines = []
+                for x in ['^[-+]\s*#', '^[-+]\s*$']:
+                   wsc_lines += list(filter(re.compile(x).match, mylines))
+                same_wsc = len(mylines) == len(wsc_lines)
 
             # Do options permit?
             same_cvs = same_cvs and self.options['replace-cvs'] == 'yes'

diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py
index 7f407ff..6e8de0f 100644
--- a/pym/portage/dispatch_conf.py
+++ b/pym/portage/dispatch_conf.py
@@ -23,18 +23,18 @@ RCS_MERGE = "rcsmerge -p -r" + RCS_BRANCH + " '%s' > '%s'"
 
 DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'"
 
-def diffstatusoutput_len(cmd):
+def diffstatusoutput(cmd, file1, file2):
     """
     Execute the string cmd in a shell with getstatusoutput() and return a
-    2-tuple (status, output_length). If getstatusoutput() raises
+    2-tuple (status, output). If getstatusoutput() raises
     UnicodeDecodeError (known to happen with python3.1), return a
     2-tuple (1, 1). This provides a simple way to check for non-zero
     output length of diff commands, while providing simple handling of
     UnicodeDecodeError when necessary.
     """
     try:
-        status, output = portage.subprocess_getstatusoutput(cmd)
-        return (status, len(output))
+        status, output = portage.subprocess_getstatusoutput(cmd % (file1, file2))
+        return (status, output)
     except UnicodeDecodeError:
         return (1, 1)
 



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2012-03-17 16:44 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2012-03-17 16:44 UTC (permalink / raw
  To: gentoo-commits

commit:     2dac56fa282645031eb29860abc403e983a04b2d
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 17 16:44:03 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Mar 17 16:44:03 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=2dac56fa

Manifest: filter file names with repoman's regex

This makes Manifest generation consistent with repoman, which is
necessary if repoman is going to ignore irrelevant files as requested
in bug #406877.

---
 bin/repoman             |    3 ++-
 pym/portage/manifest.py |   10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/bin/repoman b/bin/repoman
index 3f16603..ffedf2e 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -69,6 +69,8 @@ from portage import cvstree, normalize_path
 from portage import util
 from portage.exception import (FileNotFound, MissingParameter,
 	ParseError, PermissionDenied)
+from portage.manifest import _prohibited_filename_chars_re as \
+	disallowed_filename_chars_re
 from portage.process import find_binary, spawn
 from portage.output import bold, create_color_func, \
 	green, nocolor, red
@@ -85,7 +87,6 @@ util.initialize_logger()
 # 14 is the length of DESCRIPTION=""
 max_desc_len = 100
 allowed_filename_chars="a-zA-Z0-9._-+:"
-disallowed_filename_chars_re = re.compile(r'[^a-zA-Z0-9._\-+:]')
 pv_toolong_re = re.compile(r'[0-9]{19,}')
 bad = create_color_func("BAD")
 

diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py
index da40ae1..90324ee 100644
--- a/pym/portage/manifest.py
+++ b/pym/portage/manifest.py
@@ -1,8 +1,9 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import errno
 import io
+import re
 import warnings
 
 import portage
@@ -22,6 +23,9 @@ from portage.const import (MANIFEST1_HASH_FUNCTIONS, MANIFEST2_HASH_DEFAULTS,
 	MANIFEST2_HASH_FUNCTIONS, MANIFEST2_IDENTIFIERS, MANIFEST2_REQUIRED_HASH)
 from portage.localization import _
 
+# Characters prohibited by repoman's file.name check.
+_prohibited_filename_chars_re = re.compile(r'[^a-zA-Z0-9._\-+:]')
+
 class FileNotInManifestException(PortageException):
 	pass
 
@@ -33,10 +37,14 @@ def manifest2AuxfileFilter(filename):
 	for x in mysplit:
 		if x[:1] == '.':
 			return False
+		if _prohibited_filename_chars_re.search(x) is not None:
+			return False
 	return not filename[:7] == 'digest-'
 
 def manifest2MiscfileFilter(filename):
 	filename = filename.strip(os.sep)
+	if _prohibited_filename_chars_re.search(filename) is not None:
+		return False
 	return not (filename in ["CVS", ".svn", "files", "Manifest"] or filename.endswith(".ebuild"))
 
 def guessManifestFileType(filename):



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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2012-10-18  0:05 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2012-10-18  0:05 UTC (permalink / raw
  To: gentoo-commits

commit:     873deb19db6bdc1201b83f44f85da0d44962b98b
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 18 00:04:53 2012 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Oct 18 00:04:53 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=873deb19

glsa: account for EAPI 5 sub-slot in SLOT

---
 bin/glsa-check      |    2 +-
 pym/portage/glsa.py |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index eddc905..bfae0f9 100755
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -226,7 +226,7 @@ if mode in ["dump", "fix", "inject", "pretend"]:
 				for pkg in mergelist:
 					oldver = None
 					for x in vardb.match(portage.cpv_getkey(pkg)):
-						if vardb.aux_get(x, ["SLOT"]) == portdb.aux_get(pkg, ["SLOT"]):
+						if vardb._pkg_str(x, None).slot == portdb._pkg_str(pkg, None).slot:
 							oldver = x
 					if oldver == None:
 						raise ValueError("could not find old version for package %s" % pkg)

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index d3c3b3d..5bff687 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -378,7 +378,7 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=
 						or not match("="+rValue, portdbapi) \
 						or (minimize ^ (vercmp(c.version, rValue.version) > 0)) \
 							and match("="+c, portdbapi)) \
-					and portdbapi.aux_get(c, ["SLOT"]) == vardbapi.aux_get(best(v_installed), ["SLOT"]):
+					and portdbapi._pkg_str(c, None).slot == vardbapi._pkg_str(best(v_installed), None).slot:
 				rValue = c
 	return rValue
 


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  1:53 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  1:53 UTC (permalink / raw
  To: gentoo-commits

commit:     515e59720f25bc0335f4e718826dbbb1a5fd8d1c
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 21:35:12 2009 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 01:44:05 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=515e5972

Handle unicode encoding when dumping to stdout and start migration to using StringIO

svn path=/trunk/gentoolkit/; revision=645

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=88c18ffe936e602c45dcaa7500961623c49697ca

---
 bin/glsa-check      |    5 ++++-
 pym/portage/glsa.py |   50 +++++++++++++++++++++++++++++++-------------------
 2 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index ed0df35..0e2b7a3 100755
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -5,6 +5,7 @@
 from __future__ import print_function
 
 import sys
+import codecs
 
 from os import path as osp
 pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), "pym")
@@ -140,7 +141,9 @@ for p in params[:]:
 
 glsalist.extend([g for g in params if g not in glsalist])
 
-def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr):
+def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr, encoding="utf-8"):
+	fd1 = codecs.getwriter(encoding)(fd1)
+	fd2 = codecs.getwriter(encoding)(fd2)
 	fd2.write(white("[A]")+" means this GLSA was already applied,\n")
 	fd2.write(green("[U]")+" means the system is not affected and\n")
 	fd2.write(red("[N]")+" indicates that the system might be affected.\n\n")

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index 5bff687..57461f7 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -1,7 +1,7 @@
 # Copyright 2003-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import absolute_import
+from __future__ import absolute_import, unicode_literals
 
 import io
 import sys
@@ -9,8 +9,10 @@ try:
 	from urllib.request import urlopen as urllib_request_urlopen
 except ImportError:
 	from urllib import urlopen as urllib_request_urlopen
+import codecs
 import re
 import xml.dom.minidom
+from io import StringIO
 
 import portage
 from portage import os
@@ -140,7 +142,7 @@ def getListElements(listnode):
 		rValue.append(getText(li, format="strip"))
 	return rValue
 
-def getText(node, format):
+def getText(node, format, textfd = None):
 	"""
 	This is the main parser function. It takes a node and traverses
 	recursive over the subnodes, getting the text of each (and the
@@ -158,45 +160,54 @@ def getText(node, format):
 					replaces multiple spaces with one space.
 					I{xml} does some more formatting, depending on the
 					type of the encountered nodes.
+	@type	textfd: writable file-like object
+	@param	textfd: the file-like object to write the output to
 	@rtype:		String
 	@return:	the (formatted) content of the node and its subnodes
+			except if textfd was not none
 	"""
-	rValue = ""
+	if not textfd:
+		textfd = StringIO()
+		returnNone = False
+	else:
+		returnNone = True
 	if format in ["strip", "keep"]:
 		if node.nodeName in ["uri", "mail"]:
-			rValue += node.childNodes[0].data+": "+node.getAttribute("link")
+			textfd.write(node.childNodes[0].data+": "+node.getAttribute("link"))
 		else:
 			for subnode in node.childNodes:
 				if subnode.nodeName == "#text":
-					rValue += subnode.data
+					textfd.write(subnode.data)
 				else:
-					rValue += getText(subnode, format)
-	else:
+					getText(subnode, format, textfd)
+	else: # format = "xml"
 		for subnode in node.childNodes:
 			if subnode.nodeName == "p":
 				for p_subnode in subnode.childNodes:
 					if p_subnode.nodeName == "#text":
-						rValue += p_subnode.data.strip()
+						textfd.write(p_subnode.data.strip())
 					elif p_subnode.nodeName in ["uri", "mail"]:
-						rValue += p_subnode.childNodes[0].data
-						rValue += " ( "+p_subnode.getAttribute("link")+" )"
-				rValue += NEWLINE_ESCAPE
+						textfd.write(p_subnode.childNodes[0].data)
+						textfd.write(" ( "+p_subnode.getAttribute("link")+" )")
+				textfd.write(NEWLINE_ESCAPE)
 			elif subnode.nodeName == "ul":
 				for li in getListElements(subnode):
-					rValue += "-"+SPACE_ESCAPE+li+NEWLINE_ESCAPE+" "
+					textfd.write("-"+SPACE_ESCAPE+li+NEWLINE_ESCAPE+" ")
 			elif subnode.nodeName == "ol":
 				i = 0
 				for li in getListElements(subnode):
 					i = i+1
-					rValue += str(i)+"."+SPACE_ESCAPE+li+NEWLINE_ESCAPE+" "
+					textfd.write(str(i)+"."+SPACE_ESCAPE+li+NEWLINE_ESCAPE+" ")
 			elif subnode.nodeName == "code":
-				rValue += getText(subnode, format="keep").replace("\n", NEWLINE_ESCAPE)
-				if rValue[-1*len(NEWLINE_ESCAPE):] != NEWLINE_ESCAPE:
-					rValue += NEWLINE_ESCAPE
+				textfd.write(getText(subnode, format="keep").lstrip().replace("\n", NEWLINE_ESCAPE))
+				textfd.write(NEWLINE_ESCAPE)
 			elif subnode.nodeName == "#text":
-				rValue += subnode.data
+				textfd.write(subnode.data)
 			else:
 				raise GlsaFormatException(_("Invalid Tag found: "), subnode.nodeName)
+	if returnNone:
+		return None
+	rValue = textfd.getvalue()
 	if format == "strip":
 		rValue = rValue.strip(" \n\t")
 		rValue = re.sub("[\s]{2,}", " ", rValue)
@@ -578,16 +589,17 @@ class Glsa:
 		self.services = self.affected.getElementsByTagName("service")
 		return None
 
-	def dump(self, outstream=sys.stdout):
+	def dump(self, outstream=sys.stdout, encoding="utf-8"):
 		"""
 		Dumps a plaintext representation of this GLSA to I{outfile} or 
 		B{stdout} if it is ommitted. You can specify an alternate
-		I{encoding} if needed (default is latin1).
+		I{encoding} if needed (default is utf-8).
 		
 		@type	outstream: File
 		@param	outfile: Stream that should be used for writing
 						 (defaults to sys.stdout)
 		"""
+		outstream = codecs.getwriter(encoding)(outstream)
 		width = 76
 		outstream.write(("GLSA %s: \n%s" % (self.nr, self.title)).center(width)+"\n")
 		outstream.write((width*"=")+"\n")


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  2:27 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  2:27 UTC (permalink / raw
  To: gentoo-commits

commit:     f8960360ebca8ae85b91e24047afc21f6eda33bb
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 21:46:46 2009 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 02:25:46 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=f8960360

Change behaviour of getMinUpgrade

This allows to differentiate between situations where
the system is unaffected and unexistance of an upgrade path.

Previously, the glsa-check would treat GLSAs that had no
upgrade path (such as mask glsas) as not affecting the system.

svn path=/trunk/gentoolkit/; revision=647

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=ef38a394c5c2f5901173a53914705730850f9b3f

---
 bin/glsa-check      |   10 ++++++++++
 pym/portage/glsa.py |   15 ++++++++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
old mode 100755
new mode 100644
index 0e2b7a3..969ad84
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -207,6 +207,11 @@ if mode in ["dump", "fix", "inject", "pretend"]:
 		elif mode == "fix":
 			sys.stdout.write("fixing "+myid+"\n")
 			mergelist = myglsa.getMergeList(least_change=least_change)
+			if mergelist == None:
+				sys.stdout.write(">>> no vulnerable packages installed\n")
+			elif mergelist == []:
+				sys.stdout.write(">>> cannot fix GLSA, no unaffected packages available\n")
+				sys.exit(2)
 			for pkg in mergelist:
 				sys.stdout.write(">>> merging "+pkg+"\n")
 				# using emerge for the actual merging as it contains the dependency
@@ -225,6 +230,11 @@ if mode in ["dump", "fix", "inject", "pretend"]:
 		elif mode == "pretend":
 			sys.stdout.write("Checking GLSA "+myid+"\n")
 			mergelist = myglsa.getMergeList(least_change=least_change)
+			if mergelist == None:
+				sys.stdout.write(">>> no vulnerable packages installed\n")
+			elif mergelist == []:
+				sys.stdout.write(">>> cannot fix GLSA, no unaffected packages available\n")
+				sys.exit(2)
 			if mergelist:
 				sys.stdout.write("The following updates will be performed for this GLSA:\n")
 				for pkg in mergelist:

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index 514dcc0..76eae2b 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -342,8 +342,9 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=
 	I{vulnerableList} and returns string describing
 	the lowest version for the package that matches an atom in 
 	I{unaffectedList} and is greater than the currently installed
-	version or None if the system is not affected. Both
-	I{vulnerableList} and I{unaffectedList} should have the
+	version. It will return an empty list if the system is affected,
+	and no upgrade is possible or None if the system is not affected.
+	Both I{vulnerableList} and I{unaffectedList} should have the
 	same base package.
 	
 	@type	vulnerableList: List of Strings
@@ -361,7 +362,7 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=
 	@return:	the lowest unaffected version that is greater than
 				the installed version.
 	"""
-	rValue = None
+	rValue = ""
 	v_installed = reduce(operator.add, [match(v, vardbapi) for v in vulnerableList], [])
 	u_installed = reduce(operator.add, [match(u, vardbapi) for u in unaffectedList], [])
 
@@ -371,14 +372,14 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=
 			install_unaffected = False
 
 	if install_unaffected:
-		return rValue
-	
+		return None
+
 	for u in unaffectedList:
 		mylist = match(u, portdbapi, match_type="match-all")
 		for c in mylist:
 			i = best(v_installed)
 			if vercmp(c.version, i.version) > 0 \
-					and (rValue == None \
+					and (rValue == "" \
 						or not match("="+rValue, portdbapi) \
 						or (minimize ^ (vercmp(c.version, rValue.version) > 0)) \
 							and match("="+c, portdbapi)) \
@@ -646,7 +647,7 @@ class Glsa:
 					for v in path["vul_atoms"]:
 						rValue = rValue \
 							or (len(match(v, self.vardbapi)) > 0 \
-								and getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], \
+								and None != getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], \
 										self.portdbapi, self.vardbapi))
 		return rValue
 	


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  3:23 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  3:23 UTC (permalink / raw
  To: gentoo-commits

commit:     c7e110bae1ec05e9ecd745ac5cc7314006e5026c
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 21:49:39 2009 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 03:02:00 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c7e110ba

Restructure system affection detection.

Store "vulnerable" and "upgrade" packages in a table, and use that
data to determine which packages cannot be upgraded, and which
packages actually cause upgrades

svn path=/trunk/gentoolkit/; revision=648

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=b6a2a23926d54ccfa9a1ce331c1bc97dbe2c73d1

---
 bin/glsa-check      |   72 ++++++++++++++++++++++++--------------------------
 pym/portage/glsa.py |   61 +++++++++++++++++++++++++++---------------
 2 files changed, 74 insertions(+), 59 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index 969ad84..3cfe0ba 100644
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -205,49 +205,47 @@ if mode in ["dump", "fix", "inject", "pretend"]:
 		if mode == "dump":
 			myglsa.dump()
 		elif mode == "fix":
-			sys.stdout.write("fixing "+myid+"\n")
-			mergelist = myglsa.getMergeList(least_change=least_change)
-			if mergelist == None:
+			sys.stdout.write("Fixing GLSA "+myid+"\n")
+			if not myglsa.isVulnerable():
 				sys.stdout.write(">>> no vulnerable packages installed\n")
-			elif mergelist == []:
-				sys.stdout.write(">>> cannot fix GLSA, no unaffected packages available\n")
-				sys.exit(2)
-			for pkg in mergelist:
-				sys.stdout.write(">>> merging "+pkg+"\n")
-				# using emerge for the actual merging as it contains the dependency
-				# code and we want to be consistent in behaviour. Also this functionality
-				# will be integrated in emerge later, so it shouldn't hurt much.
-				emergecmd = "emerge --oneshot " + portage.settings["EMERGE_OPTS"] + " =" + pkg
-				if verbose:
-					sys.stderr.write(emergecmd+"\n")
-				exitcode = os.system(emergecmd)
-				# system() returns the exitcode in the high byte of a 16bit integer
-				if exitcode >= 1<<8:
-					exitcode >>= 8
-				if exitcode:
-					sys.exit(exitcode)
+			else:
+				mergelist = myglsa.getMergeList(least_change=least_change)
+				if mergelist == []:
+					sys.stdout.write(">>> cannot fix GLSA, no unaffected packages available\n")
+					sys.exit(2)
+				for pkg in mergelist:
+					sys.stdout.write(">>> merging "+pkg+"\n")
+					# using emerge for the actual merging as it contains the dependency
+					# code and we want to be consistent in behaviour. Also this functionality
+					# will be integrated in emerge later, so it shouldn't hurt much.
+					emergecmd = "emerge --oneshot " + glsaconfig["EMERGE_OPTS"] + " =" + pkg
+					if verbose:
+						sys.stderr.write(emergecmd+"\n")
+					exitcode = os.system(emergecmd)
+					# system() returns the exitcode in the high byte of a 16bit integer
+					if exitcode >= 1<<8:
+						exitcode >>= 8
+					if exitcode:
+						sys.exit(exitcode)
+			if len(mergelist):
+				sys.stdout.write("\n")
 			myglsa.inject()
 		elif mode == "pretend":
 			sys.stdout.write("Checking GLSA "+myid+"\n")
-			mergelist = myglsa.getMergeList(least_change=least_change)
-			if mergelist == None:
+			if not myglsa.isVulnerable():
 				sys.stdout.write(">>> no vulnerable packages installed\n")
-			elif mergelist == []:
-				sys.stdout.write(">>> cannot fix GLSA, no unaffected packages available\n")
-				sys.exit(2)
-			if mergelist:
-				sys.stdout.write("The following updates will be performed for this GLSA:\n")
-				for pkg in mergelist:
-					oldver = None
-					for x in vardb.match(portage.cpv_getkey(pkg)):
-						if vardb._pkg_str(x, None).slot == portdb._pkg_str(pkg, None).slot:
-							oldver = x
-					if oldver == None:
-						raise ValueError("could not find old version for package %s" % pkg)
-					oldver = oldver[len(portage.cpv_getkey(oldver))+1:]
-					sys.stdout.write("     " + pkg + " (" + oldver + ")\n")
 			else:
-				sys.stdout.write("Nothing to do for this GLSA\n")
+				mergedict = {}
+				for (vuln, update) in myglsa.getAffectionTable(least_change=least_change):
+					mergedict.setdefault(update, []).append(vuln)
+				
+				sys.stdout.write(">>> The following updates will be performed for this GLSA:\n")
+				for pkg in mergedict:
+					if pkg != "":
+						sys.stdout.write("     " + pkg + " (vulnerable: " + ", ".join(mergedict[pkg]) + ")\n")
+				if "" in mergedict:
+					sys.stdout.write("\n>>> For the following packages, no upgrade path exists:\n")
+					sys.stdout.write("     " + ", ".join(mergedict[""]))
 		elif mode == "inject":
 			sys.stdout.write("injecting " + myid + "\n")
 			myglsa.inject()

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index 76eae2b..5cc735b 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -366,26 +366,36 @@ def getMinUpgrade(vulnerableList, unaffectedList, portdbapi, vardbapi, minimize=
 	v_installed = reduce(operator.add, [match(v, vardbapi) for v in vulnerableList], [])
 	u_installed = reduce(operator.add, [match(u, vardbapi) for u in unaffectedList], [])
 
-	install_unaffected = True
-	for i in v_installed:
-		if i not in u_installed:
-			install_unaffected = False
+	# remove all unaffected atoms from vulnerable list
+	v_installed = list(set(v_installed).difference(set(u_installed)))
 
-	if install_unaffected:
+	if not v_installed:
 		return None
 
+	# this tuple holds all vulnerable atoms, and the related upgrade atom
+	vuln_update = []
+	avail_updates = set()
 	for u in unaffectedList:
-		mylist = match(u, portdbapi, match_type="match-all")
-		for c in mylist:
-			i = best(v_installed)
-			if vercmp(c.version, i.version) > 0 \
-					and (rValue == "" \
-						or not match("="+rValue, portdbapi) \
-						or (minimize ^ (vercmp(c.version, rValue.version) > 0)) \
-							and match("="+c, portdbapi)) \
-					and portdbapi._pkg_str(c, None).slot == vardbapi._pkg_str(best(v_installed), None).slot:
-				rValue = c
-	return rValue
+		# TODO: This had match_type="match-all" before. I don't think it should
+		# since we disregarded masked items later anyway (match(=rValue, "porttree"))
+		avail_updates.update(match(u, "porttree"))
+	# if an atom is already installed, we should not consider it for upgrades
+	avail_updates.difference_update(u_installed)
+
+	for vuln in v_installed:
+		update = ""
+		for c in avail_updates:
+			c_pv = portage.catpkgsplit(c)
+			if vercmp(c.version, vuln.version) > 0 \
+					and (update == "" \
+						or (minimize ^ (vercmp(c.version, update.version) > 0))) \
+					and portdbapi._pkg_str(c, None).slot == vardbapi._pkg_str(vuln, None).slot:
+				update = c_pv[0]+"/"+c_pv[1]+"-"+c_pv[2]
+				if c_pv[3] != "r0":		# we don't like -r0 for display
+					update += "-"+c_pv[3]
+		vuln_update.append([vuln, update])
+
+	return vuln_update
 
 def format_date(datestr):
 	"""
@@ -692,11 +702,18 @@ class Glsa:
 		@rtype:		List of Strings
 		@return:	list of package-versions that have to be merged
 		"""
-		rValue = []
-		for pkg in self.packages:
+		return list(set(update for (vuln, update) in self.getAffectionTable(least_change) if update))
+
+	def getAffectionTable(self, least_change=True):
+		"""
+		Will initialize the self.systemAffection list of
+		atoms installed on the system that are affected
+		by this GLSA, and the atoms that are minimal upgrades.
+		"""
+		systemAffection = []
+		for pkg in self.packages.keys():
 			for path in self.packages[pkg]:
-				update = getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], \
-					self.portdbapi, self.vardbapi, minimize=least_change)
+				update = getMinUpgrade(path["vul_atoms"], path["unaff_atoms"], minimize=least_change)
 				if update:
-					rValue.append(update)
-		return rValue
+					systemAffection.extend(update)
+		return systemAffection


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  3:23 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  3:23 UTC (permalink / raw
  To: gentoo-commits

commit:     4f0733f956d826f26b5a53c92a2c1ebf80181d91
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 21:53:30 2009 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 03:21:20 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4f0733f9

Do not inject GLSAs into the checkfile when fixing them

There is no reason applied GLSAs must be stored in a checkfile. In the
current glsa-check GUI this will make it impossible to determine whether
the system is still affected by the GLSA (e.g. by re-emerging, or when a
GLSA is changed afterwards).

The current place for the checkfile (/var/cache) is not persistent per
FHS, meaning that people might clean out the contents of their injected
GLSAs. Since glsa.py is moving to portage anyway, we can use
/var/lib/portage as a place to store the injected GLSAs. Documentation
has been updated accordingly.

Note that the old checkfile should not be moved to the previous location
on upgrade since this will cause false negatives due to the above
arguments. A message should appear on upgrade (pkg_postinst or similar).

svn path=/trunk/gentoolkit/; revision=649

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=4138f5b1b6dbcf1042663a45b3eae1e652bfc9be

---
 bin/glsa-check      |    7 +++----
 pym/portage/glsa.py |   21 ++++++++++++---------
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index 3cfe0ba..2b21d71 100644
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -55,7 +55,7 @@ modes.add_option("-f", "--fix", action="store_const",
 		const="fix", dest="mode",
 		help="Try to auto-apply this GLSA (experimental)")
 modes.add_option("-i", "--inject", action="store_const", dest="mode",
-		help="Inject the given GLSA into the checkfile")
+		help="inject the given GLSA into the glsa_injected file")
 modes.add_option("-m", "--mail", action="store_const",
 		const="mail", dest="mode",
 		help="Send a mail with the given GLSAs to the administrator")
@@ -144,7 +144,7 @@ glsalist.extend([g for g in params if g not in glsalist])
 def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr, encoding="utf-8"):
 	fd1 = codecs.getwriter(encoding)(fd1)
 	fd2 = codecs.getwriter(encoding)(fd2)
-	fd2.write(white("[A]")+" means this GLSA was already applied,\n")
+	fd2.write(white("[A]")+" means this GLSA was marked as applied (injected),\n")
 	fd2.write(green("[U]")+" means the system is not affected and\n")
 	fd2.write(red("[N]")+" indicates that the system might be affected.\n\n")
 
@@ -156,7 +156,7 @@ def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr, encoding="utf-8"):
 			if verbose:
 				fd2.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e)))
 			continue
-		if myglsa.isApplied():
+		if myglsa.isInjected():
 			status = "[A]"
 			color = white
 		elif myglsa.isVulnerable():
@@ -229,7 +229,6 @@ if mode in ["dump", "fix", "inject", "pretend"]:
 						sys.exit(exitcode)
 			if len(mergelist):
 				sys.stdout.write("\n")
-			myglsa.inject()
 		elif mode == "pretend":
 			sys.stdout.write("Checking GLSA "+myid+"\n")
 			if not myglsa.isVulnerable():

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index 5cc735b..84bf7fd 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -22,7 +22,7 @@ from portage import _unicode_decode
 from portage import _unicode_encode
 from portage.versions import pkgsplit, vercmp, best
 from portage.util import grabfile
-from portage.const import CACHE_PATH
+from portage.const import PRIVATE_PATH
 from portage.localization import _
 from portage.dep import _slot_separator
 
@@ -42,7 +42,7 @@ def get_applied_glsas(settings):
 	@rtype:		list
 	@return:	list of glsa IDs
 	"""
-	return grabfile(os.path.join(settings["EROOT"], CACHE_PATH, "glsa"))
+	return grabfile(os.path.join(settings["EROOT"], PRIVATE_PATH, "glsa_injected"))
 
 
 # TODO: use the textwrap module instead
@@ -661,14 +661,17 @@ class Glsa:
 										self.portdbapi, self.vardbapi))
 		return rValue
 	
-	def isApplied(self):
+	def isInjected(self):
 		"""
-		Looks if the GLSA IDis in the GLSA checkfile to check if this
-		GLSA was already applied.
+		Looks if the GLSA ID is in the GLSA checkfile to check if this
+		GLSA should be marked as applied.
 		
 		@rtype:		Boolean
-		@return:	True if the GLSA was applied, False if not
+		@returns:	True if the GLSA is in the inject file, False if not
 		"""
+		if not os.access(os.path.join(self.config["EROOT"],
+			PRIVATE_PATH, "glsa_injected"), os.R_OK):
+			return False
 		return (self.nr in get_applied_glsas(self.config))
 
 	def inject(self):
@@ -680,11 +683,11 @@ class Glsa:
 		@rtype:		None
 		@return:	None
 		"""
-		if not self.isApplied():
+		if not self.isInjected():
 			checkfile = io.open(
 				_unicode_encode(os.path.join(self.config["EROOT"],
-				CACHE_PATH, "glsa"),
-				encoding=_encodings['fs'], errors='strict'), 
+				PRIVATE_PATH, "glsa_injected"),
+				encoding=_encodings['fs'], errors='strict'),
 				mode='a+', encoding=_encodings['content'], errors='strict')
 			checkfile.write(_unicode_decode(self.nr + "\n"))
 			checkfile.close()


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  5:00 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  5:00 UTC (permalink / raw
  To: gentoo-commits

commit:     812c9ee0778547c0fb918ce4b62c7ba3957f6727
Author:     Paul Varner <fuzzyray <AT> gentoo <DOT> org>
AuthorDate: Tue Mar  9 16:42:04 2010 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 04:59:00 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=812c9ee0

sync with genscripts rev 343. This adds the initial py3k support and the analyse utility to gentoolkit

svn path=/trunk/gentoolkit/; revision=751

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=2f90a4b9ceff920f793541376da21d313af083d9

---
 bin/glsa-check      |    7 +++++++
 pym/portage/glsa.py |   13 +++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
old mode 100644
new mode 100755
index 2b21d71..3d047b5
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -142,6 +142,13 @@ for p in params[:]:
 glsalist.extend([g for g in params if g not in glsalist])
 
 def summarylist(myglsalist, fd1=sys.stdout, fd2=sys.stderr, encoding="utf-8"):
+	# Get to the raw streams in py3k before wrapping them with an encoded writer
+	# to avoid writing bytes to a text stream (stdout/stderr are text streams
+	# by default in py3k)
+	if hasattr(fd1, "buffer"):
+		fd1 = fd1.buffer
+	if hasattr(fd2, "buffer"):
+		fd2 = fd2.buffer
 	fd1 = codecs.getwriter(encoding)(fd1)
 	fd2 = codecs.getwriter(encoding)(fd2)
 	fd2.write(white("[A]")+" means this GLSA was marked as applied (injected),\n")

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index 155d3e5..c0c69dd 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -14,6 +14,7 @@ import re
 import operator
 import xml.dom.minidom
 from io import StringIO
+from functools import reduce
 
 import portage
 from portage import os
@@ -526,17 +527,17 @@ class Glsa:
 		self.synopsis = getText(myroot.getElementsByTagName("synopsis")[0], format="strip")
 		self.announced = format_date(getText(myroot.getElementsByTagName("announced")[0], format="strip"))
 
-		count = 1
 		# Support both formats of revised:
 		# <revised>December 30, 2007: 02</revised>
 		# <revised count="2">2007-12-30</revised>
 		revisedEl = myroot.getElementsByTagName("revised")[0]
 		self.revised = getText(revisedEl, format="strip")
-		if ((sys.hexversion >= 0x3000000 and "count" in revisedEl.attributes) or
-			(sys.hexversion < 0x3000000 and revisedEl.attributes.has_key("count"))):
-			count = revisedEl.getAttribute("count")
-		elif (self.revised.find(":") >= 0):
-			(self.revised, count) = self.revised.split(":")
+		count = revisedEl.attributes.get("count")
+		if count is None:
+			if self.revised.find(":") >= 0:
+				(self.revised, count) = self.revised.split(":")
+			else:
+				count = 1
 
 		self.revised = format_date(self.revised)
 


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-01-19  5:16 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-01-19  5:16 UTC (permalink / raw
  To: gentoo-commits

commit:     0d7e395a3227264ff8bcc2c35d024c2b39e07679
Author:     Andy Kittner <andkit <AT> gmx <DOT> de>
AuthorDate: Wed Jan 26 23:21:21 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Jan 19 05:15:18 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0d7e395a

Fix unicode vs. bytes issue in glsa-check (#341293)

http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=01d40ffed91033119bae05dac5c9cea86b94aa2e

---
 bin/glsa-check      |   17 ++++++++++-------
 pym/portage/glsa.py |    1 +
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/bin/glsa-check b/bin/glsa-check
index 3d047b5..b2da90a 100755
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -283,7 +283,7 @@ if mode == "test":
 # mail mode as requested by solar
 if mode == "mail":
 	import portage.mail, socket
-	from io import StringIO
+	from io import BytesIO
 	from email.mime.text import MIMEText
 
 	# color doesn't make any sense for mail
@@ -302,11 +302,13 @@ if mode == "mail":
 	mysubject = "[glsa-check] Summary for %s" % socket.getfqdn()
 
 	# need a file object for summarylist()
-	myfd = StringIO()
-	myfd.write("GLSA Summary report for host %s\n" % socket.getfqdn())
-	myfd.write("(Command was: %s)\n\n" % " ".join(sys.argv))
+	myfd = BytesIO()
+	line = "GLSA Summary report for host %s\n" % socket.getfqdn()
+	myfd.write(line.encode("utf-8"))
+	line = "(Command was: %s)\n\n" % " ".join(sys.argv)
+	myfd.write(line.encode("utf-8"))
 	summarylist(glsalist, fd1=myfd, fd2=myfd)
-	summary = str(myfd.getvalue())
+	summary = myfd.getvalue().decode("utf-8")
 	myfd.close()
 
 	myattachments = []
@@ -317,9 +319,10 @@ if mode == "mail":
 			if verbose:
 				sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e)))
 			continue
-		myfd = StringIO()
+		myfd = BytesIO()
 		myglsa.dump(outstream=myfd)
-		myattachments.append(MIMEText(str(myfd.getvalue()), _charset="utf8"))
+		attachment = myfd.getvalue().decode("utf-8")
+		myattachments.append(MIMEText(attachment, _charset="utf8"))
 		myfd.close()
 
 	mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, summary, myattachments)

diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index c0c69dd..1dd8a98 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -604,6 +604,7 @@ class Glsa:
 		@param	outfile: Stream that should be used for writing
 						 (defaults to sys.stdout)
 		"""
+		outstream = getattr(outstream, "buffer", outstream)
 		outstream = codecs.getwriter(encoding)(outstream)
 		width = 76
 		outstream.write(("GLSA %s: \n%s" % (self.nr, self.title)).center(width)+"\n")


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-02-11  9:39 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-02-11  9:39 UTC (permalink / raw
  To: gentoo-commits

commit:     b5e88117bf4ed0aec3ab537f8f280a15b050e40c
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 11 09:38:58 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Feb 11 09:38:58 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b5e88117

ebuild: add _reset_legacy_globals for reload

This avoids weird issues that are triggered when the module is
reloaded (like having classes redefined while instances from the old
classes are still around, triggering TypeError confusion).

---
 bin/ebuild              |    3 +--
 pym/portage/__init__.py |   31 ++++++++++++++++---------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/bin/ebuild b/bin/ebuild
index 44b3c99..1ce4c9c 100755
--- a/bin/ebuild
+++ b/bin/ebuild
@@ -35,7 +35,6 @@ else:
 
 signal.signal(debug_signum, debug_signal)
 
-import imp
 import io
 import optparse
 import os
@@ -157,7 +156,7 @@ if ebuild_portdir != vdb_path and \
 			encoding=_encodings['content'], errors='strict')
 
 	print("Appending %s to PORTDIR_OVERLAY..." % ebuild_portdir)
-	imp.reload(portage)
+	portage._reset_legacy_globals()
 
 myrepo = None
 if ebuild_portdir != vdb_path:

diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index a8b692c..bc14bae 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -657,10 +657,17 @@ if VERSION == 'HEAD':
 			return VERSION
 	VERSION = _LazyVersion()
 
-if "_legacy_globals_constructed" in globals():
-	# The module has been reloaded, so perform any relevant cleanup
-	# and prevent memory leaks.
-	if "db" in _legacy_globals_constructed:
+_legacy_global_var_names = ("archlist", "db", "features",
+	"groups", "mtimedb", "mtimedbfile", "pkglines",
+	"portdb", "profiledir", "root", "selinux_enabled",
+	"settings", "thirdpartymirrors")
+
+def _reset_legacy_globals():
+
+	global _legacy_globals_constructed
+
+	if "_legacy_globals_constructed" in globals() and \
+		"db" in _legacy_globals_constructed:
 		try:
 			db
 		except NameError:
@@ -684,7 +691,10 @@ if "_legacy_globals_constructed" in globals():
 						portdbapi.portdbapi_instances.remove(_x)
 					except ValueError:
 						pass
-				del _x
+
+	_legacy_globals_constructed = set()
+	for k in _legacy_global_var_names:
+		globals()[k] = _LegacyGlobalProxy(k)
 
 class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
 
@@ -699,16 +709,7 @@ class _LegacyGlobalProxy(proxy.objectproxy.ObjectProxy):
 		from portage._legacy_globals import _get_legacy_global
 		return _get_legacy_global(name)
 
-_legacy_global_var_names = ("archlist", "db", "features",
-	"groups", "mtimedb", "mtimedbfile", "pkglines",
-	"portdb", "profiledir", "root", "selinux_enabled",
-	"settings", "thirdpartymirrors")
-
-for k in _legacy_global_var_names:
-	globals()[k] = _LegacyGlobalProxy(k)
-del k
-
-_legacy_globals_constructed = set()
+_reset_legacy_globals()
 
 def _disable_legacy_globals():
 	"""


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-06-23 22:40 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-06-23 22:40 UTC (permalink / raw
  To: gentoo-commits

commit:     1d02521a635d81001fc5991ee9be6f8b293eeae3
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 23 22:40:38 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Jun 23 22:40:38 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1d02521a

Use /proc/<pid>/fd for solaris compat, bug 474536

---
 bin/helper-functions.sh | 6 +++++-
 pym/portage/process.py  | 4 +++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh
index 65f41f6..eb6066f 100644
--- a/bin/helper-functions.sh
+++ b/bin/helper-functions.sh
@@ -76,10 +76,14 @@ __redirect_alloc_fd() {
 	else
 			# Need to provide the functionality ourselves.
 			local fd=10
+			local fddir=/dev/fd
+			# Use /proc/<pid>/fd if available (/dev/fd
+			# doesn't work on solaris, see bug #474536).
+			[[ -d /proc/${BASHPID}/fd ]] && fddir=/proc/${BASHPID}/fd
 			while :; do
 					# Make sure the fd isn't open.  It could be a char device,
 					# or a symlink (possibly broken) to something else.
-					if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]] ; then
+					if [[ ! -e ${fddir}/${fd} ]] && [[ ! -L ${fddir}/${fd} ]] ; then
 							eval "exec ${fd}${redir}'${file}'" && break
 					fi
 					[[ ${fd} -gt 1024 ]] && die "__redirect_alloc_fd failed"

diff --git a/pym/portage/process.py b/pym/portage/process.py
index 7104552..df8a891 100644
--- a/pym/portage/process.py
+++ b/pym/portage/process.py
@@ -31,7 +31,9 @@ except ImportError:
 if sys.hexversion >= 0x3000000:
 	basestring = str
 
-for _fd_dir in ("/dev/fd", "/proc/self/fd"):
+# Use /proc/<pid>/fd if available (/dev/fd
+# doesn't work on solaris, see bug #474536).
+for _fd_dir in ("/proc/%s/fd" % os.getpid(), "/dev/fd", "/proc/self/fd"):
 	if os.path.isdir(_fd_dir):
 		break
 	else:


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-06-23 22:57 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-06-23 22:57 UTC (permalink / raw
  To: gentoo-commits

commit:     76ebfcf74e09bf40bfc790bbc7a917d71a1a0c00
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Jun 23 22:56:58 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Jun 23 22:56:58 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=76ebfcf7

Use /proc/<pid>/fd for solaris compat, bug 474536

---
 bin/helper-functions.sh |  6 +++++-
 pym/portage/process.py  | 11 ++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh
index 65f41f6..eb6066f 100644
--- a/bin/helper-functions.sh
+++ b/bin/helper-functions.sh
@@ -76,10 +76,14 @@ __redirect_alloc_fd() {
 	else
 			# Need to provide the functionality ourselves.
 			local fd=10
+			local fddir=/dev/fd
+			# Use /proc/<pid>/fd if available (/dev/fd
+			# doesn't work on solaris, see bug #474536).
+			[[ -d /proc/${BASHPID}/fd ]] && fddir=/proc/${BASHPID}/fd
 			while :; do
 					# Make sure the fd isn't open.  It could be a char device,
 					# or a symlink (possibly broken) to something else.
-					if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]] ; then
+					if [[ ! -e ${fddir}/${fd} ]] && [[ ! -L ${fddir}/${fd} ]] ; then
 							eval "exec ${fd}${redir}'${file}'" && break
 					fi
 					[[ ${fd} -gt 1024 ]] && die "__redirect_alloc_fd failed"

diff --git a/pym/portage/process.py b/pym/portage/process.py
index 7104552..6969370 100644
--- a/pym/portage/process.py
+++ b/pym/portage/process.py
@@ -37,7 +37,9 @@ for _fd_dir in ("/dev/fd", "/proc/self/fd"):
 	else:
 		_fd_dir = None
 
-if _fd_dir is not None:
+# Use /proc/<pid>/fd for SunOS (/dev/fd
+# doesn't work on solaris, see bug #474536).
+if _fd_dir is not None and platform.system() not in ('SunOS',):
 	def get_open_fds():
 		return (int(fd) for fd in os.listdir(_fd_dir) if fd.isdigit())
 
@@ -52,6 +54,13 @@ if _fd_dir is not None:
 					raise
 				return range(max_fd_limit)
 
+elif os.path.isdir("/proc/%s/fd" % os.getpid()):
+	# In order for this function to work in forked subprocesses,
+	# os.getpid() must be called from inside the function.
+	def get_open_fds():
+		return (int(fd) for fd in os.listdir("/proc/%s/fd" % os.getpid())
+			if fd.isdigit())
+
 else:
 	def get_open_fds():
 		return range(max_fd_limit)


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-06-25  7:48 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2013-06-25  7:48 UTC (permalink / raw
  To: gentoo-commits

commit:     d74ef62ae6509bad2d1a02d26a69dd4de511b87c
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Jun 25 07:48:18 2013 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Jun 25 07:48:18 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d74ef62a

Use /proc/self/fd for solaris compat, bug #474536

---
 bin/helper-functions.sh | 4 ++--
 pym/portage/process.py  | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/bin/helper-functions.sh b/bin/helper-functions.sh
index eb6066f..ecd78c3 100644
--- a/bin/helper-functions.sh
+++ b/bin/helper-functions.sh
@@ -77,9 +77,9 @@ __redirect_alloc_fd() {
 			# Need to provide the functionality ourselves.
 			local fd=10
 			local fddir=/dev/fd
-			# Use /proc/<pid>/fd if available (/dev/fd
+			# Prefer /proc/self/fd if available (/dev/fd
 			# doesn't work on solaris, see bug #474536).
-			[[ -d /proc/${BASHPID}/fd ]] && fddir=/proc/${BASHPID}/fd
+			[[ -d /proc/self/fd ]] && fddir=/proc/self/fd
 			while :; do
 					# Make sure the fd isn't open.  It could be a char device,
 					# or a symlink (possibly broken) to something else.

diff --git a/pym/portage/process.py b/pym/portage/process.py
index 6969370..7fdc133 100644
--- a/pym/portage/process.py
+++ b/pym/portage/process.py
@@ -31,15 +31,15 @@ except ImportError:
 if sys.hexversion >= 0x3000000:
 	basestring = str
 
-for _fd_dir in ("/dev/fd", "/proc/self/fd"):
+# Prefer /proc/self/fd if available (/dev/fd
+# doesn't work on solaris, see bug #474536).
+for _fd_dir in ("/proc/self/fd", "/dev/fd"):
 	if os.path.isdir(_fd_dir):
 		break
 	else:
 		_fd_dir = None
 
-# Use /proc/<pid>/fd for SunOS (/dev/fd
-# doesn't work on solaris, see bug #474536).
-if _fd_dir is not None and platform.system() not in ('SunOS',):
+if _fd_dir is not None:
 	def get_open_fds():
 		return (int(fd) for fd in os.listdir(_fd_dir) if fd.isdigit())
 


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2013-11-29 23:24 Mike Frysinger
  0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2013-11-29 23:24 UTC (permalink / raw
  To: gentoo-commits

commit:     c145e3cfcc016694f76488c21caaae37e3f3664e
Author:     Sebastian Luther <SebastianLuther <AT> gmx <DOT> de>
AuthorDate: Fri Nov 29 18:02:21 2013 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Nov 29 23:21:03 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c145e3cf

egencache: --write-timestamp to create metadata/timestamp.chk

This is required to sync repositories using rsnyc.

URL: https://bugs.gentoo.org/488972

---
 bin/egencache        | 14 ++++++++++++++
 pym/portage/const.py |  4 ++++
 2 files changed, 18 insertions(+)

diff --git a/bin/egencache b/bin/egencache
index 54c517e..915adc8 100755
--- a/bin/egencache
+++ b/bin/egencache
@@ -48,6 +48,7 @@ portage._internal_caller = True
 from portage import os, _encodings, _unicode_encode, _unicode_decode
 from _emerge.MetadataRegen import MetadataRegen
 from portage.cache.cache_errors import CacheError, StatCollision
+from portage.const import TIMESTAMP_FORMAT
 from portage.manifest import guessManifestFileType
 from portage.package.ebuild._parallel_manifest.ManifestScheduler import ManifestScheduler
 from portage.util import cmp_sort_key, writemsg_level
@@ -133,6 +134,9 @@ def parse_args(args):
 	common.add_argument("--ignore-default-opts",
 		action="store_true",
 		help="do not use the EGENCACHE_DEFAULT_OPTS environment variable")
+	common.add_argument("--write-timestamp",
+		action="store_true",
+		help="write metdata/timestamp.chk as required for rsync repositories")
 
 	update = parser.add_argument_group('--update options')
 	update.add_argument("--cache-dir",
@@ -1063,6 +1067,16 @@ def egencache_main(args):
 		gen_clogs.run()
 		ret.append(gen_clogs.returncode)
 
+	if options.write_timestamp:
+		timestamp_path = os.path.join(repo_path, 'metadata', 'timestamp.chk')
+		try:
+			with open(timestamp_path, 'w') as f:
+				f.write(time.strftime('%s\n' % TIMESTAMP_FORMAT, time.gmtime()))
+		except IOError:
+			ret.append(os.EX_IOERR)
+		else:
+			ret.append(os.EX_OK)
+
 	return max(ret)
 
 if __name__ == "__main__":

diff --git a/pym/portage/const.py b/pym/portage/const.py
index 214ede4..b2e970e 100644
--- a/pym/portage/const.py
+++ b/pym/portage/const.py
@@ -175,6 +175,10 @@ if "PORTAGE_OVERRIDE_EPREFIX" in os.environ:
 VCS_DIRS = ("CVS", "RCS", "SCCS", ".bzr", ".git", ".hg", ".svn")
 
 SUPPORTED_BINPKG_FORMATS = ("tar", "rpm")
+
+# Time formats used in various places like metadata.chk.
+TIMESTAMP_FORMAT = "%a, %d %b %Y %H:%M:%S +0000"	# to be used with time.gmtime()
+
 # ===========================================================================
 # END OF CONSTANTS -- END OF CONSTANTS -- END OF CONSTANTS -- END OF CONSTANT
 # ===========================================================================


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

* [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
@ 2014-11-17 17:43 Zac Medico
  0 siblings, 0 replies; 19+ messages in thread
From: Zac Medico @ 2014-11-17 17:43 UTC (permalink / raw
  To: gentoo-commits

commit:     77c4a4d2cb63d8e7c95840c44f5bf9b597316120
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Nov 17 16:57:23 2014 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Nov 17 17:41:15 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=77c4a4d2

unprivileged mode: fix cross-prefix support

In commit 1364fcd89384c9f60e6d72d7057dc00d8caba175, EROOT calculation
in portage.data did not account for cross-prefix support. This is
fixed by using new _target_root and _target_eprefix functions to
perform the calculation. The _target_eprefix function is also useful
in portageq, where the target EPREFIX needs to be known before
portage.settings is instantiated.

Fixes 1364fcd89384 ("Support unprivileged mode for bug #433453.")
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

---
 bin/portageq        |  4 +---
 pym/portage/data.py | 35 +++++++++++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/bin/portageq b/bin/portageq
index ef565d1..6a42bfd 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -1397,9 +1397,7 @@ def main(argv):
 		# portage.settings["EPREFIX"] here, but that would force
 		# instantiation of portage.settings, which we don't want to do
 		# until after we've calculated ROOT (see bug #529200).
-		eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX)
-		if eprefix:
-			eprefix = portage.util.normalize_path(eprefix)
+		eprefix = portage.data._target_eprefix()
 		eroot = portage.util.normalize_path(argv[2])
 
 		if eprefix:

diff --git a/pym/portage/data.py b/pym/portage/data.py
index d9b36ee..2fd287d 100644
--- a/pym/portage/data.py
+++ b/pym/portage/data.py
@@ -35,6 +35,35 @@ if not lchown:
 
 lchown = portage._unicode_func_wrapper(lchown)
 
+def _target_eprefix():
+	"""
+	Calculate the target EPREFIX, which may be different from
+	portage.const.EPREFIX due to cross-prefix support. The result
+	is equivalent to portage.settings["EPREFIX"], but the calculation
+	is done without the expense of instantiating portage.settings.
+	@rtype: str
+	@return: the target EPREFIX
+	"""
+	eprefix = os.environ.get("EPREFIX", portage.const.EPREFIX)
+	if eprefix:
+		eprefix = portage.util.normalize_path(eprefix)
+	return eprefix
+
+def _target_root():
+	"""
+	Calculate the target ROOT. The result is equivalent to
+	portage.settings["ROOT"], but the calculation
+	is done without the expense of instantiating portage.settings.
+	@rtype: str
+	@return: the target ROOT (always ends with a slash)
+	"""
+	root = os.environ.get("ROOT")
+	if not root:
+		# Handle either empty or unset ROOT.
+		root = os.sep
+	root = portage.util.normalize_path(root)
+	return root.rstrip(os.sep) + os.sep
+
 def portage_group_warning():
 	warn_prefix = colorize("BAD", "*** WARNING ***  ")
 	mylines = [
@@ -96,8 +125,7 @@ def _get_global(k):
 			# The config class has equivalent code, but we also need to
 			# do it here if _disable_legacy_globals() has been called.
 			eroot_or_parent = first_existing(os.path.join(
-				os.environ.get('ROOT', os.sep),
-				portage.const.EPREFIX.lstrip(os.sep)))
+				_target_root(), _target_eprefix().lstrip(os.sep)))
 			try:
 				eroot_st = os.stat(eroot_or_parent)
 			except OSError:
@@ -210,8 +238,7 @@ def _get_global(k):
 			# The config class has equivalent code, but we also need to
 			# do it here if _disable_legacy_globals() has been called.
 			eroot_or_parent = first_existing(os.path.join(
-				os.environ.get('ROOT', os.sep),
-				portage.const.EPREFIX.lstrip(os.sep)))
+				_target_root(), _target_eprefix().lstrip(os.sep)))
 			try:
 				eroot_st = os.stat(eroot_or_parent)
 			except OSError:


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

end of thread, other threads:[~2014-11-17 17:43 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-11  9:39 [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/ Zac Medico
  -- strict thread matches above, loose matches on Subject: below --
2014-11-17 17:43 Zac Medico
2013-11-29 23:24 Mike Frysinger
2013-06-25  7:48 Zac Medico
2013-06-23 22:57 Zac Medico
2013-06-23 22:40 Zac Medico
2013-01-19  5:16 Zac Medico
2013-01-19  5:00 Zac Medico
2013-01-19  3:23 Zac Medico
2013-01-19  3:23 Zac Medico
2013-01-19  2:27 Zac Medico
2013-01-19  1:53 Zac Medico
2012-10-18  0:05 Zac Medico
2012-03-17 16:44 Zac Medico
2012-03-11  1:40 Mike Frysinger
2011-12-08  7:26 Zac Medico
2011-06-17 22:35 Zac Medico
2011-06-04  1:39 Zac Medico
2011-02-20  0:00 Zac Medico

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