[ostree/wip/ostbuild-v2] ostbuild: More work on deploy commands



commit ac2c923b981172cefb0cc07f217d3de1780ecbd5
Author: Colin Walters <walters verbum org>
Date:   Wed May 2 14:49:32 2012 -0400

    ostbuild: More work on deploy commands

 Makefile-ostbuild.am                               |    2 +
 .../pyostbuild/builtin_build_components.py         |    9 +++-
 src/ostbuild/pyostbuild/builtin_deploy_qemu.py     |   58 ++++++++++++++++++++
 src/ostbuild/pyostbuild/builtin_deploy_root.py     |   58 ++++++++++++++++++++
 .../pyostbuild/builtin_privhelper_deploy_qemu.py   |   56 +++++++++++++++++++
 src/ostbuild/pyostbuild/builtins.py                |   12 +++--
 src/ostbuild/pyostbuild/main.py                    |    1 +
 src/ostbuild/pyostbuild/privileged_subproc.py      |   39 +++++++++++++
 8 files changed, 228 insertions(+), 7 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index b561a28..0c87e65 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -29,6 +29,7 @@ pyostbuild_PYTHON =					\
 	src/ostbuild/pyostbuild/builtin_compose.py	\
 	src/ostbuild/pyostbuild/builtin_chroot_compile_one.py	\
 	src/ostbuild/pyostbuild/builtin_compile_one.py	\
+	src/ostbuild/pyostbuild/builtin_deploy_root.py	\
 	src/ostbuild/pyostbuild/builtin_pull_components.py	\
 	src/ostbuild/pyostbuild/builtin_git_mirror.py	\
 	src/ostbuild/pyostbuild/builtin_prefix.py	\
@@ -48,6 +49,7 @@ pyostbuild_PYTHON =					\
 	src/ostbuild/pyostbuild/odict.py		\
 	src/ostbuild/pyostbuild/ostbuildlog.py		\
 	src/ostbuild/pyostbuild/ostbuildrc.py		\
+	src/ostbuild/pyostbuild/privileged_subproc.py	\
 	src/ostbuild/pyostbuild/warningfilter.py	\
 	src/ostbuild/pyostbuild/subprocess_helpers.py	\
 	src/ostbuild/pyostbuild/vcs.py			\
diff --git a/src/ostbuild/pyostbuild/builtin_build_components.py b/src/ostbuild/pyostbuild/builtin_build_components.py
index 7ae787c..5983dea 100755
--- a/src/ostbuild/pyostbuild/builtin_build_components.py
+++ b/src/ostbuild/pyostbuild/builtin_build_components.py
@@ -101,9 +101,14 @@ class OstbuildBuildComponents(builtins.Builtin):
                     return False
             else:
                 current_vcs_version = component['revision']
-                previous_vcs_version = json.loads(previous_metadata_text)['revision']
-                if current_vcs_version != previous_vcs_version:
+                previous_metadata = json.loads(previous_metadata_text)
+                previous_vcs_version = previous_metadata['revision']
+                if current_vcs_version == previous_vcs_version:
                     log("Metadata differs; VCS version unchanged")
+                    for k,v in meta_copy.iteritems():
+                        previous_v = previous_metadata.get(k)
+                        if v != previous_v:
+                            log("Key %r differs: old: %r new: %r" % (k, previous_v, v))
                 else:
                     log("Metadata differs; note vcs version is now '%s', was '%s'" % (current_vcs_version, previous_vcs_version))
         else:
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
new file mode 100755
index 0000000..5afea83
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_deploy_qemu.py
@@ -0,0 +1,58 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildDeployQemu(builtins.Builtin):
+    name = "deploy-qemu"
+    short_description = "Extract data from shadow repository to qemu"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('--prefix')
+        parser.add_argument('--bin-snapshot')
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtin_deploy_root.py b/src/ostbuild/pyostbuild/builtin_deploy_root.py
new file mode 100755
index 0000000..13f9f17
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_deploy_root.py
@@ -0,0 +1,58 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildDeployRoot(builtins.Builtin):
+    name = "deploy-root"
+    short_description = "Extract data from shadow repository to system repository"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('--prefix')
+        parser.add_argument('--bin-snapshot')
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
new file mode 100755
index 0000000..16b6bbb
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_privhelper_deploy_qemu.py
@@ -0,0 +1,56 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess,tempfile,re,shutil
+import argparse
+import time
+import urlparse
+import json
+from StringIO import StringIO
+
+from . import builtins
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+from . import privileged_subproc
+
+class OstbuildPrivhelperDeployQemu(builtins.Builtin):
+    name = "privhelper-deploy-qemu"
+    short_description = "Helper for deploy-qemu"
+
+    def __init__(self):
+        builtins.Builtin.__init__(self)
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+
+        args = parser.parse_args(argv)
+        self.args = args
+        
+        self.parse_config()
+        self.parse_bin_snapshot(args.prefix, args.bin_snapshot)
+        
+        target_names = []
+        for target in self.bin_snapshot['targets']:
+            target_names.append(target['name'])
+
+        helper = privileged_subproc.PrivilegedSubprocess()
+        sys_repo = os.path.join(self.ostree_dir, 'repo')
+        shadow_path = os.path.join(self.workdir, 'shadow-repo')
+        helper.spawn_sync(['ostree', '--repo=' + sys_repo,
+                           'pull-local', shadow_path])
+        
+builtins.register(OstbuildDeployRoot)
diff --git a/src/ostbuild/pyostbuild/builtins.py b/src/ostbuild/pyostbuild/builtins.py
index 211a14c..a167e9b 100755
--- a/src/ostbuild/pyostbuild/builtins.py
+++ b/src/ostbuild/pyostbuild/builtins.py
@@ -42,12 +42,12 @@ class Builtin(object):
         self.snapshot = None
         self.bin_snapshot = None
         self.repo = None
-        self.ostree_dir = self._find_ostree_dir()
+        self.ostree_dir = self.find_ostree_dir()
         (self.active_branch, self.active_branch_checksum) = self._find_active_branch()
         self._src_snapshots = None
         self._bin_snapshots = None
 
-    def _find_ostree_dir(self):
+    def find_ostree_dir(self):
         for path in ['/ostree', '/sysroot/ostree']:
             if os.path.isdir(path):
                 return path
@@ -180,9 +180,12 @@ class Builtin(object):
             else:
                 fatal("No repository configured, and shadow-repo not found.  Use \"ostbuild shadow-repo-init\" to make one")
 
-    def parse_snapshot(self, prefix, path):
+    def parse_prefix(self, prefix):
         if prefix is not None:
             self.prefix = prefix
+
+    def parse_snapshot(self, prefix, path):
+        self.parse_prefix(prefix)
         self._init_repo()
         if path is None:
             latest_path = self.get_src_snapshot_db().get_latest_path()
@@ -197,8 +200,7 @@ class Builtin(object):
             fatal("Unhandled 00ostree-src-snapshot-version \"%d\", expected 0" % (src_ver, ))
 
     def parse_bin_snapshot(self, prefix, path):
-        if prefix is not None:
-            self.prefix = prefix
+        self.parse_prefix(prefix)
         self._init_repo()
         if path is None:
             latest_path = self.get_bin_snapshot_db().get_latest_path()
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index 488a563..35d150a 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -29,6 +29,7 @@ from . import builtin_checkout
 from . import builtin_chroot_compile_one
 from . import builtin_compose
 from . import builtin_compile_one
+from . import builtin_deploy_root
 from . import builtin_git_mirror
 from . import builtin_pull_components
 from . import builtin_prefix
diff --git a/src/ostbuild/pyostbuild/privileged_subproc.py b/src/ostbuild/pyostbuild/privileged_subproc.py
new file mode 100755
index 0000000..982984b
--- /dev/null
+++ b/src/ostbuild/pyostbuild/privileged_subproc.py
@@ -0,0 +1,39 @@
+# Copyright (C) 2012 Colin Walters <walters verbum org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,subprocess
+
+from .ostbuildlog import log, fatal
+from . import ostbuildrc
+
+class PrivilegedSubprocess(object):
+
+    def spawn_sync(self, argv):
+        helper = ostbuildrc.get_key('privileged_exec', default='pkexec')
+
+        handlers = {'pkexec': self._pkexec_spawn_sync}
+
+        handler = handlers.get(helper)
+        if handler is None:
+            fatal("Unrecognized privileged_exec; valid values=%r" % (handlers.keys(),))
+        else:
+            handler(argv)
+
+    def _pkexec_spawn_sync(self, argv):
+        pkexec_argv = ['pkexec'] + argv
+        log("Running: %s" % (subprocess.list2cmdline(pkexec_argv), ))
+        subprocess.check_call(pkexec_argv)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]