-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpm --eval "%{lua:rpm.interactive()}" does not immediately print the output #1215
Comments
This happens because you're in a macro expansion, so all the output is collected and returned to the macro engine. |
Can I do anything to have the interneter not in the macro expansion mode?
|
This gets the job done: from ctypes import cdll, c_char_p
librpmio = cdll.LoadLibrary("librpmio.so.9")
librpmio.rpmluaRunScript(None, c_char_p(b"rpm.interactive()"), None) |
Ouch 🤣 The interactive interpreter was added years before my time, but as far as I can recall, you're the first person ever to try actually using it. There may be some resident fauna there... 🪲 🐛 |
I have it all figured out. Blog post coming. Would you consider adding something like the above to rpm itself? |
If by "something like the above" you mean something that allows actual interactive experience, sure 😅 |
I meant something a bit more sophisticated. I have so far: #!/usr/bin/python3
import sys
from ctypes import cdll, c_char_p
librpmio = cdll.LoadLibrary("librpmio.so.9")
adjust_path = b"""
if os.getenv("LUA_PATH") then
package.path = os.getenv("LUA_PATH") .. ";" .. package.path
end
"""
# first argument is an "rpmlua" pointer, but uses global one when NULL
# second argument is code
# third argument is "name", used in errors, reasonable default when NULL
librpmio.rpmluaRunScript(None, c_char_p(adjust_path), None)
if len(sys.argv) > 1:
sys.argv[-1] = '/dev/stdin' if sys.argv[-1] == '-' else sys.argv[-1]
# first argument as above, second argument is path
librpmio.rpmluaRunScriptFile(None, c_char_p(sys.argv[-1].encode("utf-8")))
else:
librpmio.rpmluaRunScript(None, c_char_p(b"rpm.interactive()"), None) |
I think it could be enough if the documentation give more reasonable example such as:
Which provides expected output:
Or IDK what else one could be interested. |
Or if there was a way to flush to the output the content collected by the macro engine .... |
Adding a native way to flush the output shouldn't be hard. This is code that for all practical purposes nobody has touched in 16 years so it's not surprising if its a bit rusty and squeaky... |
Here is my blog post about how to get a nicer console https://eng.hroncok.cz/2020/05/14/ilua-rpm-console |
Wonderfully weird stuff 😄 |
Just a word of caution: rpmluaRunScript() and rpmluaRunScriptFile() are not considered public API and are not available in the public headers on C side, although the symbols are accessible in the ABI. So they are subject to change without further notice, although the likelihood of that happening doesn't seem that great, they've been exactly the way are since their inception 16 years ago... |
My script doesn't seem to see system defined macros. Do I need to call something explicitly to load them?
|
This gets the job done: librpm = cdll.LoadLibrary("librpm.so.9")
# Load general configuration (such as macros defined in standard places)
# Second argument is target platform, NULL is the default
librpm.rpmReadConfigFiles(librpm.rpmcliRcfile, None) |
Would you accept a pull request that that adds a Note that my C skills are rusty and my autotools skills are almost nonexistent, so I will probably need some guidance. |
Interactive should mean interactive, as in getting the results right away and not when exiting the process. The interactive mode hasn't gotten much attention along the way... Fixes: rpm-software-management#1215
Thanks. |
Added in #1867 , have fun 😄 I've readline history working locally too, just need to massage the autofoo stuff to acceptable state. |
I'd liek to use the interactive Lua console, however, it doesn't seem to be very... interactive.
So far so good...
Nothing...
Nothing...
Is there a way to receive the output as I put the input?
The text was updated successfully, but these errors were encountered: