0

I want to use some math functions in a gDesklets applet, however, I can't import math in the script. I have googled but got nothing, except this similar post, yet unanswered.

I've tried to import at run time, but __import__ doesn't work:

name '__import__' is not defined                                                     
/usr/lib/gdesklets/Displays/Clock/clock.display                                      
    1
    2 #
>   3 math = __import__('math')

and neither could eval() work:

name 'eval' is not defined                                                           
/usr/lib/gdesklets/Displays/Clock/clock.display                                      
    1
    2 #
>   3 math = eval('__import__("math")')
Lenik
  • 18,830

1 Answers1

0

gDesklets is designed to be safe, so functions as import, eval, exec, etc., are disabled due to security reasons. To force enable these functions, you should change the source code:

/usr/lib/gdesklets/scripting/Script.py:

  ...
  self.__environment["str"] = str
  self.__environment["sum"] = sum
  ...
+ self.__environment["__import__"] = __import__
+ self.__environment["eval"] = eval
  ...

(+) Added these two lines, functions __import__ and eval will then be available in the user scripts.

Lenik
  • 18,830