2 # -*- coding: utf-8 -*-
6 Copyright 2004 Norman Köhring <nkoehring-at-web-dot-de>
11 This program and all of its modules are free software;
12 you can redistribute it and/or modify it under the terms of the
13 GNU General Public License as published by the Free Software Foundation;
14 either version 2 of the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 For more information read the file LICENSE
29 import sys, szstoolbox
30 from commands import getstatusoutput
31 from time import strftime,sleep,time
32 from os.path import exists as fexists
36 progname = 'Python SZS '
40 """ class for importing the modules and get there outputs
41 Usage: It should be enough to create an instance... """
44 """ initialize all the things in modules """
46 x = str(cfgM.read('modules')).strip().split(',')
48 msg.debug('Module: %s' % str(x), 3)
51 self.mods.append(__import__(mod, globals(), locals(), []))
53 msg.debug("Can't find %s. Maybe you dispelled it?" % mod, 2)
56 msg.debug("No modules to load.", 2)
71 lst[0] = lst[0].strip()
85 """ this class contains all function for the script initialization """
88 """ yes, also init needs an init! """
97 """ initialize the classes """
105 msg = szstoolbox.MSG()
106 cfg = szstoolbox.CFG('')
108 modules = moduleclass()
109 xtra = szstoolbox.XTRA()
114 """ initializes the arguments """
116 if len(sys.argv) >= 2:
117 if sys.argv[1] in ('-?','-h','--help'):
121 print 'No parameters, sorry...'
122 print '-?, -h or --help for help'
128 """ sets the variables """
134 welcome = cfgM.read('welcome').strip()
135 prog = [str(cfgM.read('prog_txt')).strip(),str(cfgM.read('prog_bar')).strip()]
136 if not fexists(prog[0].split(' ')[0]):
137 msg.debug(str(prog[0])+' doesn\'t not exists, switched it to `echo `',2)
140 msg.debug('Using '+str(prog[0])+' to display text',3)
142 if not fexists(prog[1].split(' ')[0]):
143 msg.debug(str(prog[1])+' doesn\'t not exists, switched it to `echo `',2)
146 msg.debug('Using \''+str(prog[1])+'\' to display bars',3)
148 seperator = cfg('global').read('seperator')
153 """ the main function: nothing special. it only runs the commands and maybe return the errors """
155 if 'welcome' in globals() and welcome <> '!NONE':
156 if time() - szstoolbox.starttime <= 3:
161 txtsnbars = modules.txtsnbars()
163 # for i,j in txtsnbars:
164 txts = seperator.join(txtsnbars[0]).strip()
165 bars = ','.join(txtsnbars[1]).strip(',')
167 cmdtxt = str(prog[0]+' \''+now+' '+txts+'\'')
168 cmdbar = str(prog[1]+' \''+bars+'\'')
170 error = getstatusoutput(cmdtxt)
172 error = getstatusoutput(cmdbar)
177 if __name__ == "__main__":
180 error_msg = 'noerror'
186 sleep(szstoolbox.interval)
187 except KeyboardInterrupt:
191 sys.exit("Terminated cause above error(s)") # eigentlich ist diese Zeile hirnlos :-S
195 # print 'Nr: '+str(error_nr)+' Msg:'+error_msg