View previous topic :: View next topic |
Author |
Message |
lemmingman n00b
Joined: 20 May 2008 Posts: 37
|
Posted: Mon Mar 11, 2013 8:10 pm Post subject: [Python] subprocess.call and ebuild |
|
|
Its been awhile since I've picked up my Python, so that makes this stumbling block that much more frustrating.
I have to rebuild manifests for multiple ebuilds and I thought it would be an excellent opportunity to dust off my Python skills.
Here are the contents of testdigest. I created this file using vi and hand typing the single line.
Code: | /usr/portage/app-emacs/emacs-jabber/emacs-jabber-0.8.0.ebuild |
And here is my script, oh yeah, Python 3.2.3
Code: | #!/usr/bin/python
import subprocess
for line in open('/home/euser/Desktop/testdigest'):
subprocess.call(['ebuild',line,'manifest'])
quit
|
The goal here is to have a file with all the .ebullds that require a new manifest made. Read them from the file using open() and call ebuild with the line from the file and then 'manifest' appended to the end of the line. Here is what I get when I run it.
Code: | euser@gentoo-VM ~/Desktop $ sudo ./test
Password:
euser@gentoo-VM ~/Desktop $ '/usr/portage/app-emacs/emacs-jabber/emacs-jabber-0.8.0.ebuild
' does not end with '.ebuild'. |
Of course it does end with ebuild. I've searched around for any issues calling ebuild from python, but can seem to find anything. My theory is that Python is adding a newline character to the end of the line it reads in and this is hosing up ebuild. I have also tried:
Code: | subprocess.Popen(['ebuild',line,"manifest"],universal_newlines=False) | to no avail. Any thoughts or ideas as to why it might be failing? |
|
Back to top |
|
|
eyoung100 Veteran
Joined: 23 Jan 2004 Posts: 1428
|
|
Back to top |
|
|
lemmingman n00b
Joined: 20 May 2008 Posts: 37
|
Posted: Mon Mar 11, 2013 10:45 pm Post subject: |
|
|
Thnaks for the response 'eyoung100'. I looked over 7.2, as you suggested. I think you were referring to the readline() method here? As I understand it, the example I gave uses the fastest most efficient iterator in Python. I may be mistaken, but my script is basically the same as the 4th example in 7.2.1.
I went ahead and added a few more lines to my input file. It now reads like this:
Code: | /usr/portage/app-emacs/emacs-jabber/emacs-jabber-0.8.0.ebuild
/usr/portage/app-doc/pms/pms-5.ebuild
/usr/portage/net-dns/mydns/mydns-1.2.8.31.ebuild
|
When I replace ebuild in my script with echo I get this:
Code: | #!/usr/bin/python
import subprocess
for line in open('/home/euser/Desktop/testdigest'):
subprocess.call(['echo',line])
quit
|
Code: | euser@gentoo-VM ~/Desktop $ ./test
/usr/portage/app-emacs/emacs-jabber/emacs-jabber-0.8.0.ebuild
/usr/portage/app-doc/pms/pms-5.ebuild
/usr/portage/net-dns/mydns/mydns-1.2.8.31.ebuild
|
So I am pretty sure the iteration piece is working right. The real problem is just getting ebuild to like my input. |
|
Back to top |
|
|
dol-sen Retired Dev
Joined: 30 Jun 2002 Posts: 2805 Location: Richmond, BC, Canada
|
Posted: Tue Mar 12, 2013 1:35 am Post subject: |
|
|
Try this Code: |
#!/usr/bin/python
import subprocess
with open('/home/euser/Desktop/testdigest') as f:
lines = f.read():
for line in lines.split("\n"):
if line and not line.startswith("#"):
subprocess.call(['ebuild',line,'manifest'])
quit |
_________________ Brian
Porthole, the Portage GUI frontend irc@freenode: #gentoo-guis, #porthole, Blog
layman, gentoolkit, CoreBuilder, esearch... |
|
Back to top |
|
|
eyoung100 Veteran
Joined: 23 Jan 2004 Posts: 1428
|
|
Back to top |
|
|
lemmingman n00b
Joined: 20 May 2008 Posts: 37
|
Posted: Tue Mar 12, 2013 1:34 pm Post subject: |
|
|
Thanks for the help guys. Brian, I think 'split' was the piece I was missing. I cant believe I forgot about that. |
|
Back to top |
|
|
|