本文整理汇总了Python中tito.common.run_command函数的典型用法代码示例。如果您正苦于以下问题:Python run_command函数的具体用法?Python run_command怎么用?Python run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_test_specfile
def _setup_test_specfile(self):
if self.test and not self.ran_setup_test_specfile:
# If making a test rpm we need to get a little crazy with the spec
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
sha = self.git_commit_id[:7]
fullname = "{0}-{1}".format(self.project_name, self.display_version)
munge_specfile(self.spec_file, sha, self.commit_count, fullname, self.tgz_filename)
# Custom Openshift v3 stuff follows, everything above is the standard
# builder
cmd = ". ./hack/common.sh ; echo $(os::build::ldflags)"
ldflags = run_command("bash -c '{0}'".format(cmd))
print("LDFLAGS::{0}".format(ldflags))
update_ldflags = "sed -i 's|^%global ldflags .*$|%global ldflags {0}|' {1}".format(
" ".join([ldflag.strip() for ldflag in ldflags.split()]), self.spec_file
)
# FIXME - output is never used
output = run_command(update_ldflags)
# Add bundled deps for Fedora Guidelines as per:
# https://fedoraproject.org/wiki/Packaging:Guidelines#Bundling_and_Duplication_of_system_libraries
provides_list = []
with open("./Godeps/Godeps.json") as godeps:
depdict = json.load(godeps)
for bdep in [(dep[u"ImportPath"], dep[u"Rev"]) for dep in depdict[u"Deps"]]:
provides_list.append("Provides: bundled(golang({0})) = {1}".format(bdep[0], bdep[1]))
update_provides_list = "sed -i 's|^### AUTO-BUNDLED-GEN-ENTRY-POINT|{0}|' {1}".format(
"\\n".join(provides_list), self.spec_file
)
print(run_command(update_provides_list))
self.build_version += ".git." + str(self.commit_count) + "." + str(self.git_commit_id[:7])
self.ran_setup_test_specfile = True
示例2: _clear_package_metadata
def _clear_package_metadata(self):
"""
Remove all rel-eng/packages/ files that have a relative path
matching the package we're tagging a new version of. Normally
this just removes the previous package file but if we were
renaming oldpackage to newpackage, this would git rm
rel-eng/packages/oldpackage and add
rel-eng/packages/spacewalk-newpackage.
"""
metadata_dir = os.path.join(self.rel_eng_dir, "packages")
for filename in os.listdir(metadata_dir):
metadata_file = os.path.join(metadata_dir, filename) # full path
if os.path.isdir(metadata_file) or filename.startswith("."):
continue
temp_file = open(metadata_file, 'r')
(version, relative_dir) = temp_file.readline().split(" ")
relative_dir = relative_dir.strip() # sometimes has a newline
if relative_dir == self.relative_project_dir:
debug("Found metadata for our prefix: %s" %
metadata_file)
debug(" version: %s" % version)
debug(" dir: %s" % relative_dir)
if filename == self.project_name:
debug("Updating %s with new version." %
metadata_file)
else:
print("WARNING: %s also references %s" % (filename,
self.relative_project_dir))
print("Assuming package has been renamed and removing it.")
run_command("git rm %s" % metadata_file)
示例3: setUp
def setUp(self):
TitoGitTestFixture.setUp(self)
# Guess based on python version.
# Do not use anything based on uname in case we are in container.
# Do not use `lsb_release` to avoid dependencies.
if sys.version[0:3] == '2.4':
raise SkipTest('git-annex is not available in epel-5')
status, ga_version = getstatusoutput('rpm -q git-annex')
if status != 0:
raise SkipTest("git-annex is missing")
# Setup test config:
self.config = RawConfigParser()
self.config.add_section("buildconfig")
self.config.set("buildconfig", "builder",
"tito.builder.GitAnnexBuilder")
self.config.set("buildconfig", "offline",
"true")
os.chdir(self.repo_dir)
spec = join(os.path.dirname(__file__), "specs/extsrc.spec")
self.create_project_from_spec(PKG_NAME, self.config,
spec=spec)
self.source_filename = 'extsrc-0.0.2.tar.gz'
# Make a fake source file, do we need something more real?
run_command('touch %s' % self.source_filename)
print(run_command('git-annex init'))
self.output_dir = tempfile.mkdtemp("-titotestoutput")
示例4: _update_setup_py_in_dir
def _update_setup_py_in_dir(self, new_version, package_dir=None):
"""
If this subdir has a setup.py, attempt to update it's version.
(This is a very minor tweak to the original _update_setup_py method from VersionTagger
"""
if package_dir is not None:
full_package_dir = os.path.join(self.full_project_dir, package_dir)
else:
full_package_dir = self.full_project_dir
setup_file = os.path.join(full_package_dir, "setup.py")
if not os.path.exists(setup_file):
return
debug("Found setup.py in {}, attempting to update version.".format(package_dir))
# We probably don't want version-release in setup.py as release is
# an rpm concept. Hopefully this assumption on
py_new_version = new_version.split('-')[0]
f = open(setup_file, 'r')
buf = six.StringIO()
for line in f.readlines():
buf.write(replace_version(line, py_new_version))
f.close()
# Write out the new setup.py file contents:
f = open(setup_file, 'w')
f.write(buf.getvalue())
f.close()
buf.close()
run_command("git add %s" % setup_file)
示例5: _tag_release
def _tag_release(self):
"""
Tag a new release of the package, add specfile global named commit.
(ie: x.y.z-r+1) and ldflags from hack/common.sh os::build::ldflags
"""
self._make_changelog()
new_version = self._bump_version()
new_version = re.sub(r"-.*", "", new_version)
git_hash = get_latest_commit()
update_commit = \
"sed -i 's/^%global commit .*$/%global commit {0}/' {1}".format(
git_hash,
self.spec_file
)
output = run_command(update_commit)
cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)'
ldflags = run_command('bash -c \'{0}\''.format(cmd))
# hack/common.sh will tell us that the tree is dirty because tito has
# already mucked with things, but lets not consider the tree to be
# dirty
ldflags = ldflags.replace('-dirty', '')
update_ldflags = \
"sed -i 's|^%global ldflags .*$|%global ldflags {0}|' {1}".format(
ldflags,
self.spec_file
)
# FIXME - this output is never used
output = run_command(update_ldflags)
self._check_tag_does_not_exist(self._get_new_tag(new_version))
self._update_changelog(new_version)
self._update_package_metadata(new_version)
示例6: _git_sync_files
def _git_sync_files(self, project_checkout):
"""
Copy files from our git into each git build branch and add them.
A list of safe files is used to protect critical files both from
being overwritten by a git file of the same name, as well as being
deleted after.
"""
# Build the list of all files we will copy:
debug("Searching for files to copy to build system git:")
files_to_copy = self._list_files_to_copy()
os.chdir(project_checkout)
new, copied, old = \
self._sync_files(files_to_copy, project_checkout)
os.chdir(project_checkout)
# Git add everything:
for add_file in (new + copied):
run_command("git add %s" % add_file)
# Cleanup obsolete files:
for cleanup_file in old:
# Can't delete via full path, must not chdir:
run_command("git rm %s" % cleanup_file)
示例7: setUp
def setUp(self):
self.repo_dir = tempfile.mkdtemp("-titocargotest")
print("Testing in: %s" % self.repo_dir)
os.chdir(self.repo_dir)
self.full_pkg_dir = os.path.join(self.repo_dir, "hello_tito")
run_command('mkdir -p %s' % self.full_pkg_dir)
# Initialize the repo:
os.chdir(self.full_pkg_dir)
run_command('git init')
# Next we tito init:
tito("init")
run_command('echo "offline = true" >> .tito/tito.props')
run_command('git add .tito/tito.props')
run_command("git commit -m 'set offline in tito.props'")
# Init cargo project
self.create_cargo_project()
# Init RPM package
self.create_rpm_package()
# Run tito tag
tito("tag --accept-auto-changelog")
示例8: _setup_sources
def _setup_sources(self):
"""
Create a copy of the git source for the project at the point in time
our build tag was created.
Created in the temporary rpmbuild SOURCES directory.
"""
self._create_build_dirs()
debug("Creating %s from git tag: %s..." % (self.tgz_filename,
self.git_commit_id))
create_tgz(self.git_root, self.tgz_dir, self.git_commit_id,
self.relative_project_dir,
os.path.join(self.rpmbuild_sourcedir, self.tgz_filename))
# Extract the source so we can get at the spec file, etc.
debug("Copying git source to: %s" % self.rpmbuild_gitcopy)
run_command("cd %s/ && tar xzf %s" % (self.rpmbuild_sourcedir,
self.tgz_filename))
# Show contents of the directory structure we just extracted.
debug('', 'ls -lR %s/' % self.rpmbuild_gitcopy)
# NOTE: The spec file we actually use is the one exported by git
# archive into the temp build directory. This is done so we can
# modify the version/release on the fly when building test rpms
# that use a git SHA1 for their version.
self.spec_file_name = os.path.basename(find_spec_like_file(self.rpmbuild_gitcopy))
self.spec_file = os.path.join(
self.rpmbuild_gitcopy, self.spec_file_name)
示例9: _setup_test_specfile
def _setup_test_specfile(self):
if self.test and not self.ran_setup_test_specfile:
# If making a test rpm we need to get a little crazy with the spec
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
setup_specfile_script = get_script_path("test-setup-specfile.pl")
cmd = "%s %s %s %s %s-%s %s" % \
(
setup_specfile_script,
self.spec_file,
self.git_commit_id[:7],
self.commit_count,
self.project_name,
self.display_version,
self.tgz_filename,
)
run_command(cmd)
# Custom Openshift v3 stuff follows, everything above is the standard
# builder
cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)'
ldflags = run_command('bash -c \'%s\'' % (cmd) )
update_ldflags = "sed -i 's|^%%global ldflags .*$|%%global ldflags %s|' %s" % \
(ldflags, self.spec_file)
output = run_command(update_ldflags)
self.build_version += ".git." + str(self.commit_count) + "." + str(self.git_commit_id[:7])
self.ran_setup_test_specfile = True
示例10: _git_upload_sources
def _git_upload_sources(self, project_checkout):
chain_file = find_mead_chain_file(self.builder.rpmbuild_gitcopy)
with open(chain_file, 'r') as f:
template = Template(f.read())
ref = self.builder.build_tag
if self.test:
ref = self.builder.git_commit_id
values = {
'mead_scm': self.mead_scm,
'git_ref': ref,
# Each property on its own line with a few leading spaces to indicate
# that it's a continuation
'maven_properties': "\n ".join(self.builder.maven_properties),
'maven_options': " ".join(self.builder.maven_args),
}
rendered_chain = template.safe_substitute(values)
with chdir(project_checkout):
with open("mead.chain", "w") as f:
f.write(rendered_chain)
cmd = "git add mead.chain"
if self.dry_run:
self.print_dry_run_warning(cmd)
info_out("Chain file contents:\n%s" % rendered_chain)
else:
run_command(cmd)
示例11: test_template_version_tagger
def test_template_version_tagger(self):
"""
Make sure the template is applied and results in the correct file
being included in the tag.
"""
pkg_dir = join(self.repo_dir, 'pkg3')
filename = join(pkg_dir, "tito.props")
self.write_file(filename, TEMPLATE_TAGGER_TITO_PROPS)
run_command('mkdir -p %s' % join(self.repo_dir, 'rel-eng/templates'))
self.write_file(join(self.repo_dir,
'rel-eng/templates/version.rb'), VERSION_TEMPLATE_FILE)
index = self.repo.index
index.add(['pkg3/tito.props'])
index.commit("Adding tito.props for pkg3.")
# Create another pkg3 tag and make sure we got a generated
# template file.
os.chdir(os.path.join(self.repo_dir, 'pkg3'))
tito('tag --debug --accept-auto-changelog')
new_ver = get_latest_tagged_version(TEST_PKG_3)
self.assertEquals("0.0.2-1", new_ver)
dest_file = os.path.join(self.repo_dir, 'pkg3', "version.txt")
self.assertTrue(os.path.exists(dest_file))
f = open(dest_file, 'r')
contents = f.read()
f.close()
self.assertTrue("VERSION = \"0.0.2-1\"" in contents)
示例12: _update_setup_py
def _update_setup_py(self, new_version):
"""
If this project has a setup.py, attempt to update it's version.
"""
setup_file = os.path.join(self.full_project_dir, "setup.py")
if not os.path.exists(setup_file):
return
debug("Found setup.py, attempting to update version.")
# We probably don't want version-release in setup.py as release is
# an rpm concept. Hopefully this assumption on
py_new_version = new_version.split('-')[0]
f = open(setup_file, 'r')
buf = StringIO.StringIO()
for line in f.readlines():
buf.write(replace_version(line, py_new_version))
f.close()
# Write out the new setup.py file contents:
f = open(setup_file, 'w')
f.write(buf.getvalue())
f.close()
buf.close()
run_command("git add %s" % setup_file)
示例13: _setup_test_specfile
def _setup_test_specfile(self):
if self.test and not self.ran_setup_test_specfile:
# If making a test rpm we need to get a little crazy with the spec
# file we're building off. (note that this is a temp copy of the
# spec) Swap out the actual release for one that includes the git
# SHA1 we're building for our test package:
sha = self.git_commit_id[:7]
fullname = "{0}-{1}".format(self.project_name, self.display_version)
munge_specfile(
self.spec_file,
sha,
self.commit_count,
fullname,
self.tgz_filename,
)
# Custom Openshift v3 stuff follows, everything above is the standard
# builder
cmd = '. ./hack/common.sh ; echo $(os::build::ldflags)'
ldflags = run_command("bash -c '{0}'".format(cmd))
print("LDFLAGS::{0}".format(ldflags))
update_ldflags = \
"sed -i 's|^%%global ldflags .*$|%%global ldflags {0}|' {1}".format(
' '.join([ldflag.strip() for ldflag in ldflags.split()]),
self.spec_file
)
# FIXME - output is never used
output = run_command(update_ldflags)
self.build_version += ".git." + \
str(self.commit_count) + \
"." + \
str(self.git_commit_id[:7])
self.ran_setup_test_specfile = True
示例14: patch_upstream
def patch_upstream(self):
commits = run_command('git rev-list --reverse %s..%s -- .'
% (self.upstream_tag, self.git_commit_id))
patch_filenames = []
previous_tag = self.upstream_tag
for commit in commits.splitlines():
tag = run_command('git describe --tags --match %s-%s\\* --exact-match %s 2>/dev/null || :'
% (self.project_name, self.upstream_version, commit))
if tag and tag not in BAD_TAGS:
self._generate_patch(previous_tag, tag, '%s.patch' % tag)
patch_filenames.append('%s.patch' % tag)
previous_tag = tag
if self.test:
# If this is a --test build, there will be some untagged commits at
# the end which we also need to include.
self._generate_patch(previous_tag, self.git_commit_id, '%s.patch' % self.display_version)
patch_filenames.append('%s.patch' % self.display_version)
else:
assert previous_tag == self.build_tag or not commits
(patch_number, patch_insert_index, patch_apply_index, lines) = self._patch_upstream()
for patch in patch_filenames:
lines.insert(patch_insert_index, "Patch%s: %s\n" % (patch_number, patch))
lines.insert(patch_apply_index, "%%patch%s -p1\n" % (patch_number))
patch_number += 1
patch_insert_index += 1
patch_apply_index += 2
self._write_spec(lines)
示例15: _generate_default_changelog
def _generate_default_changelog(self, last_tag):
# Grab all the commits we are interested in
commits = run_command('git log --pretty=format:%%H --relative %s..HEAD -- .'
% last_tag)
changelog = []
for sha in reversed(commits.split('\n')):
subject = run_command('git show -s --pretty="format:%s" %s'
% (self._changelog_format(), sha))
# Skip Gerrit merges
if re.match(r'Merge ".*" into', subject):
continue
# Skip Tito version bumps
if re.match(r'Automatic commit of package \[.*\] release \[.*\]', subject):
continue
# Tito's built-in cherry-pick cleaning
subject = self._changelog_remove_cherrypick(subject)
# Check for Bug: footer
body = run_command('git show -s --pretty=format:%%b %s' % sha)
m = re.search(r'^Bug:\s*(\d+)', body, re.IGNORECASE | re.MULTILINE)
if m:
bz_number = m.group(1)
subject = '%s %s' % (bz_number, subject)
# Escape rpm macros
subject = subject.replace('%', '%%')
changelog.append(subject)
return '\n'.join(changelog)