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('
'):
str = re.sub(r'.py', r'', line)
if str.find('.')<0 and str!='
' :
temp_set.add(str)
print str
return temp_set
def dpip(new_set):
ls = dls()
for str in new_set-ls:
str = str.replace('
','')
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 "^imports+([\_0-9a-zA-Z]+)|^froms+([\_0-9a-zA-Z]+)"''', shell=True,stdout=subprocess.PIPE)
for line in a.stdout.readlines():
line = line.replace('
','')
new_set.add(re.sub(r'imports+|froms+', r'', line))
dpip(new_set)