def contents(path): path = lib.normalized_path_relative_to_toolkit(path) if not os.path.exists(path): return None with async.current_call().io_lock: with open(path, 'rb') as file: return file.read()
def hash(path): path = lib.normalized_path_relative_to_toolkit(path) if not os.path.exists(path) or not os.path.isfile(path): return None with async.current_call().io_lock: with open(path, 'rb') as file: return hashlib.sha1(file.read()).hexdigest()
def write(path, data): path = lib.normalized_path_relative_to_toolkit(path) with async.current_call().io_lock: with open(path, 'wb') as file: if isinstance(data, unicode): file.write(data.encode('utf8')) else: file.write(data)