Last active
October 15, 2021 15:14
-
-
Save hroncok/63c36381e2daa12446cb70c1a30bef2e to your computer and use it in GitHub Desktop.
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
#!/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 | |
# 4th and 5th arguments were added in RPM 4.17+ only, for passing options and arguments | |
librpmio.rpmluaRunScript(None, c_char_p(adjust_path), None, None, 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, None, None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment