All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 2/3] graph-depends: split off get_version/get_depends into pkgutil.py
Date: Wed, 7 Nov 2018 19:07:53 +0100	[thread overview]
Message-ID: <20181107180753.GA4702@scaer> (raw)
In-Reply-To: <20170203205745.14488-4-patrickdepinguin@gmail.com>

Thomas DS, All,

On 2017-02-03 21:57 +0100, Thomas De Schampheleire spake thusly:
> From: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> 
> Functions to obtain the version and dependencies of a package from Python
> can be useful for several scripts. Extract this logic out of graph-depends
> into pkgutil.py.

Coming back to this script, because I'm rewriting the way graph-depends
gets the dependency tree. When you said "useful for several scripts,"
did you expect it to be useful to scripts that are not in Buildroot
(e.g. user-local scripts)?

Regards,
Yann E. MORIN.

> Signed-off-by: Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
> ---
>  support/scripts/graph-depends | 55 ++++---------------------------------------
>  support/scripts/pkgutil.py    | 55 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 59 insertions(+), 51 deletions(-)
>  create mode 100644 support/scripts/pkgutil.py
> 
> diff --git a/support/scripts/graph-depends b/support/scripts/graph-depends
> index 095619a..7aedcb5 100755
> --- a/support/scripts/graph-depends
> +++ b/support/scripts/graph-depends
> @@ -26,6 +26,8 @@ import subprocess
>  import argparse
>  from fnmatch import fnmatch
>  
> +import pkgutil
> +
>  # Modes of operation:
>  MODE_FULL = 1   # draw full dependency graph for all selected packages
>  MODE_PKG  = 2   # draw dependency graph for a given package
> @@ -122,28 +124,6 @@ host_colour = colours[2]
>  
>  allpkgs = []
>  
> -# Execute the "make <pkg>-show-version" command to get the version of a given
> -# list of packages, and return the version formatted as a Python dictionary.
> -def get_version(pkgs):
> -    sys.stderr.write("Getting version for %s\n" % pkgs)
> -    cmd = ["make", "-s", "--no-print-directory" ]
> -    for pkg in pkgs:
> -        cmd.append("%s-show-version" % pkg)
> -    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
> -    output = p.communicate()[0]
> -    if p.returncode != 0:
> -        sys.stderr.write("Error getting version %s\n" % pkgs)
> -        sys.exit(1)
> -    output = output.split("\n")
> -    if len(output) != len(pkgs) + 1:
> -        sys.stderr.write("Error getting version\n")
> -        sys.exit(1)
> -    version = {}
> -    for i in range(0, len(pkgs)):
> -        pkg = pkgs[i]
> -        version[pkg] = output[i]
> -    return version
> -
>  # Execute the "make show-targets" command to get the list of the main
>  # Buildroot PACKAGES and return it formatted as a Python list. This
>  # list is used as the starting point for full dependency graphs
> @@ -158,33 +138,6 @@ def get_targets():
>          return []
>      return output.split(' ')
>  
> -# Execute the "make <pkg>-show-depends" command to get the list of
> -# dependencies of a given list of packages, and return the list of
> -# dependencies formatted as a Python dictionary.
> -def get_depends(pkgs, rule):
> -    sys.stderr.write("Getting dependencies for %s\n" % pkgs)
> -    cmd = ["make", "-s", "--no-print-directory" ]
> -    for pkg in pkgs:
> -        cmd.append("%s-%s" % (pkg, rule))
> -    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
> -    output = p.communicate()[0]
> -    if p.returncode != 0:
> -        sys.stderr.write("Error getting dependencies %s\n" % pkgs)
> -        sys.exit(1)
> -    output = output.split("\n")
> -    if len(output) != len(pkgs) + 1:
> -        sys.stderr.write("Error getting dependencies\n")
> -        sys.exit(1)
> -    deps = {}
> -    for i in range(0, len(pkgs)):
> -        pkg = pkgs[i]
> -        pkg_deps = output[i].split(" ")
> -        if pkg_deps == ['']:
> -            deps[pkg] = []
> -        else:
> -            deps[pkg] = pkg_deps
> -    return deps
> -
>  # Recursive function that builds the tree of dependencies for a given
>  # list of packages. The dependencies are built in a list called
>  # 'dependencies', which contains tuples of the form (pkg1 ->
> @@ -204,7 +157,7 @@ def get_all_depends(pkgs):
>      if len(filtered_pkgs) == 0:
>          return []
>  
> -    depends = get_depends(filtered_pkgs, rule)
> +    depends = pkgutil.get_depends(filtered_pkgs, rule)
>  
>      deps = set()
>      for pkg in filtered_pkgs:
> @@ -377,7 +330,7 @@ if check_only:
>      sys.exit(0)
>  
>  dict_deps = remove_extra_deps(dict_deps)
> -dict_version = get_version([pkg for pkg in allpkgs
> +dict_version = pkgutil.get_version([pkg for pkg in allpkgs
>                                  if pkg != "all" and not pkg.startswith("root")])
>  
>  # Print the attributes of a node: label and fill-color
> diff --git a/support/scripts/pkgutil.py b/support/scripts/pkgutil.py
> new file mode 100644
> index 0000000..a911123
> --- /dev/null
> +++ b/support/scripts/pkgutil.py
> @@ -0,0 +1,55 @@
> +#!/usr/bin/env python
> +
> +# Copyright (C) 2010-2013 Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> +
> +import sys
> +import subprocess
> +
> +# Execute the "make <pkg>-show-version" command to get the version of a given
> +# list of packages, and return the version formatted as a Python dictionary.
> +def get_version(pkgs):
> +    sys.stderr.write("Getting version for %s\n" % pkgs)
> +    cmd = ["make", "-s", "--no-print-directory" ]
> +    for pkg in pkgs:
> +        cmd.append("%s-show-version" % pkg)
> +    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
> +    output = p.communicate()[0]
> +    if p.returncode != 0:
> +        sys.stderr.write("Error getting version %s\n" % pkgs)
> +        sys.exit(1)
> +    output = output.split("\n")
> +    if len(output) != len(pkgs) + 1:
> +        sys.stderr.write("Error getting version\n")
> +        sys.exit(1)
> +    version = {}
> +    for i in range(0, len(pkgs)):
> +        pkg = pkgs[i]
> +        version[pkg] = output[i]
> +    return version
> +
> +# Execute the "make <pkg>-show-depends" command to get the list of
> +# dependencies of a given list of packages, and return the list of
> +# dependencies formatted as a Python dictionary.
> +def get_depends(pkgs, rule):
> +    sys.stderr.write("Getting dependencies for %s\n" % pkgs)
> +    cmd = ["make", "-s", "--no-print-directory" ]
> +    for pkg in pkgs:
> +        cmd.append("%s-%s" % (pkg, rule))
> +    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
> +    output = p.communicate()[0]
> +    if p.returncode != 0:
> +        sys.stderr.write("Error getting dependencies %s\n" % pkgs)
> +        sys.exit(1)
> +    output = output.split("\n")
> +    if len(output) != len(pkgs) + 1:
> +        sys.stderr.write("Error getting dependencies\n")
> +        sys.exit(1)
> +    deps = {}
> +    for i in range(0, len(pkgs)):
> +        pkg = pkgs[i]
> +        pkg_deps = output[i].split(" ")
> +        if pkg_deps == ['']:
> +            deps[pkg] = []
> +        else:
> +            deps[pkg] = pkg_deps
> +    return deps
> -- 
> 2.10.2
> 

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

  parent reply	other threads:[~2018-11-07 18:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 20:57 [Buildroot] [PATCH 0/3] graph-depends: split off some functions to pkgutil.py Thomas De Schampheleire
2017-02-03 20:57 ` [Buildroot] [PATCH 1/3] graph-depends: avoid use of global var 'rule' in get_depends Thomas De Schampheleire
2017-02-05 14:20   ` Thomas Petazzoni
2017-02-05 20:37     ` Thomas De Schampheleire
2017-02-03 20:57 ` [Buildroot] [PATCH 1/1] support/scripts: split off get_version/get_depends into pkgutil.py Thomas De Schampheleire
2017-02-05 13:52   ` Thomas De Schampheleire
2017-02-03 20:57 ` [Buildroot] [PATCH 2/3] graph-depends: " Thomas De Schampheleire
2017-02-05 21:13   ` Yann E. MORIN
2017-02-05 21:27     ` Thomas De Schampheleire
2017-02-05 21:31       ` Yann E. MORIN
2017-02-06 12:49   ` Thomas Petazzoni
2018-11-07 18:07   ` Yann E. MORIN [this message]
2018-11-07 19:06     ` Thomas De Schampheleire
2018-11-07 19:39       ` Yann E. MORIN
2018-11-07 20:41         ` Thomas De Schampheleire
2018-11-07 21:06           ` Yann E. MORIN
2018-11-07 21:14             ` Thomas De Schampheleire
2018-11-07 22:26         ` Arnout Vandecappelle
2018-11-07 22:45           ` Yann E. MORIN
2018-11-08  8:01             ` Arnout Vandecappelle
2018-11-11 19:00               ` Yann E. MORIN
2017-02-03 20:57 ` [Buildroot] [PATCH 3/3] graph-depends: split off get_rdepends from get_depends Thomas De Schampheleire
2017-02-05 21:14   ` Yann E. MORIN
2017-02-06 12:50   ` Thomas Petazzoni

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=20181107180753.GA4702@scaer \
    --to=yann.morin.1998@free.fr \
    --cc=buildroot@busybox.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.