Ejemplo n.º 1
0
def _read_configs():
    global _commands

    _cmds = []
    _paths = get_all_files(_script_path_dir, filter=lambda x:os.path.basename(x)=='crontab')

    for _path in _paths:
        _cwd = os.path.dirname(_path)
        with open(_path, 'rb') as _handler:
            for _line in _handler:
                _line = _line.strip()
                if _line == '' or _line.startswith('#'):
                    continue
                
                _sp = _line.split()
                
                if len(_sp) < 6:
                    _logger.error('crontab file config error, path:%s, line:%s', _path, _line)
                    continue
                
                if not _validate_time_sequence(_sp[:5]):
                    _logger.error('crontab file config error, path:%s, line:%s', _path, _line)
                    continue

                _cmds.append({'time_sequence': _sp[:5], 'cmd': _sp[5:], 'cwd': _cwd})
    
    if _lock.acquire():
        try:
            _commands = _cmds
        finally:
            _lock.release()

    return _cmds
Ejemplo n.º 2
0
def _read_configs():
    global _commands

    _cmds = []
    _paths = get_all_files(_script_path_dir,
                           filter=lambda x: os.path.basename(x) == 'crontab')

    for _path in _paths:
        _cwd = os.path.dirname(_path)
        with open(_path, 'rb') as _handler:
            for _line in _handler:
                _line = _line.strip()
                if _line == '' or _line.startswith('#'):
                    continue

                _sp = _line.split()

                if len(_sp) < 6:
                    _logger.error(
                        'crontab file config error, path:%s, line:%s', _path,
                        _line)
                    continue

                if not _validate_time_sequence(_sp[:5]):
                    _logger.error(
                        'crontab file config error, path:%s, line:%s', _path,
                        _line)
                    continue

                _cmds.append({
                    'time_sequence': _sp[:5],
                    'cmd': _sp[5:],
                    'cwd': _cwd
                })

    if _lock.acquire():
        try:
            _commands = _cmds
        finally:
            _lock.release()

    return _cmds
Ejemplo n.º 3
0
 def _check():
     _has_changed = False
     _files = get_all_files(path, filter)
     _delete_files = []
     
     for _file in _files:
         _key = _file_list.get(_file, 0)
         _current_key = file_md5(_file) if content else int(os.path.getmtime(_file))
         if _key != _current_key:
             _file_list[_file] = _current_key
             _has_changed = True
         
         
     for _file in _file_list:
         if _file not in _files:
             _has_changed = True 
             _delete_files.append(_file)
             
     for _file in _delete_files:
         del _file_list[_file]
     
     if _has_changed:
         _logger.debug(_file_list)
         callback(*args, **kwargs)