Continue working on cleaning this up
This commit is contained in:
@@ -44,7 +44,8 @@ def tiny_p(cmd):
|
|||||||
stderr=subprocess.PIPE, stdin=None)
|
stderr=subprocess.PIPE, stdin=None)
|
||||||
(out, err) = sp.communicate()
|
(out, err) = sp.communicate()
|
||||||
if sp.returncode not in [0]:
|
if sp.returncode not in [0]:
|
||||||
raise RuntimeError("Failed running %s [rc=%s]" % (cmd, sp.returncode))
|
raise RuntimeError("Failed running %s [rc=%s] (%s, %s)"
|
||||||
|
% (cmd, sp.returncode, out, err))
|
||||||
return (out, err)
|
return (out, err)
|
||||||
|
|
||||||
|
|
||||||
@@ -56,19 +57,13 @@ def warn(msg):
|
|||||||
print("WARNING: %s" % (msg))
|
print("WARNING: %s" % (msg))
|
||||||
|
|
||||||
|
|
||||||
def generate_spec_contents(tmpl_fn):
|
def generate_spec_contents(tmpl_fn, revno, version):
|
||||||
|
|
||||||
# Version junk
|
|
||||||
cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')]
|
|
||||||
(stdout, _stderr) = tiny_p(cmd)
|
|
||||||
i_version = stdout.strip()
|
|
||||||
|
|
||||||
# Tmpl params
|
# Tmpl params
|
||||||
subs = {}
|
subs = {}
|
||||||
subs['version'] = i_version
|
subs['version'] = version
|
||||||
(stdout, _stderr) = tiny_p(['bzr', 'revno'])
|
subs['revno'] = revno
|
||||||
subs['revno'] = "%s" % (stdout.strip())
|
subs['release'] = revno
|
||||||
subs['release'] = "%s" % (subs['revno'])
|
|
||||||
subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz'
|
subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz'
|
||||||
subs['bd_requires'] = ['python-devel', 'python-setuptools']
|
subs['bd_requires'] = ['python-devel', 'python-setuptools']
|
||||||
|
|
||||||
@@ -90,7 +85,7 @@ def generate_spec_contents(tmpl_fn):
|
|||||||
else:
|
else:
|
||||||
requires.append(tgt_pkg)
|
requires.append(tgt_pkg)
|
||||||
|
|
||||||
base_name = 'cloud-init-%s-%s' % (i_version, subs['revno'])
|
base_name = 'cloud-init-%s-%s' % (version, subs['revno'])
|
||||||
subs['requires'] = requires
|
subs['requires'] = requires
|
||||||
|
|
||||||
(stdout, _stderr) = tiny_p([sys.executable,
|
(stdout, _stderr) = tiny_p([sys.executable,
|
||||||
@@ -126,6 +121,16 @@ def generate_spec_contents(tmpl_fn):
|
|||||||
return (base_name, '%s.tar.gz' % (base_name), contents)
|
return (base_name, '%s.tar.gz' % (base_name), contents)
|
||||||
|
|
||||||
|
|
||||||
|
def archive_code():
|
||||||
|
(stdout, _stderr) = tiny_p([sys.executable,
|
||||||
|
join(os.getcwd(), 'tar-me')])
|
||||||
|
lines = stdout.splitlines()
|
||||||
|
revno = lines[0]
|
||||||
|
version = lines[1]
|
||||||
|
arc_fn = lines[2]
|
||||||
|
return (revno, version, arc_fn)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
# Clean out the root dir and make sure the dirs we want are in place
|
# Clean out the root dir and make sure the dirs we want are in place
|
||||||
@@ -137,37 +142,22 @@ def main():
|
|||||||
for d in [root_dir, arc_dir]:
|
for d in [root_dir, arc_dir]:
|
||||||
os.makedirs(d)
|
os.makedirs(d)
|
||||||
|
|
||||||
|
# Archive the code
|
||||||
|
(revno, version, archive_fn) = archive_code()
|
||||||
|
real_archive_fn = os.path.join(arc_dir, os.path.basename(archive_fn))
|
||||||
|
shutil.copy(archive_fn, real_archive_fn)
|
||||||
|
info("Archived code to %s" % (real_archive_fn))
|
||||||
|
|
||||||
# Form the spec file to be used
|
# Form the spec file to be used
|
||||||
tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl')
|
tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl')
|
||||||
info("Generated spec file from template %s" % (tmpl_fn))
|
info("Generated spec file from template %s" % (tmpl_fn))
|
||||||
(base_name, arc_name, contents) = generate_spec_contents(tmpl_fn)
|
(base_name, arc_name, contents) = generate_spec_contents(tmpl_fn,
|
||||||
|
revno, version)
|
||||||
spec_fn = os.path.join(root_dir, 'cloud-init.spec')
|
spec_fn = os.path.join(root_dir, 'cloud-init.spec')
|
||||||
with open(spec_fn, 'w') as fh:
|
with open(spec_fn, 'w') as fh:
|
||||||
fh.write(contents)
|
fh.write(contents)
|
||||||
info("Wrote spec file to %s" % (spec_fn))
|
info("Wrote spec file to %s" % (spec_fn))
|
||||||
|
|
||||||
# Archive the code and files that we want to
|
|
||||||
with tmpdir() as td:
|
|
||||||
src_dir = os.path.join(td, base_name)
|
|
||||||
os.makedirs(src_dir)
|
|
||||||
for fn in os.listdir(os.pardir):
|
|
||||||
if fn.startswith("."):
|
|
||||||
continue
|
|
||||||
full_fn = os.path.abspath(os.path.join(os.pardir, fn))
|
|
||||||
if os.path.isfile(full_fn):
|
|
||||||
shutil.copy(full_fn, os.path.join(src_dir, fn))
|
|
||||||
else:
|
|
||||||
shutil.copytree(full_fn, os.path.join(src_dir, fn),
|
|
||||||
ignore=shutil.ignore_patterns('*.pyc',
|
|
||||||
'.bzr',
|
|
||||||
'tmp*',
|
|
||||||
'*bzr*'))
|
|
||||||
arc_fn = os.path.join(arc_dir, arc_name)
|
|
||||||
cmd = ['tar', '-zcvf', arc_fn, '-C', td]
|
|
||||||
cmd.extend(os.listdir(td))
|
|
||||||
tiny_p(cmd)
|
|
||||||
info("Archived code at %s" % (arc_fn))
|
|
||||||
|
|
||||||
# Now build it!
|
# Now build it!
|
||||||
cmd = ['rpmbuild', '-ba', spec_fn]
|
cmd = ['rpmbuild', '-ba', spec_fn]
|
||||||
info("Running rpmbuild %s" % (cmd))
|
info("Running rpmbuild %s" % (cmd))
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ ssh keys and to let the user run various scripts.
|
|||||||
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -n %{name}-%{version}-{{revno}}
|
%setup -q -n
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%{__python} setup.py build
|
%{__python} setup.py build
|
||||||
|
|||||||
Reference in New Issue
Block a user