Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Python] subprocess.call and ebuild
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
lemmingman
n00b
n00b


Joined: 20 May 2008
Posts: 37

PostPosted: Mon Mar 11, 2013 8:10 pm    Post subject: [Python] subprocess.call and ebuild Reply with quote

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
View user's profile Send private message
eyoung100
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1406

PostPosted: Mon Mar 11, 2013 8:21 pm    Post subject: Reply with quote

Take a look at 7.2
_________________
The Birth and Growth of Science is the Death and Atrophy of Art -- Unknown
Registerd Linux User #363735
Adopt a Post | Strip Comments| Emerge Wrapper
Back to top
View user's profile Send private message
lemmingman
n00b
n00b


Joined: 20 May 2008
Posts: 37

PostPosted: Mon Mar 11, 2013 10:45 pm    Post subject: Reply with quote

eyoung100 wrote:
Take a look at 7.2


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
View user's profile Send private message
dol-sen
Developer
Developer


Joined: 30 Jun 2002
Posts: 2503
Location: Richmond, BC, Canada

PostPosted: Tue Mar 12, 2013 1:35 am    Post subject: Reply with quote

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
View user's profile Send private message
eyoung100
Veteran
Veteran


Joined: 23 Jan 2004
Posts: 1406

PostPosted: Tue Mar 12, 2013 3:09 am    Post subject: Reply with quote

i was referring to f=open() which dolsen pointed you to while i was out.
_________________
The Birth and Growth of Science is the Death and Atrophy of Art -- Unknown
Registerd Linux User #363735
Adopt a Post | Strip Comments| Emerge Wrapper
Back to top
View user's profile Send private message
lemmingman
n00b
n00b


Joined: 20 May 2008
Posts: 37

PostPosted: Tue Mar 12, 2013 1:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum