Add information about writting yourself rules, revert no_command changes

This commit is contained in:
nvbn
2015-04-17 17:01:30 +02:00
parent 1503dcf294
commit 1de9c5f77b
5 changed files with 82 additions and 16 deletions
+24
View File
@@ -1,7 +1,10 @@
from functools import wraps
import os
def which(program):
"""Returns `program` path or `None`."""
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
@@ -17,3 +20,24 @@ def which(program):
return exe_file
return None
def wrap_settings(params):
"""Adds default values to settings if it not presented.
Usage:
@wrap_settings({'apt': '/usr/bin/apt'})
def match(command, settings):
print(settings.apt)
"""
def decorator(fn):
@wraps(fn)
def wrapper(command, settings):
for key, val in params.items():
if not hasattr(settings, key):
setattr(settings, key, val)
return fn(command, settings)
return wrapper
return decorator