473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Wait for a system command executed in the background

Hello
I am new to python and I am really a bad programmer...

As a linux user, I use quodlibet for listening to music. Quodlibet
allows me to write plugins in python.

I am trying to write a plugins to burn a playlist by using cdrecord, and
this either in dao or tao mode.

The basic of this plugin is the following:

- make a temp directory
- convert the songs in my playlist into wave files in the temp directory
using mplayer and renaming them with 3 digits number so that the order
of my playlist is conserved
- normalize the wave files
- burn the cd
- delete the temp directory.
At the time, I have a working solution (not fully developped by
myself...), but in this solution os.system is used to start the
different shell commands and the commands do not have a & at the end.
Therefore during the whole execution of the plugin, quodlibet is not
responsive.

What I would like to is program the whole such that I can use & at the
end of the shell commands and each command to be executed one after the
other! (I tried to put & simply at the end of each shell command with
the result that each where started at the same time)

Here is the plugin:

################################################## #########################
import os, string, re
import util
import sys
import shutil
from qltk import ErrorMessage
from shutil import copy
from plugins.songsmenu import SongsMenuPlugin

class _Base(SongsMenuPlugin):
PLUGIN_ICON = 'gtk-cdrom'
PLUGIN_VERSION = '0.1'

# XXX : pb potentiel: si deux utilisateurs utilisent ce plugin
# en meme temps, ils vont se marcher sur les pieds...
destdir = "/tmp/cd_QL"

convert_cmd = "mplayer -ao pcm:file=%(dest)s %(source)s"
normalize_cmd = "normalize -m %(path)s/*.wav"
burn_cmd = "cdrecord -v -eject %(flags)s -pad -audio
%(path)s/*.wav"
burn_flags = ''

def plugin_songs(self, songs):
if not self.check_mplayer():
return

self.setup()
try:
try:
for num, song in enumerate(songs):
self.makewav(song, num)
self.normalize()
self.burn()
except Exception, e:
ErrorMessage(
None,
"Unknown error",
"An error occured while processing files:\n%s." % e
).run()
finally:
self.teardown()

def check_mplayer(self):
if not util.iscommand("mplayer"):
ErrorMessage(
None,
"Mplayer not found",
"Mplayer is used to convert files in wave files."
).run()
return False
return True

def setup(self):
os.mkdir(self.destdir)

def makewav(self, song, num):
source = song['~filename'].replace(" ", "\
").replace("'","\\'")
dest = os.path.join(self.destdir, "%03d.wav" % num)
cmd = self.convert_cmd % dict(source=source, dest=dest)
os.system(cmd)

def normalize(self):
os.system(self.normalize_cmd % dict(path=self.destdir))

def burn(self):
flags = self.burn_flags
cmd = self.burn_cmd % dict(path=self.destdir, flags=flags)
os.system(cmd)

def teardown(self):
shutil.rmtree(self.destdir)
class DAO(_Base):
PLUGIN_ID = 'Burn CD w/o blanks'
PLUGIN_NAME = _('Burn CD w/o blanks')
PLUGIN_DESC = 'Burn CD w/o blanks.'
burn_flags = '-dao'
class TAO(_Base):
PLUGIN_ID = 'Burn CD with blanks'
PLUGIN_NAME = _('Burn CD with blanks')
PLUGIN_DESC = 'Burn CD with blanks.'

# on exporte seulement ces deux classes
__all__ = ['DAO', 'TAO']

################################################## ###########################

and yeah, please consider that I am new to python and do understand
something to the thread!
Thanks in advance

--
Brice
Arch Linux (Linux user nb. 372699)
-----
"Unix IS user friendly, it is just selective about who his friends are"
Nov 5 '06 #1
1 1650
On 2006-11-05, Dennis Lee Bieber <wl*****@ix.netcom.comwrote:
On Sun, 5 Nov 2006 18:32:39 +0100, Brice
<mealier_brice@NO_SPAM_yahoo.frdeclaimed the following in
comp.lang.python:

>>
At the time, I have a working solution (not fully developped by
myself...), but in this solution os.system is used to start the
different shell commands and the commands do not have a & at the end.
Therefore during the whole execution of the plugin, quodlibet is not
responsive.
Might it not be easier to just write each of those commands to a
temporary file, then at the end submit that file as a shell script that
runs in the background? {Maybe the last command should be one the
deletes the file itself?}
At the time being I don't see other possible solution. Let's see if
someone else's got an idea.

Thx

--
Brice
Arch Linux (Linux user nb. 372699)
-----
"Unix IS user friendly, it is just selective about who his friends are"
Nov 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chang LI | last post by:
I tried to launch "python.exe test.py" in another program. After the launch the console was showed and exited on Windows. I want the console stay there. Is there a Python statement to wait an event...
2
by: Rasmus Grøndahl Olsen | last post by:
I have tried to write a wait function but it seems like it will not brake the while loop. I tried two different solutions. Can anyone tell me what I am doing wrong, and come with another...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
12
by: Perecli Manole | last post by:
I am having some strange thread synchronization problems that require me to better understand the intricacies of Monitor.Wait/Pulse. I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock...
5
by: chenthil | last post by:
In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other...
5
by: Deepak | last post by:
I am programing a ping application which pings various centers . I used timer loop and it pings one by one. Now when i finish pinging one center it should wait for the ping_completed function to...
16
by: Anonymous User | last post by:
When i use system() it always get return code 11 and the command is not executed regardless of the command used. Does anyone know what is with it? Environment is Linux, glibc and gcc. Regards,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.