#79 Add rpmlua
Closed 2 years ago by churchyard. Opened 3 years ago by churchyard.
churchyard/rpmdevtools rpmlua  into  main

file added
+47
@@ -0,0 +1,47 @@ 

+ #!/usr/bin/python3

+ # Copyright (c) 2020-2021 Fedora Project

+ #

+ # This program is free software; you can redistribute it and/or

+ # modify it under the terms of the GNU General Public License

+ # as published by the Free Software Foundation; either version 2

+ # of the License, or (at your option) any later version.

+ # 

+ # This program is distributed in the hope that it will be useful,

+ # but WITHOUT ANY WARRANTY; without even the implied warranty of

+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ # GNU General Public License for more details.

+ # 

+ # You should have received a copy of the GNU General Public License

+ # along with this program; if not, write to the Free Software Foundation,

+ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

+ import sys

+ from ctypes import cdll, c_char_p

+ from ctypes.util import find_library

+ 

+ 

+ librpm = cdll.LoadLibrary(find_library("rpm"))

+ librpmio = cdll.LoadLibrary(find_library("rpmio"))

+ 

+ 

+ # Load general configuration (such as macros defined in standard places)

+ # Second argument is target platform, NULL is the default

+ librpm.rpmReadConfigFiles(librpm.rpmcliRcfile, None)

+ 

+ 

+ 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)

See https://eng.hroncok.cz/2020/05/14/ilua-rpm-console

I have not added it yet to Makefile.am. Let me know if I should.

Yeah, I think this would be fine to install by default.

rebased onto f258696c738ae2c78654bd63357d7f35816c7bcd

3 years ago

Can you help me with that?

Yeah, I can. I'll take a look tomorrow for this. :wine_glass:

So this is going to be a problem. librpm's soname will change depending on the host RPM release.

Can we change this to properly link to librpm and librpmio?

rebased onto cd4b421

3 years ago

Not sure "properly link" is what this is, but I've added calls to find_library.

Guys, fishing internal symbols out of librpmio is okay for a personal hack but NOT okay for "an official" tool such as it would be in rpmdevtools. These APIs are internal for a reason, and you're doing both us and the users a disservice by not respecting that. Please.

Right. My idea is that they are stable yet not official. How to proceed?

That they have been untouched for a long time doesn't mean much - they are getting incompatibly changed in 4.17 due to bunch of new developments. Not because of this, but despite it.

I can either open a ticket for RPM to provide "rpmlua" executable that does what this script does, or to put the necessary functions to the API. Which one is more likely?

I believe this is now coming in RPM itself, so we can close this, right?

Pull-Request has been closed by churchyard

2 years ago
Metadata
Changes Summary 1