← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad-layers:launchpad-publisher-parts into launchpad-layers:main

 

Simone Pelosi has proposed merging ~pelpsi/launchpad-layers:launchpad-publisher-parts into launchpad-layers:main.

Commit message:
Added launchpad-publisher-parts layer
    
Added a new layer that will be used by the publisher charm to call run-parts algorithm on a given repository with a given revision number



Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad-layers/+git/launchpad-layers/+merge/444721
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad-layers:launchpad-publisher-parts into launchpad-layers:main.
diff --git a/launchpad-publisher-parts/config.yaml b/launchpad-publisher-parts/config.yaml
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/launchpad-publisher-parts/config.yaml
diff --git a/launchpad-publisher-parts/icon.svg b/launchpad-publisher-parts/icon.svg
new file mode 100644
index 0000000..b2889cc
--- /dev/null
+++ b/launchpad-publisher-parts/icon.svg
@@ -0,0 +1 @@
+<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg"; viewBox="0 0 165.39062 165.39062"><defs><style>.cls-1{fill:#e9500e;}.cls-2{fill:#fff;}</style></defs><rect class="cls-1" width="165.39062" height="165.39062"/><path class="cls-2" d="M29.63876,57.97189C43.189,67.692,61.13456,69.25577,77.65457,62.15038c16.25576-6.87157,27.74036-21.43444,29.97828-38.0075.04663-.34331.11016-.81367-1.59861-1.24044l-10.10934-2.197c-.3254-.04494-.79136-.04967-1.15258,1.22455C91.37844,36.07384,84.34062,45.04243,72.6347,50.1123c-11.77316,5.10029-23.18748,4.05279-35.91893-3.29386-.58119-.27843-.91909-.26086-1.45568.52577l-5.77947,8.65163A1.34512,1.34512,0,0,0,29.63876,57.97189Z" transform="translate(0.39062 0.39062)"/><path class="cls-2" d="M79.86106,139.66026l10.3631.565c1.74155.03446,1.79122-.42981,1.83717-.77312,2.23826-16.5734-4.97222-33.66107-18.81739-44.59422C59.196,83.62132,41.47815,80.36935,25.83365,86.14747a1.33956,1.33956,0,0,0-.67918,1.85373l3.28,9.88226c.30952.90153.62816,1.011,1.26443.89409,14.22464-3.70543,25.50717-1.68748,35.50635,6.3512,9.94174,7.9934,14.34865,18.50754,13.86883,33.08867C79.08524,139.50144,79.53735,139.615,79.86106,139.66026Z" transform="translate(0.39062 0.39062)"/><path class="cls-2" d="M86.50488,70.59048a10.50817,10.50817,0,0,0-1.39587-.09461A9.35237,9.35237,0,0,0,79.39915,72.382a9.61981,9.61981,0,1,0,7.10573-1.79156Z" transform="translate(0.39062 0.39062)"/><path class="cls-2" d="M138.26869,53.18923,133.457,43.97736c-.68628-1.51583-1.22793-1.36985-1.79594-1.17657-15.382,6.63165-25.99848,21.22156-28.40434,39.03776-2.40755,17.82971,3.97169,34.72681,17.0647,45.19906a1.177,1.177,0,0,0,.90794.32844,1.48362,1.48362,0,0,0,.99546-.54l6.76175-8.11166c.62342-.78393.35783-1.18333.0321-1.52461-10.60639-10.44454-14.5764-20.81677-12.84905-33.60769,1.73682-12.86121,8.51918-22.08254,21.34457-29.019C138.52854,53.95289,138.36533,53.421,138.26869,53.18923Z" transform="translate(0.39062 0.39062)"/></svg>
\ No newline at end of file
diff --git a/launchpad-publisher-parts/layer.yaml b/launchpad-publisher-parts/layer.yaml
new file mode 100644
index 0000000..69f7ca7
--- /dev/null
+++ b/launchpad-publisher-parts/layer.yaml
@@ -0,0 +1,7 @@
+includes:
+  - layer:basic
+options:
+  launchpad-publisher-parts:
+    repository: lp:ubuntu-archive-publishing
+    revision: 123
+repo: https://git.launchpad.net/launchpad-layers
diff --git a/launchpad-publisher-parts/lib/charms/launchpad/parts.py b/launchpad-publisher-parts/lib/charms/launchpad/parts.py
new file mode 100644
index 0000000..e09e6b3
--- /dev/null
+++ b/launchpad-publisher-parts/lib/charms/launchpad/parts.py
@@ -0,0 +1,28 @@
+# Copyright 2022 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+import os.path
+import subprocess
+
+from charmhelpers.core import hookenv
+
+
+# Get bzr branch at given revision
+def get_bzr_repository(repository, revision=-1):
+    hookenv.log("Getting " + repository + " -r " + str(revision))
+
+    bzr_cmd = "bzr branch " + repository
+    rev_arg = ""
+    if revision:
+        rev_arg = " -r " + str(revision)
+    bzr_cmd += rev_arg
+
+    subprocess.check_call(bzr_cmd, shell=True)
+
+
+# Call run-parts algorithm on a given folder
+def run_parts_on_folder(wd="."):
+    hookenv.log("Calling run-parts in folder " + wd)
+
+    if os.path.isdir(wd):
+        subprocess.check_call(["sudo", "run-parts", wd])
diff --git a/launchpad-publisher-parts/reactive/launchpad-publisher-parts.py b/launchpad-publisher-parts/reactive/launchpad-publisher-parts.py
new file mode 100644
index 0000000..c779655
--- /dev/null
+++ b/launchpad-publisher-parts/reactive/launchpad-publisher-parts.py
@@ -0,0 +1,26 @@
+# Copyright 2022 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+from charms.launchpad.parts import get_bzr_repository, run_parts_on_folder
+from charms.layer import options
+from charms.reactive import set_flag, when_not
+
+
+def run_parts_on_repository():
+    repository = (
+        options().get("launchpad-publisher-parts", {}).get("repository", "")
+    )
+    revision = (
+        options().get("launchpad-publisher-parts", {}).get("revision", "")
+    )
+
+    # Expecting a bzr repository lp:repo-name
+    folder = repository.split(":")[1]
+    get_bzr_repository(repository, revision)
+    run_parts_on_folder(folder)
+
+
+@when_not("launchpad.publisher-parts.configured")
+def configure():
+    run_parts_on_repository()
+    set_flag("launchpad.publisher-parts.configured")
diff --git a/launchpad-publisher-parts/templates/macros.j2 b/launchpad-publisher-parts/templates/macros.j2
new file mode 100644
index 0000000..8cddb14
--- /dev/null
+++ b/launchpad-publisher-parts/templates/macros.j2
@@ -0,0 +1,6 @@
+{#- An optional configuration entry. #}
+{%- macro opt(name, value) %}
+{%-   if value is defined and value is not none %}
+{{ name }}: {{ value }}
+{%-   endif %}
+{%- endmacro %}