Ticket #242 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

Pass environment variables to 'CommandAction'

Reported by: peter@… Owned by: jluebbe
Priority: minor Milestone: milestone5
Component: framework/oeventsd Version: milestone4
Keywords: Cc:

Description

We are currently unable to set environment variables for 'Command' actions defined in rules.yaml. This prevents oeventsd from executing any application that affects the display as the DISPLAY environment variable can't be set.

Change History

comment:1 Changed 4 years ago by peppertarts

Here is my patch. I've also added some error checking as oeventsd does some strange things if you ask it to execute a program that doesn't exist.

--- framework/framework/subsystems/oeventsd/fso_actions.py	2008-11-16 18:58:06.000000000 +0000
+++ framework/framework/subsystems/oeventsd/fso_actions.py	2009-05-14 02:13:59.000000000 +0100
@@ -266,14 +268,18 @@
 #=========================================================================#
     function_name = 'Command'
 
-    def __init__( self, cmd = 'true' ):
+    def __init__( self, cmd = 'true', env = { '':'' } ):
         self.cmd = cmd
+        self.env = env
 
     def trigger(self, **kargs):
         logger.info( "CommandAction %s", self.cmd )
 
-        # FIXME check return value
-        result = subprocess.call( shlex.split( self.cmd ) )
+        try:
+               result = subprocess.call( shlex.split( self.cmd ), env=self.env )
+	        logger.info("Command returned - %s", "Success" if result == 0 else "Failed")
+        except OSError, err:
+               logger.error( "Unable to execute command: %s", err )
 
     def __repr__(self):
         return "CommandAction(%s)" % self.cmd

comment:2 Changed 4 years ago by peppertarts

The reason I wanted to execute a program that affects X was to raise the Zhone window (Or any other window) when I received a call. I am doing this using wmctrl. It may be nice to include this app (It's in OE) and the below rule in future FSO images.

--- framework/etc/freesmartphone/oevents/rules.yaml
+++ framework/etc/freesmartphone/oevents/rules.yaml
@@ -47,6 +47,7 @@
     actions: 
              - RingTone()
              - SetDisplayBrightness("pcf50633_bl", 90)
+             - Command('wmctrl -a zhone', { 'DISPLAY':':0.0' })
 -
     while: CallStatus()
     filters: Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))

comment:3 Changed 3 years ago by stefan

  • Owner changed from jluebbe to mickey
  • Status changed from new to assigned

comment:4 Changed 3 years ago by jluebbe

  • Owner changed from mickey to jluebbe
  • Status changed from assigned to accepted

comment:5 Changed 3 years ago by jluebbe

  • Status changed from accepted to closed
  • Resolution set to fixed

This feature is now implemented.

Note: See TracTickets for help on using tickets.