Changeset 1535

Show
Ignore:
Timestamp:
04/23/08 11:34:30 (23 months ago)
Author:
JensDiemer
Message:
  • autoamtic plugin menu:
  • first updates for show_internals (but only "system_info" updated)
Location:
trunk/pylucid
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/plugins_internal/show_internals/show_internals.py

    r1154 r1535  
    2828 
    2929class show_internals(PyLucidBasePlugin): 
    30     def link( self ): 
    31         return '<a href="%smenu">show_internals</a>' % self.URLs["action"] 
    32  
    33     #_______________________________________________________________________ 
    34  
    35     def lucidTag(self): 
    36 #        url = self.URLs.actionLink("menu") 
    37         url = "FIXME" 
    38         self.response.write('<a href="%s">show internals</a>' % url) 
    3930 
    4031    def menu(self): 
    41         self.response.write( 
    42             "<h4>show internals <small>(%s)</small></h4>" % \ 
    43                                                         __version__.strip("$ ") 
    44         ) 
    45         self.response.write(self.module_manager.build_menu()) 
     32        self.build_menu() 
    4633 
    4734    #_______________________________________________________________________ 
     
    195182        """ Allgemeine System Informationen """ 
    196183        self.menu() 
    197         from PyLucid.buildin_plugins.show_internals.system_info \ 
     184        from PyLucid.plugins_internal.show_internals.system_info \ 
    198185                                                            import SystemInfo 
    199         s = SystemInfo(self.request, self.response) 
     186        s = SystemInfo(self.context, self.response) 
    200187        s.display_all() 
    201188 
  • trunk/pylucid/PyLucid/plugins_internal/show_internals/show_internals_cfg.py

    r1103 r1535  
    2929        "menu_description"  : "System Info", 
    3030    }, 
    31     "colubrid_debug": { 
    32         "must_login"        : True, 
    33         "must_admin"        : True, 
    34     }, 
    35     "session_data": { 
    36         "must_login"        : True, 
    37         "must_admin"        : True, 
    38         "menu_section"      : "system", 
    39         "menu_description"  : "Session data", 
    40     }, 
    41     "log_data": { 
    42         "must_login"        : True, 
    43         "must_admin"        : True, 
    44         "menu_section"      : "system", 
    45         "menu_description"  : "LOG data", 
    46     }, 
    47     "sql_status": { 
    48         "must_login"        : True, 
    49         "must_admin"        : True, 
    50         "menu_section"      : "SQL", 
    51         "menu_description"  : "SQL table status", 
    52     }, 
    53     "optimize_sql_tables": { 
    54         "must_login"    : True, 
    55         "must_admin"    : True, 
    56     }, 
    57     "python_modules": { 
    58         "must_login"        : True, 
    59         "must_admin"        : True, 
    60         "menu_section"      : "misc", 
    61         "menu_description"  : "Display all Python Modules", 
    62     }, 
    63     "debug_plugin_data": { 
    64         "must_login"        : True, 
    65         "must_admin"        : True, 
    66         "menu_section"      : "Modules/Plugins", 
    67         "menu_description"  : "Debug all installed module/plugin data", 
    68     }, 
    69     "module_info": { 
    70         "must_login"    : True, 
    71         "must_admin"    : True, 
    72     }, 
     31#    "session_data": { 
     32#        "must_login"        : True, 
     33#        "must_admin"        : True, 
     34#        "menu_section"      : "system", 
     35#        "menu_description"  : "Session data", 
     36#    }, 
     37#    "log_data": { 
     38#        "must_login"        : True, 
     39#        "must_admin"        : True, 
     40#        "menu_section"      : "system", 
     41#        "menu_description"  : "LOG data", 
     42#    }, 
     43#    "sql_status": { 
     44#        "must_login"        : True, 
     45#        "must_admin"        : True, 
     46#        "menu_section"      : "SQL", 
     47#        "menu_description"  : "SQL table status", 
     48#    }, 
     49#    "optimize_sql_tables": { 
     50#        "must_login"    : True, 
     51#        "must_admin"    : True, 
     52#    }, 
     53#    "python_modules": { 
     54#        "must_login"        : True, 
     55#        "must_admin"        : True, 
     56#        "menu_section"      : "misc", 
     57#        "menu_description"  : "Display all Python Modules", 
     58#    }, 
     59#    "debug_plugin_data": { 
     60#        "must_login"        : True, 
     61#        "must_admin"        : True, 
     62#        "menu_section"      : "Modules/Plugins", 
     63#        "menu_description"  : "Debug all installed module/plugin data", 
     64#    }, 
     65#    "module_info": { 
     66#        "must_login"    : True, 
     67#        "must_admin"    : True, 
     68#    }, 
    7369} 
  • trunk/pylucid/PyLucid/plugins_internal/show_internals/system_info.py

    r1154 r1535  
    2121 
    2222 
    23 import sys, os, locale 
    24  
     23import sys, os, locale, subprocess 
     24 
     25from PyLucid.tools.subprocess2 import Subprocess2 
    2526from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    2627 
     
    3132        self.PyLucid_info() 
    3233        self.system_info() 
     34        self.cmd_info() 
     35        self.proc_info() 
    3336        self.encoding_info() 
    3437        self.envion_info() 
    35         self.colubrid_debug_link() 
    3638 
    3739    #_________________________________________________________________________ 
     
    4345        self.response.write('<legend>PyLucid["URLs"]:</legend>') 
    4446        self.response.write("<pre>") 
    45         for k,v in self.URLs.items(): 
    46             self.response.write("%15s: '%s'\n" % (k,v)) 
    47         self.response.write("</pre>") 
    48         self.response.write("</fieldset>") 
    49  
    50         self.response.write('<fieldset id="system_info">') 
    51         self.response.write('<legend>self.i18n.debug():</legend>') 
    52         self.response.write("<pre>") 
    53         self.i18n.debug(response_out=True) 
     47 
     48        data = [(len(v), k, v) for k,v in self.URLs.items()] 
     49 
     50        max_len = max([len(k) for k in self.URLs]) 
     51        line = "%%%ss: '%%s'\n" % max_len 
     52 
     53        for _,k,v in sorted(data): 
     54            self.response.write(line % (k,v)) 
     55 
    5456        self.response.write("</pre>") 
    5557        self.response.write("</fieldset>") 
     
    6567            self.response.write("<dd>%s</dd>" % " - ".join( os.uname() )) 
    6668 
     69        try: 
     70            loadavg = os.getloadavg() 
     71            loadavg = ", ".join([str(round(i,2)) for i in loadavg]) 
     72            self.response.write("<dt>load average:</dt>") 
     73            self.response.write("<dd>%s</dd>" % loadavg) 
     74        except OSError: 
     75            # Not available 
     76            pass 
     77 
    6778        self.response.write("<dt>sys.version:</dt>") 
    6879        self.response.write("<dd>Python v%s</dd>" % sys.version) 
     
    7788        self.response.write("</dl>") 
    7889 
    79         #_____________________________________________________________________ 
    80  
    81         self.cmd_info( "uptime", "uptime" ) 
    82         self.cmd_info( "lokal Angemeldete Benutzer", "who -H -u --lookup" ) 
    83         self.cmd_info( "disk", "df -T -h" ) 
    84         self.cmd_info( "RAM", "free -m" ) 
     90 
     91 
     92    def proc_info(self): 
     93        """ 
     94        Dispaly some proc files 
     95        """ 
     96        files = ["/proc/meminfo", "/proc/stat", "/proc/loadavg"] 
     97 
     98        self.response.write("<h3>proc info</h3>") 
     99 
     100        self.response.write('<dl id="system_info">') 
     101        for proc_file in files: 
     102            self.response.write("<dt>'%s':</dt>" % proc_file) 
     103            try: 
     104                f = file(proc_file, "r") 
     105            except Exception, e: 
     106                self.response.write("<dd>Error: %s</dd>" % e) 
     107            else: 
     108                for line in f: 
     109                    self.response.write("<dd>%s</dd>" % line) 
     110                f.close() 
     111        self.response.write("</dl>") 
    85112 
    86113    #_________________________________________________________________________ 
     
    170197    #_________________________________________________________________________ 
    171198 
    172     def cmd_info(self, info, command, cwd="/"): 
    173         self.response.write( 
    174             '<fieldset id="system_info"><legend>%s:</legend>' % info 
    175         ) 
    176         try: 
    177             process = self.tools.subprocess2(command, cwd, 5) 
    178         except Exception,e: 
    179             self.response.write("Can't get: %s" % e) 
    180         else: 
    181             self.response.write("<pre>%s</pre>" % process.out_data) 
    182         self.response.write("</fieldset>") 
    183  
    184  
    185  
    186  
    187  
    188  
    189  
    190  
     199    def cmd_info(self): 
     200        """ 
     201        Use some commandline programms and display the output 
     202        """ 
     203        commands = ("uptime", "who -H -u --lookup", "df -T -h", "free -m") 
     204 
     205        for command in commands: 
     206            self.response.write( 
     207                """<fieldset><legend>'%s':</legend>""" % command 
     208            ) 
     209            try: 
     210                p = Subprocess2(command, 
     211                    stdout=subprocess.PIPE, 
     212                    shell = True, 
     213                    timeout = 1 
     214                ) 
     215            except Exception, e: 
     216                self.response.write("Error: %s" % e) 
     217            else: 
     218                if not p.killed: 
     219                    # read only if process ended normaly, otherwise it blocked! 
     220                    msg = "<pre>%s</pre>" % p.process.stdout.read() 
     221                else: 
     222                    msg = "Proecess was killed. Returncode: %s" % ( 
     223                        p.process.returncode 
     224                    ) 
     225                self.response.write(msg) 
     226 
     227            self.response.write("</fieldset>") 
     228 
     229 
     230 
     231 
     232 
     233 
     234 
     235 
  • trunk/pylucid/PyLucid/system/BasePlugin.py

    r1532 r1535  
    9898            ) 
    9999 
    100         context = { 
    101             "plugin_name": self.plugin_name, 
    102             "version": plugin_config.__version__, 
    103             "menu_data": menu_data, 
    104         } 
     100        self.context["PAGE"].title = "%s (%s)" % ( 
     101            self.plugin_name.replace("_", " "), plugin_config.__version__ 
     102        ) 
     103 
     104        context = {"menu_data": menu_data,} 
    105105 
    106106        # Change the internal_page and use them from "admin_menu" plugin.