-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find files wil now replace system paths with rpm macros (fix #351)
- Loading branch information
Showing
2 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,85 @@ | ||
from rpg.plugin import Plugin | ||
import re | ||
|
||
|
||
class FindFilePlugin(Plugin): | ||
|
||
MACROS = [ | ||
("/usr/local/share/javadoc", "%{_javadocdir}"), | ||
("/usr/share/javadoc", "%{_javadocdir}"), | ||
("/usr/local/share/java", "%{_javadir}"), | ||
("/usr/share/java", "%{_javadir}"), | ||
("/usr/local/share/man", "%{_mandir}"), | ||
("/usr/share/man", "%{_mandir}"), | ||
(r"/usr/local/lib64/perl\d", "%{perl_sitearch}"), | ||
(r"/usr/local/lib64/perl\d", "%{perl_sitearch}"), | ||
(r"/usr/local/share/perl\d", "${perl_sitelib}"), | ||
(r"/usr/local/share/perl\d", "${perl_sitelib}"), | ||
(r"/usr/local/lib64/python2.\d/site-packages", "%{python_sitearch}"), | ||
(r"/usr/lib64/python2.\d/site-packages", "%{python_sitearch}"), | ||
(r"/usr/local/lib/python2.\d/site-packages", "%{python_sitelib}"), | ||
(r"/usr/lib/python2.\d/site-packages", "%{python_sitelib}"), | ||
(r"/usr/local/lib64/python3.\d/site-packages", "%{python3_sitearch}"), | ||
(r"/usr/lib64/python3.\d/site-packages", "%{python3_sitearch}"), | ||
(r"/usr/local/lib/python3.\d/site-packages", "%{python3_sitelib}"), | ||
(r"/usr/lib/python3.\d/site-packages", "%{python3_sitelib}"), | ||
("/usr/local/share/doc", "%{_defaultdocdir}"), | ||
("/usr/share/doc", "%{_defaultdocdir}"), | ||
("/usr/local/share/licenses", "%{_defaultlicencedir}"), | ||
("/usr/share/licenses", "%{_defaultlicencedir}"), | ||
("/usr/local/lib/rpm/fileattrs", "%{_fileattrsdir}"), | ||
("/usr/lib/rpm/fileattrs", "%{_fileattrsdir}"), | ||
("/usr/local/lib64/gfortran/modules", "%{fmoddir}"), | ||
("/usr/lib64/gfortran/modules", "%{fmoddir}"), | ||
("/usr/local/lib/gfortran/modules", "%{fmoddir}"), | ||
("/usr/lib/gfortran/modules", "%{fmoddir}"), | ||
("/usr/local/include", "%{_includedir}"), | ||
("/usr/include", "%{_includedir}"), | ||
("/usr/local/sbin", "%{_sbindir}"), | ||
("/usr/sbin", "%{_sbindir}"), | ||
("/usr/local/bin", "%{_bindir}"), | ||
("/usr/bin", "%{_bindir}"), | ||
("/usr/local/lib64", "%{_libdir}"), | ||
("/usr/lib64", "%{_libdir}"), | ||
("/usr/local/libexec", "%{_libexecdir}"), | ||
("/usr/libexec", "%{_libexecdir}"), | ||
("/usr/local/lib", "%{_libdir}"), | ||
("/usr/lib", "%{_libdir}"), | ||
("/usr/local/share/info", "%{_infodir}"), | ||
("/usr/share/info", "%{_infodir}"), | ||
("/usr/local/share", "%{_datadir}"), | ||
("/usr/share", "%{_datadir}"), | ||
("/var/lib", "%{_sharedstatedir}"), | ||
("/var", "%{_localstatedir}"), | ||
("/etc", "%{_sysconfdir}"), | ||
] | ||
|
||
def installed(self, project_dir, spec, sack): | ||
""" Finds files that will be installed and | ||
appends them to files macro """ | ||
for item in list(project_dir.glob('**/*')): | ||
if item.is_file(): | ||
spec.files.add(("/" + str(item.relative_to(project_dir)), | ||
None, None)) | ||
|
||
def relative(_file, _relative): | ||
return "/" + str(_file.relative_to(_relative)) | ||
|
||
def append(_file, _spec): | ||
_spec.files.add((_file, None, None)) | ||
|
||
def find_n_replace(_file, f, *r): | ||
match = re.search("^" + f[0], _file) | ||
if match: | ||
return f[1] + _file[len(match.group(0)):] | ||
else: | ||
return find_n_replace(_file, *r) if r else _file | ||
|
||
def ite(_spec, _proj_dir, f, *r): | ||
if f.is_file(): | ||
append(find_n_replace(relative(f, _proj_dir), *self.MACROS), | ||
_spec) | ||
if r: | ||
ite(_spec, _proj_dir, *r) | ||
|
||
def iterate(_spec, _proj_dir, _glob): | ||
if _glob: | ||
ite(_spec, _proj_dir, *_glob) | ||
|
||
iterate(spec, project_dir, list(project_dir.glob('**/*'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters