[yocto] [opkg-devel] [opkg-utils PATCH] opkg.py/opkg-make-index: Add option to include all fields
Alejandro del Castillo
alejandro.delcastillo at ni.com
Fri Oct 6 14:50:49 PDT 2017
yep, that makes sense, thanks for the contribution
merged
On 10/05/2017 12:03 PM, Jeffrey Pautler wrote:
> If the -f option is enabled, opkg-make-index will include user-defined
>
> fields in the package index rather than discarding them. This change is
>
> motivated by the fact that opkg now has support for user-defined fields
>
> in the package index.
>
> Signed-off-by: Jeffrey Pautler <jeffrey.pautler at ni.com>
>
> ---
>
> opkg-make-index | 11 +++++++----
>
> opkg.py | 28 ++++++++++++++++++----------
>
> 2 files changed, 25 insertions(+), 14 deletions(-)
>
> diff --git a/opkg-make-index b/opkg-make-index
>
> index 3f757f6..3227fc0 100755
>
> --- a/opkg-make-index
>
> +++ b/opkg-make-index
>
> @@ -11,7 +11,7 @@ import re
>
> verbose = 0
>
> def usage():
>
> - sys.stderr.write("%s [-h] [-s] [-m] [-a] [-l Packages.filelist]
> [-p Packages] [-r Packages.old] [-L localesdir] [-v] packagesdir\n" %
> (sys.argv[0],))
>
> + sys.stderr.write("%s [-h] [-s] [-m] [-a] [-f] [-l
> Packages.filelist] [-p Packages] [-r Packages.old] [-L localesdir] [-v]
> packagesdir\n" % (sys.argv[0],))
>
> sys.exit(-1)
>
> def to_morgue(filename):
>
> @@ -43,7 +43,8 @@ stamplist_filename = "Packages.stamps"
>
> opt_s = 0
>
> opt_m = 0
>
> opt_a = 0
>
> -(opts, remaining_args) = getopt.getopt(sys.argv[1:], "hl:p:vsmr:L:a")
>
> +opt_f = 0
>
> +(opts, remaining_args) = getopt.getopt(sys.argv[1:], "hl:p:vsmr:L:af")
>
> for (optkey, optval) in opts:
>
> if optkey == '-h':
>
> usage()
>
> @@ -64,6 +65,8 @@ for (optkey, optval) in opts:
>
> locales_dir = optval
>
> if optkey == '-a':
>
> opt_a = 1
>
> + if optkey == '-f':
>
> + opt_f = 1
>
> if ( not remaining_args ):
>
> usage()
>
> @@ -81,7 +84,7 @@ if old_filename:
>
> if (verbose):
>
> sys.stderr.write("Reading package list from " + old_filename
> + "\n")
>
> old_packages = opkg.Packages()
>
> - old_packages.read_packages_file(old_filename)
>
> + old_packages.read_packages_file(old_filename, opt_f)
>
> for k in list(old_packages.packages.keys()):
>
> p = old_packages.packages[k]
>
> old_pkg_hash[p.filename] = p
>
> @@ -122,7 +125,7 @@ for abspath in files:
>
> if not pkg:
>
> if (verbose):
>
> sys.stderr.write("Reading info for package %s\n" %
> (filename,))
>
> - pkg = opkg.Package(abspath, relpath=pkg_dir)
>
> + pkg = opkg.Package(abspath, relpath=pkg_dir, all_fields=opt_f)
>
> if opt_a:
>
> pkg_key = ("%s:%s:%s" % (pkg.package, pkg.architecture,
> pkg.version))
>
> diff --git a/opkg.py b/opkg.py
>
> index 9131755..cdadcab 100644
>
> --- a/opkg.py
>
> +++ b/opkg.py
>
> @@ -45,6 +45,7 @@ from stat import ST_SIZE
>
> import arfile
>
> import tarfile
>
> import textwrap
>
> +import collections
>
> class Version(object):
>
> """A class for holding parsed package version information."""
>
> @@ -123,7 +124,7 @@ class Package(object):
>
> # 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):
>
> + def __init__(self, fn=None, relpath=None, all_fields=None):
>
> self.package = None
>
> self.version = 'none'
>
> self.parsed_version = None
>
> @@ -153,6 +154,7 @@ class Package(object):
>
> self.fn = fn
>
> self.license = None
>
> + self.user_defined_fields = collections.OrderedDict()
>
> if fn:
>
> # see if it is deb format
>
> f = open(fn, "rb")
>
> @@ -176,7 +178,7 @@ class Package(object):
>
> except KeyError:
>
> control = tarf.extractfile("./control")
>
> try:
>
> - self.read_control(control)
>
> + self.read_control(control, all_fields)
>
> except TypeError as e:
>
> sys.stderr.write("Cannot read control file '%s' -
> %s\n" % (fn, e))
>
> control.close()
>
> @@ -215,7 +217,7 @@ class Package(object):
>
> self.size = stat[ST_SIZE]
>
> return int(self.size)
>
> - def read_control(self, control):
>
> + def read_control(self, control, all_fields=None):
>
> import os
>
> line = control.readline()
>
> @@ -227,19 +229,22 @@ class Package(object):
>
> line = line.rstrip()
>
> lineparts = re.match(r'([\w-]*?):\s*(.*)', line)
>
> if lineparts:
>
> - name = lineparts.group(1).lower()
>
> + name = lineparts.group(1)
>
> + name_lowercase = name.lower()
>
> value = lineparts.group(2)
>
> while 1:
>
> line = control.readline()
>
> if not line: break
>
> if line[0] != ' ': break
>
> value = value + '\n' + line
>
> - if name == 'size':
>
> + if name_lowercase == 'size':
>
> self.size = int(value)
>
> - elif name == 'md5sum':
>
> + elif name_lowercase == 'md5sum':
>
> self.md5 = value
>
> - elif name in self.__dict__:
>
> - self.__dict__[name] = value
>
> + elif name_lowercase in self.__dict__:
>
> + self.__dict__[name_lowercase] = value
>
> + elif all_fields:
>
> + self.user_defined_fields[name] = value
>
> else:
>
> print("Lost field %s, %s" % (name,value))
>
> pass
>
> @@ -490,6 +495,9 @@ class Package(object):
>
> if self.license: out = out + "License: %s\n" % (self.license)
>
> if self.priority: out = out + "Priority: %s\n" % (self.priority)
>
> if self.tags: out = out + "Tags: %s\n" % (self.tags)
>
> + if self.user_defined_fields:
>
> + for k, v in self.user_defined_fields.items():
>
> + out = out + "%s: %s\n" % (k, v)
>
> out = out + "\n"
>
> return out
>
> @@ -523,12 +531,12 @@ class Packages(object):
>
> else:
>
> return 1
>
> - def read_packages_file(self, fn):
>
> + def read_packages_file(self, fn, all_fields=None):
>
> f = open(fn, "r")
>
> while True:
>
> pkg = Package()
>
> try:
>
> - pkg.read_control(f)
>
> + pkg.read_control(f, all_fields)
>
> except TypeError as e:
>
> sys.stderr.write("Cannot read control file '%s' -
> %s\n" % (fn, e))
>
> continue
>
> --
>
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google
> Groups "opkg-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to opkg-devel+unsubscribe at googlegroups.com
> <mailto:opkg-devel+unsubscribe at googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=DwMFaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=wNcrL2akRn6jfxhHaKavUrJB_C9JAMXtynjLd8ZzgXQ&m=ovQLEvQ9Lx-7vCjplOAzesO39gF_IJUaWHnH7MYJRKk&s=Cjo25iHoDUxMx8anWywj0hPZTramOkXjGn9UCLksWcU&e=>.
--
Cheers,
Alejandro
More information about the yocto
mailing list