本文整理匯總了Python中rpm.expandMacro方法的典型用法代碼示例。如果您正苦於以下問題:Python rpm.expandMacro方法的具體用法?Python rpm.expandMacro怎麽用?Python rpm.expandMacro使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rpm
的用法示例。
在下文中一共展示了rpm.expandMacro方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: installed
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def installed(self, project_dir, spec, sack):
""" Compiles all python files depending on which python version they
are and appends them into files macro """
python_version = ""
for py_file in list(project_dir.glob('**/*.py')):
if rpm.expandMacro("%{python_sitearch}") in str(py_file) or\
rpm.expandMacro("%{python_sitelib}") in str(py_file):
python_version = "python2"
elif rpm.expandMacro("%{python3_sitearch}") in str(py_file) or\
rpm.expandMacro("%{python3_sitelib}") in str(py_file):
python_version = "python3"
Command([python_version + ' ' + sw +
' -c \'import compileall; compileall.compile_file("' +
str(py_file) + '")\'' for sw in ["-O", ""]]).execute()
spec.files.update([("/" + str(_f.relative_to(project_dir)), None, None)
for _f in project_dir.glob('**/*.py*')])
示例2: expand_macro
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def expand_macro(self, macro):
if not self._rpmspec:
self.load_rpmspec()
if not RPM_AVAILABLE:
raise exception.RpmModuleNotAvailable()
return rpm.expandMacro(macro)
示例3: execute
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def execute(self, work_dir=None):
""" executes command in work_dir (instance of pathlib.Path),
can raise CalledProcessError """
cd_workdir = []
if work_dir:
cd_workdir = ["cd %s" % path_to_str(work_dir.resolve())]
command_lines = self._assign_rpm_variables() + cd_workdir + \
[rpm.expandMacro(x) for x in self._command_lines]
return self._cmd_output(command_lines)
示例4: get_default_save_path
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def get_default_save_path():
"""Return default save path for the packages"""
macro = '%{_topdir}'
if rpm:
save_path = rpm.expandMacro(macro)
else:
save_path = rpm_eval(macro)
if not save_path:
logger.warning("rpm tools are missing, using default save path "
"~/rpmbuild/.")
save_path = os.path.expanduser('~/rpmbuild')
return save_path
示例5: update_spec
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def update_spec(spec_file, commit_hash, archive_name, packager, email, reader):
''' Update the release tag and changelog of the specified spec file
to work with the specified commit_hash.
'''
LOG.debug('Update spec file: %s', spec_file)
release = '%s%s%s' % (date.today().strftime('%Y%m%d'), reader.short, commit_hash)
output = []
version = None
rpm.spec(spec_file)
with open(spec_file) as stream:
for row in stream:
row = row.rstrip()
if row.startswith('Version:'):
version = row.split('Version:')[1].strip()
if row.startswith('Release:'):
if commit_hash in row:
raise DgrocException('Spec already up to date')
LOG.debug('Release line before: %s', row)
rel_num = row.split('ase:')[1].strip().split('%{?dist')[0]
rel_list = rel_num.split('.')
if reader.short in rel_list[-1]:
rel_list = rel_list[:-1]
if rel_list[-1].isdigit():
rel_list[-1] = str(int(rel_list[-1])+1)
rel_num = '.'.join(rel_list)
LOG.debug('Release number: %s', rel_num)
row = 'Release: %s.%s%%{?dist}' % (rel_num, release)
LOG.debug('Release line after: %s', row)
if row.startswith('Source0:'):
row = 'Source0: %s' % (archive_name)
LOG.debug('Source0 line after: %s', row)
if row.startswith('%changelog'):
output.append(row)
output.append(rpm.expandMacro('* %s %s <%s> - %s-%s.%s' % (
date.today().strftime('%a %b %d %Y'), packager, email,
version, rel_num, release)
))
output.append('- Update to %s: %s' % (reader.short, commit_hash))
row = ''
output.append(row)
with open(spec_file, 'w') as stream:
for row in output:
stream.write(row + '\n')
LOG.info('Spec file updated: %s', spec_file)
示例6: fix_rpmdb
# 需要導入模塊: import rpm [as 別名]
# 或者: from rpm import expandMacro [as 別名]
def fix_rpmdb(self, expected_rpmdb_dir = None,
db_load = 'db_load', rpm = 'rpm'):
logger.info("fixing RPM database for guest")
current_rpmdb_dir = rpm_mod.expandMacro('%{_dbpath}')
if expected_rpmdb_dir is None:
expected_rpmdb_dir = sh.run(
['python', '-c', 'import rpm; print rpm.expandMacro("%{_dbpath}")'],
chroot = self.chroot,
pipe = sh.READ,
env = self.yum_conf.env,
).strip()
# input directory
rpmdb_dir = os.path.join(self.chroot, current_rpmdb_dir.lstrip('/'))
logger.info('converting "Packages" file')
in_pkg_db = os.path.join(rpmdb_dir, 'Packages')
tmp_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages.tmp')
out_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages')
out_command = sh.run(
[db_load, tmp_pkg_db],
chroot = self.chroot, pipe = sh.WRITE,
env = self.yum_conf.env,
)
bdb.db_dump(in_pkg_db, out_command)
out_command.close()
os.rename(
os.path.join(self.chroot, tmp_pkg_db.lstrip('/')),
os.path.join(self.chroot, out_pkg_db.lstrip('/'))
)
logger.info('removing all the files except "Packages"')
for f in os.listdir(rpmdb_dir):
if f in ('.', '..', 'Packages'): continue
os.unlink(os.path.join(rpmdb_dir, f))
logger.info("running `rpm --rebuilddb'")
sh.run(
[rpm, '--rebuilddb'],
chroot = self.chroot,
env = self.yum_conf.env,
)
if current_rpmdb_dir != expected_rpmdb_dir:
# Red Hat under Debian; delete old directory (~/.rpmdb possibly)
logger.info("removing old RPM DB directory: $TARGET%s",
current_rpmdb_dir)
shutil.rmtree(os.path.join(self.chroot, current_rpmdb_dir.lstrip('/')))
self.rpmdb_fixed = True
#-----------------------------------------------------------------------------
# vim:ft=python