Python rpm.expandMacro() Examples
The following are 6
code examples of rpm.expandMacro().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rpm
, or try the search function
.
Example #1
Source File: python.py From rpg with GNU General Public License v2.0 | 6 votes |
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*')])
Example #2
Source File: specfile.py From rdopkg with Apache License 2.0 | 5 votes |
def expand_macro(self, macro): if not self._rpmspec: self.load_rpmspec() if not RPM_AVAILABLE: raise exception.RpmModuleNotAvailable() return rpm.expandMacro(macro)
Example #3
Source File: command.py From rpg with GNU General Public License v2.0 | 5 votes |
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)
Example #4
Source File: utils.py From pyp2rpm with MIT License | 5 votes |
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
Example #5
Source File: dgroc.py From dgroc with GNU General Public License v3.0 | 4 votes |
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)
Example #6
Source File: yum.py From yumbootstrap with GNU General Public License v3.0 | 4 votes |
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