paramiko
def setup_ssh(d_, username_, password_):
ssh_ = paramiko.SSHClient()
ssh_.load_system_host_keys()
ssh_.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_.connect(d_, username=username_, password=password_)
return ssh_
celery
proj
celery.py
from celery import Celery
from . import celeryconfig
app = Celery('tasks')
app.config_from_object(celeryconfig)
-
celeryconfig.py
:
BROKER_URL = 'redis://localhost:6379'
CELERYBEAT_SCHEDULE = {
‘every-ten-minute': {
'task': 'tasks.upload',
'schedule': crontab(minute='* /10', hour='9-18'),
'args': (),
},
}
CELERY_IMPORTS = ["proj.tasks"]
tasks.py
from proj.celery import app
@app.task(name='tasks.upload')
def upload():
pass
argparser
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--device")
parser.add_argument("-r", "--record", default=False)
args = parser.parse_args()
host = args.device
record = args.record
logging
base_dir = os.path.dirname(__file__)
with open(os.path.join(base_dir, 'logging.yaml')) as f:
d = yaml.load(f)
logging.config.dictConfig(d)
clogger = logging.getLogger('clogger')
flogger = logging.getLogger('flogger')
mlogger = logging.getLogger('mlogger')
logging.yaml
:
version: 1
formatters:
simpleFormater:
format: '%(asctime)s - %(levelname)s: %(message)s'
datefmt: '%Y/%m/%d %H:%M:%S'
handlers:
console:
class: logging.StreamHandler
formatter: simpleFormater
level: DEBUG
stream: ext://sys.stdout
file:
class : logging.FileHandler
formatter: simpleFormater
level: WARNING
filename: sesame.log
loggers:
clogger:
level: DEBUG
handlers: [console]
flogger:
level: WARNING
handlers: [file]
mlogger:
level: INFO
handlers: [console, file]