# coding:utf-8from datetime import date, timedelta
from subprocess import check_output
from time import time, strftime
from sys import argv
classExecutor:def__init__(self,**kwargs):# 起始秒数
self.t = time()# 传参:https://yellow520.blog.youkuaiyun.com/article/details/122088401
self.parameters = kwargs
for a in argv[1:]:
k, v = a.split('=',1)
self.parameters[k.strip()]= v.strip()def__str__(self):
t = self.second
if t <60:return'%.2fs'% t
if t <3600:return'%.2fmin'%(t /60)else:return'%.2fh'%(t /3600)@propertydefsecond(self):"""程序运行秒数"""return time()- self.t
@propertydefnow(self):return strftime('%Y-%m-%d %H:%M:%S')defsh(self, cmd):"""执行Shell命令"""print cmd
output = check_output(cmd, shell=True).strip()print'当前时间:%s'% self.now
print'运行时长:%s'% self
return output
@propertydefyesterday(self):
yesterday = date.today()- timedelta(days=1)return yesterday.strftime('%Y-%m-%d')@propertydefymd