[yocto] [opkg-utils][PATCH 1/3] opkg.py: Allow filename to be a relative path

Paul Barker paul at paulbarker.me.uk
Thu May 8 09:54:43 PDT 2014


In order to support package files residing in a different directory to the
'Packages' index file, we need to allow filename entries in the index to be
relative paths. In order to not break existing code, filename remains the
basename of fn by default. However, if the new relpath argument is set then
filename is the path of fn relative to relpath.

Signed-off-by: Paul Barker <paul at paulbarker.me.uk>
---
 opkg.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/opkg.py b/opkg.py
index c839100..ae0fbcd 100644
--- a/opkg.py
+++ b/opkg.py
@@ -116,7 +116,12 @@ def parse_version(versionstr):
 class Package:
     """A class for creating objects to manipulate (e.g. create) opkg
        packages."""
-    def __init__(self, fn=None):
+
+    # fn: Package file path
+    # relpath: If this argument is set, the file path is given relative to this
+    #   path when a string representation of the Package object is created. If
+    #   this argument is not set, the basename of the file path is given.
+    def __init__(self, fn=None, relpath=None):
         self.package = None
         self.version = 'none'
         self.parsed_version = None
@@ -150,7 +155,10 @@ class Package:
             # see if it is deb format
             f = open(fn, "rb")
 
-            self.filename = os.path.basename(fn)
+            if relpath:
+                self.filename = os.path.relpath(fn, relpath)
+            else:
+                self.filename = os.path.basename(fn)
 
             ## sys.stderr.write("  extracting control.tar.gz from %s\n"% (fn,)) 
 
-- 
1.9.2




More information about the yocto mailing list