import subprocess

Command=subprocess.Popen(["ln -s /usr/share/arduino/Arduino.mk"],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate() 
pName=input('Enter the project name:')
print (pName)
Command=subprocess.Popen(["mkdir "+pName],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
#Command=subprocess.Popen(["rm "+pName+"/Makefile"],stdout=subprocess.PIPE,shell=True)
#(Out1,err)=Command.communicate()
#Command=subprocess.Popen(["cd "+pName],stdout=subprocess.PIPE,shell=True)
#(Out1,err)=Command.communicate()
s=pName+".ino"
f = open(s,"w")
f.write("hsjsjkbskjsc")
f.close()
Command=subprocess.Popen(["mv "+s+"  "+pName],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
#Command=subprocess.Popen(pName+'/'+pName+'.ino'],stdout=subprocess.PIPE,shell=True)
#(Out1,err)=Command.communicate()
#subprocess.check_call(['nano'pName+'/'+pName+'.ino'])
Command=subprocess.Popen(['echo "ARDUINO_DIR = /usr/share/arduino">>'+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
Command=subprocess.Popen(['echo "BOARD_TAG = uno">>'+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
Command=subprocess.Popen(['echo "ARDUINO_PORT = /dev/ttyACM*">>'+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
#Command=subprocess.Popen(['echo "ARDUINO_LIBS = LiquidCrystal Ethernet Ethernet/utility SPI SimpleDHT">>'+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
#(Out1,err)=Command.communicate()
Command=subprocess.Popen(['echo "include /usr/share/arduino/Arduino.mk">>'+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
Command=subprocess.Popen(['make -C '+pName],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
Command=subprocess.Popen(['make -C '+pName+' upload'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
Command=subprocess.Popen(['rm '+pName+'/Makefile'],stdout=subprocess.PIPE,shell=True)
(Out1,err)=Command.communicate()
print (Out1)

