Update of /cvsroot/freevo/freevo/WIP/Thomas
In directory sc8-pr-cvs1:/tmp/cvs-serv19562
Added Files:
commands.py
Log Message:
Initial Import of Mike Ruelles commands plugin. I will try to integrate
and maintain it for now.
--- NEW FILE: commands.py ---
#if 0 /*
# -----------------------------------------------------------------------
# commands.py - a simple plugin to run arbitrary commands from a directory.
# it determines success or failure of command based on its
# exit status.
# -----------------------------------------------------------------------
# $Id: commands.py,v 1.1 2003/07/06 23:22:04 the_krow Exp $
#
# Notes: add the following to local_conf.py
# plugin.activate('commands', level=45)
# COMMANDS_DIR = '/usr/local/freevo_data/Commands'
#
# Todo: possibly add an action to display logs.
# echo of output of command to screen.
# -----------------------------------------------------------------------
# $Log: commands.py,v $
# Revision 1.1 2003/07/06 23:22:04 the_krow
# Initial Import of Mike Ruelles commands plugin. I will try to integrate
# and maintain it for now.
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2003 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------------------------------------------------------- */
#endif
#python modules
import os, popen2, fcntl, select, time
#freevo modules
import config
import menu
import rc
from gui.AlertBox import AlertBox
from gui.AlertBox import PopupBox
import plugin
from item import Item
#import skin
import util
#get the sinfletons so we can add our menu and get skin info
#skin = skin.get_singleton()
menuwidget = menu.get_singleton()
TRUE = 1
FALSE = 0
# This is the class that actually runs the commands. Eventually
# hope to add actions for different ways of running commands
# and for displaying stdout and stderr of last command run.
class CommandItem(Item):
def makeNonBlocking(self, fd):
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
def getCommandOutput(self, command, outputfile, erroutputfile):
child = popen2.Popen3(command, 1) # capture stdout and stderr from command
child.tochild.close() # don't need to talk to child
outfile = child.fromchild
outfd = outfile.fileno()
errfile = child.childerr
errfd = errfile.fileno()
self.makeNonBlocking(outfd) # don't deadlock!
self.makeNonBlocking(errfd)
outeof = erreof = 0
while 1:
ready = select.select([outfd,errfd],[],[]) # wait for input
if outfd in ready[0]:
outchunk = outfile.read()
if outchunk == '': outeof = 1
outputfile.write(outchunk)
if errfd in ready[0]:
errchunk = errfile.read()
if errchunk == '': erreof = 1
erroutputfile.write(errchunk)
if outeof and erreof: break
select.select([],[],[],.1) # give a little time for buffers to fill
err = child.wait()
if (os.WIFEXITED(err)):
outputfile.write('process exited with status ' + str(os.WEXITSTATUS(err)))
if (os.WIFSTOPPED(err)):
outputfile.write('process ws stopped with signal ' +
str(os.WSTOPSIG(err)))
if (os.WIFSIGNALED(err)):
outputfile.write('process terminated with signal ' + str(os.WTERMSIG(err)))
return err
def actions(self):
"""
return a list of actions for this item
"""
items = [ ( self.flashpopup , 'Run Command' ) ]
return items
# 1) make running popup
# 2) run command (spawn and then get exit status)
# 3) figure out success/failure status (pick correct msg and icon)
# 4) dispose running popup
# 5) make new alert popup with messages
def flashpopup(self, menuw=None):
popup_string="Running Command..."
pop = PopupBox(text=popup_string)
pop.show()
print self.cmd
myout = open(os.path.join(config.LOGDIR,'command_stdout.log'), 'wb')
myerr = open(os.path.join(config.LOGDIR,'command_stderr.log'), 'wb')
status = self.getCommandOutput(self.cmd, myout, myerr)
myout.close()
myerr.close()
print status
icon=""
message=""
if status:
icon='bad'
message='Command Failed'
else:
icon='ok'
message='Command Completed'
pop.destroy()
pop = AlertBox(text=message)
pop.show()
# this is the item for the main menu and creates the list
# of commands in a submenu.
class CommandMainMenuItem(Item):
def actions(self):
"""
return a list of actions for this item
"""
items = [ ( self.create_commands_menu , 'commands' ) ]
return items
def create_commands_menu(self, arg=None, menuw=None):
command_items = []
for command in os.listdir(config.COMMANDS_DIR):
cmd_item = CommandItem()
cmd_item.name = command
cmd_item.cmd = os.path.join(config.COMMANDS_DIR, command)
command_items += [ cmd_item ]
if (len(command_items) == 0):
command_items += [menu.MenuItem('No Commands found',
menuwidget.goto_prev_page, 0)]
command_menu = menu.Menu('Commands', command_items,
reload_func=menuwidget.goto_main_menu)
rc.app(None)
menuwidget.pushmenu(command_menu)
menuwidget.refresh()
# our plugin wrapper, just creates the main menu item and adds it.
class PluginInterface(plugin.MainMenuPlugin):
def items(self, parent):
item = CommandMainMenuItem()
item.name = 'Commands'
item.parent = parent
return [ item ]
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog