#!/usr/bin/python


# script for Ubuntu to make Icon Theme contain any Icon theme in your system with Ubuntu Mono Icons 
# author : Alwan Al-Zahrani <alwan.sa@gmail.com>
# Version : 0.002
# License : GPL 5.5

import shutil
import os

print "Asslam alaykum(Peace be upon you)\n\nThis script make new icon theme contain any Icon theme in your system with Mono Icons for Panel.\n\nyou will go in The following steps :-\n1-Type the name of new icon theme.\n2-choose Mono Dark or Mono Light.\n3-generate list of all icon themes in your system.\n4-then Type the name of icon theme which you want mono panel icons for it.\n5-go to Appearance and click customize button then choose icons tap and you will find new icon theme."
print "\n\nby: Alwan <alwan.sa@gmail.com>"
try:
	raw_input("\n\nPress enter to continue or Ctrl+C to quit")
except KeyboardInterrupt:
	print "\nBye\n"
	quit()

home=os.getenv('HOME')
i=[]
icondir="%s/.icons" %home
icondir1="/usr/share/icons"

for files in os.listdir(icondir1) :    
	if os.path.isdir(os.path.join(icondir1,files)):
		i.append(files)

for files in os.listdir(icondir) :    
	if os.path.isdir(os.path.join(icondir,files)):
		i.append(files)
i.sort()
k=i

name_of_new_icon_theme=raw_input("\n-Type The name of new icon theme: ")

while name_of_new_icon_theme in i:
	print "ERROR:This name already used in your icon themes\nTry again "
	name_of_new_icon_theme=raw_input("\n-Type The name of new icon theme: ")



icon_type=input("\n1-Ubuntu Mono for  Light theme\n2-Ubuntu Mono for  Dark theme \nType 1 or 2 ? :")
g=[1,2]
while icon_type not in g:
	print "ERROR: Wrong Choice\nTry again"
	icon_type=input("\n1-Ubuntu Mono for  Light theme\n2-Ubuntu Mono for  Dark theme \nType 1 or 2 ? :")


print "\n\n"	


for i in i:
	print i

icon_theme=raw_input("\n(from the list above and Be sure of the spelling)\nType the name of icon theme which you want mono for it\n:")
while icon_theme not in k:
	print "ERROR:i can't find this icon theme Be sure of the spelling\nTry again "
	icon_theme=raw_input("\nType the name of icon theme which you want mono for it\n:")

def i_t():	
	if (icon_type==1):
		shutil.copytree("/usr/share/icons/ubuntu-mono-light","%s/.icons/%s"%(home,name_of_new_icon_theme))
		#os.system('cd / && cp -r /usr/share/icons/ubuntu-mono-light ~/.icons/%s'%name_of_new_icon_theme )
	elif (icon_type==2):
		shutil.copytree("/usr/share/icons/ubuntu-mono-dark","%s/.icons/%s"%(home,name_of_new_icon_theme))
		#os.system('cd / && cp -r /usr/share/icons/ubuntu-mono-dark ~/.icons/%s'%name_of_new_icon_theme )
	else:
		print "Wrong Choice"
		quit()


def mk():
	indext = open('%s/.icons/%s/index.theme'%(home,name_of_new_icon_theme),'r' )
	rd=indext.readlines()
	rd[1:4]=("Name=%s\nComment=Smooth modern theme designed to be intuitive.\nInherits=%s\n" %(name_of_new_icon_theme , icon_theme))
	indext = open('%s/.icons/%s/index.theme' %(home,name_of_new_icon_theme),'w')
	indext.writelines(rd)
	indext.close()



i_t()
mk()

print "\nDone\nNow go to Appearance  and click customize button then choose icons tap and you\nwill find new icons called '%s'"%name_of_new_icon_theme
raw_input("")

