1

BASH CODE:

source /proj/common/tools/repo/etc/profile.d/repo.sh
repo project init $branch
repo project sync
source poky/fnc-init-build-env build
bitbake -g $image

I converted this bash code into python(version 2.7). While executing my python code, I am getting repo command not found message.

PYTHON CODE:

os.system("source /proj/common/tools/repo/etc/profile.d/repo.sh")
os.system("repo project init " + branch)
os.system("repo project sync")
os.system("source poky/fnc-init-build-env build")
os.chdir("poky/build")
os.system("bitbake -g " + image)

ERROR MESSAGE:

sh: repo: command not found
sh: repo: command not found

I tried with subprocess.call(), I am getting the same error message.

3
  • Each os.system call invokes a unique shell. The os.system("source ... command had no effect on the next shell used with os.system(" repo .... Generally, you won't have luck here unless you reimplement repo.sh also. Commented Apr 24, 2018 at 4:37
  • Aside from the subshell problem, what is the point of this? If it's an exercise I'm afraid you have misunderstood. Converting to a Python script would involve zero invocations of os.system with the original source code, unless absolutely necessary. As in, no library exists to do this in Python, and writing one would be prohibitively expensive. Commented Apr 24, 2018 at 4:47
  • i tried with subprocess. subprocess.call(["source /proj/common/tools/repo/etc/profile.d/repo.sh", "repo project init " + branch, "repo project sync","source poky/fnc-init-build-env build","bitbake -g " + image], shell=True). It shows same error message Commented Apr 24, 2018 at 5:00

2 Answers 2

1

The problem is in this call:

os.system("source /proj/common/tools/repo/etc/profile.d/repo.sh")

The problem is that it runs source in a separate subshell and when the subshell exits all changes to the environment (cd commands if there are any and environment variables, most notable PATH) are gone.

My advice is to continue using the shell script you've used — just call it from Python with one os.system() call. Inside the shell script you can use source.

Sign up to request clarification or add additional context in comments.

3 Comments

When i execute the same command in python interactive mode, sometimes it is working. Sometimes it is not working. I don't know why.
Depends on the value of PATH that you've sent before starting Python.
when i execute "source poky/fnc-init-build-env build" in bash , directory will changed inside poky build (.i.e./data/users/dependencies/Lseries/poky/build). But when i execute in python,directory is not going inside poky/build.
0

You could at least use the full path for the repo command.

That would avoid the subshell to have to know where the repo command is (meaning have the right PATH set on each os.system call).

7 Comments

Can i know how to use that
In your regular shell, do which repo: that will give you the full path to use.
is there any way to perform this functionality using python code
@sabarishs a which equivalent done in python would be: stackoverflow.com/a/15133367/6309
Now i am getting error , when i execute " os.system("bitbake -g fss-image-full-l100")" . Because , directory is not going inside " poky/build". Please help me in solving this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.