Форум сайта python.su
0
есть скрипт
/code python
#!/usr/bin/env python
import os
import re #include Regexp
import sys
basedir = u“/home”.decode()
show_log = True
def get_cms_type(dir):
res = is_wp(dir)
if not res:
res = is_joomla(dir)
if not res:
return False
return res
# STARTBLOCK get cms functions/
# @param = dirname
# @return result
# result = “cms_name”
# result = “cms_ver” (default 0)
# result =
# result = “cms_path”
def is_wp(dir):
path = dir
if os.path.exists(path):
catalog = get_dirs(path)
else:
print “ Can not open ” + dir
return False
result = {}
if os.path.exists(path +“/wp-includes/version.php”):
fversion = open(path + “/wp-includes/version.php”)
s = fversion.readline()
while s:
s = s.strip(' \t\n\r')
match = re.search(u“(^\$wp_version)”, s)
if match:
result = “WP”
result = path
ver = re.search(u"+", s)
if ver != None:
result = ver.group()
break
else:
result = 0
s = fversion.readline()
fversion.close()
if not ‘cms_name’ in result:
return False
if os.path.exists(path + “/wp-content”):
plugins = get_dirs(path + “/wp-content/plugins”)
result = plugins
if not result:
result = “WP”
if not result:
result = 0
return result
def is_joomla(dir):
return False
# ENDBLOCK get cms functions/
def get_user_sites(dir):
path = basedir + “/” + dir
if os.path.exists(path):
cms_sites = walk_near(path);
if cms_sites:
for site in cms_sites:
print “path: ” + site
print “ CMS: ” + site
print “ ver:” + site
print “ plugins: ”,
print site
else:
print “can not open ” + path + “ folder”
return False
def walk_near(path):
found_cms = False;
tree = os.walk(path)
wp_sites =
for root, dirs, files in tree:
try:
for dir in dirs:
new_path = os.path.join(root, dir)
cms_site = is_wp(new_path)
if cms_site:
found_cms = True
wp_sites.append(cms_site)
if found_cms:
found_cms = False
except:
print “exception”
return wp_sites
def get_dirs(path):
dirs = os.listdir(path)
result =
for dir in dirs:
if not os.path.isfile(path + “/” + dir):
result.append(dir)
return result
def main():
users = sys.argv
if not users:
print “Error, no params”
return False
for user in users:
print “Try to get cms system of user ” + user
res = get_user_sites(user)
print “”
return
main()
/code
нужно переделать что бы использовал find из баша для поиска этих папок и файла
помогите плизз не могу врубиться
Отредактировано wfsdexter (Июль 28, 2012 01:12:55)
Офлайн
16
Оформите код тегом
[code python] [/code]
Отредактировано GaiveR (Июль 28, 2012 00:54:37)
Офлайн
14
Что за мода пошла - не юзать code? Это заразное?
Офлайн