HacX. snap
authorCarl Hetherington <cth@carlh.net>
Sun, 26 Apr 2020 23:14:05 +0000 (01:14 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 26 Apr 2020 23:14:05 +0000 (01:14 +0200)
cdist

diff --git a/cdist b/cdist
index 9e6be5f10d47b6e9b7779bb7e2621a843fae3fe9..536742ab051556ad93466d1be3e28bf0c0156b78 100755 (executable)
--- a/cdist
+++ b/cdist
@@ -31,6 +31,7 @@ import inspect
 import getpass
 import shlex
 import multiprocessing
+import textwrap
 
 TEMPORARY_DIRECTORY = '/var/tmp'
 
@@ -781,6 +782,7 @@ class OSXUniversalTarget(OSXTarget):
             for p in packages:
                 copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
 
+
 class SourceTarget(Target):
     """Build a source .tar.bz2"""
     def __init__(self):
@@ -801,6 +803,50 @@ class SourceTarget(Target):
             p = os.path.abspath('%s-%s.tar.bz2' % (name, tree.version))
             copyfile(p, os.path.join(output_dir, os.path.basename(devel_to_git(tree.git_commit, p))))
 
+
+class SnapTarget(Target):
+    """Build a snap"""
+    def __init__(self):
+        super(SnapTarget, self).__init__('snap')
+
+    def command(self, c):
+        command('%s %s' % (self.variables_string(), c))
+
+    def cleanup(self):
+        rmtree(self.directory)
+
+    def package(self, project, checkout, output_dir, options):
+        makedirs(os.path.join(self.directory, 'plugins'))
+        f = open(os.path.join(self.directory, 'plugins', 'cdist.py'), 'w')
+        print("""
+import snapcraft
+
+class CdistPlugin(snapcraft.BasePlugin):
+    def build(self):
+        print('cdist plugin builds!')
+""", file=f)
+        f.close()
+
+        f = open(os.path.join(self.directory, 'snapcraft.yaml'), 'w')
+        print('name: %s' % project, file=f)
+        tree = globals.trees.get(project, checkout, self)
+        print('version: %s' % tree.version, file=f)
+        print('summary: %s' % tree.cscript['summary'], file=f)
+        print('description: |', file=f)
+        for l in textwrap.wrap(' '.join(tree.cscript['description'].split())):
+            print("\t%s" % l, file=f)
+        print('confinement: devmode', file=f)
+        print('base: core18', file=f)
+        print('parts:', file=f)
+        for t in tree.dependencies({}):
+            print("\t%s:" % t[0].name, file=f)
+            print("\t\tplugin: cdist", file=f)
+            print("\t\tsource-type: git", file=f)
+            print("\t\tsource: git://%s/%s" % (config.get('git_prefix'), t[0].name), file=f)
+            print("\t\tsource-commit: %s" % t[0].git_commit, file=f)
+
+
+
 # @param s Target string:
 #       windows-{32,64}
 #    or ubuntu-version-{32,64}
@@ -812,6 +858,7 @@ class SourceTarget(Target):
 #    or source
 #    or flatpak
 #    or appimage
+#    or snap
 # @param debug True to build with debugging symbols (where possible)
 def target_factory(args):
     s = args.target
@@ -849,6 +896,8 @@ def target_factory(args):
         target = FlatpakTarget(args.project, args.checkout)
     elif s == 'appimage':
         target = AppImageTarget(args.work)
+    elif s == 'snap':
+        target = SnapTarget()
 
     if target is None:
         raise Error("Bad target `%s'" % s)