From cd4b4215ccdece0b7edb935cec00eb3f47dcef8d Mon Sep 17 00:00:00 2001 From: Miro HronĨok Date: Feb 11 2021 00:56:03 +0000 Subject: Add rpmlua See https://eng.hroncok.cz/2020/05/14/ilua-rpm-console --- diff --git a/rpmlua b/rpmlua new file mode 100755 index 0000000..081839a --- /dev/null +++ b/rpmlua @@ -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)