ostbuild: Move autodiscover-meta to ostbuild executor
This commit is contained in:
parent
122b31ed3b
commit
853dda39e7
|
|
@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile
|
||||||
bin_SCRIPTS += ostbuild
|
bin_SCRIPTS += ostbuild
|
||||||
|
|
||||||
bin_SCRIPTS += \
|
bin_SCRIPTS += \
|
||||||
src/ostbuild/ostbuild-autodiscover-meta \
|
|
||||||
src/ostbuild/ostbuild-commit-artifacts \
|
src/ostbuild/ostbuild-commit-artifacts \
|
||||||
src/ostbuild/ostbuild-chroot-compile-one-impl \
|
src/ostbuild/ostbuild-chroot-compile-one-impl \
|
||||||
src/ostbuild/ostbuild-nice-and-log-output \
|
src/ostbuild/ostbuild-nice-and-log-output \
|
||||||
|
|
@ -34,6 +33,7 @@ pyostbuild_PYTHON = \
|
||||||
src/ostbuild/pyostbuild/ostbuildlog.py \
|
src/ostbuild/pyostbuild/ostbuildlog.py \
|
||||||
src/ostbuild/pyostbuild/subprocess_helpers.py \
|
src/ostbuild/pyostbuild/subprocess_helpers.py \
|
||||||
src/ostbuild/pyostbuild/builtin_compile_one.py \
|
src/ostbuild/pyostbuild/builtin_compile_one.py \
|
||||||
|
src/ostbuild/pyostbuild/builtin_autodiscover_meta.py \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot
|
bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot
|
||||||
|
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
#!/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
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Discover source metadata from current directory")
|
|
||||||
parser.add_argument('--meta')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
AUTODISCOVERED_KEYS = {}
|
|
||||||
KEYS = {}
|
|
||||||
|
|
||||||
def _register_discover_func(key, func):
|
|
||||||
if key not in AUTODISCOVERED_KEYS:
|
|
||||||
AUTODISCOVERED_KEYS[key] = []
|
|
||||||
AUTODISCOVERED_KEYS[key].append(func)
|
|
||||||
|
|
||||||
def _discover_name_from_cwd():
|
|
||||||
return os.path.basename(os.getcwd())
|
|
||||||
_register_discover_func('NAME', _discover_name_from_cwd)
|
|
||||||
|
|
||||||
def _discover_version_from_git():
|
|
||||||
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
|
|
||||||
_register_discover_func('VERSION', _discover_version_from_git)
|
|
||||||
|
|
||||||
def _discover_branch_from_git():
|
|
||||||
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
|
|
||||||
_register_discover_func('BRANCH', _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)
|
|
||||||
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -23,6 +23,7 @@ import argparse
|
||||||
|
|
||||||
from . import builtins
|
from . import builtins
|
||||||
from . import builtin_compile_one
|
from . import builtin_compile_one
|
||||||
|
from . import builtin_autodiscover_meta
|
||||||
|
|
||||||
def usage(ecode):
|
def usage(ecode):
|
||||||
print "Builtins:"
|
print "Builtins:"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue