您的位置:首页 > 编程语言 > Python开发

python 自动下载 moudle

2014-04-29 21:02 225 查看
import sys,re,subprocess
import os
from subprocess import CalledProcessError

new_set = set()
ls = set()

def dls():
temp_set = set()
a = subprocess.check_output("ls -R", shell=True)
for line in a.split('\n'):
str = re.sub(r'.py', r'', line)
if  str.find('.')<0  and str!='\n' :
temp_set.add(str)
print str
return temp_set

def dpip(new_set):
ls = dls()
for str in new_set-ls:
str = str.replace('\n','')
with open('daicy.py', 'w') as f:
f.write('import '+str)
try:
a = subprocess.check_call('python daicy.py', shell=True)
if a!=0:
command = 'pip  install  '+str
print command
subprocess.call(command, shell=True)
except CalledProcessError, e:
print 'except:', e
command = 'pip  install  '+str
print command
os.system(command)
finally:
pass

a = subprocess.Popen('''find -name '*.py' | xargs grep -h -o -w  -s "^import\s\+\([\_0-9a-zA-Z]\+\)\|^from\s\+\([\_0-9a-zA-Z]\+\)"''', shell=True,stdout=subprocess.PIPE)
for line in a.stdout.readlines():
line = line.replace('\n','')
new_set.add(re.sub(r'import\s+|from\s+', r'', line))

dpip(new_set)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: