[ostree] ostbuild: Move autodiscover-meta to ostbuild executor
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] ostbuild: Move autodiscover-meta to ostbuild executor
- Date: Fri, 23 Dec 2011 17:11:21 +0000 (UTC)
commit 853dda39e76582cb4c971c878913e89b85ce0dfc
Author: Colin Walters <walters verbum org>
Date: Fri Dec 23 10:48:57 2011 -0500
ostbuild: Move autodiscover-meta to ostbuild executor
Makefile-ostbuild.am | 2 +-
src/ostbuild/ostbuild-autodiscover-meta | 81 -----------------
.../pyostbuild/builtin_autodiscover_meta.py | 91 ++++++++++++++++++++
src/ostbuild/pyostbuild/main.py | 1 +
4 files changed, 93 insertions(+), 82 deletions(-)
---
diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am
index 0758860..96b2e37 100644
--- a/Makefile-ostbuild.am
+++ b/Makefile-ostbuild.am
@@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile
bin_SCRIPTS += ostbuild
bin_SCRIPTS += \
- src/ostbuild/ostbuild-autodiscover-meta \
src/ostbuild/ostbuild-commit-artifacts \
src/ostbuild/ostbuild-chroot-compile-one-impl \
src/ostbuild/ostbuild-nice-and-log-output \
@@ -34,6 +33,7 @@ pyostbuild_PYTHON = \
src/ostbuild/pyostbuild/ostbuildlog.py \
src/ostbuild/pyostbuild/subprocess_helpers.py \
src/ostbuild/pyostbuild/builtin_compile_one.py \
+ src/ostbuild/pyostbuild/builtin_autodiscover_meta.py \
$(NULL)
bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot
diff --git a/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py b/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py
new file mode 100755
index 0000000..6808024
--- /dev/null
+++ b/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2011 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,re,subprocess,tempfile,shutil
+import argparse
+
+from . import builtins
+from .ostbuildlog import log, fatal
+
+class OstbuildAutodiscoverMeta(builtins.Builtin):
+ name = "autodiscover-meta"
+ short_description = "Extract metadata from the current source directory"
+
+ def execute(self, argv):
+ parser = argparse.ArgumentParser(self.short_description)
+ parser.add_argument('--meta')
+
+ args = parser.parse_args(argv)
+
+ KEYS = {}
+ AUTODISCOVERED_KEYS = {}
+
+ def _register_discover_func(key, func):
+ if key not in AUTODISCOVERED_KEYS:
+ AUTODISCOVERED_KEYS[key] = []
+ AUTODISCOVERED_KEYS[key].append(func)
+
+ _register_discover_func('NAME', self._discover_name_from_cwd)
+ _register_discover_func('VERSION', self._discover_version_from_git)
+ _register_discover_func('BRANCH', self._discover_branch_from_git)
+
+ if args.meta:
+ f = open(args.meta)
+ for line in f.readlines():
+ (k,v) = line.split('=', 1)
+ KEYS[k.strip()] = v.strip()
+ f.close()
+
+ for (key,hooks) in AUTODISCOVERED_KEYS.iteritems():
+ if key in KEYS:
+ continue
+ for func in hooks:
+ value = func()
+
+ if value is None:
+ continue
+
+ KEYS[key] = value
+ break
+
+ for (key,value) in KEYS.iteritems():
+ print "%s=%s" % (key, value)
+
+ def _discover_name_from_cwd(self):
+ return os.path.basename(os.getcwd())
+
+ def _discover_version_from_git(self):
+ if os.path.isdir('.git'):
+ try:
+ version = subprocess.check_output(['git', 'describe'])
+ except subprocess.CalledProcessError, e:
+ version = subprocess.check_output(['git', 'rev-parse', 'HEAD'])
+ return version.strip()
+ return None
+
+ def _discover_branch_from_git(self):
+ if os.path.isdir('.git'):
+ try:
+ ref = subprocess.check_output(['git', 'symbolic-ref', 'HEAD'])
+ return ref.replace('refs/heads/', '').strip()
+ except subprocess.CalledProcessError, e:
+ return None
+ return None
+
+builtins.register(OstbuildAutodiscoverMeta)
diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py
index 916f6da..5cd5587 100755
--- a/src/ostbuild/pyostbuild/main.py
+++ b/src/ostbuild/pyostbuild/main.py
@@ -23,6 +23,7 @@ import argparse
from . import builtins
from . import builtin_compile_one
+from . import builtin_autodiscover_meta
def usage(ecode):
print "Builtins:"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]