You are not logged in.
Pages: 1
Hello all
When trying to write a python script, I realized that when I try to call makepkg command on a PKGBUILD in an inner file, for instance
makepkg package_name/PKGBUILD, I get an error saying
==> ERROR: PKGBUILD does not exist.
But when I change my current directory to the directory of PKGBUILD file,
cd package_name, and run
makepkg PKGBUILDI face no problems. So, is it true that I have to strictly be in the PKGBUILD file's directory to be able to call makepkg on it? If that is the case, how can I run
makepkg PKGBUILDafter downloading the package directory using python subprocess? Because using
subprocess.call("cd " + package_file_name, shell=True)does not do anything at all.
Thanks!
Last edited by huzo11 (2018-11-14 07:55:58)
Be nice and live for others.
https://prismatically.blog
Offline
-p <buildscript>
Read the package script buildscript instead of the PKGBUILD
default; see PKGBUILD(5). The buildscript must be located in the
directory makepkg is called from.Offline
Similarly, for the Python part of the question, "RTFM" would also help, as would a better understanding of processes. Every process has a current working directory. This is abbreviated as "cwd". For example, you can find the working directory of process $pid in /proc/$pid/cwd. The various Python subprocess methods also have an optional parameter with this name.
Because using
subprocess.call("cd " + package_file_name, shell=True)does not do anything at all.
That starts a shell as a subprocess, which inherits the cwd of the parent (the Python interpreter). The shell executes the cd command, changing the cwd of its own process, and then exits (no other shell commands left to execute). Then the Python script continues, but its cwd was not affected by any changes in the child process, so if you make a separate subprocess.call for makepkg, that would still be in the "outer directory".
You could also change the cwd of the Python process with os.chdir() (and query it with os.getcwd()), but check out the cwd parameter for subprocess methods first.
Offline
-p <buildscript> Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.
If this means that -p allows me to do what I want, I do get an error "option requires an argument -- 'p'". Else, too bad I can't do it. Thanks!
Be nice and live for others.
https://prismatically.blog
Offline
The description for -p means that makepkg requires you to change the working directory to the location of your PKGBUILD. Raynman already gave you the correct hint:
subprocess.call(..., cwd="package_dir")https://docs.python.org/3/library/subprocess.html
Last edited by progandy (2018-11-14 09:47:44)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
Allan wrote:-p <buildscript> Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.If this means that -p allows me to do what I want, I do get an error "option requires an argument -- 'p'". Else, too bad I can't do it. Thanks!
Your comment is completely unrelated to the description of the "-p" option. Please read the description rather than simply throwing command-line switches at the metaphorical wall like spaghetti in an attempt to see what sticks.
Particularly, since descriptions exist because they're meant to be read. It does no one any good at all to say things if you just ignore them.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Also using the comman `makepkg PKGBUILD` makes little sense. It will work under the proper conditions, but only because "PKGBUILD" in that command is essentially ignored. This would be clear from a reading of even the first line of the man page.
The -p flag allows you to specify a file named something other that PKGBUILD, but as the very short description clearly and concisely notes, it must still be in the current working directory that makepkg is called from.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Are you sure that you're pointing to the pkgbuild file properly? Can you try editing your script to read "~/package_name/PKGBUILD" and run to see if that works?
Offline
*Headdesk*
AlienofOne, read the thread, or the man page, before posting. That is nonsensical advice.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
-p <buildscript>
Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.
If you want to run your shell command from specific directory there is way you have to call your command from Python:
subprocess.Popen("ls", cwd="/working/directory")But running cd shell command will not work because it is shell internal command
Last edited by sincomil (2018-11-14 14:57:57)
Offline
Thank you guys.
subprocess.call(... , cwd="dir") was exactly what I was looking for! ![]()
Be nice and live for others.
https://prismatically.blog
Offline
manpage wrote:-p <buildscript>
Read the package script buildscript instead of the PKGBUILD default; see PKGBUILD(5). The buildscript must be located in the directory makepkg is called from.If you want to run your shell command from specific directory there is way you have to call your command from Python:
subprocess.Popen("ls", cwd="/working/directory")But running cd shell command will not work because it is shell internal command
Not only did someone already explain above, how to use subprocess with cwd properly, you're also wrong that cd won't work. In fact, someone explained above, why it *does* work.
subprocess.Popen supports a shell=True parameter which will make the string run inside the /bin/sh shell and thus cd works fine. It's the wrong way to do it, but it does work...
However, as (again) explained above, if you launch a subprocess, then use it to cd inside the subprocess, then immediately end the subprocess, it quite obviously doesn't do anything meaningful. It's not because it's an internal command. if it was because it's an internal command, then the OP would not have gotten "does not do anything at all", the OP would have gotten:
>>> import subprocess
>>> subprocess.Popen(['cd'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.7/subprocess.py", line 769, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.7/subprocess.py", line 1516, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cd': 'cd'Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Pages: 1