python 自动下载 moudle

来源:互联网 发布:海马软件删不掉 编辑:程序博客网 时间:2024/05/16 13:59
import sys,re,subprocess
import osfrom subprocess import CalledProcessErrornew_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:              passa = 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)


0 0
原创粉丝点击