def clean_junk_locks(self): for path, dirnames, filenames in walk_on_path(self.path): filenames = filenames or [] for dirname in dirnames: folder_path = join_paths(path, dirname) for filename in get_dir_filenames(folder_path): if not filename.startswith('.'): filenames.append(join_paths(dirname, filename)) for filename in filenames: filename = to_string(filename) if filename.startswith('.'): continue file_path = join_paths(path, filename) if '.' in filename: # Delete inactive positions locks binary = get_file_binary(file_path, mode='r') if binary: info = binary.split() if len(info) >= 2 and info[0] == DOMAIN_NAME and maybe_integer(info[1]): try: getpgid(int(info[1])) except OSError as error: if error.errno is errno.ESRCH: remove_file_quietly( file_path, retries=self.retries, retry_errno=self.retry_errno) else: # Clean locks wait list # Get last modified time, to check if file as been updated in the process modified_time = file_modified_time(file_path) if modified_time: binary = get_file_binary(file_path, mode='r') if binary: # Find alive locks keep_codes = binary.splitlines() for i, line in enumerate(keep_codes): info = line.split() if len(info) >= 2 and info[0] == DOMAIN_NAME and maybe_integer(info[1]): try: getpgid(int(info[1])) except OSError as error: if error.errno is errno.ESRCH: # Add empty line to keep position number keep_codes[i] = '' # Check if file as been updated in the process last_modified_time = file_modified_time(file_path) if last_modified_time and modified_time == last_modified_time: if not any(keep_codes): remove_file_quietly(file_path) else: with open(file_path, 'w') as f: f.write(NEW_LINE.join(keep_codes))
def validator(): last_update = file_modified_time(self.config_path) if self.last_update_time < last_update: self.last_update_time = last_update self.start_applications(debug=True) # Return sleep seconds return abs(self.validate_config_seconds or 15)
def __init__(self, config_path): self.config_path = config_path self.applications = [] self.validate_config_seconds = 15 self.start_applications() # Start thread for config ini validation self.last_update_time = file_modified_time(self.config_path) self.validate_config_update()
def _get_binary(self, path, expire=MARKER): if expire is MARKER: expire = self.expire if expire: modified_time = file_modified_time(path) if not modified_time: return None elif (modified_time + expire) < NOW_TIME(): self._delete_path(path) return None return get_file_binary(path, mode='rb', retries=self.retries, retry_errno=self.retry_errno)
def _contains(self, path, expire=MARKER): if expire is MARKER: expire = self.expire if expire: modified_time = file_modified_time(path) if not modified_time: return False if (modified_time + self.expire) < NOW_TIME(): self._delete_path(path) return False return isfile(path)