public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: <Cedric_Hombourger@mentor.com>
To: <isar-users@googlegroups.com>
Cc: Cedric Hombourger <Cedric_Hombourger@mentor.com>
Subject: [PATCH 2/5] meta: move reprepro handling code to its own class
Date: Sun, 4 Feb 2018 17:54:51 +0000	[thread overview]
Message-ID: <20180204175454.220-3-Cedric_Hombourger@mentor.com> (raw)
In-Reply-To: <20180204175454.220-1-Cedric_Hombourger@mentor.com>

From: Cedric Hombourger <Cedric_Hombourger@mentor.com>

The reprepro handling code (cache creation and update) may be
re-used in the buildchroot recipe to later add required build
packages to the full repo (if one should be created). Move the
code to its own class and inherit it from the image class (the
only user at this time).

Signed-off-by: Cedric Hombourger <Cedric_Hombourger@mentor.com>
---
 meta/classes/image.bbclass    | 47 +----------------------------------------
 meta/classes/reprepro.bbclass | 49 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 46 deletions(-)
 create mode 100644 meta/classes/reprepro.bbclass

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index e2cb01b..b20db18 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -17,53 +17,8 @@ KERNEL_IMAGE ?= "${@get_image_name(d, 'vmlinuz')}"
 INITRD_IMAGE ?= "${@get_image_name(d, 'initrd.img')}"
 
 inherit ${IMAGE_TYPE}
-call_reprepro() {
-    for i in $(seq 1 ${REPREPRO_LOCK_ATTEMPTS}); do
-        #  According to `sh` manual page, shell exit statuses fall between
-        # 0-255. The EEXIST error code is (-17), so casting to usigned 8-bit
-        # integer results value (239).
-        eexist=$(python -c 'import errno; print(256-errno.EEXIST)')
-        retval="0"
-        reprepro $* || retval="$?"
-
-        # If reprepro has failed to get database lock, it returns EEXIST code.
-        # In this case we continue trying to get lock until max amount of
-        # attempts is reached.
-        if [ $retval -eq $eexist ]; then
-            bbwarn "Failed to get reprepro lock, trying again..."
-            sleep 5
-        else
-            break
-        fi
-    done
-
-    if [ $retval -ne 0 ]; then
-        bbfatal "reprepro failed"
-    fi
-}
-
-CACHE_CONF_DIR = "${DEPLOY_DIR_APT}/${DISTRO}/conf"
-do_cache_config[dirs] = "${CACHE_CONF_DIR}"
-do_cache_config[stamp-extra-info] = "${DISTRO}"
-
-# Generate reprepro config for current distro if it doesn't exist. Once it's
-# generated, this task should do nothing.
-do_cache_config() {
-    if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then
-        sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \
-            ${FILESDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions
-    fi
-
-    path_cache="${DEPLOY_DIR_APT}/${DISTRO}"
-    path_databases="${DEPLOY_DIR_DB}/${DISTRO}"
-
-    if [ ! -d "${path_databases}" ]; then
-        call_reprepro -b ${path_cache} \
-                      --dbdir ${path_databases} \
-                      export ${DEBDISTRONAME}
-    fi
-}
 
+inherit reprepro
 addtask cache_config before do_populate
 
 do_populate[stamp-extra-info] = "${DISTRO}-${MACHINE}"
diff --git a/meta/classes/reprepro.bbclass b/meta/classes/reprepro.bbclass
new file mode 100644
index 0000000..dfe48cb
--- /dev/null
+++ b/meta/classes/reprepro.bbclass
@@ -0,0 +1,49 @@
+# This software is a part of ISAR.
+# Copyright (C) 2015-2017 ilbers GmbH
+
+CACHE_CONF_DIR = "${DEPLOY_DIR_APT}/${DISTRO}/conf"
+do_cache_config[dirs] = "${CACHE_CONF_DIR}"
+do_cache_config[stamp-extra-info] = "${DISTRO}"
+
+# Generate reprepro config for current distro if it doesn't exist. Once it's
+# generated, this task should do nothing.
+do_cache_config() {
+    if [ ! -e "${CACHE_CONF_DIR}/distributions" ]; then
+        sed -e "s#{DISTRO_NAME}#"${DEBDISTRONAME}"#g" \
+            ${FILESDIR}/distributions.in > ${CACHE_CONF_DIR}/distributions
+    fi
+
+    path_cache="${DEPLOY_DIR_APT}/${DISTRO}"
+    path_databases="${DEPLOY_DIR_DB}/${DISTRO}"
+
+    if [ ! -d "${path_databases}" ]; then
+        call_reprepro -b ${path_cache} \
+                      --dbdir ${path_databases} \
+                      export ${DEBDISTRONAME}
+    fi
+}
+
+call_reprepro() {
+    for i in $(seq 1 ${REPREPRO_LOCK_ATTEMPTS}); do
+        #  According to `sh` manual page, shell exit statuses fall between
+        # 0-255. The EEXIST error code is (-17), so casting to usigned 8-bit
+        # integer results value (239).
+        eexist=$(python -c 'import errno; print(256-errno.EEXIST)')
+        retval="0"
+        reprepro $* || retval="$?"
+
+        # If reprepro has failed to get database lock, it returns EEXIST code.
+        # In this case we continue trying to get lock until max amount of
+        # attempts is reached.
+        if [ $retval -eq $eexist ]; then
+            bbwarn "Failed to get reprepro lock, trying again..."
+            sleep 5
+        else
+            break
+        fi
+    done
+
+    if [ $retval -ne 0 ]; then
+        bbfatal "reprepro failed"
+    fi
+}
-- 
2.11.0


  parent reply	other threads:[~2018-02-04 17:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-04 17:54 [PATCH 0/5] support creation of a full repo for offline/reproducible builds Cedric_Hombourger
2018-02-04 17:54 ` [PATCH 1/5] base: add populate_repo task to include distro packages to the repo Cedric_Hombourger
2018-02-05 10:06   ` Alexander Smirnov
2018-02-04 17:54 ` Cedric_Hombourger [this message]
2018-02-04 17:54 ` [PATCH 3/5] buildchroot: use reprepro to populate the full repo Cedric_Hombourger
2018-02-04 17:54 ` [PATCH 4/5] reprepro: create the -updates distribution Cedric_Hombourger
2018-02-04 17:56 ` [PATCH 5/5] multistrap: make the security feed optional Cedric_Hombourger
2018-02-05  7:18 ` [PATCH 0/5] support creation of a full repo for offline/reproducible builds Jan Kiszka
2018-02-05  9:11   ` Benedikt Niedermayr
2018-02-05 10:26   ` Alexander Smirnov
2018-02-05 10:31     ` Jan Kiszka
2018-02-05 11:22     ` Benedikt Niedermayr
2018-02-05 10:08 ` Benedikt Niedermayr
2018-02-05 10:16   ` chombourger

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=20180204175454.220-3-Cedric_Hombourger@mentor.com \
    --to=cedric_hombourger@mentor.com \
    --cc=isar-users@googlegroups.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox