Changeset 772

Show
Ignore:
Timestamp:
06/05/07 20:05:26 (6 years ago)
Author:
ggpolo
Message:

Added a python script to control start/stop multiplatform for Scheduler. Changed setup.py, BasePaths?.py and Paths.py to use directory share/scripts to hold this control script. You can start/stop Scheduler from GUI right now.

Location:
branch/ggpolo
Files:
3 added
7 modified

Legend:

Unmodified
Added
Removed
  • branch/ggpolo/config/umit.conf

    r625 r772  
    2121config_dir = config 
    2222docs_dir = docs 
     23scripts_dir = share/scripts 
    2324 
    2425[search] 
  • branch/ggpolo/setup.py

    r762 r772  
    6464sql_dir = os.path.join('share', 'umit', 'sql') 
    6565maemo_dir = os.path.join("maemo") 
     66scripts_dir = os.path.join('share', 'umit', 'scripts') 
    6667 
    6768dist_config_dir = os.path.join('dist', config_dir) 
     
    151152                [os.path.join('config', 'tl.conf')] + 
    152153                [os.path.join('config', 'tl_colors_evt_std.conf')] + 
     154                [os.path.join('config', 'scheduler-schemas.conf')] + 
    153155                glob(os.path.join('config', '*.xml'))+ 
    154156                glob(os.path.join('config', '*.txt'))), 
     
    156158               # UmitDB sql 
    157159               (sql_dir, glob(os.path.join("umitDB/sql", '*.sql'))), 
     160 
     161               # Scheduler script 
     162               (scripts_dir, [os.path.join('share', 'scripts',  
     163                                           'scheduler_control.py')]), 
    158164 
    159165               (misc_dir, glob(os.path.join('misc', '*.dmp'))),  
     
    254260        parser.set(sec, "pixmaps_dir", os.path.join(self.install_data,  
    255261                                                    pixmaps_dir)) 
     262        parser.set(sec, "scripts_dir", os.path.join(self.install_data, 
     263                                                    scripts_dir)), 
    256264        parser.set(sec, "icons_dir", os.path.join(self.install_data, icons_dir)) 
    257265        parser.set(sec, "locale_dir", os.path.join(self.install_data,  
  • branch/ggpolo/umitCore/BasePaths.py

    r748 r772  
    4848                  umit_opt = 'umit.opt', 
    4949                  pixmaps_dir = os.path.join('share', 'pixmaps'), 
     50                  scripts_dir = os.path.join('share', 'scripts'), 
    5051                  i18n_dir = os.path.join('share','locale'), 
    5152                  i18n_message_file = 'umit.mo', 
     
    6667                  tl_conf = "tl.conf", 
    6768                  tl_colors_std = "tl_colors_evt_std.conf", 
     69                   
     70                  # scheduler 
     71                  sched_schemas = "scheduler-schemas.conf", 
     72                  sched_control = "scheduler_control.py", 
    6873 
    6974                  services = "nmap-services", 
  • branch/ggpolo/umitCore/Paths.py

    r748 r772  
    3939                        "config_dir", 
    4040                        "misc_dir", 
    41                         "docs_dir"] 
     41                        "docs_dir", 
     42                        "scripts_dir"] 
     43    
     44    scripts_files_list = ["sched_control"] 
    4245     
    4346    config_files_list = ["config_file", 
     
    5255                         "tl_conf", 
    5356                         "tl_colors_std", 
     57                         "sched_schemas", 
    5458                         "umit_version"] 
    5559     
     
    6165    misc_files_list = ["services_dump", 
    6266                       "os_dump", 
    63                        "os_classification"] 
     67                       "os_classification", 
     68                       "sched_running"] 
    6469     
    6570    other_settings = ["nmap_command_path"] 
     
    125130                return return_if_exists(os.path.join(self.config_parser.get(self.paths_section, "misc_dir"), 
    126131                                                     base_paths[name])) 
    127          
     132            elif name in self.scripts_files_list: 
     133                return return_if_exists(os.path.join(self.config_parser.get(self.paths_section, "scripts_dir"), base_paths[name])) 
     134 
    128135            try: 
    129136                return self.__dict__[name] 
     
    172179    copy_config_file("tl.conf", main_dir, user_dir) 
    173180    copy_config_file("tl_colors_evt_std.conf", main_dir, user_dir) 
     181    copy_config_file("scheduler-schemas.conf", main_dir, user_dir) 
    174182    copy_config_file("wizard.xml", main_dir, user_dir) 
    175183 
  • branch/ggpolo/umitCore/Scheduler.py

    r770 r772  
    3333from umitCore.SendMail import send_mail 
    3434from umitCore.Paths import Path 
     35from umitCore.BasePaths import base_paths 
    3536from umitDB.xmlstore import XMLStore 
    3637 
     
    3940    umitdb_ng = Path.umitdb_ng 
    4041except: 
    41     from umitCore.Paths import Path 
    4242    Path.set_umit_conf(join(split(__file__)[0], 'config', 'umit.conf')) 
    4343 
     
    391391running_scans = { } 
    392392 
    393 def stop(): 
    394     """ 
    395     Clean temp files used by running scans. 
    396     """     
    397     for running, opts in running_scans.items(): 
    398         print "Cleaning up scan \"%s\"" % opts[3] 
    399         scan = opts[0] 
    400         scan.close() # delete temporary files 
    401          
    402  
    403 def run(schema_file=None): 
     393def start(schema_file=None): 
    404394    """ 
    405395    Run scheduler forever. 
    406396    """ 
    407397    if not schema_file: 
    408         print "Get file from umitCore.Path" 
    409         print "Not working yet" 
    410         sys.exit(0) 
     398        schema_file = Path.sched_schemas 
    411399 
    412400    next_time = calc_next_time() 
    413401 
    414402    s = Scheduler(schema_file) 
    415  
     403     
    416404    scount = 0 
    417405    while 1: # run forever and ever ;) 
     
    419407 
    420408        if current_time < next_time: 
    421            time.sleep(next_time - current_time + .1) 
     409            time.sleep(next_time - current_time + .1) 
    422410 
    423411        # check if time has changed by more than two minutes (clock changes) 
     
    475463                scount -= 1 
    476464                del running_scans[running] 
    477  
     465             
    478466        next_time += 60 
    479467 
     468def stop(): 
     469    """ 
     470    Stop Scheduler. 
     471    """ 
     472    #try: 
     473    #    os.remove(os.path.split(Path.config_file)[0] + "/schedrunning") 
     474    #except OSError, e: # scheduler wasnt running probably. 
     475    #    print e 
     476    #    sys.exit(0) 
     477     
     478    for running, opts in running_scans.items(): 
     479        print "Cleaning up scan \"%s\"" % opts[3] 
     480        scan = opts[0] 
     481        scan.close() # delete temporary files 
    480482 
    481483if __name__ == "__main__": 
    482     try: 
    483         run('schema-sample.conf') 
    484     except KeyboardInterrupt: 
    485         stop() 
    486  
     484    cmds = {"start":start(), 
     485            "stop":stop() 
     486           } 
     487    cmds[sys.argv[1]] 
  • branch/ggpolo/umitCore/SendMail.py

    r770 r772  
    2727 
    2828def send_mail(mail_from, mail_to, subject, text, f_attach, server="localhost", 
    29               authrequired=0, user='', password=''): 
     29              authrequired=False, user='', password=''): 
    3030    """ 
    3131    Send email with attachment. 
  • branch/ggpolo/umitGUI/MainWindow.py

    r767 r772  
    5252from umitDB.xmlstore import XMLStore 
    5353from umitInventory.viewer import InvViewer 
     54import umitCore.Scheduler as Scheduler 
     55import subprocess 
    5456 
    5557root = False 
     
    261263            ), 
    262264 
     265            # Scan Scheduler 
     266            ('Scheduler', None, _('_Scheduler'), None), 
     267             
     268            ('Sched Status', None, _('Scheduler S_tatus'),  
     269             None, _("View Scheduler Status"), 
     270             self._view_schedstat), 
     271             
    263272            # Top Level 
    264273            ('Help', None, _('_Help'), None), 
     
    312321            <menuitem action='Compare Results'/> 
    313322            <menuitem action='Search Scan'/> 
     323            <menu action='Scheduler'> 
     324                <menuitem action='Sched Status' /> 
     325            </menu> 
    314326            <menu action='Inventory'> 
    315327                <menuitem action='Add Scan Inv'/> 
     
    353365        self.ui_manager.insert_action_group(self.main_action_group, 0) 
    354366        self.ui_manager.add_ui_from_string(self.default_ui) 
     367 
     368    def _view_schedstat(self, action): 
     369        """ 
     370        View scheduler status and change its status if requested. 
     371        """ 
     372        controller = Path.sched_control 
     373        try: 
     374            open(os.path.split(Path.config_file)[0] + "/schedrunning", 'r') 
     375             
     376            cmd_button_text = _("Stop Scheduler") 
     377            status_text = _("running") 
     378            start = False 
     379        except IOError: 
     380            cmd_button_text = _("Run Scheduler") 
     381            status_text = _("stopped") 
     382            start = True 
     383         
     384        # Show dialog 
     385        dlg = HIGDialog(buttons=(cmd_button_text, gtk.RESPONSE_CLOSE, 
     386                                 gtk.STOCK_OK, gtk.RESPONSE_OK)) 
     387             
     388        alert = HIGEntryLabel("<b>%s</b>" % _("Scheduler Status")) 
     389             
     390        text = HIGEntryLabel(_('Scheduler is %s!' % status_text)) 
     391        hbox = HIGHBox() 
     392        hbox.set_border_width(5) 
     393        hbox.set_spacing(12) 
     394             
     395        vbox = HIGVBox() 
     396        vbox.set_border_width(5) 
     397        vbox.set_spacing(12) 
     398         
     399        if start: 
     400            image = gtk.Image() 
     401            image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG) 
     402            hbox.pack_start(image) 
     403         
     404        vbox.pack_start(alert) 
     405        vbox.pack_start(text)         
     406        hbox.pack_start(vbox) 
     407             
     408        dlg.vbox.pack_start(hbox) 
     409        dlg.vbox.show_all() 
     410             
     411        response = dlg.run() 
     412        dlg.destroy() 
     413             
     414        if response == gtk.RESPONSE_CLOSE: 
     415            if start: 
     416                subprocess.Popen([sys.executable, controller, 'start']) 
     417            else: 
     418                subprocess.Popen([sys.executable, controller, 'stop']) 
    355419 
    356420    def _view_inv(self, action):