public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:depres_wip commit in: roverlay/depres/simpledeprule/, config/
Date: Thu, 12 Jul 2012 18:10:07 +0000 (UTC)	[thread overview]
Message-ID: <1342116583.cd3cd5bdf11b620e15487952b60d283e04b716e9.dywi@gentoo> (raw)

commit:     cd3cd5bdf11b620e15487952b60d283e04b716e9
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 12 17:28:32 2012 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 12 18:09:43 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cd3cd5bd

dependency rule reader: read .bz2 and .gzip files

---
 config/R-overlay.conf                   |    1 +
 roverlay/depres/simpledeprule/reader.py |   31 ++++++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/config/R-overlay.conf b/config/R-overlay.conf
index 8c0f985..01f0037 100644
--- a/config/R-overlay.conf
+++ b/config/R-overlay.conf
@@ -168,6 +168,7 @@
 #  list of (simple) dependency rule files or dirs
 #   Please see the rule example file for file format.
 #   Directories will be non-recursively scanned for files.
+#   Files can also be compressed, either bzip2 (.bz2 file ext) or gzip (.gz)
 #  * defaults to <unset>, which effectively disables dependency resolution
 #     since no other dependency resolution methods are available.
 #     This gives poor results!

diff --git a/roverlay/depres/simpledeprule/reader.py b/roverlay/depres/simpledeprule/reader.py
index 40c6353..abb16a6 100644
--- a/roverlay/depres/simpledeprule/reader.py
+++ b/roverlay/depres/simpledeprule/reader.py
@@ -2,8 +2,13 @@
 # Copyright 2006-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 import os
+import sys
 import logging
 
+import gzip
+import bz2
+import mimetypes
+
 from roverlay.depres.simpledeprule.rulemaker import SimpleRuleMaker
 
 class SimpleDependencyRuleReader ( object ):
@@ -18,6 +23,9 @@ class SimpleDependencyRuleReader ( object ):
 
 		self._rmaker = SimpleRuleMaker()
 
+		self._mimetypes = mimetypes.MimeTypes()
+		self.guess_ftype = self._mimetypes.guess_type
+
 		self.rule_add = rule_add
 	# --- end of __init__  (...) ---
 
@@ -40,7 +48,6 @@ class SimpleDependencyRuleReader ( object ):
 				self.read_file ( f )
 	# --- end of read_dir (...) ---
 
-
 	def read_file ( self, filepath ):
 		"""Reads a file that contains simple dependency rules
 		(SimpleIgnoreDependencyRules/SimpleDependencyRules).
@@ -56,11 +63,26 @@ class SimpleDependencyRuleReader ( object ):
 			self.logger.debug (
 				"Reading simple dependency rule file %{!r}.".format ( filepath )
 			)
-			fh = open ( filepath, 'r' )
+			ftype = self.guess_ftype ( filepath )
+
+			compressed = True
+
+			if ftype [1] == 'bzip2':
+				fh = bz2.BZ2File ( filepath, mode='r' )
+			elif ftype [1] == 'gzip':
+				fh = gzip.GzipFile ( filepath, mode='r' )
+			else:
+				fh = open ( filepath, 'r' )
+				compressed = False
+
+
+			if compressed and sys.version_info >= ( 3, ):
+				readlines = ( l.decode().strip() for l in fh.readlines() )
+			else:
+				readlines = ( l.strip() for l in fh.readlines() )
 
-			for line in fh.readlines():
+			for line in readlines:
 				lineno += 1
-				line    = line.strip()
 
 				if not line:
 					# empty (the rule maker catches this, too)
@@ -76,7 +98,6 @@ class SimpleDependencyRuleReader ( object ):
 							filepath, lineno
 						)
 					)
-				# ---
 
 			if fh: fh.close()
 



                 reply	other threads:[~2012-07-12 18:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1342116583.cd3cd5bdf11b620e15487952b60d283e04b716e9.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox