#!/usr/bin/env python

# gimp_new_template
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release.
from gimpfu import *
from datetime import date



def python_new_template(image, layer, descIn):
	
	#open file and read it in to lines to process
	f = open("plug-ins/tmplt.py","r")					###### no file when run from GUI ####### 
	lines = f.readlines()
	f.close()
	
		
	newDesc = descIn.title()							#ready to replace oldDesc, capitalize first letter each word
	fnamePrep = descIn.replace(" ","_")					#replace spaces with underscore
	fnamePrep1 = fnamePrep.lower()						#ready to replace "template"
	fName = fnamePrep1+(".py")							#filename to write to	
	
	today = date.today()
	newDate = today.strftime("%B %Y")					#ready to replace oldDate
	verDate = today.strftime("%d/%m/%Y")				#ready to replace oldDate
	
	f = open("plug-ins/"+str(fName),"w")				#output file
	
	
	for line in lines:
		line = line.replace("template",fnamePrep1)
		line = line.replace("oldDate",newDate)
		line = line.replace("iniDate",verDate)
		line = line.replace("oldDesc",newDesc)			
		f.write(line)
	f.close()
		
	
	
register(
	"python_fu_new_template",                           
	"GIMP new_template",
	"GIMP new_template",
	"David Marsden",
	"David Marsden",
	"October 2021",
	"<Image>/Python-Fu/New Template...",            	#Menu path
	"",													#No Image
	[
	(PF_STRING, "descIn", "Two, Three word description", ""),
	],		
	[],
	python_new_template)

main()


