def safe_unlink(path): try: unlink(path) except OSError, e: if e.errno != ENOENT: raise def safe_float(s): try: return float(s) except ValueError: return 0.0 def _basearchive_name(config_name): return path(_basedir) / config_name + '.tgz' def _timestamp_name(config_name): return _basearchive_name + '.timestamp' def _basearchive_needs_updating(config_name): timestamp_file = _timestamp_name(config_name) if timestamp_file.access(R_OK): timestamp = safe_float(timestamp_file.bytes()) cur_time = time() return timestamp + _update_timeout < cur_time return True def _gen_basearchive(pb_options): if _run(pb_options): timestamp.write_text(str(time())) return True else: safe_unlink(basearchive) def _prepare_basearchive(config_name): basearchive = _basearchive_name(config_name) timestamp = _timestamp_name(config_name) if basearchive.exists(): if _basearchive_needs_updating(config_name): pb = _get_args(config_name, '--update') return _gen_basearchive(pb) else: return True else: pb = _get_args(config_name, '--create') return _gen_basearchive(pb)