Beispiel #1
0
 def test_store_timestamp(self):
     """Make sure we are storing (updating) the timestamp"""
     db = Worker('/tmp/pacha_test/pacha_test.db')
     db.insert('/tmp',None, None, timestamp=9997446874)
     db.closedb()
     watch = daemon.SingleRepository('/tmp')
     watch.store_timestamp(111)
     dbase = Worker('/tmp/pacha_test/pacha_test.db')
     repo = [i for i in dbase.get_repo('/tmp')]
     actual = repo[0][4]
     expected = u'111'
     self.assertEqual(actual, expected) 
Beispiel #2
0
def start(config=None, foreground=False, run_once=False):

    if config == None:
        config=ConfigMapper(DB_FILE).stored_config()

    if not foreground:
        log_path = config['log_path']
        log_enable = config['log_enable']
        if not log_enable or log_path is None:
            daemon = supay.Daemon(name='pacha', log=False, pid_dir=PID_DIR)
        if log_enable and log_enable:
            daemon = supay.Daemon(name='pacha', catch_all_log=log_path, pid_dir=PID_DIR)

        daemon.start()
        daemon_log.debug('Daemon started')

    while True:
        try:
            db = Worker(DB_FILE)
            daemon_log.debug('reading repos from database')
            repos = [i for i in db.get_repos()]
            db.closedb()
            freq = frecuency(config['frequency'])
            #### *** DVCS Support HERE *** ###
#            try:
#                master = config['master']
#                if master == 'True':
#                    hg.update(config['hosts_path'])
#                    daemon_log.debug('machine set to master')
#            except AttributeError, error:
#                pass
            for repo in repos:
                daemon_log.debug('looping over repos in db')
                repo_path = repo[1]
                if os.path.exists(repo_path): # catches a path no longer there
                    stat_check = SingleRepository(repo_path)
                    stat_check.synchronize()
                else:
                    pass
                    daemon_log.warning('path %s does not exist' % repo_path)
            if run_once:
                raise KeyboardInterrupt
            daemon_log.debug('daemon going to sleep for %s seconds' % freq)
            time.sleep(freq)

        except KeyboardInterrupt:
            print "Exiting from foreground daemon"
            sys.exit(0)

        except Exception, error:
            daemon_log.error('Fatal exception - daemon killed')
            daemon_log.error(error)
            sys.exit(1)