* [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/, config/
@ 2012-07-12 18:04 André Erdmann
0 siblings, 0 replies; only message in thread
From: André Erdmann @ 2012-07-12 18:04 UTC (permalink / raw
To: gentoo-commits
commit: b25aa857b00b549832828ddbfa9589694e97bcbd
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 17:28:32 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=b25aa857
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()
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-07-12 18:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-12 18:04 [gentoo-commits] proj/R_overlay:master commit in: roverlay/depres/simpledeprule/, config/ André Erdmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox