Commit ceee86e4 by zhangwei

commit 1

parent 3af6c512
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.13 (D:\Python27\python.exe)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ops.iml" filepath="$PROJECT_DIR$/.idea/ops.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CreatePatchCommitExecutor">
<option name="PATCH_PATH" value="" />
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<created>1489119831342</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1489119831342</updated>
</task>
<servers />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
</project>
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/3/9 16:50
# @Author : Stock Zhang
# @Site :
# @File : checkitems.py
# @Software: PyCharm
from tools import *
import sys
import os
import stat
import pwd
def checkIsDirectory(path):
# print(path)
if not os.path.isdir(path):
echo(path,"isnt directory!",False,space=1)
sys.exit(1)
else:
echo(path,"have been checked!",True,space=1)
return True
def checkPermission(obj,uid=33):
if (os.stat(obj).st_uid != 33) or (os.stat(obj).st_gid !=33):
echo(obj,"owner or group isnot 'www-data(uid=33 or gid=33)'",False,1)
def checkDirectoryIsWrite(path,user=33):
if not isinstance(user,int):
user_info=pwd.getpwnam(user)
uid=user_info.pw_uid
else:
uid=user
st=os.stat(path)
mode=st.st_mode
return( (st.st_uid == uid) and ((mode & stat.S_IWUSR) > 0))
def traversal(root):
for dirpath,dirnames,filenames in os.walk(root):
for filename in filenames:
yield os.path.join(dirpath,filename)
for dirname in dirnames:
yield os.path.join(dirpath,dirname)
def check(appname,appdir):
d="%s/%s" % (appdir,appname)
if not os.path.islink(d):
echo(appname,"link isnt exits!",False,space=1)
sys.exit(1)
else:
echo(appname,"link is ok!",True,space=1)
realpath = os.path.realpath(d)
if checkIsDirectory(realpath):
for root in traversal(realpath):
checkPermission(root)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/3/9 16:50
# @Author : Stock Zhang
# @Site :
# @File : checklist.py
# @Software: PyCharm
from tools import *
from checkitems import *
APP_LIST = ['summer-hill','official-web','user-center']
LOG_LIST = ['/usr/local/php7/var/log/php_errors.log']
APP_DIR = "/web/neo"
if __name__ == '__main__':
if len(sys.argv) < 2:
Usage()
appListName = sys.argv[1].split(",")
for appname in appListName:
if appname in APP_LIST:
echo(appname,"is checking......",True)
check(appname,APP_DIR)
else:
echo(appname,"not available!",False)
echo(appname,"had been checked!",True)
print('*'*80)
for log in LOG_LIST:
echo(log,"is checking......",True)
if checkDirectoryIsWrite(log):
echo(log,"can be writen",True,1)
else:
echo(log,"cannt be writen!",False,1)
#!/usr/bin/env python
\ No newline at end of file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/3/9 16:50
# @Author : Stock Zhang
# @Site :
# @File : tools.py
# @Software: PyCharm
import sys
def Usage():
print """Usage:
python checklist.py appname
- appname: application name,eg:summer-hill
"""
sys.exit(1)
def echo(cls,contents,flag,space=0):
space="\t"*space
if flag:
print("%s\033[1;32;40m[+OK]: '%s' %s\033[0m" % (space,cls,contents))
else:
print("%s\033[5;31;40m[-ERR]: '%s' %s\033[0m" % (space,cls,contents))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment