[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 2/3] Add a function to find a (possibly compressed) file



Signed-off-by: Emilio Pozuelo Monfort <pochu@debian.org>
---
 daklib/utils.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/daklib/utils.py b/daklib/utils.py
index 5e84c35..e6785c6 100644
--- a/daklib/utils.py
+++ b/daklib/utils.py
@@ -1381,3 +1381,25 @@ def is_in_debug_section(control):
     section = control['Section'].split('/', 1)[-1]
     auto_built_package = control.get("Auto-Built-Package")
     return section == "debug" and auto_built_package == "debug-symbols"
+
+################################################################################
+
+def get_possibly_compressed_file(filename):
+    """
+
+    @type  filename: string
+    @param filename: path to a control file (Sources, Packages, etc) to
+                     look for
+
+    @rtype string
+    @return: path to the (possibly compressed) control file, or null if the
+             file doesn't exist
+    """
+    _compressions = ('', '.xz', '.gz', '.bz2')
+
+    for ext in _compressions:
+        _file = filename + ext
+        if os.path.exists(_file):
+            return _file
+
+    raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename)
-- 
2.9.3


Reply to: