DIR : /home/kozerus/public_html/tl.py

/home/kozerus/public_html

# ka1.py	20190214_1444 go wii
# ka1.py	20190214_0230 go htms2host
# ka1.py	20190213_2300 go png2gif png+gif+size=png_gif-size.gif
# ka1.py	20190212_1500 go gif2gifs imgs/ani/work/ring/ring.gif = gifs(ring0,1,2, 00,01,02, 10,11,12, 20,21,22)
# ka1.py	20190210_2200 go htms2htm .
# ka1.py	20190210_2100 go php2php .
# ka1.py	20190204_1730 go newhtm .
# ka1.py	20190204_1730 go 
# ka1.py	20190115_0300 do_sl find.wl
# ka1.py	20190114_1723 do_tlwl tl.psv
# ka1.py	20190112_1200 do_tlwl tl.psv
# ka1.py	20190112_1100 do_tl tl.psv
# ka1.py	20190111_1123 do_tl(a0,a1,a2,a3)
# ka1.py	20180704_0000
# ka1.py	20180520_1300
# ===========================
# convert map_venice.jpg    -page +142+242 push_pin.png \ -flatten  map_push_pin.jpg

import sys
import os, os.path, time, fnmatch
import subprocess
import datetime
import re
import base64
from subprocess import PIPE, Popen

alen = len(sys.argv)
a0=""
a1=""
a2=""
a3=""
progid="tl"
if( alen > 0 ): a0=sys.argv[0] 
if( alen > 1 ): a1=sys.argv[1]
if( alen > 2 ): a2=sys.argv[2]
if( alen > 3 ): a3=sys.argv[3]
# print "argv={} a0={} arg1={} arg2={} arg3={}\n".format( argv, a0, a1, a2, a3 )


def ko_dttm():
	import datetime
	import time

	now = datetime.datetime.now();
	today = now.date();
	moment = now.time();
	today = datetime.date.today()
	dttm =  now.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"

#	dttm =  now.strftime('%m/%d/%Y')  # This writes "06/24/1984"
#	today =today.year + today.month + today.day + "_" 
#	today += today.hour + today.minute + today.second

#	print('The current time is :', time.ctime())
#	newtime = time.time() + 20
#	print('20 secs from now :', time.ctime(newtime))
#	print progid, "MSG: dttm today=",today,time.ctime()


#  9. Obtain the number of days and seconds between the epoch and now, or the total number of seconds that have passed:
#	delta = now - epoch
#	days = delta.days
#	seconds = delta.seconds
#	total_seconds = delta.total_seconds()
#	delta = now - epoch
#	days = delta.days

#	string_date = str(my_date)
# 12. Recover a date object from a string like ?1984-06-24?:
#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
	

	return(dttm)

def ko_do(a0,a1,a2,a3):
	print '{} {} ko_do: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	print __file__
	print os.path.join(os.path.dirname(__file__), '..')


def ko_dodo(a0,a1,a2,a3):
	print '{} {} ko_dodo: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	print __file__
	print os.path.join(os.path.dirname(__file__), '..')


def ko_do_mp42gif(a0,a1,a2,a3):
	dttm=ko_dttm()
	print '{} {} ko_do_mp42gif: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	print __file__
	print os.path.join(os.path.dirname(__file__), '..')
	print os.path.dirname(os.path.realpath(__file__))
	print os.path.abspath(os.path.dirname(__file__))



	print progid,dttm,"ko_do a1,a2=", a1,a2
	colors = "white black ivory darkslategrey red white blue yellow".split(" ")
	colors = "ivory yellow".split(" ")
	fonts = "./fonts/yokkmokk.ttf ariel".split(" ")
	
	cats = "cat acct biz cont test".split(" ")
	cats = "cat acct biz cont edu food gov konabus law lib med med media org phy rel sci stlc util".split(" ")
	fonts = "ShearBeauty LokiCola fixed Courier AvantGarde-Book Bookman-Demi Helvetica NewCenturySchlok-Roman Palatino-Roman Symbol ./fonts/yokkmokk.ttf Times-Roman ".split(" ")
	ifile="./imgs/btn/koeye.png"
	pointsize_default = 38


# print(os.path.isdir("./us/imgs/cat"))
# print(os.path.exists("/home/el/myfile.txt"))
#	results = os.popen('cat us.psv').read()
#	print "results=".format(results)

	mkdir_flag='true'
	mktn_flag='true'
	mkim_flag='true'

	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12
	print '{} {} do BUGS_101: document_root={}'.format( progid, dttm, document_root )
	print '{} {} do BUGS_102: mktn_flag={}'.format( progid, dttm, mktn_flag )
	print '{} {} do BUGS_103: mkim_flag={}'.format( progid, dttm, mkim_flag )

	if not os.path.isfile(a2):
		print("{} {} ERR: NOTFOUND ifile={}  ".format( progid,dttm,a2))
		sys.exit()

	print progid,dttm, "runwl a1={} a2={} a3={}".format( a1,a2,a3 )
	wl_filename=a2
	linematch_beg='<div id="div_runwl">'
	linematch_end="</div>"

	out_filename=a2.replace(".txt", ".out" )
	index_sl_filename=a2.replace(".txt", ".html" )
	index_slv_filename=a2.replace(".txt", ".html" )
	index_tl_filename=a2.replace(".txt", ".html" )

	print("{} {} MSG_110: a2={}  ".format( progid,dttm,a2))
	print("{} {} MSG_111: index_sl_filename={}  ".format( progid,dttm,index_sl_filename))
	print("{} {} MSG_112: index_slv_filename={}  ".format( progid,dttm,index_slv_filename))
	print("{} {} MSG_113: index_tl_filename={}  ".format( progid,dttm,index_tl_filename))



	wl_file=open( wl_filename, "r" )
	out_file=open( out_filename, "wb" )





	if( os.path.exists( a2 )):
		with open(a2) as f:
			j=0
			for line in f:
				j += 1
				pathfile=line.split()[8]
				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]

				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}/{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}/{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}/{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}/{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}/{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}/{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}/{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}/{}/img/{}_%03d.gif'.format(document_root,path,file)

				print "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4)
				print "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg)
				print "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1)
				print "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs)
				print "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif)


				abs_tn_path='{}/{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}/{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}/{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}/{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )

				print 'i_pathfile={}'.format( i_pathfile)	
				print 'o_pathfile={}'.format( o_pathfile)	

				print 'abs_tn_path={}'.format( abs_tn_path)	
				print 'abs_tn_pathfile={}'.format( abs_tn_pathfile )	
				print 'abs_im_path={}'.format( abs_im_path)	
				print 'abs_im_pathfile={}'.format( abs_im_pathfile )	

				print 'tn_path={}'.format( tn_path)	
				print 'tn_pathfile={}'.format( tn_pathfile )	
				print 'im_path={}'.format( im_path)	
				print 'im_pathfile={}'.format( im_pathfile )	

				print '{} pathfile={}'.format( j, pathfile )
#				print '   path={} base={} file={} ext={}'.format( path, base, file, ext )
#				print '   tn_pathfile={}'.format(tn_pathfile)
#				print '   im_pathfile={}'.format(im_pathfile)


# BUGS160
#				mybase="kludge"
#				syscmd="ffmpeg -i 1.mp4 -vf fps=1/60 ffmpeg_img%03d.jpg"
#				syscmd="ffmpeg -i 1.mp4 -vf fps=1/60 {}_%03d.jpg".format(mybase)
#				os.system(syscmd)
				





				if( not os.path.exists( abs_tn_path )):
					syscmd_mkdir='mkdir {}'.format( abs_tn_path )
					print '{} {} NOTFOUND: abs_tn_path={} {}'.format( progid, dttm, abs_tn_path, syscmd_mkdir )
					if( mkdir_flag == 'true' ): os.system( syscmd_mkdir )
				else:
					print '{} {} FOUND: abs_tn_path={}'.format( progid, dttm, abs_tn_path )
					syscmd_mktn='cp {}/imgs/btn/koeye.png {}'.format( document_root, abs_tn_pathfile )
					print '{} {} syscmd_mktn={}'.format( progid, dttm, syscmd_mktn )
					if( mktn_flag == 'true' ): os.system( syscmd_mktn )

				if( not os.path.exists( abs_im_path )):
					syscmd_mkdir='mkdir {}'.format( abs_im_path )
					print '{} {} NOTFOUND: abs_im_path={}'.format( progid, dttm, abs_im_path )
					if( mkdir_flag == 'true' ): os.system( syscmd_mkdir )
				else:
					print '{} {} FOUND: abs_im_path={}'.format( progid, dttm, abs_im_path )
					syscmd_mkim='cp {}/imgs/btn/koeyeb.png {}'.format( document_root, abs_im_pathfile )
					print '{} {} syscmd_mkim={}'.format( progid, dttm, syscmd_mkim )
					if( mkim_flag == 'true' ): os.system( syscmd_mkim )


					flag_im = "y"
					ffmpeg_fps="1"
					ffmpeg_fps="1/60"
					ffmpeg_fps="1/10"
					ffmpeg_fps="1/20"

					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1/60 {}".format(i_pathfile_mp4, o_pathfile_jpg )
					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1 {}".format(i_pathfile_mp4, o_pathfile_jpg )
#					syscmd_ffmpeg="ffmpeg -i {} -vf fps=1/10 -s 360x240 {}".format(i_pathfile_mp4, o_pathfile_jpg )
					syscmd_ffmpeg="ffmpeg -i {} -vf fps={} -s 360x240 {}".format(i_pathfile_mp4, ffmpeg_fps, o_pathfile_jpg )
					print "{} {} BUGS_200 syscmd_ffmpeg={}\n".format( progid, dttm, syscmd_ffmpeg )
					if( flag_im == "y" ): os.system( syscmd_ffmpeg )

# mogrify -resize 320 *.jpg 
# convert -delay 15 -loop 0 *.jpg douglas.gif

					flag_tn = "y"
					flag_jpgs_rm = ""
					syscmd_jpg12png="convert {} -size 100x200 {}".format(i_pathfile_jpg1, o_pathfile_png )
#					syscmd_jpgs2gif_mogrify="mogrify -resize 200 {}".format(i_pathfile_jpgs)
					syscmd_jpgs2gif="convert -delay 15 -loop 0 {} {}".format(i_pathfile_jpgs, o_pathfile_gif )
					syscmd_jpgs_rm="rm {}".format(i_pathfile_jpgs )
					print "{} {} BUGS_201 syscmd_ffmpeg={}\n".format( progid, dttm, syscmd_ffmpeg )
					print "{} {} BUGS_202 syscmd_jpg12png={}\n".format( progid, dttm, syscmd_jpg12png )
					print "{} {} BUGS_203 syscmd_jpgs2gif={}\n".format( progid, dttm, syscmd_jpgs2gif )
					print "{} {} BUGS_204 syscmd_jpgs_rm={}\n".format( syscmd_jpgs_rm )
					if( flag_tn == "y" ): os.system( syscmd_jpg12png )
#					if( flag_tn == "y" ): os.system( syscmd_jpgs2gif_mogrify )
					if( flag_tn == "y" ): os.system( syscmd_jpgs2gif )
#					if( flag_jpgs_rm == "y" ): os.system( syscmd_jpgs_rm )

#					exit();

# convert   -delay 20   -loop 0  -size 100x200 sphere*.gif   animatespheres.gif


##					flag_ffmpeg_seek = ""
##					seekpoint=10
##					if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )
##					ffmpeg_seek_cmd = 'ffmpeg  -i {} -vf fps={} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( i_pathfile, "1/60", o_pathfile )
##					ffmpeg -y -ss $SEEK_POINT -i input.ogv -vcodec mjpeg -vframes 1 -an -s 120x90 -f rawvideo output.jpg
##					ffmpeg_seek_cmd = 'ffmpeg -y -ss {} -i {} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( seekpoint, i_pathfile, o_pathfile )
##					ffmpeg_seek_cmd = 'ffmpeg  -i {} -vf fps=1/60 -s 1920x1000 -f rawvideo {}'.format( i_pathfile, o_pathfile )
##					print progid,dttm, "ko_go ffmpeg_seek_cmd={}\n".format( ffmpeg_seek_cmd )
##					subprocess.call( ffmpeg_seek_cmd )
##					if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )

#					im_cmd='mogrify -resize x100 -write {} {}'.format( abs_tn_pathfile, i_pathfile )
#					print progid,dttm, "ko_go im_cmd={}\n".format( im_cmd )
#					if( flag_im == "yes" ): os.system( im_cmd )
#					subprocess.call( im_cmd )
#					os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 



#				print '<a href="{}" data-poster="/imgs/btn/koeye.png">'.format(pathfile)
#				print '<img src="/imgs/btn/koeye.png" alt="{}" data-description="{}"></a>'.format(pathfile,base)


#				print "{} <a href={} _target=_blank>".format(j, base)
#				print " <img src={} _target=_blank>".format(base)
#				print "	</a>"
# 				print progid,dttm,j, pathfile, path, base, file, ext

				htmdiv = ''
				htmdiv += '<a href="{}" target=_blank class="thumbnamil">\n'.format(i_pathfile_mp4)
				htmdiv += '	<img src="{}" border=0>\n'.format( o_pathfile_png )
				htmdiv += '	<span><img src="{}" border=0></span>\n\n'.format( o_pathfile_gif )
				print "{} {} MSG_122:  htmdiv={}".format( progid, dttm, htmdiv )
				ofile=open(o_pathfile_htm, "a+")
				ofile.write(htmdiv)
				ofile.close()

#		pathfile=a2
#		if( not os.path.isdir( catpath )):
#			syscmd_mkdir = "mkdir ./us/imgs/{}".format( cat )
#			print progid,dttm, "ko_do: syscmd_mkdir={}".format( syscmd_mkdir )
#			os.system( syscmd_mkdir )


	ofile=open(o_pathfile_htm, "a+")
	htmdiv += '	</div>\n'

	print "{} {} MSG_121:  o_pathfile_htm={}".format( progid, dttm, o_pathfile_htm )
	print "{} {} MSG_122:  htmdiv={}".format( progid, dttm, htmdiv )

	ofile.write(htmdiv)
	ofile.close()

	exit()


#	import subprocess
	direct_output = subprocess.check_output('ls', shell=True) #could be anything here.
	proc = subprocess.Popen(["cat", "us.psv"], stdout=subprocess.PIPE, shell=True)
	(out, err) = proc.communicate()
	print "program output:", out


	for cat in cats:
		if( not os.path.isdir( catpath )):
			syscmd_mkdir = "mkdir ./us/imgs/{}".format( cat )
			print progid,dttm, "ko_do: syscmd_mkdir={}".format( syscmd_mkdir )
#			os.system( syscmd_mkdir )


		for color in colors:
			for font in fonts:
				dttm=ko_dttm()
				stroke=color
				gravity="center"
				pointsize=28
				fontcode=font.replace("./fonts/","").replace(".ttf","").replace("-","").lower()
				if( fontcode == "newcenteryschlokroman" ): fontcode="schlok"
				pointsize=pointsize_default

#				ofile="./us/imgs/cat_{}.png".format( cat )
				ofile="./us/imgs/koeye_{}_{}_{}.png".format( cat, color, fontcode )
				ifile2="./kodome.png"


#		convert -background none  -fill white \
#			-font Ravie  -pointsize 36   label:A   label_A_white.png
#		composite -gravity center label_A_white.png   rose:   compose_over.gif
#
#		convert  rose:   label_A_white.png \
#			-geometry +5-15   -composite   convert_over.gif
#
#		convert -background none  -fill black \
#			-font Ravie  -pointsize 36   label:A   label_A_black.png
#		composite -compose Dst_Over  -geometry +5+5 \
#			label_A_black.png  label_A_white.png   compose_under.png
#		composite -compose Src  -size 100x100  plasma:tomato-dodgerblue \
#			rose:   compose_crop.gif


#		composite -compose Src -gravity South 
#			hand_point.gif   rose:   -alpha set   compose_expand.gif

#		composite -compose Copy -gravity South 
#			hand_point.gif   rose:   -alpha set   compose_copy.gif
#		composite -compose Dst_In  -gravity center 
#			label_A_white.png  rose: -alpha Set  compose_mask.png
#		convert -size 60x60  compose_xor_2.png  
#			\( xc:none -fill green  -draw 'circle 30,21 30,3'  \) 
#			-compose Xor   -composite   compose_xor_3.png
#		convert -size 60x60 
#			\( xc:none -fill blue   -draw 'circle 21,39 24,57' \) 
#			\( xc:none -fill red    -draw 'circle 39,39 36,57' \) 
#			-compose Xor   -composite   compose_xor_2.png
#		convert -size 64x64 gradient:             gradient_src.png
#		convert -size 64x64 gradient: -rotate 90  gradient_dst.png
#		composite gradient_src.png -compose Multiply gradient_dst.png \
#			gradient_result.png
# two grayscale gradients the brightest colors will wrap to form a second gradient.
#		convert -size 60x60 gradient:    gradient.png
#		composite  gradient.png gradient.png -compose ModulusAdd  compose_add.png
#		composite gradient.png \( gradient.png -rotate -90 \) \
#			-compose ModulusAdd   gradient_diagonal.png
#		convert gradient.png \( +clone +clone +clone +clone \) \
#			-background gray50 -compose ModulusAdd -flatten  gradient_venetian.png
#		convert -size 64x64  xc:dodgerblue \
#			-draw 'fill skyblue   circle 32,32 7,27'  circle_blue.jpg
#		convert circle_blue.jpg -shade 120x30 -auto-level circle_shaded.jpg
#		convert circle_shaded.jpg  circle_blue.jpg \
#			-compose Overlay -composite   circle_shaded_tinted.jpg

#		convert rose: -fill gray50 -colorize 100% \
#			-raise 4 -normalize -blur 0x4  lighting_effect.png
#		convert rose: lighting_effect.png \
#			-compose hardlight -composite  compose_hardlight.png
#		composite -dissolve {argument}  -gravity South \
#			star.gif   dragon_sm.gif -alpha Set   {result}
#		composite -blend {argument}  -gravity South \
#			compose_R.png compose_plus_GB.png  -alpha Set  {result}
#		composite  -tile star.gif   netscape:   tile.gif
#		convert -background none -pointsize 36 label:'Tile Under'  png:- |\
#		composite -tile bg.gif  -   -compose Dst_Over   tile_under.gif

#		convert overlay_figure.gif   overlay_bgnd.gif  \
#			-compose ChangeMask  -composite  overlay_removed.png

# convert handhi.gif -set  delay 20 handhi_20.gif
# convert koeye.png handhi_10.gif -compose CopyOpacity  koeye_hand_10.gif

#		convert overlay_bgnd.gif  overlay_figure.gif \
#			-compose ChangeMask  -composite  overlay_changed.png
#		convert overlay_figure.gif overlay_bgnd.gif -compose ChangeMask  -composite \
#			-channel A -negate      overlay_unchanged.png
#		onvert -size 100x100 xc: +noise Random -separate \
#		          null: \( xc: +noise Random -separate -threshold 30% -negate \) \
#		              -compose CopyOpacity -layers composite \
#		          -set dispose background -set delay 20 -loop 0   glitter_overlay.gif
#		convert glitter_overlay.gif \
#		          -compose Screen -bordercolor GoldenRod -border 0x0  glitter_gold.gif
#		convert glitter_overlay.gif null: -size 100x100 \
#		          plasma:red-firebrick plasma:red-firebrick  plasma:red-firebrick \
#		          -compose Screen -layers composite    glitter_plasma.gif
#		convert -size 100x100 -fill white -background black -font Candice \
#		          -gravity center -pointsize 90 label:A    glitter_mask.gif
#		  convert glitter_plasma.gif null: glitter_mask.gif +matte \
#		          -compose CopyOpacity -layers composite   glitter_masked.gif
#		

#		  convert \( neon_h.gif -coalesce -append \) \
#		          \( neon_e.gif -coalesce -append \) \
#		          \( neon_l.gif -coalesce -append \) \
#		          \( neon_l.gif -coalesce -append \) \
#		          \( neon_o.gif -coalesce -append \) \
#		          +append  -crop x60 +repage  -set delay 100  neon_hello.gif
#		
#		
#		  convert neon_h.gif'[0]' neon_e.gif'[0]' neon_l.gif'[0]' neon_l.gif'[0]' \
#		          +append \( +clone \) -append \
#		          \( neon_o.gif -coalesce -append \)    +append \
#		          \( +clone \) -append \( +clone \) -append \( +clone \) -append \
#		          -crop x60 +repage   -set delay 3 \
#		          \( -clone 0  -set delay 300 \) -swap 0,-1 +delete \
#		          \( -clone 1  -set delay  10 \) -swap 1,-1 +delete \
#		          \( +clone    -set delay 200 \) +swap      +delete \
#		          -quiet -layers OptimizeFrame   neon_hell.gif

#		 convert  -flip  storm.gif   cmd_flip_legacy.gif

#		 identify -format '%k\n' tree.gif
#		 mogrify -format gif  -size 200x200  -pointsize 18 \
#		          -font Candice -gravity north  -annotate 0 "%f" \
#		          -font Ravie   -gravity Center -annotate 0 "%f" \
#		          -font Gecko   -gravity south  -annotate 0 "%f" \
#		          -size 100x64   xc:gold  xc:orange   xc:tomato
#		convert  -size 32x32 xc:none -draw 'circle 15.5,15.5 15.5,0'  circle.gif
#		mogrify  -alpha Set -draw 'image Dst_In 0,0 0,0 "circle.gif"'  mogrify_*.gif

#	convert \( eye.gif    news.gif  +append \) \
#          \( storm.gif  tree.gif  +append \) \
#          -append  cmd_array2.gif
#convert -respect-parenthesis \
#          -font Arial   label:"This is a line of plain text." \
#          \( -font Candice -pointsize 16 -fill red -undercolor lightblue \
#              label:"A line using a lot of different settings." \) \
#          label:"Text is back to normal -- like Magick\!" \
#          -append  cmd_settings_lots.gif
#

# ani.gif resize
# 	convert anim.gif -coalesce anim_coalesce.gif
#	convert -size <original size> anim_coalesce.gif -resize 24x24 anim_resize_24.gif.
#	convert in_animation.gif -coalesce -crop WxH+X+Y +repage -layers optimize out_animation.gif
#	convert tANtN.gif -background white -alpha background tANtN_new.gif
#	convert tANtN.gif -alpha off -channel rgb -evaluate set 0 -channel rgba -alpha on tANtN_new.gif

#	convert logo: -transparent white -duplicate 3 logo_4f.gif
#	convert logo_4f.gif -alpha off logo_4f_aoff.gif
#	convert logo_4f.gif -coalesce -alpha off -evaluate set 0 -alpha on logo_4f_black.gif
#	convert logo_4f_black.gif -alpha off logo_4f_black_aoff.gif

#	convert warning.gif  -coalease -draw 'image DstOver 0,0 0,0 "koeye.png"' -layers optimize koeye_warning.gif






# convert handhi_10.gif -coalesce -gravity NorthEast -draw image over 0,0 0,0 'koeye.png' -layers Optimize koeye_hand10.gif 

# overlay
				cmd_overlay = "convert {} -coalesce -gravity NorthEast -draw image over 0,0 0,0 '{}' -layers Optimize {}".format( ifile, ifile2, ofile )
				print progid,dttm, "ko_do: cmd_overlay={}".format( cmd_overlay )

# composite_overlay
# convert handhi_10.gif -draw 'image over 0,0 0,0' koeye.png -composite koeye_hand_10.gif
				cmd_coverlay = "convert {} -colorspace sRGB \ ".format( ifile )
				cmd_coverlay += " \( +clone -size 300x150 -tile gradient:LightYellow \ "
				cmd_coverlay += " -draw 'color 0,0 reset' \) \ "
				cmd_coverlay += " \( +clone -size 300x150 -tile plasma:tomato \ "
				cmd_coverlay += " -draw 'color 0,0 reset' \) \ "
				cmd_coverlay += " -reverse  -composite {}".format( ofile )
#				print progid,dttm, "ko_do: cmd_coverlay={}".format( cmd_coverlay )

#				cmd_convert="convert input.jpg -gravity South -annotate 0 '%f' output.jpg"

				if( len( cat ) >5 ):  pointsize=pointsize_default - 20
				if( fontcode == "yokkmokk" ):  pointsize=pointsize_default + 10
				cmd_convert="convert {} -font {} -stroke {} -gravity {} -pointsize {} -annotate 0 '{}' {}".format(ifile,font,stroke,gravity,pointsize,cat,ofile)
				print progid,dttm, "ko_do: cmd_convert={}".format( cmd_convert )
				os.system( cmd_convert )
	return("ko_do_return");



def ko_find(a1,a2):
	import subprocess
	import re
# bugs	from ffvideo import VideoStream
# bugs	import VideoStream
# bugs	import ffviceo

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
#	if( a2 != "" ):
	if( a1 != "" ):
		dttm=ko_dttm()
		print progid,dttm, "ko_go: a2=",a2
#		ko_listdir( sys.argv[2], sys.argv[3] )
		pathfile=a2
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print progid,dttm, "ko_go: path=",path," base=",base," ext=",ext

	if( a2 == "" ): todofile=a2


	dttm=ko_dttm()
	print progid,dttm,"ko_go a1=",a1
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print progid,dttm, "ko_go_find syscmd={}".format( syscmd_find )
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print progid,dttm, "ko_go ofilename={}".format( ofilename )
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#               syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#               syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
                syscmd='find . -name "*.mp4" -exec ls {} \; > '
                syscmd+=todofile
                syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
                print progid,dttm, "ko_go_find syscmd={}".format( syscmd )
                print progid,dttm, "ko_go_find pathcode={}".format( pathcode )
		os.system( syscmd )

	print progid,dttm, "ko_find todofile={}".format( todofile )
	return( "ko_find")


def runwl(a1,a2,a3):
	print progid,dttm, "runwl a1={} a2={} a3={}".format( a1,a2,a3 )
	wl_filename=a2
	linematch_beg='<div id="div_runwl">'
	linematch_end="</div>"

	db3_filename=wl_filename.replace(".todo", ".db3" )
	out_filename=wl_filename.replace(".todo", ".txt" )

	wl_file=open( wl_filename, "r" )
	out_file=open( out_filename, "wb" )

	j=0
	mode=""
	for line in wl_file:
		j=j+1
		f_file=line
		t_file=pathfile_fmt(f_file)
		print progid,dttm, "runwl {} t_file={} {}".format( j,t_file,f_file )
		if re.search( linematch_beg, line ):
			mode = "match"
		if re.search( linematch_end, line ):
			mode = ""

		print progid,dttm, "runwl wl_filename={} {} {}".format( wl_filename,j,line )

	wl_file.close
	return( "runwl_break" )

	sys_in, sys_out, sys_err = os.popen3(syscmd)  
	sys_outs = "".join(sys_out.read()).split("\n")
	sys_out_len = len( sys_outs )
	print "BUGS_410 sys_out_len={} sys_outs={}\n".format( sys_out_len, sys_outs )

	j=0
	for sys_out in sys_outs:
		j=j+1
		print "BUGS_430 j={} sys_out={}".format(j,sys_out)

	return( "runwl_ok" )

def load_lines_new(pathfiles):
	print "{} {} load_lines_new:  pathfiles={}".format( progid,dttm, pathfiles)

#	for j in range(1,10):
#		print "go_jsg j={}".format(j )
#		if j == 5: continue
#		if j == 8: break



	print "BUGS_380 pathfiles={}".format(pathfiles)

	lines_new=""	
	j=0
	for pathfile in pathfiles.split("\n"):
		j=j+1
		print "BUGS_395 j={} pathfile={}=".format(j, pathfile)
		if( len( pathfile ) < 3 ): continue

		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		dotext=os.path.splitext(base)[1]
		ext=dotext.replace(".", "")
		code=file.replace(".", "_")
		print "BUGS_400 ext={} dotext={}\n".format( ext, dotext )

		b64_raw = ""

 		if(os.path.isdir(path)):
			print "{} {} FOUND_DIR j={} path={} ".format( progid,dttm, j, path )
		if(os.path.exists(pathfile)):
			print "{} {} FOUND_FILE j={} pathfile={} ".format( progid,dttm, j, pathfile )
			b64_raw = base64.b64encode(open( pathfile, "rb").read()) 

#		print "BUGS_410 {} {} j={} code={} pathfile={} b64_raw={}".format( progid,dttm, j, code, pathfile, b64_raw )

		id="{}_{}".format( code, ext )

		b64_htm = ""
		print "BUGS_415 ext={} dotext={}\n".format( ext, dotext )
		b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )

		if( ext == "css"):
			b64_htm='<style id="{}" src="data:text/css;base64,{}" ></style>\n'.format( id, b64_raw )
		if( ext == "js"):
			b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )
		if( ext == "png" or ext=="gif" or ext=="jpg" or ext=="jpeg" ):
	 		b64_htm='<img id="{}" src="data:img/{};base64,{}" > \n'.format( id, ext, b64_raw )
		if( b64_htm == "" ):
			b64_htm='<script id="{}" src="data:text/plain;base64,{}" ></script>\n'.format( id, b64_raw )
#	 		b64_htm='<!-- <img id="{}" src="data:img/{};base64,{}" > -->\n'.format( id, ext, b64_raw )

#		if ext == "js":
#		if ext == "png":
#			b64_htm='<img id="{}" src="data:img/png;base64,{}" >\n'.format( id, b64_raw )
#		if ext == "gif":
#			b64_htm='<img id="{}" src="data:img/gif;base64,{}" >\n'.format( id, b64_raw )
#		if ext == "jpg":
#			b64_htm='<img id="{}" src="data:img/jpg;base64,{}" >\n'.format( id, b64_raw )


#		if n == 0:
#			print "You typed zero.\n"
#		elif n== 1 or n == 9 or n == 4:
#		    print "n is a perfect square\n"
#		elif n == 2:
#		    print "n is an even number\n"
#		elif  n== 3 or n == 5 or n == 7:
#		    print "n is a prime number\n"



		lines_new += "{}".format( b64_htm )

#	print "BUGS_410 {} {} lines_new={} pathfile={}".format( progid,dttm, lines_new, pathfile)
	return( lines_new )





def go_jsg(a1,a2):
	dttm=ko_dttm()
	print "{} {} a={} a2={}".format( progid, dttm, a1, a2 )

	j=0
	file_cur="index_jsg_basic.html"
	file_new="index_jsg_basic_new.html"
	file_old="index_jsg_basic_old.html"

	file_cur="./jsg/demos/basic.html"
#	file_new="./jsg/demos/basic_new.html"
	file_new="index_jsg_basic.html"
	file_old="./jsg/demos/basic_old.html"

	match_status=""
	match_beg="<title>"
	match_end="</title>"

	f_cur=open( file_cur, "r" )
	f_new=open( file_new, "wb" )
	print "{} {} go_jsg cur={} new={} ".format( progid,dttm, file_cur, file_new )

	pathfiles = """
./jsg/demos/demos.css
./jsg/demos/jsg_google.css
./jsg/css/jsgrid.css
./jsg/css/theme.css
./jsg/external/jquery/jquery-1.8.3.js
./jsg/demo/db.js
./jsg/src/jsgrid.core.js
./jsg/src/jsgrid.load-indicator.js
./jsg/src/jsgrid.load-strategies.js
./jsg/src/jsgrid.sort-strategies.js
./jsg/src/jsgrid.field.js
./jsg/src/fields/jsgrid.field.text.js
./src/fields/jsgrid.field.number.js
./jsg/src/fields/jsgrid.field.select.js
./jsg/src/fields/jsgrid.field.checkbox.js
./jsg/src/fields/jsgrid.field.control.js
"""
	lines_new=load_lines_new(pathfiles)
#	print "{} {} new={}  go_jsg pathfiles={}".format( progid,dttm, lines_new, pathfiles )

	for line in f_cur:
		j=j+1
		f_file=line
		if re.search( "</head>", line ): f_new.write( "	-->\n\n" )
		f_new.write( line )
		if re.search( match_beg, line ):
			f_new.write( lines_new )
			f_new.write( "\n\n<!--\n" )
			match_status = "match"
			print "{} {} go_jsg MATCH_BEG  j={} match={} line={}".format( progid, dttm, j, match_beg, line )
			print "{} {} go_jsg MATCH_BEG  j={} match={} lines_new={}".format( progid, dttm, j, match_beg, lines_new )
		if re.search( match_end, line ):
			print "{} {} go_jsg MATCH_END  j={} match={} line={}".format( progid, dttm, j, match_end, line )
			match_status = ""

	f_cur.close
	f_new.close
	print "{} {} go_jsg j={} cur={} new={} old={}".format( progid, dttm, j, file_cur, file_new, file_old )
	return( "" )

def ko_kov(a1,a2):
	import subprocess
	import re
	dttm=ko_dttm()
	print("{} {} ko_kov: a2={} a3={}".format( progid, dttm, sys.argv[2], sys.argv[3] ))
	j=0
	kovlist = ""
	kovlist += "kov_ko|"
	kovlist += "kov_new|"
	kovlist += "kov_focus|"
	kovlist += "kov_food|"
	kovlist += "kov_courtreport|"
	kovlist += "kov_where|"
	kovlist += "kov_work|"
	kovlist += "kov_memes|"
	kovlist += "kov_kids|"
	kovlist += "kov_dogs|"
	kovlist += "kov_preserve|"
	kovlist += "kov_protect|"
	kovlist += "kov_jtfdc|"
	kovlist += "kov_jtfinc|"
	kovlist += "kov_byrdpucker|"
	kovlist += "kov_jkwii|"
	kovlist += "kov_kou|"
	kovlist += "kov_kassil|"
	kovlist += "kov_konet|"
	kovlist += "kov_iperms|"
	kovlist += "kov_konabus|"
	kovlist += "kov_kt|"
	kovlist += "kov_go|"
	kovlist += "kov_old"

	j=0
	for kovid in kovlist.split("|"):
		j=j+1
		syscmd_cp="cp index_kov.html {}.html".format( kovid )
		print( "ko_kov_830 DISABLED j={} syscmd={}".format(j, syscmd_cp))
#		os.system(syscmd_cp)
		
	return()
def mth2mm(month):
    months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    return months.index(month) + 1



def go(a1,a2):
	import subprocess
	import re

	dttm=ko_dttm()

	print( "BUGS_850 {} {} {}".format(dttm, a0, a1))

	wlfile=a1
	psvfil=wlfile.replace(".txt", ".psv" )
	sqlfil=wlfile.replace(".txt", ".sql" )

	wl = open( wlfile, "r")
	sql = open( sqlfil, "wb")
	psv = open( psvfil, "wb")

	ext=wlfile.replace("find_","").replace(".txt","")
	tblnam=ext
	print( "BUGS_871 psvfil={} tblnam={}".format(psvfil,tblnam))
	print( "BUGS_872 sqlfil={} tblnam={}".format(sqlfil,tblnam))

	(i,j,k) = (0,0,0)
	sqlout = ""

	sqlout += "create table if not exists {} as select * from files limit 5;\n".format(tblnam)
	sqlout += "delete from {};\n".format(tblnam)
	

	
	for line in wl:
		j=j+1
		dttm=ko_dttm()
		pathfile=line.split()[8]
		size=line.split()[4]
		mth=line.split()[5]
		mm=mth2mm(mth)
		day=line.split()[6]
		yyyyhms=line.split()[7]
		yyyy=line.split()[7]
		if( yyyy.find(":")): yyyy="2021"
#		ctime="{},{},{}".format(yyyyhms.split(':'),mm,day)
		ctime="{},{},{}".format(yyyy,mm,day)
		cdate="{},{},{}".format(yyyy,mm,day)


		pathfile=pathfile.replace("'","")
		pathfile=pathfile.replace(" ","_")

		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1].replace( ".", "" )

#		size=os.path.getsize(pathfile)	
#		ctime=get_ctime(pathfile)
		print( "{}_{} pathfile={} line={}".format(dttm,j,pathfile,line))
		print( "{}_{} pathfile={} path={} base={} file={} ext={} size={} ctime={}".format(dttm,j,pathfile,path,base,file,ext,size,ctime ))





		i=i+1
		j=i+1
		startdate="1900,1,1"
		enddate="1900,1,1"
		headline=base
		text="text"
		media=pathfile
		credit="credit"
		caption="caption"
		f_name=file
		f_type=ext
		f_size=size
		fbid="fb_{}".format(ext)
		tlid="tl_{}".format(ext)
		
		starttime="00:00"
		endtime="00:00"
		thumbnail="{}".format("/imgs/btn/ko.png")
		link="{}".format(base)
		tn="{}_{}.png".format("/imgs/btn/btn",ext)
		title="{}".format(base)
		fpathfile=pathfile
		tpathfile=""
		fn_dttm=ctime
		fn_dt=ctime
		fn_tm=ctime
		exif_dttm=""
		desc="pathfile"
	
		psvout=""
#		psvout="{}|{}|{}|{}|{}|{}|{}\n".format(pathfile,path,base,file,ext,size,ctime)
		psvout += "{}|".format( progid )
		psvout += "{}|".format( dttm )
		psvout += "{}|".format( "status" )
		psvout += "{}|".format( "krow" )
		psvout += "{}|".format( f_name )
		psvout += "{}|".format( f_type )
		psvout += "{}|".format( f_size )
		psvout += "{}|".format( "f_error" )
		psvout += "{}|".format( "f_tmp" )
		psvout += "{}|".format( "t_name" )
		psvout += "{}|".format( "referer" )
		psvout += "{}|".format( "query_string" )
		psvout += "{}|".format( "user_agent" )
		psvout += "{}|".format( "remote_addr" )
		psvout += "{}|".format( "remote_port" )
		psvout += "{}|".format( "server_addr" )
		psvout += "{}|".format( "server_port" )
		psvout += "{}|".format( "grp" )
		psvout += "{}|".format( "ord" )
		psvout += "{}|".format( "avid" )
		psvout += "{}|".format( fbid )
		psvout += "{}|".format( tlid )
		psvout += "{}|".format( pathfile )
		psvout += "{}|".format( path )
		psvout += "{}|".format( file )
		psvout += "{}|".format( base )
		psvout += "{}|".format( ext )
		psvout += "{}|".format( size )
		psvout += "{}|".format( ctime )
		psvout += "{}|".format( "mtime" )
		psvout += "{}|".format( fpathfile )
		psvout += "{}|".format( "tpathfile" )
		psvout += "{}|".format( fn_dttm )
		psvout += "{}|".format( "fn_dt" )
		psvout += "{}|".format( "fn_tm" )
		psvout += "{}|".format( "exif_dttm" )
		psvout += "{}|".format( "exif_dt" )
		psvout += "{}|".format( "exif_tm" )
		psvout += "{}|".format( "exif_zm" )
		psvout += "{}|".format( "exif_path" )
		psvout += "{}|".format( "exif_file" )
		psvout += "{}|".format( "exif_imgsize" )
		psvout += "{}|".format( "exif_ctime" )
		psvout += "{}|".format( "exif_duration" )
		psvout += "{}|".format( starttime )
		psvout += "{}|".format( endtime )
		psvout += "{}|".format( title )
		psvout += "{}|".format( thumbnail )
		psvout += "{}|".format( "alt" )
		psvout += "{}|".format( link )
		psvout += "{}|".format( "linktarget" )
		psvout += "{}|".format( "src" )
		psvout += "{}|".format( tn )
		psvout += "{}|".format( "tn1" )
		psvout += "{}|".format( "tn2" )
		psvout += "{}|".format( startdate )
		psvout += "{}|".format( enddate )
		psvout += "{}|".format( headline )
		psvout += "{}|".format( text )
		psvout += "{}|".format( "assets" )
		psvout += "{}|".format( media )
		psvout += "{}|".format( credit )
		psvout += "{}|".format( caption )
		psvout += "{}|".format( i )
		psvout += "{}|".format( j )
		psvout += "{}|".format( k )
		psvout += "{}|".format( "l" )
		psvout += "{}|".format( "w" )
		psvout += "{}|".format( "h" )
		psvout += "{}|".format( "t" )
		psvout += "{}|".format( "x" )
		psvout += "{}|".format( "y" )
		psvout += "{}|".format( "z" )
		psvout += "{}|".format( "t1" )
		psvout += "{}|".format( "x1" )
		psvout += "{}|".format( "y1" )
		psvout += "{}|".format( "z1" )
		psvout += "{}|".format( "t2" )
		psvout += "{}|".format( "x2" )
		psvout += "{}|".format( "y2" )
		psvout += "{}|".format( "z2" )
		psvout += "{}|".format( "temp" )
		psvout += "{}\n".format( desc )
	
		print( "PSVOUT i={} j={} base={} psvout={}".format( i,j,base,psvout))
		psv.write(psvout)

		sqlout=""
		sqlout="insert or replace into {} ('pathfile') values ('{}')\n".format(tblnam,pathfile)
		
#		sqlout="insert or replace into {} ('pathfile','base','ext','size','ctime') values ('{}','{}','{}','{}','{}')".format(tblnam,pathfile,base,ext,size,ctime)
		sqlout="insert or replace into {} ( 'pathfile','path','base', 'file','ext','size','ctime' ) values ( '{}','{}','{}','{}','{}','{}','{}' );\n".format ( tblnam,pathfile,path,base,file,ext,size,ctime ) 
		print( "SQLOUT={}".format(sqlout))
		sql.write(sqlout)

	wl.close()
	psv.close()
	sql.close()
	print( "{}_{} go psvfil={}".format(progid,dttm,psvfil))
	print( "{}_{} go sqlfil={}".format(progid,dttm,sqlfil))
	exit()


	if( sys.argv[2] == "find"):
		print "pqpqpqpqpqpqpqpqpqpqpqpq"
		pathfile=sys.argv[3]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		brackets = "{}"
		sys_lslat = "ls -lat {}".format( pathfile )
		sys_find='find {} -type f -name "{}"  -exec ls -lat {} \;'.format(path,base,brackets)
		print progid,dttm,"ko_find sys_find=",sys_find




#		convert_gif2pngs = "convert {} {}".format(newgif, newpngs )
#		print "BUGS_1670 gif2gifs g={} convert_gif2pngs={}\n".format( g, convert_gif2pngs )
#		os.system( convert_gif2pngs )


#		lines = kocmd(sys_lslat).split('\n')
		lines = kocmd(sys_find).split('\n')
		lineslen = len(lines)
#		print "BUGS_1670 line={} llen={}\rn".format( lines, lineslen )
		
		j=0
		for line in lines:
			j=j+1
			print "go find j={}  line={}".format(j,line)
			flds=line.split(" ")
			fldlen=len(flds)
			print "j={} fldlen={} line={}".format(j,fldlen,line)
#			perms=flds[0]
#			kludge=line.split(" ")[1]
#			permu=flds[1]
#			permg=flds[2]
#			size=flds[4]
#			mth=flds[5]
#			dd=flds[6]
#			hh_mm=flds[7]
#			pathfile=flds[8]
#			print "flds j={} size={} mth={} dd={} hh_mm={} pathfile={}".format(j,size,mth,dd,hh_mm,pathfile)
#
#			lsnam=line.split(" ")[lslen-1]
#			png_file = gif_file
#			pngnam = "{}/{}{}-{}.png".format(gif_path, png_file, giftag, r )
#			if( p < pnglen-1 ):
#				pngs += "{} ".format(pngnam)
#				print "BUGS_1671 pnglen={} p={} r={}".format( pnglen, p, r)
#				print "BUGS_1672 pnglen={} p={} r={} pngnam={}".format(pnglen,p,r,pngnam)
#				print "BUGS_1673 lsnam={}\n".format(lsnam)
#			p=p+1
#
#		convert_pngs2gif = "convert {} {}".format( pngs, newgif )
#		print "BUGS_1680 pnglen={} convert_pngs2gif={}\n".format( pnglen, convert_pngs2gif )
#		os.system( convert_pngs2gif )
#		print "BUGS_1680 pnglen={} ls_png={}\n".format( pnglen, ls_png )
#		exit()





	print "bdbdbdbdbdbdbdbdbdbdbdbd"

	exit()

	ko_usid2host( usid, grp )
	exit()

	if( sys.argv[1].match("find")):
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		print "GO FIND"
		exit()




	exit()

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
	if( a2 != "" ):
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print progid,dttm, "ko_go: path=",path," base=",base," ext=",ext


	dttm=ko_dttm()
	print progid,dttm,"ko_go a1=",a1
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

	syscmd="pwd;date"
	print progid,dttm, "ko_go_syscmd syscmd={}".format( syscmd)
	os.system( syscmd)





	exit()

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print progid,dttm, "ko_go_find syscmd={}".format( syscmd_find )
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print progid,dttm, "ko_go ofilename={}".format( ofilename )
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#               syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#               syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
                syscmd='find . -name "*.mp4" -exec ls {} \; > '
                syscmd+=todofile
                syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
                print progid,dttm, "ko_go_find syscmd={}".format( syscmd )
                print progid,dttm, "ko_go_find pathcode={}".format( pathcode )
		os.system( syscmd )

	ifilename=todofile
	print progid,dttm, "go ifilename={}".format( ifilename )
	return("go")


#	ifile = open(ifilename, "r" )
##	j=0
#	ofilename_mv="ko_go_mv.sh"
#	oline_mv = "# ko_go_mv.sh {}\n".format(dttm)
#	ofile_mv = open( ofilename_mv, "wb" )
#	ofile_mv.write( oline_mv )
#	mv.close()








def ko_go(a1,a2):
	import subprocess
	import re
# bugs	from ffvideo import VideoStream
# bugs	import VideoStream
# bugs	import ffviceo

#	if( sys.argv[1].match("listdir")):
#	if( sys.argv[1] == "listdir" ):
#	if( a2 != "" ):
	dttm=ko_dttm()

	if( sys.argv[2] == "." ):
		print "{} {} ko_go: go . .".format( progid, dttm )
		print "{} {} ko_go: go find ../i 'oagland.mpr' .".format( progid, dttm )
		print "{} {} ko_go: go uslist .".format( progid, dttm )
#		print "{} {} ko_go: go uslaw .".format( progid, dttm )
		print "{} {} ko_go: go usmed .".format( progid, dttm )
		print "{} {} ko_go: go cp .".format( progid, dttm )
		print "{} {} ko_go: go scp .".format( progid, dttm )
		print "{} {} ko_go: go ssh .".format( progid, dttm )
		exit()

	print "BUGS_970"
	if( sys.argv[2] == "find" ):
		pathfile=sys.argv[3]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		ext = ext.replace( ".", "" )
		filid =os.path.splitext(base)[0]
		findname=base
		findpath=path
		j=0
		findthis = "go find path={} base={}".format(path, base)
		sys_find="find {} -name {} -exec ls -lat {} \;"
		finds = ko_find( path, base )
		for find in finds:
			print "go find j={} find={}".format( j, find )
		exit()

	print "EXIT_1000"
	exit()
	import sqlite3
	dttm=ko_dttm()
	sqlfil="ko.db3"
	sqlcmd="select cat,test,testdt from lab"
	sqlcmd="select * from uslist"
	sqlcmd="select usid,dttm,status,url,img,tn,id,grp from uslist "
	print progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )
	fildb3="ko.db3"

	try:
		sqldb = sqlite3.connect(fildb3)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print "r0={} r1={} r3={}".format( row[0], row[1], row[2] )
# err		print "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] )
#		print(row)

	print progid,dttm,"ko_usid2host sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )


	db = sqlite3.connect(fildb3)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()

	sqlcmd='''select usid,dttm,status,url,img,tn,id,grp from uslist'''
	cursor.execute(sqlcmd)
#	cursor.execute('''select name, email, phone from uslist limit 4''')

	osflag = ""
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['usid'], row['url'], row['img'], row['tn'], row['id'], row['grp'], row['status']))
		grp=row['grp']
		id=row['id']
		url=row['url']
		img=row['img']
		tn=row['tn']
		status=row['status']

		syscmd_mkdir_grp = "mkdir uw/{}".format(grp)
		print "usid2host syscmd_mkdir_grp={}".format( syscmd_mkdir_grp )

		syscmd_mkdir_grpid = "mkdir uw/{}/{}".format(grp,id)
		print "usid2host grp={} id={} syscmd_mkdir_grpid={}".format( grp, id, syscmd_mkdir_grp)

		osflag = ""
		print "osflag={}".format(osflag)
#		if( osflag == "y" ): os.system( syscmd_mkdir_grp )
#		if( osflag == "y" ): os.system( syscmd_mkdir_grpid )


#	db.close()
#	return( "ko_usid2host" )




	def sql_cr(fildb3, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)


	uslist = load_uslist()
	j=0
	status="todo"
	dttm=ko_dttm()
	for us in uslist:
		print "j={} us={}".format(j, us)

		url=us.split("|")[0]
		img=us.split("|")[1]
		tn=us.split("|")[2]
		id=us.split("|")[3]
		grp=us.split("|")[4]
		status="todo"

		sqltbl = "uslist"
		sqlcols = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'{}','{}','{}','{}','{}','{}','{}'".format(id,grp,url,img,tn,status,dttm)

		sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
		print "{}".format(sql_insert)
#		print "usid2host j={} sql_insert={}".format(j,sql_insert)
#		print "j={} grp={} id={} url={} img={}".format( j, grp, id, url, img )
#		cur.execute(sql_insert)
		cursor.execute(sql_insert)

#		def sql_insert(fildb3, sql_insert ):
#			sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
#
#
#		def sql_insert(fildb3, sqlcmd ):
#		sqlcmd = """INSERT INTO table1 (
#		sqlcmd = """insert or replace into  uslist (
#				'id','grp','url','img','tn','status','dttm' )
#			VALUES (
#				sqlval
##				value1, value2 ,...
#				); """
#
		j=j+1
	db.close()
	return("ko_sql_return");




	if( sys.argv[2] == "filio" ):
		curfil = sys.argv[3]
		base = curfil.split(".")[0]
		base = os.path.basename( curfil )
		ext = os.path.splitext(base)[1]
		ext = ext.replace( ".", "" )
		filid =os.path.splitext(base)[0]

		dttg = dttm
		dttg = dttg.replace( ":","")
		dttg = dttg.replace( "-","")

		oldtxt="<html>"
		curtxt="<!-- html {} -->\n".format( base )
		newtxt=""
		newfil="{}_new_{}.{}\n".format( filid, dttg, ext )
		oldfil="{}_old_{}.{}\n".format( filid, dttg, ext )
		if( os.path.exists(curfil)):
			cpcmd = "cp {} {}".format( curfil, oldfil )
#			print "{} {} ko_go: go filio cpcmd={}".format( progid, dttm, cpcmd )
#			os.system( cpcmd )
		print "{} {} ko_go: go filio \n curfil={} \n oldfil={} \n newfil={} \n oldtxt={} \n newtxt={} ".format( progid, dttm, curfil, oldfil, newfil, oldtxt, newtxt )
		exit
		newtxt=filio( curfil,filid )
#		newf = open( newfil, "w" )
#		newf.write( newtxt )
#		newf.close		
#		print "{}".format(newtxt)

	if( sys.argv[2] == "htms2htm" ):
		htmout=htms2htm( "svc/jqgrid")
		print "{} {} ko_go: go htmout={} ".format( progid, dttm, htmout )

	if( sys.argv[2] == "phps2php" ):
		phpout=phps2php('')
		print "{} {} ko_go: go phpout={} ".format( progid, dttm, phpout )

	if( sys.argv[2] == "newhtm" ):
		print "{} {} ko_go: go newhtm ".format( progid, dttm )
		htmids=sys.argv[3]

		if( htmids == '.' ):
			htmout=newhtm('templet kogrids kov_hideshow dragons ajaxdb3 kovs_utl')
			print ('{}').format(htmout)
			exit()
		if( len(htmids) > 3 ):
			htmout=newhtm(htmids)
			print ('{}').format(htmout)	
			exit
#		if( htmids == "txt" ):
#			htmout_txt=newhtm('templet kogrids kov_hideshow dragons ajaxdb3 kovs_utl')
#			print( 'htmout_txt={}'.format(htmout_txt)
#			exit
#		if( htmids == 'psv' ):
#			htmids=newhtm('templet|kogrids|kov_hideshow|dragons|ajaxdb3|kov_utl')
#			print( 'htmout_psv={}'.format(htmout_psv)
#		if( htmids == 'csv'):
#			htmout_csv=newhtm('templet,kogrids,kov_hideshow,dragons,ajaxdb3,kov_utl')
#			print( 'htmout_csv={}'.format(htmout_csv)
#		if( htmids == 'spl' ):
#			htmout_spl=newhtm('templet,kogrids,kov_hideshow,dragons,ajaxdb3,kov_utl')
#			print( 'htmout_spl={}'.format(htmout_spl)
#		return( htmout)
#		exit


#	if( sys.argv[2] == "uslaw" ):
	if( sys.argv[2] == "uslist" ):
		uslist = load_uslist()
		k=0
		for usline in uslist:
			k=k+1
			url = usline.split("|")[0]
			img = usline.split("|")[1]
			tn = usline.split("|")[2]
			id = usline.split("|")[4]
			code=img.replace(".png","")
			code=code.replace("/imgs/us/", "")
			code=code.replace( id, "" )
			code=code.replace( "_", "" )

			urlus="/us/{}/{}/".format( id, code )
			print "id={} ".format( id )

			syscmd_mkdir_id = "mkdir us/{}/".format( id )
			syscmd_mkdir_idcode = "mkdir us/{}/{}/".format( id, code )
			syscmd_mkdir_idcode_img = "mkdir us/{}/{}/imgs".format( id, code )
			syscmd_mkdir_idcode_tn = "mkdir us/{}/{}/imgs/tn".format( id, code )
			syscmd_cp_index = "cp index.html us/{}/{}/index.html".format( id, code )
			syscmd_cp_img = "cp imgs/btn/koeyeb.png us/imgs/{}_{}.png".format( id, code )
			syscmd_cp_tn = "cp imgs/btn/koeyew.png us/imgs/tn/tn_{}_{}.png".format( id, code )

			htmout = '\n' 
			htmout += '	<div id="drag">\n'
			htmout += '		<div class="drag">\n'
			htmout += '		<a href="{}" target=_blank class="thumbnail">\n'.format(url)
			htmout += '			<img  class="drg" src=/us/imgs/tn/tn_{}_{}.png border=0 height=200>\n'.format(id, code)
			htmout += '			<span><img class="drg" src=/us/imgs/{}_{}.png border=0 height=400></span>\n'.format(id, code)
			htmout += '			</a>\n'
			htmout += '			</div>\n'
			htmout += '		</div>\n'
			syscmd_htmout = 'echo "{}" >> us/{}/{}/index.html'.format( htmout, id, code )

			print "syscmd_mkdir_id={}".format( syscmd_mkdir_id )
			print "syscmd_mkdir_idcode={}".format( syscmd_mkdir_idcode )
			print "syscmd_mkdir_idcode_img={}".format( syscmd_mkdir_idcode_img )
			print "syscmd_mkdir_idcode_tn={}".format( syscmd_mkdir_idcode_tn )

#			print "syscmd_cp_index={}".format( syscmd_cp_index )
#			print "syscmd_htmout={}".format( syscmd_htmout )
#			print "syscmd_cp_img={}".format( syscmd_cp_img )
#			print "syscmd_cp_tn={}".format( syscmd_cp_tn )

			os.system( syscmd_mkdir_id )
			os.system( syscmd_mkdir_idcode )
			os.system( syscmd_mkdir_idcode_img )
			os.system( syscmd_mkdir_idcode_tn )
			os.system( syscmd_cp_index )
			os.system( syscmd_cp_img )
			os.system( syscmd_cp_tn )
			os.system( syscmd_htmout )
			exit()

#			print "code={} k={} id={} ".format(code, k, id )
#			print "{} {} go usline k={} code={} url={} id={}".format(progid,dttm,k,code, url,id)
#			print "{} {} go usline k={} url={} img={} tn={} id={} usline={}".format(progid,dttm,k, url,img,tn,id, usline)
		exit()




	if( sys.argv[2] == "usmed" ):
#		my_date = datetime.date(*[int(i) for i in string_date.split("-")])

		usmeds_default = [
"smith",
"katyal",
"bammimore",
"rechtin",
"mcdonough"
			]
		k=0
		klim=len(usmeds_default)
		usmeds=usmeds_default
		if( sys.argv[3].isdigit() ):	
			print "BUGS IS_DIGIT k={} klim={}".format(k, klim )
			k=int(sys.argv[3])
			if( k <= klim ):
				print "BUGS IS_DIGIT_K k={} klim={}".format(k, klim )
				usmeds = [usmeds_default[k-1]]
		else:
			print "BUGS NO_DIGIT k={} klim={}".format(k, klim )
			


			if( sys.argv[3] == "rechtin" ):
				usmeds =  [sys.argv[3]]
			if( sys.argv[3] == "mcdonough" ):
				usmeds = [sys.argv[3]] 
			if( sys.argv[3] == "jkwii" ):
				usmeds =  ["jkwii"]

#			k=int(sys.argv[3])
#			klim=5
#			if( isinstance(k, int)):

#			print "{} {} go_usmed argv3=int k={} len={}".format( progid, dttm, k, klim )
#			if( k <= klim ):
#				print "{} {} go_usmed ONE argv3=int k={} len={}".format( progid, dttm, k, klim )
#				usmeds = [usmeds_default[k]]
#			else:
#				print "{} {} go_usmed ALL  argv3=int k={} len={}".format( progid, dttm, k, klim )
#				usmeds = usmeds_default
	
			if( sys.argv[3] == "." ):
				usmeds = usmeds_default
	
	



		uhdata = (
"ko0|kozerus@ko0.us|~/public_html",
"ko2|kotwous@ko2.us|~/public_html",
"ka1|konet@ka11|/ht",
"ka2|konet@ka21|/ht",
"ka11|konet@ka11|/Volumes/ka1tbr1",
"ka12|konet@ka11|/Volumes/ka1tbr2",
"ka21|konet@ka21|/Volumes/ka2tbr1",
"ka22|konet@ka21|/Volumes/ka2tbr2"
			)

		uhlist = (
"ko0|kozerus@ko0.us|~/public_html",
"ko2|kotwous@ko2.us|~/public_html"
			)



		j=0
		for uhline in uhlist:
			j=j+1
			uhcode = uhline.split("|")[0]
			uhhost = uhline.split("|")[1]
			uhroot = uhline.split("|")[2]
			print "{} {} {} uhcode={} uhhost={} uhroot={}".format( progid, dttm, j, uhcode, uhhost,uhroot )
			k=0
			for usmed in usmeds:
				k=k+1

				j=j+1
				print "{} {} usmed={} k={} uhhost={} uhroot={}".format( progid, dttm, usmed, k, uhhost, uhroot )
				sshcmd_mkdir_us_med='ssh {} "mkdir {}/us/med/"'.format( uhhost, uhroot )
				sshcmd_mkdir_us_med_usmed='ssh {} "mkdir {}/us/med/{}/"'.format( uhhost, uhroot, usmed )
				sshcmd_mkdir_us_med_usmed_imgs='ssh {} "mkdir {}/us/med/{}/imgs/"'.format( uhhost, uhroot, usmed )
				sshcmd_mkdir_us_med_usmed_imgs_tn='ssh {} "mkdir {}/us/med/{}/imgs/tn/"'.format( uhhost, uhroot, usmed )
	
				scpcmd_us_img="scp us/imgs/med_{}.png {}:{}/us/imgs/".format( usmed, uhhost, uhroot )
				scpcmd_us_tn="scp us/imgs/tn/tn_med_{}.png kozerus@ko0.us:{}us/imgs/tn/".format( usmed, uhhost, uhroot )
			
				cpcmd_us_med_usmed_index_html = "cp us/med/index.html us/med/{}/index.html".format(usmed)
				cpcmd_us_med_index_us_med_usmed_html = "cp us/med/index_us_med.html us/med/index_us_med_{}.html".format(usmed)
	
				scpcmd_us_med_usmed_imgs_tn="scp us/med/{}/imgs/tn/*.png {}:{}/us/med/{}/imgs/tn/".format( usmed, uhhost, uhroot, usmed )
				scpcmd_us_med_usmed_imgs="scp us/med/{}/imgs/*.png {}:{}/us/med/{}/imgs/".format( usmed,  uhhost, uhroot, usmed )
				scpcmd_us_med_usmed="scp us/med/{}/*.* {}:{}/us/med/{}/".format(usmed, uhhost, uhroot , usmed )
				scpcmd_us_med_usmed_index_html = "scp us/med/{}/index.html {}:{}/us/med/{}".format(usmed, uhhost, uhroot ,usmed )
				scpcmd_us_med_index_us_med_usmed_html = "scp us/med/index_us_med_{}.html {}:{}/us/med/".format(usmed, uhhost, uhroot )


				print "{} {} usmed={} sshcmd_mkdir_us_med={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med )
				print "{} {} usmed={} sshcmd_mkdir_us_med_usmed={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed )
				print "{} {} usmed={} sshcmd_mkdir_us_med_usmed_imgs={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed_imgs )
				print "{} {} usmed={} sshcmd_mkdir_us_med_usmed_imgs_tn={}".format( progid, dttm,usmed,  sshcmd_mkdir_us_med_usmed_imgs_tn )


				print "{} {} usmed={} cpcmd_us_med_index_us_med_usmed_html={}".format( progid, dttm, usmed,  cpcmd_us_med_index_us_med_usmed_html )
				print "{} {} usmed={} cpcmd_us_med_usmed_index_html={}".format( progid, dttm, usmed,  cpcmd_us_med_usmed_index_html )


				print "{} {} usmed={} scpcmd_us_med_usmed_imgs_tn={}".format(  progid, dttm,usmed, scpcmd_us_med_usmed_imgs_tn )
				print "{} {} usmed={} scpcmd_us_med_usmed_imgs={}".format(  progid, dttm,usmed, scpcmd_us_med_usmed_imgs)
				print "{} {} usmed={} scpcmd_us_med_usmed={}".format( progid, dttm,usmed,  scpcmd_us_med_usmed)
	
				print "{} {} usmed={} scpcmd_us_img={}".format( progid, dttm, usmed, scpcmd_us_img )
				print "{} {} usmed={} scpcmd_us_tn={}".format( progid, dttm, usmed,  scpcmd_us_tn )

				print "{} {} usmed={} scpcmd_us_med_usmed_index_html={}".format( progid, dttm, usmed,  scpcmd_us_med_usmed_index_html )
				print "{} {} usmed={} scpcmd_us_med_index_us_med_usmed_html={}".format( progid, dttm, usmed,  scpcmd_us_med_index_us_med_usmed_html )

#				os.system( sshcmd_mkdir_us_med )
#				os.system( sshcmd_mkdir_us_med_usmed )
#				os.system( sshcmd_mkdir_us_med_usmed_imgs )
#				os.system( sshcmd_mkdir_us_med_usmed_imgs_tn )

#				os.system( cpcmd_us_med_index_us_med_usmed_html )
#				os.system( cpcmd_us_med_usmed_index_html )

#				os.system( scpcmd_us_med_usmed_imgs_tn )
#				os.system( scpcmd_us_med_usmed_imgs)
#				os.system( scpcmd_us_med_usmed)

#				os.system( scpcmd_us_img )
#				os.system( scpcmd_us_tn )

#				os.system( scpcmd_us_med_usmed_index_html )
#				os.system( scpcmd_us_med_index_us_med_usmed_html )
			exit()

	if( sys.argv[2] == "cp" ):
		print progid,dttm, "ko_go cp: a2=",a2
		syscmd_cp_ko0dt="cat index.html | sed s!-=kako=-!-=ko0us=-!g > index_ko0dt.html"
		syscmd_cp_ko2dt="cat index.html | sed s!-=kako=-!-=ko2us=-!g > index_ko2dt.html"
		syscmd_cp_ka1dt="cat index.html | sed s!-=kako=-!-=ka1lo=-!g > index_ka1dt.html"
		syscmd_cp_ka2dt="cat index.html | sed s!-=kako=-!-=ka2lo=-!g > index_ka2dt.html"

		print "{} {} ko_go cp ko0dt: syscmd_cp_ko0dt={}".format(progid,dttm,syscmd_cp_ko0dt)
		os.system( syscmd_cp_ko0dt )
		print "{} {} ko_go cp ko2dt: syscmd_cp_ko2dt={}".format(progid,dttm,syscmd_cp_ko2dt)
		os.system( syscmd_cp_ko2dt )
		print "{} {} ko_go cp ka1dt: syscmd_cp_ka1dt={}".format(progid,dttm,syscmd_cp_ka1dt)
		os.system( syscmd_cp_ka1dt )
		print "{} {} ko_go cp ka2dt: syscmd_cp_ka2dt={}".format(progid,dttm,syscmd_cp_ka2dt)
		os.system( syscmd_cp_ka2dt )

		syscmd_cp_ko0="cat index_ko0dt.html | sed s!-=dttm=-!-={}=-!g > index_ko0.html".format(dttm)
		syscmd_cp_ko2="cat index_ko2dt.html | sed s!-=dttm=-!-={}=-!g > index_ko2.html".format(dttm)
		syscmd_cp_ka1="cat index_ka1dt.html | sed s!-=dttm=-!-={}=-!g > index_ka1.html".format(dttm)
		syscmd_cp_ka2="cat index_ka2dt.html | sed s!-=dttm=-!-={}=-!g > index_ka2.html".format(dttm)

		print "{} {} ko_go cp ko0: syscmd_cp_ko0={}".format(progid,dttm,syscmd_cp_ko0)
		os.system( syscmd_cp_ko0 )
		print "{} {} ko_go cp ko2: syscmd_cp_ko2={}".format(progid,dttm,syscmd_cp_ko2)
		os.system( syscmd_cp_ko2 )
		print "{} {} ko_go cp ka1: syscmd_cp_ka1={}".format(progid,dttm,syscmd_cp_ka1)
		os.system( syscmd_cp_ka1 )
		print "{} {} ko_go cp ka2: syscmd_cp_ka2={}".format(progid,dttm,syscmd_cp_ka2)
		os.system( syscmd_cp_ka2 )
		exit()

	if( sys.argv[2] == "ssh" ):
		sshcmd = "pwd;date;uname;"
		sshcmd_ko0='ssh kozerus@ko0.us \"{}\"'.format( sshcmd )
		sshcmd_ko2='ssh kotwous@ko2.us "{}"'.format( sshcmd )
		sshcmd_ka1='ssh konet@ka1.lo "{}"'.format( sshcmd )
		sshcmd_ka2='ssh konet@ka2.lo "{}"'.format( sshcmd )

		if( sys.argv[3] == "." ) or ( sys.argv[3] == "ko" ):
			print( "{} {} ko_go ssh: sshcmd_ko0={}".format(progid,dttm,sshcmd_ko0))
#			os.system( sshcmd_ko0 )
			print( "{} {} ko_go ssh: ssycmd_ko2={}".format(progid,dttm,sshcmd_ko2))
#			os.system( sshcmd_ko2 )

		if( sys.argv[3] == "ko0" ):
			print( "{} {} ko_go ssh: sshcmd_ko0={}".format(progid,dttm,sshcmd_ko0))
#			os.system( sshcmd_ko0 )

		if( sys.argv[3] == "ko2" ):
			print( "{} {} ko_go ssh: ssycmd_ko2={}".format(progid,dttm,sshcmd_ko2))
#			os.system( sshcmd_ko2 )
		if( sys.argv[3] == "ka1" ):
			print( "{} {} ko_go ssh: ssycmd_ka1={}".format(progid,dttm,sshcmd_ka1))
#			os.system( sshcmd_ka1 )
		if( sys.argv[3] == "ka2" ):
			print( "{} {} ko_go ssh: ssycmd_ka2={}".format(progid,dttm,sshcmd_ka2))
#			os.system( sshcmd_ka2 )
		exit()

	if( sys.argv[2] == "scp" ):
		print progid,dttm, "ko_go scp: a2=",a2
		scpcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
		scpcmd_ko2 = "scp index_ko2.html kotwous@ko2.us:~/public_html/index.html"
		scpcmd_ka1 = "cp index_ka1.html /ht/index.html"
		scpcmd_ka2 = "scp index_ka2.html konet@ka2.lo/ht/index.html"

		scpcmd_ka10 = "cp index_ka10.html /ht/index.html"
		scpcmd_ka11 = "cp index_ka11.html /Volumes/ka1tbr1/ht/index.html"
		scpcmd_ka12 = "cp index_ka12.html /Volumes/ka1tbr2/ht/index.html"
		scpcmd_ka20 = "scp index_ka20.html konet@ka2.lo:~/ht/index.html"
		scpcmd_ka21 = "scp index_ka21.html konet@ka2.lo:~/Volumes/ka2tbr1/index.html"
		scpcmd_ka22 = "scp index_ka22.html konet@ka2.lo:~/Volumes/ka2tbr2/index.html"

		if( sys.argv[3] == "." ) or ( sys.argv[3] == "ko" ):
			print "{} {} ko_go scp ko0: scpcmd_ko0={}".format( progid, dttm, scpcmd_ko0)
			os.system( scpcmd_ko0 )
			print "{} {} ko_go scp ko2: scpcmd_ko2={}".format( progid, dttm, scpcmd_ko2)
			os.system( scpcmd_ko2 )

		if( sys.argv[3] == "ko0" ):
			print "{} {} ko_go scp ko0: scpcmd_ko0={}".format( progid, dttm, scpcmd_ko0)
			os.system( scpcmd_ko0 )
		if( sys.argv[3] == "ko2" ):
			print "{} {} ko_go scp ko2: scpcmd_ko2={}".format( progid, dttm, scpcmd_ko2)
			os.system( scpcmd_ko2 )


		if( sys.argv[3] == "ka1" ):
			print "{} {} ko_go scp ka1: scpcmd_ka1={}".format( progid, dttm, scpcmd_ka1)
#			os.system( scpcmd_ka1 )
		if( sys.argv[3] == "ka10" ):
			print "{} {} ko_go scp ka10: scpcmd_ka10={}".format( progid, dttm, scpcmd_ka10)
#			os.system( scpcmd_ka10 )
		if( sys.argv[3] == "ka11" ):
			print "{} {} ko_go scp ka11: scpcmd_ka11={}".format( progid, dttm, scpcmd_ka11)
#			os.system( scpcmd_ka11 )
		if( sys.argv[3] == "ka12" ):
			print "{} {} ko_go scp ka12: scpcmd_ka12={}".format( progid, dttm, scpcmd_ka12)
#			os.system( scpcmd_ka12 )
		if( sys.argv[3] == "ka1" ):
			print "{} {} ko_go scp ka1: scpcmd_ka1={}".format( progid, dttm, scpcmd_ka1)
#			os.system( scpcmd_ka1 )

		exit()



		if( sys.argv[3] == "ko"):
			sshcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
			sshcmd_ko2 = "scp index_ko2.html kozerus@ko2.us:~/public_html/index.html"
			print progid,dttm, "ko_go ssh ko?: sshcmd_ko0=",sshcmd_ko0
			print progid,dttm, "ko_go ssh ko?: sshcmd_ko2=",sshcmd_ko2
#			os.system( sshcmd_ko0 )
#			os.system( sshcmd_ko2 )
		if( sys.argv[3] == "ko0"):
			sshcmd_ko0 = "scp index_ko0.html kozerus@ko0.us:~/public_html/index.html"
			print progid,dttm, "ko_go ssh ko?: sshcmd_ko0=",sshcmd_ko0
#			os.system( sshcmd_ko0 )
		if( sys.argv[3] == "ko2"):
			sshcmd_ko2 = "scp index_ko2.html kozerus@ko2.us:~/public_html/index.html"
			print progid,dttm, "ko_go ssh ko?: sshcmd_ko2=",sshcmd_ko2
			os.system( sshcmd_ko0 )
		if( sys.argv[3] == "ka"):
			print progid,dttm, "ko_go ssh ka?: a2=",a2
		if( sys.argv[3] == "ka1"):
			print progid,dttm, "ko_go ssh ka1: a2=",a2
		if( sys.argv[3] == "ka2"):
			print progid,dttm, "ko_go ssh ka2: a2=",a2





	exit()

	if( sys.argv[2] != "" ):
		dttm=ko_dttm()
		print progid,dttm, "ko_go: a2=",a2
#		ko_listdir( sys.argv[2], sys.argv[3] )
		pathfile=sys.argv[2]
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print progid,dttm, "ko_go: path=",path," base=",base," ext=",ext


	dttm=ko_dttm()
	print progid,dttm,"ko_go a1=",a1
	pathfile="."
	ofilename="ko_go.csv"
	ifilename=ofilename
	tmp_pathfile="ko_go.tmp"
	todo_pathfile="ko_go.todo"
	db3_pathfile="ko_go.db3"

	if( a1 != "" ): pathfile=a1

	syscmd="pwd;date"
	print progid,dttm, "ko_go_syscmd syscmd={}".format( syscmd)
	os.system( syscmd)





	exit()

#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd_find = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base, "{}", tmp_pathfile )
	print progid,dttm, "ko_go_find syscmd={}".format( syscmd_find )
#	os.system( syscmd_find )

	pathcode=path.replace("/","-")
	pathcode=pathcode.replace(".","")

	if( os.path.isfile(ofilename)):
		print progid,dttm, "ko_go ofilename={}".format( ofilename )
	else:
		todofile_dttm="ka1_{}.todo".format(dttm)
		todofile="ka1{}.todo".format( pathcode )
#               syscmd='find . -name "* *.mp4" -exec ls {} \; > '^
#               syscmd='find . -name "*--*.mp4" -exec ls {} \; > 'M
                syscmd='find . -name "*.mp4" -exec ls {} \; > '
                syscmd+=todofile
                syscmd = 'find {} -name "{}" -exec ls {} \; > {}'.format( path, base,"{}", todofile )
                print progid,dttm, "ko_go_find syscmd={}".format( syscmd )
                print progid,dttm, "ko_go_find pathcode={}".format( pathcode )
		os.system( syscmd )

	ifilename=todofile
	print progid,dttm, "ko_go ifilename={}".format( ifilename )
	return("ko_go")


	ifile = open(ifilename, "r" )
	j=0
	ofilename_mv="ko_go_mv.sh"
	oline_mv = "# ko_go_mv.sh {}\n".format(dttm)
	ofile_mv = open( ofilename_mv, "wb" )
	ofile_mv.write( oline_mv )


	ofilename_png="ko_go_png.sh"
	oline_png = "# ko_go_png.sh {}\n".format(dttm)
	ofile_png = open( ofilename_png, "wb" )
	ofile_png.write( oline_png )

#	oline_png = "# ko_go_png.sh end\n"
#	ofile_png.write( oline_png )
#	ofile_png.close()

	ofilename_tn="ko_go_tn.sh"
	oline_tn = "# ko_go_tn.sh {}\n".format(dttm)
	ofile_tn = open( ofilename_tn, "wb" )
	ofile_tn.write( oline_tn )

	ifilename_htm = "ka1_av.html"
	ofilename_htm = "ka1_av_out.html"
	iline_htm = ""
	oline_htm = ""
	

	ofilename_psv = "ko_go.psv"
	oline_psv = "idx|status|dttm|id|filnam|png|tn|size|cr_dttm|m_dttm|t1|t2|duration|desc\n"
	ofile_psv = open( ofilename_psv, "wb" )
	ofile_psv.write( oline_psv )

	ifile_htm = open( ifilename_htm, "r" )
	ofile_htm = open( ofilename_htm, "wb" )
	oline_htm = "<!-- {} {} -->\n".format( ofilename_htm, dttm )
	data_htm = '<div id="div_h5g" >'
	
#	data_htm += '<a href="{}" ><img src="{}" alt="{}" data-description="{}"></a>\n'
#		.format( "./pn/imgs/pano_jtf_entrance_jtf.jpg",
#			"./pn/imgs/pano_jtf_entrance_jtf.jpg",
#			"pano_jtf_entrance",
#			"The storm is raging up above, and waves are dashing high."
#			)

#	data_htm = '<a href="{}" ><img src="{}" alt="{}" data-descriptn="{}"></a>\n'.format( jpg_pathfile, tn_pathfile, jpg_pathfile, jpg_pathfile )
	ofile_htm.write( oline_htm )
	ofile_htm.write( data_htm )
	data_htm=""

	t1=20
#	data_htm = '<a href="{}#t={}" data-poster="{}">'.format( "ka11_avril.mp4", t1, tn_pathfile )
#	data_htm += '<img src="{}" alt="{}" data-description="{}"></a>\n'.format( tn_pathfile, t_pathfile, f_pathfile )
#	data_htm = ""


	ofile_htm.write( oline_htm )


#	oline_tn = "# ko_go_tn.sh end\n"
#	ofile_tn.write( oline_tn )
#	ofile_tn.close()



	for iline in ifile:
		pattern = re.compile( "^#" )
		if( pattern.match(iline) ): continue
		j=j+1
		dttm=ko_dttm()
		pathfile=iline
		path=os.path.dirname(pathfile)
		base=os.path.basename(pathfile)
		file=os.path.splitext(base)[0]
		ext=os.path.splitext(base)[1]
		filecode_tuple=str(j),"-",file,"-",ext
		filecode = "".join(filecode_tuple)

		if( path == "." ): path="./"
		path_imgs="./imgs/mp4/"
		path_tn="./imgs/mp4/tn/"
		f_pathfile=iline
		t_pathfile=t_pathfile.replace(".//","./",1)


		db3_pathfile="ko_go.db3"
		psv_pathfile="ko_go.psv"
		bsv_pathfile="ko_go.bsv"
		tmp_pathfile="ko_go.tmp"
		print progid,dttm,"db3={}".format( db3_pathfile )
		print progid,dttm,"psv={}".format( psv_pathfile )
		print progid,dttm,"bsv={}".format( bsv_pathfile )
		print progid,dttm,"tmp={}".format( tmp_pathfile )
		
		png_pathfile="{}{}".format( path_imgs, t_base )
		png_pathfile=png_pathfile.replace(".mp4", "_mp4.png" )
		png_pathfile_000=png_pathfile.replace("_mp4.png", "_mp4_%00d.png" )

		jpg_pathfile=png_pathfile.replace( ".png", ".jpg" )
		jpg_pathfile_000=png_pathfile_000.replace( ".png", ".jpg" )

		tn_pathfile="{}tn_{}".format( path_tn, t_base )
		tn_pathfile=tn_pathfile.replace(".mp4", "_mp4.png" )


		print progid,dttm,j,"f_pathfile={}".format( f_pathfile )
		print progid,dttm,j,"t_pathfile={}".format( t_pathfile )
		print progid,dttm,j,"png_pathfile={}".format( png_pathfile )
		print progid,dttm,j,"tn_pathfile={}".format( tn_pathfile )
		print progid,dttm,j,"png_pathfile_000={}".format( png_pathfile_000 )

#		print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
#		print progid,dttm,j,"filecode_tuple=",filecode_tuple

#		png_filename="./imgs/mp4/"
#		png_filename+=t_filename.replace(".mp4",".png")

#		tn_filename="./imgs/tn/tn_"
#		tn_filename+=t_filename.replace(".mp4",".png")

#		print progid,dttm, "ko_go ifile {} {} iline={}".format( ifilename, j, iline )
#		print progid,dttm, "ko_go ifile {} {} t_filename={}".format( ifilename, j, t_filename )
#		print progid,dttm, "ko_go ifile {} {} png_filename={}".format( ifilename, j, png_filename )
#		print progid,dttm, "ko_go ifile {} {} tn_filename={}".format( ifilename, j, tn_filename )

		if( f_pathfile != t_pathfile ):
			oline_mv = 'mv "{}" {}\n'.format( f_pathfile, t_pathfile )
			ofile_mv.write( oline_mv ) 
			print progid,dttm, "ko_go_mv ofilename_mv={} j={} oline_mv={}".format( ofilename_mv, j, oline_mv )

		oline_png = "cp ./imgs/mp4/mp4.png {}\n".format( png_pathfile )
		ofile_png.write( oline_png )
		print progid,dttm, "ko_go_png ofilename_png={} j={} oline_png={}".format( ofilename_png, j, oline_png )

		oline_tn = "mogrify -resize x100 -write {} {}\n".format( png_pathfile, tn_pathfile )
		ofile_tn.write( oline_tn )
		print progid,dttm, "ko_go_tn ofilename_tn={} j={} oline_tn={}".format( ofilename_tn, j, oline_tn )


#		video_input_path = '/your/video.mp4'
#		img_output_path = '/your/image.jpg'
#		subprocess.call(['ffmpeg', '-i', video_input_path, '-ss', '00:00:00.000', '-vframes', '1', img_output_path]

#		syscmd = "['ffmpeg', '-i', f_pathfile, '-ss', '00:00:00.000', '-vframei', '1', png_pathfile]"

		flag_im = ""
		flag_ffmpeg_seek = ""

		seekpoint=10
#		ffmpeg -y -ss $SEEK_POINT -i input.ogv -vcodec mjpeg -vframes 1 -an -s 120x90 -f rawvideo output.jpg
		ffmpeg_seek_cmd = 'ffmpeg -y -ss {} -i {} -vcodec mjpeg -vframes 1 -an -s 1920x1000 -f rawvideo {}'.format( seekpoint, t_pathfile, jpg_pathfile )
		print progid,dttm, "ko_go ffmpeg_seek_cmd={}\n".format( ffmpeg_seek_cmd )
#		subprocess.call( ffmpeg_seek_cmd )
		if( flag_ffmpeg_seek == "yes" ): os.system( ffmpeg_seek_cmd )

		im_cmd='mogrify -resize x100 -write {} {}'.format( tn_pathfile, jpg_pathfile )
		print progid,dttm, "ko_go im_cmd={}\n".format( im_cmd )
		if( flag_im == "yes" ): os.system( im_cmd )
#		subprocess.call( im_cmd )
#		os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

		data_htm += "\n"
		data_htm += '<a href="{}#t={}" data-poster="{}">'.format( t_pathfile, t1, tn_pathfile )
		data_htm += '<img src="{}" alt="{}" data-description="{}"></a>\n'.format( tn_pathfile, t_pathfile, f_pathfile )

		fps="1/20"
		ffmpeg_cmd = "ffmpeg -y -i {} -vf fps={} {}".format(  f_pathfile, fps, jpg_pathfile_000 )
		print progid,dttm, "ko_go_ffmpeg ffmpeg_cmd={}\n".format( ffmpeg_cmd )
#		os.system( ffmpeg_cmd )
#		subprocess.call(['ffmpeg', '-i', f_pathfile, '-ss', '00:00:00.000', '-vframes', '1', png_pathfile ])
#		subprocess.call( ffmpeg_seek_cmd )
#		subprocess.call( ffmpeg_cmd )

#		start_tm=5
#		pil_image = VideoStream('0.flv').get_frame_at_sec(5).image()
#		pil_image.save('frame5sec.jpeg')
#		pil_image = VideoStream(f_pathfile ).get_frame_at_sec(start_tm).image()
#		pil_image.save(png_filepath)


	ifile.close()

	ofile_htm.write( data_htm )
#	data_htm = "	</div>"
#	ofile_htm.write( data_htm )
	ofile_htm.close()

	ofile_mv.write( oline_mv )
	oline_mv = "# ko_go_mv.sh end\n"
	ofile_mv.write( oline_mv )
	ofile_mv.close()

	ofile_png.write( oline_png )
	oline_png = "# ko_go_png.sh end\n"
	ofile_png.write( oline_png )
	ofile_png.close()

	ofile_tn.write( oline_tn )
	oline_tn = "# ko_go_tn.sh end\n"
	ofile_tn.write( oline_tn )
	ofile_tn.close()

	ifilename = "ka1_h5g.html"
	ofilename = "ka1_h5g_out.html"
	ifile = open( ifilename, "r" )
	ofile = open( ofilename, "wb" )

	print dttm, "ifilename=",ifilename, " ofilename=", ofilename	
	ka1_sl_html_hdr = ""
	ka1_sl_html_dta = ""
	ka1_sl_html_ftr = ""
	j=0
	mode="hdr"
	for line in ifile:
		out="ko_go {} {} {}\n".format( ifilename, j, line )
		print out
		j=j+1
# err		if line.match('div_sl_images" ): break
#		if line == 'div_sl_images': 

		if re.search( 'id="div_h5g"', line ):
			mode = "dta"
			ofile.write( line )
			ofile.write( data_htm )
		else:
			ofile.write( line )
	ifile.close()
	ofile.close()
	return( "ko_go")

#	ifile = open(ifilename, "wb" )
#	for line in ifile:
#		print progid,dttm, "ko_go ifile line={}".format( line )
#	ifile.read

#	for pathfile in pathfiles:
#		j=j+1
#		dttm=ko_dttm()
#		path=os.path.dirname(pathfile)
#		base=os.path.basename(pathfile)
#		file=os.path.splitext(base)[0]
#		ext=os.path.splitext(base)[1]
#		filecode_tuple=str(j),"-",file,"-",ext
#		filecode = "".join(filecode_tuple)
#		print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
#		print progid,dttm,j,"filecode=",filecode
#		print progid,dttm,j,"filecode_tuple=",filecode_tuple
#
#		b64dta=""
#		if( not os.path.isfile( pathfile )):	
#
#
#			filesize = os.path.getsize(pathfile)
#			ctime=time.ctime(os.path.getctime(pathfile))
#			ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))
#
#			print progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile
#	files=os.system( syscmd )
#	print progid,dttm, "ko_im syscmd={}".format( files )
	return( "ko_go" );


	syscmd="mkdir {}/tn".format( pathfile )
	print progid,dttm, "ko_im syscmd{}".format( syscmd )
#	os.system( syscmd )

	syscmd="mogrify  -resize x300 -set filename:name %f  -write '{}/tn/tn_%[filename:name]' {}".format( pathfile, pathfile )
	print progid,dttm, "ko_im syscmd{}".format( syscmd )
#	os.system( syscmd )
	os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

	exit()

	print progid,dttm,"ko_im syscmd={}".format( syscmd )
	os.system( syscmd )


#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
#	from subprocess import call
#	call(["ls", "-l" )
#	os.system( "ls -lat /Volumes/ka1tbr2/ht/imgs/links/*.*" )
#	print subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE).stdout.read(	
#	return_code = subprocess.call("echo Hello World", shell=True) 
	return("ko_im_return");


def splitgift(delimiters, string, maxsplit=0):
#	import re
	regexPattern = '|'.join(map(re.escape, delimiters))
	return re.split(regexPattern, string, maxsplit)

def kocmd(command):
	process = Popen(
		args=command,
		stdout=PIPE,
		shell=True
		)
	return process.communicate()[0]

def cmdline(command):
	process = Popen(
		args=command,
		stdout=PIPE,
		shell=True
		)
	return process.communicate()[0]

def gif2gifs(gif):

	print "{} {} gif1={} ".format( progid, dttm, gif )
	j=0
	gif_path=os.path.dirname(gif)
	gif_base=os.path.basename(gif)
	gif_file=os.path.splitext(gif_base)[0]
	gif_ext=os.path.splitext(gif_base)[1].replace(".","")
	giftags = "b d p q".split(" ")
	g=0
	for giftag in giftags:
		g=g+1
		newgif = "{}/{}{}.{}".format(gif_path, gif_file, giftag, gif_ext)
		newpngs = "{}/{}{}.png".format( gif_path, gif_file, giftag )
		print "BUGS_1650 gif2gifs g={} newgif = {}\n".format(g, newgif)

		if( giftag == "d" ) or (giftag == "q" ):
			convert_negate = "convert {} -negate {}".format( gif, newgif )
			print "gif2gifs NEGATE-d g={} convert_negate={}\n".format( g, convert_negate )
			os.system( convert_negate )
		else:
			cp_newgif = "cp {} {}".format( gif, newgif )
			print "gif2gifs g={} cp_newgif={}\n".format( g, cp_newgif )
			os.system( cp_newgif )

		print "BUGS_1660 gif2gifs g={} newgif = {}\n".format(g, newgif)
		if( giftag == "p" ) or ( giftag == "d" ):

			convert_gif2pngs = "convert {} {}".format(newgif, newpngs )
			print "BUGS_1670 gif2gifs g={} convert_gif2pngs={}\n".format( g, convert_gif2pngs )
			os.system( convert_gif2pngs )

			ls_pngs = "ls -lat {}/*.png".format( gif_path )

			lines = cmdline(ls_pngs).split('\n')
			pnglen = len(lines)
			print "BUGS_1670 line={} pnglen={}\rn".format( lines, pnglen )

		
			p=0
			r=pnglen-p-2
			pngs = ""
			for line in lines:
				r=pnglen-p-2
				lslen=len(line.split(" "))
				lsnam=line.split(" ")[lslen-1]
				png_file = gif_file
				pngnam = "{}/{}{}-{}.png".format(gif_path, png_file, giftag, r )
				if( p < pnglen-1 ):
					pngs += "{} ".format(pngnam)
#				print "BUGS_1671 pnglen={} p={} r={}".format( pnglen, p, r)
#				print "BUGS_1672 pnglen={} p={} r={} pngnam={}".format(pnglen,p,r,pngnam)
#				print "BUGS_1673 lsnam={}\n".format(lsnam)
				p=p+1

			convert_pngs2gif = "convert {} {}".format( pngs, newgif )
			print "BUGS_1680 pnglen={} convert_pngs2gif={}\n".format( pnglen, convert_pngs2gif )
			os.system( convert_pngs2gif )
#			print "BUGS_1680 pnglen={} ls_png={}\n".format( pnglen, ls_png )



#			print "BUGS_1681 ls_pngs={} pnglen=\n{}\n".format( ls_pngs, pnglen )
#			print "BUGS_1682 ls_pngs={} lines=\n{}\n".format( ls_pngs, lines )


#			pnglen=0
#			r=0
#			for line in lines:
#				png_file = line.split("-")[0]
#				newpng = "{}/{}-{}.png".format(gif_path, png_file, pnum )	
#				pnum=pnglen+1
#				print "BUGS_1682 pgnlen={} pnum={} line={}\n".format(pnglen, line )
#				print "BUGS_1682 pnglen={} line={}\n".format(pnglen, line )
#			print "BUGS_1681 PNGLEN ls_pngs={} pnglen={}\n".format( ls_pngs, pnglen )
#			exit()


#			print cmdline(lslat_pngs)
#			print "BUGS_1682 lslat_pngs={} cmdout={}\n".format( lslat_pngs, cmdout )
#			print cmdline('ls -lat imgs/ani/work/ring/*.gif')
##			print "BUGS_1683 ls -lat *.gif={} cmdout={}\n".format( cmdout )
##			print "BUGS_16950 gif2gifs g={} ls_pngs={} pngs0={}\n".format( g, ls_pngs, pngs.split("\n") )
##			print "BUGS_16951 gif2gifs g={} ls_pngs={} pngs1={}\n".format( g, ls_pngs, pngs.split("\n") )
##			print "BUGS_16952 gif2gifs g={} ls_pngs={} pngs2={}\n".format( g, ls_pngs, pngs.split("\n") )
	
			rm_pngs = "rm {}/{}{}-*.png".format( gif_path, gif_file, giftag )
			print "gif2gifs g={} rm_pngs={}\n".format( g, rm_pngs )
			os.system( rm_pngs )


		btnpath="imgs/gif/"
		cp_newgif = "cp {} {}".format( newgif, btnpath )
		print "gif2gifs g={} cp_newgif={}\n".format( g, cp_newgif )
		os.system( cp_newgif )

#		delays = "1 5 10 100"
		delays = "1 2 3 4 5 6 7 8 9 10 20 30 40 50 70 80 90 100"
		for delay in delays.split(" "):
			newgif_delay = "{}/{}{}_{}.gif".format( gif_path, gif_file, giftag, delay )
			convert_delay = "convert -delay {} {} {}".format( delay, newgif, newgif_delay )
#			print "BUGS_1730 delay={} newgif={}".format(delay, newgif)
#			print "BUGS_1730 convert_delay={}".format( convert_delay )
			os.system( convert_delay )

			btnpath="imgs/gif/"
			cp_newgif_delay = "cp {} {}".format( newgif_delay, btnpath )
			print "gif2gifs cp_newgif={}\n".format( cp_newgif_delay )
			os.system( cp_newgif )


def png2gif(gif,png):


	png="imgs/ani/work/heart/koeye.png"
	gif="imgs/ani/work/heart/heart.gif"
	print "{} {} png2gif png={} gif={}".format( progid, dttm, png, gif )

	gif_path=os.path.dirname(gif)
	gif_base=os.path.basename(gif)
	gif_file=os.path.splitext(gif_base)[0]
	gif_ext=os.path.splitext(gif_base)[1].replace(".","")


	png_path=os.path.dirname(png)
	png_base=os.path.basename(png)
	png_file=os.path.splitext(png_base)[0]
	png_ext=os.path.splitext(png_base)[1].replace(".","")
	btn_path="imgs/gif"


	

	newgif = "{}/{}_{}.gif"
	w=200
	h=80
	x=0
	y=0
	pngtag = "koeye"
	newgif = "{}/{}_{}.gif".format( gif_path, png_file, gif_file )
	newbtn = "{}/{}_{}.gif".format( btn_path, png_file, gif_file )

#	print "new_png\n pngi={}\n gifi={}\n".format( pngi, gifi )
	for size in "100x40 200x80 400x160".split(" "):
		pngi = "{}/{}{}.png\n".format( gif_path, png_file, size.split("x")[0] )
		gifi = "{}/{}{}.gif\n".format( gif_path, gif_file, size.split("x")[0] )

#		im_pngsize = "convert {} -size {} {}".format( png, size, pngi )
#		print "im_pngsize={}".format(im_pngsize)
#		os.system( im_pngsize )

#		im_gifsize = "convert {} -size {} {}".format( gif, size, gifi )
#		print "im_gifsize={}".format(im_gifsize)
#		os.system( im_gifsize )
		
		w=size.split("x")[0]
		h=size.split("x")[1]
		y=0

		for x in "0 50 100 150".split( " " ):
			gifo = "{}/{}_{}{}_{}.gif".format( gif_path, png_file, gif_file, size.split("x")[0], x )

			im_png2gif = "composite  {} {} -compose Dst_Over -geometry {}x{}+{}+{} {}".format( pngi, gifi, w,h,x,y, gifo )
			im_png2gif = "convert  {} -coalese -draw 'image over {},{} {},{}' {} -composite {}".format( gifi, w,h,x,y, pngi, gifo )
			img_png2gif = "convert {} -draw 'image over 0,0 {},0' {} -composite {}".format( gifi, x, pngi, gifo) 
			print "im_png2gif={}".format(im_png2gif)
			os.system( im_png2gif )

# convert heart200.gif \( koeye200.png -repage 0x0+120+0 \)  heartk200_120.gif

	exit()
			

# convert script_k.gif -coalesce  coalesced_k.gif
# convert coalesced_k.gif  -background black -shadow 100x3+2+5 \
#          -background SkyBlue -alpha remove    shadows_k.gif
# convert shadows_k.gif  null:  coalesced_k.gif \
#          -layers Composite          compose_shadow.gif
#  gif_anim_montage compose_shadow.gif compose_shadow_frames.gif		


#	composite -compose Dst_Over -geometry 520x320+20+80 image.jpeg overlay.png final.pnconvert animation.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gifg
#	convert animation.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gif
	im_png2gif = 'convert {} -coalesce -gravity NorthEast -draw \'image over 0,0 0,0 "{}"\' -layers Optimize {}'.format( gif, png, newgif )
	im_png2btn = 'convert {} -coalesce -gravity NorthEast -draw \'image over 0,0 50,50 "{}"\' -layers Optimize {}'.format( gif, png, newbtn )

	im_png2gif1 = "composite -compose Dst_Over -geometry {}x{}+{}+{} {} {} {}".format( w,h,x,y,png,gif,newgif)
	im_png2btn1 = "composite -compose Dst_Over -geometry {}x{}+{}+{} {} {} {}".format( w,h,x,y,png,gif,newbtn)

	print "png2gif NEWGIF im_png2gif={}\n".format(im_png2gif)
	print "png2gif NEWBTN im_png2gif={}\n".format(im_png2gif)
	os.system( im_png2gif )
	os.system( im_png2btn )

#	 convert -dispose none -channel RGBA \
#	          \( medical.gif -repage 100x60+5+14  -coalesce -set delay 100 \) \
#	          \( medical.gif -repage 100x44+34+6  -coalesce -set delay 10 \
#	             -motion-blur 0x12+0  -motion-blur 0x12+180 -wave -8x200 \) \
#	          \( medical.gif -repage 100x60+63+14 -coalesce -set delay 100 \) \
#	          \( medical.gif -repage 100x44+34+6  -coalesce -set delay 10 \
#	             -motion-blur 0x12+0  -motion-blur 0x12+180 -wave +8x200 \) \
#	          null: \( +page  -size 120x15 xc:SkyBlue xc:RoyalBlue \
#	                   -size 120x70 gradient:SkyBlue-RoyalBlue \
#	                   +swap -append -blur 0x3 -background white -rotate -25 \
#	                \) -gravity center -compose DstOver -layers Composite \
#	          -loop 0   speed.miff
#	
#	  convert   speed.miff  speed.gif
#	  gif_anim_montage  speed.gif  speed_frames.gif


	exit()


def load_gifs():
	gifs = (

'imgs/ani/work/penny.gif',
'imgs/ani/work/apple.gif',
'imgs/ani/work/rings.gif',
'imgs/ani/work/bh.gif',
'imgs/ani/work/dollars.gif',
'imgs/ani/work/eye1.gif',
'imgs/ani/work/eye2.gif',
'imgs/ani/work/eye3.gif',
'imgs/ani/work/film.gif',
'imgs/ani/work/firebubbles.gif',
'imgs/ani/work/firework.gif',
'imgs/ani/work/geard2.gif',
'imgs/ani/work/gears2.gif',
'imgs/ani/work/header.gif',
'imgs/ani/work/heart.gif',
'imgs/ani/work/knot.gif',
'imgs/ani/work/laser1.gif',
'imgs/ani/work/laser2.gif',
'imgs/ani/work/laser3.gif',
'imgs/ani/work/meterbars.gif',
'imgs/ani/work/meterdots.gif',
'imgs/ani/work/rotate.gif',
'imgs/ani/work/soccorball.gif',
'imgs/ani/work/sun.gif',
'imgs/ani/work/taz.gif',
'imgs/ani/work/trcx_sxygirl_b1.gif',
'imgs/ani/work/trcx_sxygirl_b2.gif',
'imgs/ani/work/trcx_sxygirl_b3.gif',
'imgs/ani/work/trcx_sxygirl_kick.gif',
'imgs/ani/work/trcx_sxygirl_l.gif',
'imgs/ani/work/trcx_sxygirl_w2.gif',
'imgs/ani/work/trcx_sxygirl_w3.gif',
'imgs/ani/work/trcx_szygirl_b4.gif',
'imgs/ani/work/trophy.gif',
'imgs/ani/work/warning.gif',
'imgs/ani/work/welcome.gif',
'imgs/ani/work/worksign.gif'
	)
	return(gifs)





def gif2pngs(gif):
	pngs = ""

	pngs = (
'imgs/ani/work/ring/ring1-0.png',
'imgs/ani/work/ring/ring1-1.png',
'imgs/ani/work/ring/ring1-2.png',
'imgs/ani/work/ring/ring1-3.png',
'imgs/ani/work/ring/ring1-4.png',
'imgs/ani/work/ring/ring1-5.png',
'imgs/ani/work/ring/ring1-6.png',
'imgs/ani/work/ring/ring1-7.png',
'imgs/ani/work/ring/ring1-8.png',
'imgs/ani/work/ring/ring1-9.png',
'imgs/ani/work/ring/ring1-10.png',
'imgs/ani/work/ring/ring1-11.png',
'imgs/ani/work/ring/ring1-12.png',
'imgs/ani/work/ring/ring1-13.png',
'imgs/ani/work/ring/ring1-14.png',
'imgs/ani/work/ring/ring1-15.png',
'imgs/ani/work/ring/ring1-16.png',
'imgs/ani/work/ring/ring1-17.png'
	)
	
#	print "gif2pngs gif={} path={} base={} file={} ext={}".format( gif,path,base,file,ext)
#	print "gif2pngs pngs={} ".format( pngs)
	return(pngs)

	gifs = (
"imgs/ani/work/heart.gif|/imgs/btn/koeye.png|koeye_heart.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringb.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringw.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringbl.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringbr.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringwl.gif"
"imgs/ani/work/ring.gif|imgs/btn/ringwr.gif"
"imgs/ani/work/eyeball1.gif|/imgs/btn/koeye.png|koeye_eyeball1.gif",
"imgs/ani/work/eyeball2.gif|/imgs/btn/koeye.png|koeye_eyeball2.gif",
"imgs/ani/work/eyeball3.gif|/imgs/btn/koeye.png|koeye_eyeball3.gif",
"imgs/ani/work/penny.gif|koeye.png|koeye_penny.gif",
"imgs/ani/work/dollar.gif|koeye.png|koeye_dollar.gif",
"imgs/ani/work/rainbow.gifi|/imgs/btn/koeye.png|koeye_laser_rainbow.gif"
	)
	return( gifs )


def filio(pathfile,filid ):
	wl_file = open( pathfile, "r" )
	htmout = ""
	linematch_beg = "jkwii"
	linematch_end = "skwii"
	linematch_txt = "<h1>{}</h1>\n".format( filid )
	j=0
	for line in wl_file:
		j=j+1
		f_file=line
		t_file=pathfile_fmt(f_file)
#		print "pathfile={} j={} line={}".format(pathfile,j,line)
		newtxt = ""
		newtxt = "	<h1>{}</h1>\n".format(filid)
		if re.search( linematch_beg, line ):
			mode = "match"
			continue
		if re.search( linematch_end, line ):
			mode = ""
			htmout += linematch_txt
			htmout += line
		htmout += line
#		print progid,dttm, "filio pathfile={} {} {}".format( pathfile,j,line )

	wl_file.close
	return(htmout)



def htms2htm( path ):
#	path="/svc/jqgrid"
	img = "/imgs/btn/kob.png"
	tn = "/imgs/btn/kow.png"
#	old_pathfile = "{}/{}".format(path,htmid)
	new_pathfile = "jqgrid.html"

	htmids = load_htmids()
	print '{} {} htms2htm htmids={}'.format( progid, dttm, htmids)

	k=0
	htmout_links=""
	htmout_body=""
	for htmid in htmids:
		k=k+1
		filtxt = "";
		url= "";
		url = "{}/{}.html".format( path, htmid )
		htm_pathfile="{}/{}.html".format( path, htmid)
		filtxt = filio(htm_pathfile,htmid )
		
#		print '{} {} k={} phps2php htm_pathfile={} htmid={}'.format( progid, dttm, k,htm_pathfile, htmid)
#		print '{} {} k={} phps2php filtxt={} htmid={}'.format( progid, dttm, k, filtxt, htmid)

		htmout_links += '<a class="popover" href={} target=_blank>\n'.format( url )
		htmout_links += '	<img src="{}" border=0 onclick="htmid();">\n'.format(tn,htmid)
		htmout_links += '	<span><img src="{}" border=0 onclick="htmid()\n">'.format(img,htmid)
		htmout_links += '	</a>\n';

		htmout_body += '	<div id="jqgrid_{}" >\n'.format( htmid )
		htmout_body += '		<h1> jqgrid_{}</h1 >\n'.format( htmid )
		htmout_body += filtxt
		htmout_body += '		</div>'

	htmout = ""
	htmout += "<html><head>\n"
	htmout += "	<title>jqgrid</title>\n"
	htmout += htmcss_popover('ko')
	htmout += "	</head>\n"
	htmout += "<body>\n"
	htmout += htmout_links
	htmout += htmout_body
	htmout += "	</body\n"
	htmout += "	</html\n"

	newfil = open( new_pathfile, "w" )
	newfil.write(htmout)

	print '{} {} k={} phps2php htmout_links={}'.format( progid, dttm, k, htmout_links)
	print '{} {} k={} phps2php htmout_body={}'.format( progid, dttm, k, htmout_body)
	newfil.close()


	return(htmout)

def load_phpids():
	phpids = (
"example",
"someurl",
"bigset",
"search",
"subgrid",
"dbconfig",
"server",
"editing",
"server_ado",
"JSON"
	)
	return( phpids )


def phps2php( path ):
	path="svc/jqgrid"
	phpids = load_phpids()
	print '{} {} phps2php phpids={}'.format( progid, dttm, phpids)
	phpids_len=len(phpids)
	print '{} {} len={}  phpids={}'.format( progid, dttm,phpids_len, phpids )

	j=0
	phpout=""
	for phpid in phpids:
		j=j+1
		print '{} {} j={} phps2php phpid={}'.format( progid, dttm, j, phpid)
		continue
	return(phpout)
	
def load_htmids():
	htmids = (
		"adding", "afterinsrow", "bigset", 
		"calendar", "celledit", "cmultiex", "csvalid", "custbutt", "custfrm",
		"datatype", "defparams", "deleting", "demo", "editing",
		"example", "exportex", "formatter", "getex", "gridwidth",
		"hiddengrid", "hidedyn", "hideex", "hideshow", "jqgrid",
		"jsonex", "jsonmap", "jsonopt", "jsubgrid",
		"loadcml", "loaderror", "loadoncex", "localex", 
		"manipex", "masterex", "methods", "methods32", "multiex", "navgrid", "navgrid2", "postdata", 
		"refactor", "resizecol", "resizeex", 
		"rowedex1", "rowedex2", "rowedex3", "rowedex4", "rowedex5",
		"scrgrid", "search1", "search2", "searching", "selectall", "setcolumns", 
		"setex", "subgrid", "subgrid_grid",
		"tbltogrid", "toolbar", "treegrid", "treegrid2",
		"xmlex", "xmlimp", "xmlmap"
		)
	return(htmids)

def newhtm( htmids ):
	print '{} {} newhtm htmids={}'.format( progid, dttm, htmids )

#	htmids_txt=re.split( " ", htmids)
#	htmids_csv=re.split( ",", htmids)
#	htmids_psv=re.split( "|", htmids)
#	htmids_txtlen=len(htmids_txt)
#	htmids_csvlen=len(htmids_csv)
#	htmids_psvlen=len(htmids_psv)
#	htmidss = re.split('; |, |\*|\n', htmids)
#	splitgift(delimiters, htmids, maxsplit=0):

	htmidss = splitgift('; |, |\*|\n\ ', htmids, maxsplit=0)

	htmidss_len = len( htmidss )
	fmt='txt'

	print '{} {} newhtm htmidss={}'.format( progid, dttm, htmidss)
#	print '{} {} newhtm htmids={}'.format( progid, dttm, htmids)
#	print '{} {} newhtm htmids_txt={}'.format( progid, dttm, htmids_txt)
#	print '{} {} newhtm htmids_csv={}'.format( progid, dttm, htmids_csv)
#	print '{} {} newhtm htmids_psv={}'.format( progid, dttm, htmids_psv)
	print '{} {} newhtm len spl={}'.format( progid, dttm, htmidss_len )
	z=0
	print '{} {} len={} z={} newhtm htmidss={}'.format( progid, dttm,htmidss_len, z, htmidss )
	for htmid in htmidss:
		z=z+1
		print '{} {} z={} newhtm htmid={}'.format( progid, dttm, z, htmid)
		continue
		htmout = ""
		htmout += '<html>\n'
		htmout += '	<head>\n'
		htmout += '	<title>-= {} =- -= {} =- -= {} =-</title>\n'.format( progid, htmid, dttm )
		htmout += '		</title>\n'
		htmout += '		</head>\n'
		htmout += '<body onload="startup">>\n'
		htmout += '	<div id="div_{}" >\n'.format( htmid )
		htmout += '	<h1>{}</h1>'.format( htmid )
		htmout += '	<	/div id="div_{}_end">\n'.format( htmid )
		htmout += '	</body>\n'
		htmout += '	</html>\n'
	return(htmout)
	
	

def pathfile_fmt(f_pathfile):

	path=os.path.dirname(f_pathfile)
	base=os.path.basename(f_pathfile)
	file=os.path.splitext(base)[0]
	ext=os.path.splitext(base)[1]

	t_pathfile=f_pathfile.replace( "\n", "" )
	t_base=base
#	t_filename=iline.replace(" ", "_").replace("#","_").replace("/","-").replace("-","",1).lower().replace("#","")
	t_base=t_base.lower()
	t_base=t_base.replace( "\n", "" )
	t_base=t_base.replace(" ", "_")
	t_base=t_base.replace("#","_")
#	t_base=t_base.replace("/","-")
	t_base=t_base.replace("-","",1)
	t_base=t_base.replace("#","")
	t_base=t_base.replace(":","_")
	t_base=t_base.replace("_pm","")
	t_base=t_base.replace("_am","")
	t_base=t_base.replace("(","")
	t_base=t_base.replace(")","")
	t_base=t_base.replace("&","")
	t_base=t_base.replace("'","")
	t_base=t_base.replace("+","")
	t_base=t_base.replace("~","")
	t_base=t_base.replace("__","_")
	t_base=t_base.replace("__","_")
	t_base=t_base.replace("--","-")
	t_base=t_base.replace("--","-")
	t_pathfile="{}/{}".format( path, t_base )
	return(t_pathfile)

def load_uslist():
	uslist = [
#		"/us/med/kov_rechtin.html|/imgs/us/med_rechtin.png|med_rechtin|/imgs/btn/koeye.png|med",
#		"http://lawdonovan.com|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",

		"https://www.linkedin.com/in/alan-cohen-2314473b/|/imgs/us/law_cohen_alan_w.png|law__cohen_alan_w|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://www.fdazol.com/|/imgs/us/law_azol.png|law_azol_f|/imgs/btn/koeye.png|law",

		"https://jmhalumni.com|/imgs/us/jmhalumni.png|ed_jmhalumni|/imgs/btn/koeye.png|edu",
		"https://johnmarshallhighschool.com|/imgs/us/johnmarshallhighschool.png|ed_johnmarshallhighschool|/imgs/btn/koeye.png|edu",
		"https://www.greatschools.org/kentucky/brandenburg/1993-Brandenburg-High-School/|/imgs/us/brandenburg_highschool.png|ed_brandenburg-highschool|/imgs/btn/koeye.png|edu",
		"https://www.hazelwoodschools.org/Page/3143|/imgs/us/hazelwood_schools.png|ed_hazelwood_schools|/imgs/btn/koeye.png|edu",
		"https://bw.edu|/imgs/us/bw.png|ed_bw|/imgs/btn/koeye.png|edu",

		"http://oldtowndonuts.com|/imgs/us/oldtowndonuts.png|food_oldtowndonuts|/imgs/btn/koeye.png|food",
		"http://farkaspastries.com|/imgs/us/farkaspastries.png|food_farkaspastries|/imgs/btn/koeye.png|food",
		"https://www.facebook.com/HansaImportHouse|/imgs/us/hansaimporthouse.png|food_hansaimporthouse|/imgs/btn/koeye.png|food",
		"http://havanagrillco.com|/imgs/us/havanagrillco.png|food_havanagrillco|/imgs/btn/koeye.png|food",
		"http://spiros-restaurant.com|/imgs/us/spiros_restaurant.png|food_spiros_restaurant|/imgs/btn/koeye.png|food",
		"https://www.opentable.com/jake-and-tellys-greek-taverna?page=1|/imgs/us/food_jake_tellys.png|food_jake_tellys|/imgs/btn/koeye.png|food",
		"http://edelweissrest.com|/imgs/us/edelweissrest.png|food_edelweissrest|/imgs/btn/koeye.png|food",
		"http://bierwerks.com|/imgs/us/food_bierwerks.png|food_bierwerks|/imgs/btn/koeye.png|food",
		"http://www.savellispizzapastasubs.com/|/imgs/us/food_savellispizza.png|food_savellispizza|/imgs/bmtn/koeye.png|food",
		"https://www.facebook.com/woohoogreekfood2/|/imgs/us/woohoogreekfood2.png|food_woohoogreekfood2|/imgs/btn/koeye.png|food",

		"https://bdo.com/about/us-locations/bdo-st-louis|/imgs/us/bdo-stl.png|acct_bdo-stl|/imgs/btn/koeye.png|fin",
		"https://bdo.com/about/us-locations/bdo-cleveland-office|/imgs/us/bdo-cle.png|acct_bdo-cle|/imgs/btn/koeye.png|fin",
		"http://www.gatewayloan.com/|/imgs/us/gateway_mortgage.png|gateway_mortgage|/imgs/btn/koeye.png|fin",
		"https://chesonsulting.com|/imgs/us/checonsulting.png|biz_checonsulting|/imgs/btn/koeye.png|biz",
		"http://saic.com|/imgs/us/saic.png|saic|/imgs/btn/koeye.png|biz",
		"http://leidos.com|/imgs/us/leidos.png|leidos|/imgs/btn/koeye.png|biz",


		"http://ko2.us/index_focus.com|/imgs/us/focus_solutions.png|focus_solutions|/imgs/btn/koeye.png|biz",
		"http://www.finduslocal.com/hardware-stores/kentucky/brandenburg/allens-s-t-hardware-inc|/imgs/us/biz_allens_hardware.png|biz_allens_hardware|/imgs/btn/koeye.png|biz",
		"http://growwarehouse.com|/imgs/us/grow_warehouse.png|grow_warehouse|/imgs/btn/koeye.png|biz",
		"https://www.facebook.com/avondanceandmartialarts|/imgs/us/avondanceandmartialarts.png|avondanceandmartialarts|/imgs/btn/koeye.png|phy",
		"https://www.facebook.com/avondanceandmartialarts|/imgs/us/avondanceandmartialarts.png|avondanceandmartialarts|/imgs/btn/koeye.png|phy",
		"http://www.savellidanceandmartialarts.com/?load=html|/imgs/us/savelli_dance_martialarts.png|savelli_dance_martialarts|/imgs/btn/koeye.png|phy",
		"http://myfusiondance.com/?load=html|/imgs/us/fusion_dance.png|fusion_dance|/imgs/btn/koeye.png|phy",
		"http://www.superseriesbaseball.com/|/imgs/us/super_series_baseball.png|super_series_baseball|/imgs/btn/koeye.png|phy",

		"https://ftknox.afceachapters.org/|/imgs/us/afcea_knox.png|afcea_knox|/imgs/btn/koeye.png|org",
		"https://scott.afceachapters.org/|/imgs/us/afcea_scott.png|afcea_scott|/imgs/btn/koeye.png|org",
		"https://www.ble-t.org/|/imgs/us/ble.png|ble|/imgs/btn/koeye.png|org",
		"http://www.doevalley.org/|/imgs/us/doe_valley.png|doe_valley|/imgs/btn/koeye.png|org",

		"http://www.chapelofthecross.org/|/imgs/us/chapel_of_the_cross.png|chapel_of_the_cross|/imgs/btn/koeye.png|rel",
		"https://www.lds.org/temples/details/st.-louis-missouri-temple|/imgs/us/lds_stl.png|lds_stl|/imgs/btn/koeye.png|rel",
		"https://www.bethanyenglish.org/|/imgs/us/bethany_english_lutheran.png|bethany_english_lutheran|/imgs/btn/koeye.png|rel",
		"https://www.meadecountymessenger.com/|/imgs/us/meade_county_messenger.png|meade_county_messenger|/imgs/btn/koeye.png|media",
		"/index_byrdpucker.html|/imgs/us/byrdpucker.png|byrdpucker|/imgs/btn/koeye.png|byrdpucker",
		"/index_jtfinc.html|/imgs/us/jtfinc.png|jtfinc|/imgs/btn/koeye.png|jtfinc",
		"/index_jtfdc.html|/imgs/us/jtfdc.png|jtfdcr|/imgs/btn/koeye.png|jtfdc",
		"/index_jtfdcr.html|/imgs/us/jtfdcr.png|jtfdcr|/imgs/btn/koeye.png|jtfdcr",
		"/index_jtfdcr.html|/imgs/us/jtfdcr.png|jtfdcr|/imgs/btn/koeye.png|jtfdcr",
		"https://mars.jpl.nasa.gov/msl/multimedia/raw/?s=#/?slide=2088|/imgs/us/mars_jpl_nasa.png|mars_jpl_nasa|/imgs/btn/koeye.png|sci",
		"https://mars.nasa.gov/mer/gallery/all/opportunity.html|/imgs/us/mars_nasa_gov.png|mars_nasa_gov|/imgs/btn/koeye.png|sci",
		]
	return(uslist)


def load_uslaws ():
	uslaws = [
		"http://lawdonovan.com|/imgs/us/lawdonovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://lawdonovan.com|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		"https://www.linkedin.com/in/alan-cohen-2314473b/|/imgs/us/law_cohen_alan_w.png|law__cohen_alan_w|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/law_cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://www.fdazol.com/|/imgs/us/law_azol.png|law_azol_f|/imgs/btn/koeye.png|law",
		"http://lawdonovan.com|/imgs/us/lawdonovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://nathanscohen.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		"https://twitter.com/AlanWCohenEsq|/imgs/us/cohen_alan_w_twitter.png|cohen_alan_w_twitter|/imgs/btn/koeye.png|law",
		"http://www.primerus.com/attorneys/alexander-h-kuehling-esq-rosenblum-goldenhersh-st-louis-missouri-mo.htm|/imgs/us/law_kuehling_alexander.png|law_law_kuehling_alexander|/imgs/btn/koeye.png|law",
		"http://elsterlaw.com/henry-elster-attorney-missouri-best/|/imgs/us/law_elster_henry.png|law_elster_henry|/imgs/btn/koeye.png|law",
		"https://pview.findlaw.com/view/2830721_1|/imgs/us/law_walters_alan.png|law_walters_alan|/imgs/btn/koeye.png|law",
		"https://www.thompsoncoburn.com/|/imgs/us/law_thompson_coburn.png|law__thompson_coburn|/imgs/btn/koeye.png|law",
		"http://koreintillery.com/|/imgs/us/law_korein_tillery.png|law_korein_tillery|/imgs/btn/koeye.png|law",
		"http://www.smithbrownllc.com/|/imgs/us/law_smith_brown.png|law_smith_brown|/imgs/btn/koeye.png|law",
		"http://index_party.html|/imgs/us/law_donovan.png|law_donovan|/imgs/btn/koeye.png|law",
		"http://index_jtfdc.com/|/imgs/us/law_cohen_nathan_s.png|law__cohen_nathan_s|/imgs/btn/koeye.png|law",
		]
	return(uslaws)





def ko_im(a1,a2):
	print progid,dttm,"ko_im a1=",a1
	pathfile="."
	if( a1 != "" ): pathfile=a1
#	syscmd="ls -lat {} | exiftool -s -csv".format( pathfile )
	syscmd="mkdir {}/tn".format( pathfile )
	print progid,dttm, "ko_im syscmd{}".format( syscmd )
#	os.system( syscmd )

	syscmd="mogrify  -resize x300 -set filename:name %f  -write '{}/tn/tn_%[filename:name]' {}".format( pathfile, pathfile )
	print progid,dttm, "ko_im syscmd{}".format( syscmd )
#	os.system( syscmd )
	os.system( "mogrify  -resize x300 -set filename:name %f  -write './pn/imgs/tn/tn_%[filename:name]' ./pn/imgs/*.jpg" ) 

	exit()

	print progid,dttm,"ko_im syscmd={}".format( syscmd )
	os.system( syscmd )


#	my_date = datetime.date(*[int(i) for i in string_date.split("-")])
#	from subprocess import call
#	call(["ls", "-l" )
#	os.system( "ls -lat /Volumes/ka1tbr2/ht/imgs/links/*.*" )
#	print subprocess.Popen("echo Hello World", shell=True, stdout=subprocess.PIPE).stdout.read(	
#	return_code = subprocess.call("echo Hello World", shell=True) 
	return("ko_im_return");


def ko_sql(sqlfil,sqlcmd):
	import sqlite3
	sqlfil="ka1.db3"
	sqlcmd="select cat,test,testdt from lab"
	print progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )

	try:
		sqldb = sqlite3.connect(sqlfil)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
#	cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
#	sqlcmd="select * from leds"
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print "cat={} test={} testdt={}".format( row[0], row[1], row[2] )
# err		print "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] )
#		print(row)

	print progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )


	db = sqlite3.connect(sqlfil)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()
	cursor.execute('''select name, email, phone from us0''')
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['name'], row['email'], row['phone']))
	db.close()
	return( "ko_sql" )




	def sql_cr(sqldb, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)

	def sql_insert(sqldb, sqlcmd ):
		sqlcmd = """INSERT INTO table1 (
				column1, column2 ,..)
			VALUES (
				value1, value2 ,...
				); """

	return("ko_sql_return");


def ko_usid2host(grp, usid):
	import sqlite3
	dttm=ko_dttm()
	sqlfil="ko.db3"
	sqlcmd="select cat,test,testdt from lab"
	sqlcmd="select * from uslist"
	sqlcmd="select usid,dttm,status,url,img,tn,id,grp from uslist "
	print progid,dttm,"ko_sql sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )
	fildb3="ko.db3"

	try:
		sqldb = sqlite3.connect(fildb3)
	except Error as e:
		print(e)

	cur = sqldb.cursor()
#	cur.execute("SELECT * FROM tasks")
#	cur.execute("SELECT * FROM tasks WHERE priority=?", (priority,))
#	sqlcmd="select * from leds"
	cur.execute(sqlcmd)
	rows = cur.fetchall()
	for row in rows:
		print "r0={} r1={} r3={}".format( row[0], row[1], row[2] )
# err		print "cat={} test={} testdt={}".format( row['cat'], row['test'], row['testdt'] )
#		print(row)

	print progid,dttm,"ko_usid2host sqlfil={} sqlcmd={}\n".format( sqlfil, sqlcmd )


	db = sqlite3.connect(fildb3)
	db.row_factory = sqlite3.Row
	cursor = db.cursor()

	sqlcmd='''select usid,dttm,status,url,img,tn,id,grp from uslist'''
	cursor.execute(sqlcmd)
#	cursor.execute('''select name, email, phone from uslist limit 4''')

	osflag = ""
	for row in cursor:
# 		row['name'] returns the name column in the query, row['email'] returns email column.
		print('{0} : {1}, {2}'.format(row['usid'], row['url'], row['img'], row['tn'], row['id'], row['grp'], row['status']))
		grp=row['grp']
		id=row['id']
		url=row['url']
		img=row['img']
		tn=row['tn']
		status=row['status']

		syscmd_mkdir_grp = "mkdir uw/{}".format(grp)
		print "usid2host syscmd_mkdir_grp={}".format( syscmd_mkdir_grp )

		syscmd_mkdir_grpid = "mkdir uw/{}/{}".format(grp,id)
		print "usid2host grp={} id={} syscmd_mkdir_grpid={}".format( grp, id, syscmd_mkdir_grp)

		osflag = ""
		print "osflag={}".format(osflag)
#		if( osflag == "y" ): os.system( syscmd_mkdir_grp )
#		if( osflag == "y" ): os.system( syscmd_mkdir_grpid )


#	db.close()
#	return( "ko_usid2host" )




	def sql_cr(fildb3, sqlcmd ):
		sqlcmd= """ CREATE TABLE IF NOT EXISTS pd (
                                        id integer PRIMARY KEY,
                                        code text NOT NULL,
                                        dttm text NOT NULL,
                                        ctime text,
                                        filsiz text,
                                        pathfile text,
                                        path text,
                                        base text,
                                        ext text,
                                        link text,
                                        title text,
                                        desc text
                                    ); """
		cur.execute(sqlcmd)


	uslist = load_uslist()
	j=0
	status="todo"
	dttm=ko_dttm()
	for us in uslist:
		print "j={} us={}".format(j, us)

		url=us.split("|")[0]
		img=us.split("|")[1]
		tn=us.split("|")[2]
		id=us.split("|")[3]
		grp=us.split("|")[4]
		status="todo"

		sqltbl = "uslist"
		sqlcols = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'id', 'grp', 'url', 'img', 'tn','status','dttm'"
		sqlvals = "'{}','{}','{}','{}','{}','{}','{}'".format(id,grp,url,img,tn,status,dttm)

		sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
		print "{}".format(sql_insert)
#		print "usid2host j={} sql_insert={}".format(j,sql_insert)
#		print "j={} grp={} id={} url={} img={}".format( j, grp, id, url, img )
#		cur.execute(sql_insert)
		cursor.execute(sql_insert)

#		def sql_insert(fildb3, sql_insert ):
#			sql_insert = "insert or replace into {} ( {} ) values ( {} )".format( sqltbl, sqlcols, sqlvals )
#
#
#		def sql_insert(fildb3, sqlcmd ):
#		sqlcmd = """INSERT INTO table1 (
#		sqlcmd = """insert or replace into  uslist (
#				'id','grp','url','img','tn','status','dttm' )
#			VALUES (
#				sqlval
##				value1, value2 ,...
#				); """
#
		j=j+1
	db.close()
	return("ko_sql_return");


def ko_img(a1,a2):
	from PIL import Image, ImageFilter
	imgfil=a1
	imgout=a2
	print progid,dttm,"ko_img imgfil=",imgfil," imgout=",imgout

#Read image
#	im = Image.open( 'image.jpg' )
	im = Image.open( imgfil )
	im.show()
	im_sharp = im.filter( ImageFilter.SHARPEN )
#	im_sharp.save( 'image_sharpened.jpg', 'JPEG' )
	im_sharp.save( imgout, 'JPEG' )

#Splitting the image into its respective bands, i.e. Red, Green,
#and Blue for RGB
	r,g,b = im_sharp.split()

#Viewing EXIF data embedded in image
	exif_data = im._getexif()
	exif_data

	return("ko_img_return");



def wiisk( a1,a2,a3 ):
	dttm=dttm()
	print "{} {} wiisk ".format(progid, dttm, a1, a2, a3 )
	exit()

def wiijk( a1,a2,a3 ):
	dttm=dttm()
	print "{} {} wiijk ".format(progid, dttm, a1, a2, a3 )
	exit()

def wii( a1,a2,a3 ):
	dttm=dttm()
	print "{} {} wiijk ".format(progid, dttm, a1, a2, a3 )
	exit()









def ko_find(path,name):
	import subprocess
	import os

# 	syscmd "find {} -type f {} -exec ls -s \{\} \; | sort -n -r | head -5".format( path, name)
#	syscmd="find ./ht f -exec ls -lat {} \;"
	syscmd='find ./imgs -name "btn_*.gif" f -exec ls -lat {} \;'
	stdout=""
	print progid,dttm,"ko_find: syscmd=",syscmd

# ok	p = os.popen('ls -lat')
# ok	p = os.popen('ls -lat ./imgs/ok*.*')
# 	p = os.popen("ls -lat ./imgs/ok*.*")

#	syscmd="ls -lat ./imgs/ok*.*"
	syscmd="ls -lat "+path

	syscmd='find ./imgs -name \"btn_*.gif\"  -exec ls -lat {} \;'
	print progid,dttm,"ko_find syscmd=",syscmd
	p = os.popen("syscmd")
	print(p.read())
	
	print progid,dttm,"MSG:  ko_subprocess p=", p
	print progid,dttm,"MSG:  ko_subprocess syscmd=", syscmd
#	process = subprocess.Popen("syscmd", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	process = subprocess.Popen(['ls -lat ', 'rb'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	stdout, stderr = process.communicate()
	print progid,dttm,"MSG:  ko_subprocess stdout=", stdout
#	print stdout
	return(stdout)



def ko_glob( pattern ):
	import glob

	out = glob.glob( pattern )
#	print(glob.glob("/home/adam/*.txt"))
#	out = glob.glob( "./imgs/ko/icons/*.gif" )
#	out = glob.glob( "./imgs/*.gif" )
#	out = glob.glob( "./imgs/*.jpg" )
#	out = glob.glob( "/Volumes/ka1tbr2/ht/*.png" )
#	globcmd = "/Volumes/ka1tbr2/ht/*.php"
#	print "BUGS95_ko_glob out=",out

#	out = glob.glob( pattern )
#	print "ko_glob BUGS_beg:  pattern=", pattern
#	print "ko_glob BUGS_beg:  out=", pattern
	return(out)
	
def ko_ls( dir, endswith ):
	import os
#	arr_txt = [x for x in os.listdir(dir) if x.endswith(".txt")]
#	arr_gif = [x for x in os.listdir(dir) if x.endswith(".gif")]
#	return(os.listdir(dir))
	out = [x for x in os.listdir(dir) if x.endswith(endswith)]
	return( out )


def ko_subprocess( syscmd ):
	import subprocess

#	process = subprocess.Popen("ps -p 2993 -o time --no-headers", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#	process = subprocess.Popen(syscmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	syscmd="ls -lat /Volumes/ka1tbr2/ht/"
	process = subprocess.Popen("syscmd", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	stdout, stderr = process.communicate()
	print progid,dttm,"MSG:  ko_subprocess"
#	print stdout
	return(stdout)



def ko_walk( dir, kludge ):
	for root, dirs, files in os.walk(dir):  
		for filename in files:
			print(filename)



def ko_listdir( dir, pattern ):
#	listOfFiles = os.listdir('.')  
# 	pattern = "*.py"  
	listOfFiles = os.listdir( dir )

	for entry in listOfFiles:  
		if fnmatch.fnmatch(entry, pattern):
			print (entry)

def startup():
	global progid, dttm
	progid = "ka1"
	dttm=ko_dttm()


#	print "arg1=", str(sys.argv[1:])
#	print "arg1:1=", str(sys.argv[1:2])
#	print "arg2:1=", str(sys.argv[2:3])
# 	print progid,dttm, "MSG:  startup\n\n"

#	try:
#		thevariable
#	except NameError:
#		print "well, it WASN'T defined after all!"
#	else:
#		print "sure, it was defined."`






#	if( len(sys.argv) == 1 ):
	if( len(sys.argv) < 2 ):
		print progid, dttm, "pqpqpqpqpqpqpqpqpq"
		print progid, "do <a1> <a2>"
		print progid, "do <a1> <a2>"
		print progid, "dodo <a1> <a2>"
		print progid, "do_mp42gif <a1> <a2>"
		print progid, "do_sl <a1> <a2>"
		print progid, "do_tl <a1> <a2>"
		print progid, "do_tlwl <a1> <a2>"
		print progid, "do_tlpsv <a1> <a2>"
		print progid, "go <a1> <a2>"
		print progid, "find <path/file> <todofile>"
		print progid, "mkwl <path/file> <todofile>"
		print progid, "viwl <todofile> <a2>"
		print progid, "runwl <todofile> <a2>"
		print progid, "go <a1> <a2>"
		print progid, "go pub ko	# index2index_ko0 <a2>"
		print progid, "go_jsg <a1> <a2>"
		print progid, "go <a1> <a2>"
		print progid, "kov . .  # cp index.html kov_.html"
		print progid, "ko_go <dir>  # find mp4 with embeded spaces"
		print progid, "im <dir>  # imagemagic"
		print progid, "sl <dir> "
		print progid, "tl <dir> "
		print progid, "b64 <dir> "
		print progid, "sql <dir> "
		print progid, "glob <dir> "
		print progid, "find <dir> "
		print progid, "ls <dir> <txt|png|gif|...> "
		print progid, "sys <dir> "
		print "{} {} pqpqpqpqpqpqpqpqpq".format( progid, dttm )
		print progid, "usid2host <usid>	<host># "
		print progid, "gif2size <gif>	<wxh># png+gif=png_gif.gif"
		print progid, "png2gif <gif,png>	# png+gif=png_gif.gif"
		print progid, "gifs2gifs <gifs>	# gifs.txt"
		print progid, "gif2gifs <pathfile,oldtxt,newtxt>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go filio <pathfile,oldtxt,newtxt>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go htms2htm <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go phps2php <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go newhtm <id,id,id>	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go uslaw .	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go usmed usmedid	# pub med_(rechtin,mcdonough)  index(_ko0_ko2)"
		print progid, "go cp .	# cp index.html index(_ko0_ko2_ka1_ka2).html"
		print progid, "go scp ko	# scp index(ko0_ko2_ka1_ka2).html ko0us ko2us"
		print progid, "go ssh ko	# ssh (ko0_ko2) sshcmd"
#		print progid, "listdir <dir> <pattern>"
#		print progid, "walk <dir> <pattern>"
#		print progid, "joshtest <dir> <pattern>"
		print progid, " "
		print progid, "wiisk <usid>	<host># "
		print progid, "wiijk <usid>	<host># "
		print progid, "wii <usid>	<host># "
		dttm=ko_dttm()
		print "{} {} bdbdbdbdbdbdbdbdbd".format( progid, dttm )

		exit()
	dttm=ko_dttm()

	if( a1 == "sys" ):
		syscmd = sys.argv[2]
		print progid,dttm, "MSG: startup_syscmd=",syscmd
		sysout = ko_subprocess( syscmd )
		print progid,dttm, "MSG: startup_sysout=",sysout
		exit()

	if( a1 == "do" ):
		out=ko_do( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do out=", out,a0,a1,a2,a3
		exit()

	if( a1 == "dodo" ):
		out=ko_dodo( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_dodo out=", out,a0,a1,a2,a3
		exit()

	if( a1 == "do_mp42gif" ):
		out=ko_do_mp42gif( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do_mp42gif out=", out,a0,a1,a2,a3
		exit()

	if( a1 == "do_sl" ):
		out=ko_do_sl( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do_tl out=", out, a0,a1,a2,a3
		exit()

	if( a1 == "do_tl" ):
		out=ko_do_tl( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do_tl out=", out, a0,a1,a2,a3
		exit()

	if( a1 == "do_tlwl" ):
		out=ko_do_tlwl( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do_tlwl out=", out, a0,a1,a2,a3
		exit()

	if( a1 == "do_tlpsv" ):
		out=ko_do_tlpsv( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_do_tlpsv out=", out, a0,a1,a2,a3
		exit()

	if( a1 == "ko_dodo" ):
		out=ko_dodo( a0,a1,a2,a3 )
		print progid,dttm, "MSG: startup_dodo out=", out, a0,a1,a2,a3
		exit()

	if( a1 == "viwl" ):
		out=ko_find( a1, a2 )
		syscmd_vi="vi {}".format( a1 )
		print progid,dttm, "MSG: syscmd_vi=".format(syscvmd_vi)
#		os.system(syscmd_vi)
		exit()

	if( a1 == "runwl" ):
		out="runwl a1={} a2={} a3={}\n".format( a1, a2, a3 )
		runwl( a1, a2, a3 )
		print progid,dttm, "MSG: runwl wlfile=", a1
		exit()


	if( a1 == "mkwl" ):
		out=ko_find( a1, a2 )
		print progid,dttm, "MSG: startup_go out=", out
		exit()
	if( a1 == "find" ):
		out=ko_find( a1, a2 )
		print progid,dttm, "MSG: startup_go out=", out
		exit()
	if( a1 == "ko_find" ):
		out=ko_find( a1, "" )
		print progid,dttm, "MSG: startup_im out=", out
		exit()

	if( sys.argv[1] == "go" ):
		out=go( sys.argv[2], sys.argv[3] )
		print progid,dttm, "MSG: startup_go out=", out
		exit()

	if( sys.argv[1] == "kogo" ):
		out=ko_go( sys.argv[2], sys.argv[3] )
		print progid,dttm, "MSG: startup_go out=", out
		exit()

	if( sys.argv[1] == "go_jsg" ):
		out=go_jsg( a1, a2 )
		print progid,dttm, "MSG: startup_go_jsg out=", out
		exit()

	if( sys.argv[1] == "kov" ):
		out=ko_kov( a1, a2 )
		print progid,dttm, "MSG: kov out=", out
		exit()

	if( sys.argv[1] == "go" ):
		out=go( a1, a2 )
		print progid,dttm, "MSG: ko out=", out
		exit()

	if( sys.argv[1] == "ko_go" ):
		out=ko_go( a1, a2 )
		print progid,dttm, "MSG: ko_go out=", out
		exit()

	if( sys.argv[1] == "im" ):
		out=ko_im( sys.argv[2], "" )
		print progid,dttm, "MSG: startup_im out=", out
		exit()

	if( sys.argv[1] == "sql" ):
		out=ko_sql( sys.argv[2], sys.argv[3] )
		print progid,dttm, "MSG: startup_sql out=", out
		exit()


	if( sys.argv[1] == "find" ):
		out=ko_find( sys.argv[2], sys.argv[3] )
		print progid,dttm, "MSG: startup_find out=", out
		exit()


	if( sys.argv[1] == "b64" ):
		import base64
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print progid,dttm, "MSG: startup_b64 pathdir=", pathdir
#		print progid,dttm, "MSG: startup_b64 pathcode=", pathcode
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print "BUGS270 csvout=" + csvout

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=ko_dttm()
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
			print progid,dttm,j,"filecode=",filecode
			print progid,dttm,j,"filecode_tuple=",filecode_tuple

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print progid,dttm,j,"ctime_ymd=",ctime_ymd
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print "BUGS_350 filecode=",filecode
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx"
				
#				if( not os.path.isfile( b64_pathfile )):
#					print progid,dttm,j,"b64_pathfile=",b64_pathfile
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print progid,dttm,j,"pathfile b64dta=",pathfile, b64dta
			print progid,dttm,j,"pathfile=",pathfile

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile
		exit()

	if( sys.argv[1] == "sl" ):
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)
		path=pathdir.replace( os.path.basename(pathdir),"", 1)

# print(os.path.splitext("path_to_file")[0])
# basenaem no ext if( pathdir == "" ): pathdir="."; pathcode="";
# print(basename("/a/b/c.txt"))

		pathfiles=ko_glob( pathdir )
#		print progid,dttm, "MSG: startup_b64 pathdir=", pathdir
#		print progid,dttm, "MSG: startup_b64 pathcode=", pathcode
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print "BUGS270 csvout=" + csvout

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		j=0

#		for letter in 'Python':     # First Example
#			if letter == 'h':
#				break
#			print 'Current Letter :', letter
#		exit()

		filename = "ka1_av.html"
		filename = "test_av.html"
		file = open( filename, "r" )
		ka1_av_html_hdr = ""
		ka1_av_html_dta = ""
		ka1_av_html_ftr = ""
		j=0
		mode="hdr"
		for line in file:
# err			if line.match('div_sl_images" ): break
#			if line == 'div_sl_images': 

			if re.search( '<div id="div_sl_images">', line ):
				mode = "dta"
				filenames = [
					'./imgs/btn/ko.png',
					'./imgs/btn/p1.png',
					'./imgs/btn/p12.png',
					'./imgs/btn/ok.png'
					]

#				fruits = ['banana', 'apple',  'mango']
#				for ka1 in range(len(filenames)):
#					print 'BUGS_430 filename=', filenames[ka1]

#				a_href=""

#				fruits = ['banana', 'apple',  'mango']

				tncodes = ['tn', 'tn1', 'tn2', 'tn3']
				for tncode in tncodes:
					tnpath = "{}{}".format( path, tncode )
					tnpathfile = "{}/{}_*".format(tnpath,tncode )
					syscmd = "mkdir {}".format(tnpath )
#					print 'BUGS_520 tnpath=',tnpath
#					print 'BUGS_520 tnpathfile=',tnpathfile
#					print 'BUGS_520 mkdir syscmd=', syscmd 
					if not os.path.isdir( tnpath ):
						os.system( syscmd )
# print(os.path.isdir("/home/el"))
# print(os.path.exists("/home/el/myfile.txt"))


# 					syscmd = 'mogrify  -resize x400 -set filename:name %f  -write "./pn/imgs/tng/tng_%[filename:name]' ./pn/imgs/*.png
					syscmd = 'mogrify  -resize x100 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					if ( tncode == "tn1" ):
						syscmd = 'mogrify  -resize x100 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					if ( tncode == "tn2" ):
						syscmd = 'mogrify  -resize x200 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir )
					if ( tncode == "tn3" ):
						syscmd = 'mogrify  -resize x300 -set filename:name %f  -write "{}/{}_%[filename:name]" {}'.format( tnpath, tncode, pathdir ) 
					print 'BUGS_530 mogrify syscmd=', syscmd 
					os.system( syscmd )


				for pathfile in pathfiles:
					j=j+1
					dttm=ko_dttm()
					path=os.path.dirname(pathfile)
					base=os.path.basename(pathfile)
					file=os.path.splitext(base)[0]
					ext=os.path.splitext(base)[1]
					filecode_tuple=str(j),"-",file,"-",ext
					filecode = "".join(filecode_tuple)
#					print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
#					print progid,dttm,j,"filecode=",filecode
#					print progid,dttm,j,"filecode_tuple=",filecode_tuple
					filename=pathfile
#					tn_filename=pathfile.replace(base,"/tn/tn_".join(base))
					tn_filename="{}/tn/tn_{}".format( path,base )
#					print progid,dttm,j,"tn_filename=",tn_filename


					a_href = ""
#					a_href += '<a href="./sl/bg/imgs/space/Universe_and_planets_digital_art_wallpaper_dk.jpg" class="thumb_link"><span class="selected"></span><img src="./sl/bg/imgs/space/Universe_and_planets_digital_art_wallpaper_dk_thumb.jpg" title="X-Wing on patrol" alt="X-Wing on patrol" class="thumb" /></a>'
					a_href += "<a href='{}' class='thumb_link'>\n".format( filename )
					a_href += '<span class="selected"></span>'
					a_href += '<img src="{}" height=100 title="{}" alt="{}" class="thumb" /></a>\n'.format( tn_filename,filename,filename )
					print a_href
#				continue

#			if re.match( '<div id="div_sl_images">', line ):
#				mode = "dta_match"
#				continue

			if '<div id="sl_images"' in line.lower():
				mode = "dta"
				continue
#			if j == 88:
#				mode = "dta"
#				continue
			if mode == "hdr":
				ka1_av_html_hdr += line
			if mode == "dta":
				ka1_av_html_dta += line
			print line
#			print "BUGS_409 line=",j," line=", line, " mode=",mode
			j=j+1
#		print "BUGS_410 line=",j," ka1_av_html_hdr=", ka1_av_html_hdr
#		print "BUGS_410 line_len=",j
			
				
		
#		print file.read()
#		ka1_av_html_hdr = file.readline(500)
#		print "ka1_av_html_hdr=",ka1_av_html_hdr

#		print file.readline(100)
#		print file.readlines()
#		for line in file:
#			print line,

#		ka1_av_html = ""
#		ka1_av_html += ka1_av_html_hdr()
#		ka1_av_html += ka1_av_html_hdr
#		ka1_av_html += ka1_av_html_dta()
#		ka1_av_html += ka1_av_html_ftr()
#		print ka1_av_html
		exit()

		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print progid,dttm, "MSG: startup_b64 pathdir=", pathdir
#		print progid,dttm, "MSG: startup_b64 pathcode=", pathcode
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
#		print "BUGS270 csvout=" + csvout

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=ko_dttm()
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
			print progid,dttm,j,"filecode=",filecode
			print progid,dttm,j,"filecode_tuple=",filecode_tuple

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print progid,dttm,j,"ctime_ymd=",ctime_ymd
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print "BUGS_350 filecode=",filecode
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx"
				
#				if( not os.path.isfile( b64_pathfile )):
#					print progid,dttm,j,"b64_pathfile=",b64_pathfile
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print progid,dttm,j,"pathfile b64dta=",pathfile, b64dta
			print progid,dttm,j,"pathfile=",pathfile

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile
		exit()

	if( sys.argv[1] == "tl" ):
		import base64
		j=0
		pathdir=sys.argv[2]
		chars_to_remove = [ '.', '*' ]
		pathcode=pathdir.translate(None,''.join(chars_to_remove))
		pathcode=pathcode.replace("/","-")
		pathcode=pathcode.replace("-","", 1)

		ka1_tl_html = ""
		ka1_tl_html += ka1_tl_html_hdr()
		ka1_tl_html += ka1_tl_html_dta()
		ka1_tl_html += ka1_tl_html_json_hdr()
		ka1_tl_html += ka1_tl_html_json_dta()
		ka1_tl_html += ka1_tl_html_json_ftr()
		ka1_tl_html += ka1_tl_html_ftr()
		print ka1_tl_html
		exit()

		if( pathdir == "" ): pathdir="."; pathcode="";

		pathfiles=ko_glob( pathdir )
#		print progid,dttm, "MSG: startup_b64 pathdir=", pathdir
#		print progid,dttm, "MSG: startup_b64 pathcode=", pathcode
#		b64_pathfile=pathdir+"/"+"b64_"+base

		htm_pathfile="./"+progid+"_b64_"+pathcode+".htm"
		htm_pathfile = htm_pathfile.replace( "-.htm", ".htm" )

		csv_pathfile="./"+progid+"_b64_"+pathcode+".csv"
		csv_pathfile = csv_pathfile.replace( "-.csv", ".csv" )

#		print progid,dttm, "MSG: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG: startup_b64 csv_pathfile=", csv_pathfile
		csvfil = open(csv_pathfile, "wb" )

		csvout = ''
		jsout = ""
		htmout = ""

		csvout = "recno,progid,status,dttm,pathfile,path,base,file,ext,filsiz,ctime,desc"
		print "BUGS270 csvout=" + csvout

		htmfil = open(htm_pathfile, "wb" )
#		jsout += '<script id="script_',pathcode,'" >\n'
		jsout += "<script id='script_myb64'\n"

		jsout += "function load_myb64() {\n"

		jsout += "	var myb64 = new array()\n"

# bugs tuple 	htmout += "	<div id='", pathcode, "' >\n"
# bugs tuple	htmout += '	<div id="', pathcode[0], '" >\n'
		htmout += '	<div id="div_myb64" >\n'

		for pathfile in pathfiles:
			j=j+1
			dttm=ko_dttm()
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			filecode_tuple=str(j),"-",file,"-",ext
			filecode = "".join(filecode_tuple)
			print progid,dttm,j,"pathfile=",pathfile, path, base,file,ext
			print progid,dttm,j,"filecode=",filecode
			print progid,dttm,j,"filecode_tuple=",filecode_tuple

			b64dta=""
			if( os.path.isfile( pathfile )):	


				filesize = os.path.getsize(pathfile)
				ctime=time.ctime(os.path.getctime(pathfile))
				ctime_ymd = time.strftime('%Y-%m-%d_%H:%M:%S', time.gmtime(os.path.getmtime(pathfile)))


# err				ctime=os.path.getctime(pathfile)
#				ctime_ymd =  datetime.datetime.strftime(ctime,'%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				print progid,dttm,j,"ctime_ymd=",ctime_ymd
#				ctime_ymd = "YYYY-MM-SS_hh:mm:ss"
#				ctime_ymd =  ctime.strftime('%Y-%m-%d_%H:%M:%S')  # This writes "06/24/1984"
#				d = datetime.strptime(time.ctime(),"%a %b %d %H:%M:%S %Y")
#				d = datetime.strptime(ctime,"%a %b %d %H:%M:%S %Y")
#				d = time.ctime(os.path.getctime(pathfile))
#				ctime_ymd = d.strftime('%Y-%d-%m_%H:%M:%S')
				print progid,dttm,j,"ctime_ymd=",ctime_ymd,filesize,pathfile

				image = open( pathfile, 'rb') 
				imgbin = image.read()
#				b64dta = base64.encodestring(imgbin)
				b64dta = base64.b64encode(imgbin)
				b64ext = ext.replace( '.', '' )	

				csvout += "{},{},{},{},{},{},{},{},{},{},{},\n".format(
					j,"status",progid,dttm,pathfile,path,base,file,ext,
					filesize,ctime_ymd,"desc")

#				jsout += 'myb64[{}] = "data:image/{};base64,{}"\n'.format(j, b64ext, b64dta )
# bugs tuple			jsout += 'myb64['",filecode,"'] = "data:image/png;base64,{}"\n'.format(j, b64dta )
				jsout += 'myb64['
# bugs tuple				jsout += filecode.join()
				jsout += '] = "data:image/{};base64,{}"\n'.format( b64ext, b64dta )
				
				htmout += "\n"
				print "BUGS_350 filecode=",filecode
#				htmout += '<a href=?q=myb64,',filecode,' id="',filecode,'" target=_blank >\n'
				htmout += '<a href=?q=myb64_{} id="{}" target=_blank >\n'.format( filecode, filecode )
#				htmout += '	<img id="{}" src="data:image/{};base64,{}"><br>\n'.format(filecode,b64ext,b64dta)
#				htmout += '	<img src="data:image/{};base64,{}"><br>\n'.format(b64ext,b64dta)
				htmout += '{} {} <img src="data:image/{};base64,{}">\n'.format(j,filecode, b64ext, b64dta )

				print progid,dttm,j, "BUGS_322: b64dta=",b64dta,"xxxxxxxxx"
				
#				if( not os.path.isfile( b64_pathfile )):
#					print progid,dttm,j,"b64_pathfile=",b64_pathfile
#					b64ddta = base64.decodestring(b64dta) 
#					b64img = open(b64_pathfile, 'wb')
##					b64img = open('deer_decode.gif', 'wb')
#					b64img.write(b64ddta)

#			print progid,dttm,j,"pathfile b64dta=",pathfile, b64dta
			print progid,dttm,j,"pathfile=",pathfile

		jsout += "	return(myb64)\n"
		jsout += "	}\n"
		jsout += "	</script>\n"


		htmout += "		</div>\n"

#		htmout += '	<script id="script_myb64">'
#		htmout += '		var img, k;'
#		htmout += '		for( k=0; k<j; k++ ) {'
#		htmout += '			img = "<img src=", myb64[k], "></a><br>"'
#		htmout += '			document.write( img );'
#		htmout += '			}'
#		htmout += '		</script>'

		htmfil.write( htmout )
		htmfil.write( jsout )
		htmfil.close()

		csvfil.write( csvout )
		csvfil.close()
#		print progid,dttm, "MSG_360: startup_b64 htm_pathfile=", htm_pathfile
#		print progid,dttm, "MSG_360: startup_b64 csv_pathfile=", csv_pathfile
		exit()

	if( sys.argv[1] == "glob" ):
		j=0
		out=ko_glob( sys.argv[2] )
		print progid,dttm, "MSG: startup_glob path", sys.argv[2]
		print progid,dttm, "MSG: startup_glob out=", out
		for pathfile in out:
			j=j+1
			path=os.path.dirname(pathfile)
			base=os.path.basename(pathfile)
			file=os.path.splitext(base)[0]
			ext=os.path.splitext(base)[1]
			
			print j,"pathfile=",pathfile, path, base,file,ext
		exit()

	if( sys.argv[1] == "ls" ):
		out = ko_ls( sys.argv[2], sys.argv[3] )
		print progid,dttm, "MSG: startup_ls", out
		exit()


#	if( sys.argv[1].match("listdir")):
	if( sys.argv[1] == "listdir" ):
		print progid,dttm, "MSG: startup_listdir"
		ko_listdir( a1, a2, a3 )
		exit()

#	if( sys.argv[1].match("walk")):
	if( a1 == "walk" ):
		print progid,dttm, "MSG: startup_walk"
		ko_walk( sys.argv[2], sys.argv[3] )
		exit()


	if( sys.argv[1] == "gifs2gifs" ):
		gif1 = sys.argv[2]
		gif2 = sys.argv[3]
 		gifs = load_gifs()
		j=0
		for gif in gifs:
			j=j+1
			print "gif2gifs DISABLE j={} gif={}".format(j, gif)
#			gif2gifs( gif )
		exit()

	if( sys.argv[1] == "gif2size" ):
		gifold = sys.argv[2]
		sizexy = sys.argv[3]
#		giftmp = "tmp.gif"
		giftmp = gifold.replace( ".gif", "_tmp.gif" )

		sizexy_default = "200x80"
		if( sizexy == "." ): sizexy = sizexy_default

		giftag = "_{}.gif".format( sizexy )
		gifnew = gifold.replace( ".gif", giftag )

#		convert do.gif -coalesce temporary.gif
		convert_coalesce = "convert {} -coalesce {}".format( gifold, giftmp )
		print "gif2size convert_coalesce={} ".format(convert_coalesce)
		os.system( convert_coalesce )



#		convert -size <original size> temporary.gif -resize 24x24 smaller.gif
#		convert_gif2size = "convert -size {} -resize {} {}".format(  giftmp, sizexy, gifnew )
		convert_gif2size = "convert {}  -resize {} {}".format(  giftmp, sizexy, gifnew )


#		print "gif2size gifold={} giftmp={} gifnew={}".format(gifold, giftmp, gifnew)
		print "gif2size convert_gif2size={} ".format(convert_gif2size)
		os.system( convert_gif2size )







		exit()

	if( sys.argv[1] == "gif2gifs" ):
		gif1 = sys.argv[2]
		gif2 = sys.argv[3]

		print "gif2gifs gif={}".format(gif1)
		gif2gifs( gif1 )
		exit()

	if( sys.argv[1] == "png2gif" ):
		gif = sys.argv[2]
		png = sys.argv[3]
		if( png == "." ): png="imgs/btn/koeye.png"
		if( png == "." ): png="imgs/ani/work/knot/koeye_100x40.png"
		png2gif( gif,png )
		exit()

	if( sys.argv[1] == "usid2host" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		ko_usid2host( usid, grp )
		exit()

	if( sys.argv[1] == "wiisk" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wiisk( usid, grp,"" )
		exit()
	if( sys.argv[1] == "wiijk" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wiijk( usid, grp,"" )
		exit()
	if( sys.argv[1] == "wii" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		wii( usid, grp,"" )
		exit()
	if( sys.argv[1] == "jkwii" ):
		usid = sys.argv[2]
		grp = sys.argv[3]
		exit()


	print progid, "ERR: unsupported command"
	print "argc=", len(sys.argv)
	print "args=", str(sys.argv)
	print "a0={} argv0={}".format(a0, str(sys.argv[0]))
	print "a1={} argv1={}".format(a1, str(sys.argv[1]))
	print "a2={} argv2={}".format(a2, str(sys.argv[2]))
	print "a3={} argv3={}".format(a3, str(sys.argv[3]))

def commands():
	import re
	print sys.argv[1]
	if re.match( sys.argv[1], 'help' ):
		print progid, "MSG: help"
	print progid, "ERR: unsupported cmd"
	return 



def ko_dir2b64():
	import base64
	encoded = base64.b64encode(open("ka1.png", "rb").read())

# b64encode ka1.png X | sed '1d;$d' | tr -d '\n' > b64_ka.png
# <img src="data:image/png;base64,ENCODED_PNG"
# 
# im: composite {overlay} {background} [{mask}] [-compose {method}]   {result}
# im: convert  {background} {overlay} [{mask}] [-compose {method}] -composite   {result}


# pqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpqpq
# bdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbdbd

def ka1_av_html_read(filename):
	file = open( filename, "r" )
	print file.read()
	print file.readline(100)
	print file.readlines()
	for line in file:
		print line,

def ka1_av_html_hdr():
	ka1_av_html_hdr = "ka1_av_html_hdr\n" 
	return( ka1_av_html_hdr );

def ka1_av_html_dta():
	ka1_av_html_dta = "ka1_av_html_dta\n"
	return( ka1_av_html_dta );

def ka1_av_html_ftr():
	ka1_av_html_ftr = "ka1_av_html_ftr\n"
	return( ka1_av_html_ftr);


def ka1_tl_html_hdr():
	ka1_tl_html_hdr = "ka1_tl_html_hdr"
	return( ka1_tl_html_hdr );

def ka1_tl_html_json_htr():
	ka1_tl_html_json_htr = "ka1_tl_html_json_hdr"
	return( ka1_tl_html_json_hdr );

def ka1_tl_html_json_dta():
	ka1_tl_html_json_dta = "ka1_tl_html_json_dta"
	return( ka1_tl_html_json_dta );

def ka1_tl_html_json_ftr():
	ka1_tl_html_json_ftr = "} ] } } \n"
	return( ka1_tl_html_json_ftr );


def ka1_tl_html_ftr():
	ka1_tl_html_ftr = "ka1_tl_html_ftr"
	return( ka1_tl_html_ftr );


def ko_do_sl(a0,a1,a2,a3):
	dttm=ko_dttm()
	print '{} {} ko_do_sl: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	json_beg=''
	dttm=ko_dttm()

	ifile=a2
	ofile=a3
	if ofile == '': 
		ofile=ifile.replace('.wl', '.htm')
	print '{} {} ko_do_sl MSG_2300 ifile={} ofile={}'.format(progid, dttm, ifile,ofile)

	if os.path.isfile( ofile ):
		print '{} {} ko_do_sl ERR_FOUND: ofile={}'.format(progid,dttm, ofile )
#		exit()
	else:
		print '{} {} ko_do_sl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile )

	if not os.path.isfile( ifile ):
		print '{} {} ko_do_sl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile )
		exit()
	else:
		print '{} {} ko_do_sl MSG_FOUND: ifile={}'.format(progid,dttm, ifile )

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	
#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print '{} {} ko_do_tl MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size )
	print '{} {} ko_do_tl MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size )
	
# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	psvline=''
	htmline=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		
		with open(wlfile) as f:
			j=0
			for line in f:
				j += 1

#				m = re.match( '.psv', wlfile )
#				if m:
#				print 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile ))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					pathfile=line.split('|')[13]
					print '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)
				else:
					pathfile=line.split()[8]
					print '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext )
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print "BUGS_141 i_pathfile={}".format(i_pathfile)
				print "BUGS_142 ht_pathfile={}".format(ht_pathfile)
				if ext=='.mp4' : print "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4)
				if ext=='.jpg' : print "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg)
#				if ext=='.jpg' : print "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1)
#				if ext=='.jpg' : print "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs)
				if ext=='.gif' : print "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif)
				if ext=='.png' : print "BUGS_146 o_pathfile_png={}".format(o_pathfile_png)


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


				startdate_yyyy='2019'
				startdate_mm='01'
				startdate_dd='01'
				startdate='{},{},{}'.format(startdate_yyyy,startdate_mm,startdate_dd)
				enddate_yyyy='2019'
				enddate_mm='01'
				enddate_dd='31'
				enddate='{},{},{}'.format(enddate_yyyy,enddate_mm,enddate_dd)
				startdate=yyyymmdd
				enddate=yyyymmdd

				headline='headline_end ifile={}'.format(ifile)
				text='text_end ifile={} dttm={} ofile={}'.format(ifile, dttm, ofile )
				tag='tage_end ifile={}'.format( ifile )
				media='/imgs/btn/koeye.png'
				tn=ht_pathfile
				media=ht_pathfile
#				media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#				thumbnail='/imgs/btn/tn/tn_koeye.png'
				thumbnail='/tn/tn_{}'.format( tn )
				credit='credit_end ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				caption='caption ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				tn=pathfile.replace('/IMG', '/tn/tn_IMG').replace('JPG','png')

				htmline += '<a href="/{}" class="thumb_link">'.format(pathfile)
				htmline += '	<span class="selected"></span>\n'
				htmline += '	<img src="/{}" height=100 title="{}" alt="{}" class="thumb" />\n'.format(tn, file, file)
				htmline += '\n'

				print '{} {} MSG_2400 j={} htmline={}'.format(j,progid,dttm,htmline)


	
				psvline += 'id_{}|'.format(j)
				psvline += 'status_{}|'.format(j)
				psvline += 'dttm_{}|'.format(dttm)
				psvline += 'code_{}|'.format(j)
				psvline += 'grp_{}|'.format(j)
				psvline += 'idx_{}|'.format(j)
				psvline += 'tlid_{}|'.format(j)
				psvline += 'title_{}|'.format(j)
				psvline += 'begdt_{}|'.format(startdate)
				psvline += 'enddt_{}|'.format(enddate)
				psvline += 'headline_{}|'.format(ifile)
				psvline += 'tag_{}|'.format(j)
				psvline += 'media_{}|'.format(ifile)
				psvline += 'tn_{}|'.format(ifile)
				psvline += 'credit_{}|'.format(j)
				psvline += 'eras_{}|'.format(j)
				psvline += 'e_begdt_{}|'.format(j)
				psvline += 'e_enddt{}|'.format(j)
				psvline += 'e_head{}|'.format(j)
				psvline += 'etag_{}|'.format(j)
				psvline += 'charts_{}|'.format(j)
				psvline += 'c_begdt{}|'.format(j)
				psvline += 'c_enddt{}|'.format(j)
				psvline += 'c_head{}|'.format(headline)
				psvline += 'c_val{}|'.format(j)
				psvline += 'filddt{}|'.format(startdate)
				psvline += 'exifdt_{}|'.format(j)
				psvline += 'tempdt_{}|'.format(j)
				psvline += 'desc_{}|'.format(j)
				psvline += '\n'


	psvhdr  = ''
	psvhdr += 'id|status|dttm|code|grp|idx|tlid|'
	psvhdr += 'title|begdt|enddt|headline|tag|'
	psvhdr += 'media|tn|credit|'
	psvhdr += 'eras|e_begdt}e_enddt}e_head}e_tag|'
	psvhdr += 'charts|c_begdt|c_enddt|c_head|c_val|'
	psvhdr += 'filedt|exifdt|tempdt|desc|b64'
	psvhdr += '\n'
	psvdata = ''
	psvdata += psvhdr
	psvdata += psvline

	ofile_psv=ofile
	out_file_psv=open( ofile, "wb" )
	out_file_psv.write(htmline)
	out_file_psv.close()

#	csvdata=psvdata.replace('|', ',')
#	ofile_csv=ofile.replace('.psv', '.csv')

#	out_file_csv=open( ofile_csv, "wb" )
#	out_file_csv.write(csvdata)
#	out_file_csv.close()



	dttm=ko_dttm()
	print '{} {} MSG_END: do_tlwl ifile={} ofile={}'.format(progid, dttm, ifile, ofile )
	return(psvdata)











def day2num(day):
	return{
	        'Sun' : 1,
	        'Mon' : 2,
	        'Tue' : 3,
	        'Wed' : 4,
	        'Thr' : 5,
	        'Fri' : 6,
	        'Sat' : 7
		}[day]

def mth2num(mth):
	return{
	        'Jan' : 1,
	        'Feb' : 2,
	        'Mar' : 3,
	        'Apr' : 4,
	        'May' : 5,
	        'Jun' : 6,
	        'Jul' : 7,
	        'Aug' : 8,
	        'Sep' : 9, 
	        'Oct' : 10,
	        'Nov' : 11,
	        'Dec' : 12
		}[mth]
def ko_do_tl(a0,a1,a2,a3):
	print '{} {} ko_do_tlpsv: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)

def ko_do_tlwl(a0,a1,a2,a3):
	dttm=ko_dttm()
	print '{} {} ko_do_tlwl: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	json_beg=''
	dttm=ko_dttm()

	ifile=a2
	ofile=a3
	if ofile == '': 
		ofile=ifile.replace('.wl', '.json')
	print '{} {} ko_do_tlwl MSG_2300 ifile={} ofile={}'.format(progid, dttm, ifile,ofile)

	if os.path.isfile( ofile ):
		print '{} {} ko_do_tl ERR_FOUND: ofile={}'.format(progid,dttm, ofile )
#		exit()
	else:
		print '{} {} ko_do_tl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile )

	if not os.path.isfile( ifile ):
		print '{} {} ko_do_tl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile )
		exit()
	else:
		print '{} {} ko_do_tl MSG_FOUND: ifile={}'.format(progid,dttm, ifile )

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	

#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print '{} {} ko_do_tl MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size )
	print '{} {} ko_do_tl MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size )
	
# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	psvline=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		
		with open(wlfile) as f:
			j=0
			for line in f:
				j += 1

#				m = re.match( '.psv', wlfile )
#				if m:
#				print 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile ))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					pathfile=line.split('|')[13]
					print '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)
				else:
					pathfile=line.split()[8]
					print '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext )
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print "BUGS_141 i_pathfile={}".format(i_pathfile)
				print "BUGS_142 ht_pathfile={}".format(ht_pathfile)
				if ext=='.mp4' : print "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4)
				if ext=='.jpg' : print "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg)
#				if ext=='.jpg' : print "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1)
#				if ext=='.jpg' : print "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs)
				if ext=='.gif' : print "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif)
				if ext=='.png' : print "BUGS_146 o_pathfile_png={}".format(o_pathfile_png)


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


				startdate_yyyy='2019'
				startdate_mm='01'
				startdate_dd='01'
				startdate='{},{},{}'.format(startdate_yyyy,startdate_mm,startdate_dd)
				enddate_yyyy='2019'
				enddate_mm='01'
				enddate_dd='31'
				enddate='{},{},{}'.format(enddate_yyyy,enddate_mm,enddate_dd)
				startdate=yyyymmdd
				enddate=yyyymmdd

				headline='headline_end ifile={}'.format(ifile)
				text='text_end ifile={} dttm={} ofile={}'.format(ifile, dttm, ofile )
				tag='tage_end ifile={}'.format( ifile )
				media='/imgs/btn/koeye.png'
				tn=ht_pathfile
				media=ht_pathfile
#				media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#				thumbnail='/imgs/btn/tn/tn_koeye.png'
				thumbnail='{}'.format( tn )
				credit='credit_end ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )
				caption='caption ht_pathfile={} dttm={}'.format( ht_pathfile, dttm )

	
				psvline += 'id_{}|'.format(j)
				psvline += 'status_{}|'.format(j)
				psvline += 'dttm_{}|'.format(dttm)
				psvline += 'code_{}|'.format(j)
				psvline += 'grp_{}|'.format(j)
				psvline += 'idx_{}|'.format(j)
				psvline += 'tlid_{}|'.format(j)
				psvline += 'title_{}|'.format(j)
				psvline += 'begdt_{}|'.format(startdate)
				psvline += 'enddt_{}|'.format(enddate)
				psvline += 'headline_{}|'.format(ifile)
				psvline += 'tag_{}|'.format(j)
				psvline += 'media_{}|'.format(ifile)
				psvline += 'tn_{}|'.format(ifile)
				psvline += 'credit_{}|'.format(j)
				psvline += 'eras_{}|'.format(j)
				psvline += 'e_begdt_{}|'.format(j)
				psvline += 'e_enddt{}|'.format(j)
				psvline += 'e_head{}|'.format(j)
				psvline += 'etag_{}|'.format(j)
				psvline += 'charts_{}|'.format(j)
				psvline += 'c_begdt{}|'.format(j)
				psvline += 'c_enddt{}|'.format(j)
				psvline += 'c_head{}|'.format(headline)
				psvline += 'c_val{}|'.format(j)
				psvline += 'filddt{}|'.format(startdate)
				psvline += 'exifdt_{}|'.format(j)
				psvline += 'tempdt_{}|'.format(j)
				psvline += 'desc_{}|'.format(j)
				psvline += '\n'


	psvhdr  = ''
	psvhdr += 'id|status|dttm|code|grp|idx|tlid|'
	psvhdr += 'title|begdt|enddt|headline|tag|'
	psvhdr += 'media|tn|credit|'
	psvhdr += 'eras|e_begdt}e_enddt}e_head}e_tag|'
	psvhdr += 'charts|c_begdt|c_enddt|c_head|c_val|'
	psvhdr += 'filedt|exifdt|tempdt|desc|b64'
	psvhdr += '\n'
	psvdata = ''
	psvdata += psvhdr
	psvdata += psvline

	ofile_psv=ofile
	out_file_psv=open( ofile, "wb" )
	out_file_psv.write(psvdata)
	out_file_psv.close()

	csvdata=psvdata.replace('|', ',')
	ofile_csv=ofile.replace('.psv', '.csv')

	out_file_csv=open( ofile_csv, "wb" )
	out_file_csv.write(csvdata)
	out_file_csv.close()



	dttm=ko_dttm()
	print '{} {} MSG_END: do_tlwl ifile={} ofile={}'.format(progid, dttm, ifile, ofile )
	return(psvdata)


def ko_do_tlpsv(a0,a1,a2,a3):
	dttm=ko_dttm()
	print '{} {} ko_do_tlpsv: a0={} a1={} a2={} a3={}'.format(progid,dttm, a0,a1,a2,a3)
	json_beg=''
	dttm=ko_dttm()
	exit()

	ifile=a2
	ofile=a3
	if re.search( '.psv' ):
		delimeter='|'
		if ofile == '': ofile=ifile.replace('.psv', '.json')
	else:
		delimeter=','
		if ofile == '': ofile=ifile.replace('.csv', '.json')

	if os.path.isfile( ofile ):
		print '{} {} ko_do_tl ERR_FOUND: ofile={}'.format(progid,dttm, ofile )
		exit()
	else:
		print '{} {} ko_do_tl MSG_NOTFOUND: ofile={}'.format(progid,dttm, ofile )

	if not os.path.isfile( ifile ):
		print '{} {} ko_do_tl ERR_NOTFOUND: ifile={}'.format(progid,dttm, ifile )
		exit()
	else:
		print '{} {} ko_do_tl MSG_FOUND: ifile={}'.format(progid,dttm, ifile )

#	if not os.path.isdir( tnpath ):
#		os.system( syscmd )
	

#import os.path, time
#	print("last modified: %s" % time.ctime(os.path.getmtime(ifile)))
#	print("created: %s" % time.ctime(os.path.getctime(ifile)))

# import os, time
	(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(ifile)
#	print("last modified: %s" % time.ctime(mtime))
#	print("atime: %s" % time.ctime(atime))
	print("created: %s" % time.ctime(ctime))

	(day, mth, dd, hh_mm_ss, yyyy ) = time.ctime(ctime).split()
	hhmmss=hh_mm_ss.replace( ':', ',' )
	mm=mth2num(mth)
	yyyymmdd='{},{},{}'.format( yyyy,mm,dd )
#	print '{} {} ko_do_tlpsv MSG_DATE: ifile={} day={}, mth={}, dd={},hh_mm_ss={}, yyyy={} size={}'.format(progid,dttm, ifile, day,mth,dd,hh_mm_ss,yyyy, size )
	print '{} {} ko_do_tlpsv MSG_DATE: ifile={} yyyymmdd={}, hhmmss={}, size={}'.format(progid,dttm, ifile, yyyymmdd,hhmmss, size )
	exit()
	


# json_beg
	headline='<h1>ofile={} main {} timeline headline: ofile={}</h1>'.format(ifile, dttm, ofile)
# bugs	headline='<a href="{}" target=_blank><img src="{}" border=0></a>'.format( ifile, ifile )
	type='default'
	text='header_text yyyymmdd={} day={} size={}'.format( yyyymmdd, day, size )
	startdate_beg='1900,01,01'
	startdate_beg=yyyymmdd

	json_beg+='{"timeline": { \n'
	json_beg+='"headline":"{}",\n'.format(headline)
	json_beg+='"type":"{}",\n'.format(type)
	json_beg+='"text":"{}",\n'.format(text)
	json_beg+='"startDate":"{}",\n'.format(startdate_beg)
	json_beg+='"date": [\n'

#	print 'json_beg={}\n'.format(json_beg)





# json_defail
	document_root_ko0="/home2/kozerus/public_html"
	document_root_ko2="/home1/kotwous/public_html"
	document_root_ka10="/ht"
	document_root_ka11="/Volumes/ka1tbr1/ht"
	document_root_ka12="/Volumes/ka1tbr2/ht"
	document_root=document_root_ka12



	json_detail=''
	wlfile=a2
	if( os.path.exists( wlfile )):
		ifmt='wl'
		if re.search( '.psv$', wlfile ): ifmt='psv'
		
		with open(wlfile) as f:
			j=0
			ifmt='psv'
			for line in f:
				j += 1


#				m = re.match( '.psv', wlfile )
#				if m:
#				print 'BUGS_RE re.search={}'.format( re.search( '.psv$', wlfile ))
#				if re.search( '.psv$', wlfile ):

				if ifmt == 'psv':
					id = line.split('|')[0]
					status = line.split('|')[1]
					dttm = line.split('|')[2]
					code = line.split('|')[3]
					grp = line.split('|')[4]
					idx = line.split('|')[5]
					tlid = line.split('|')[6]
					title = line.split('|')[7]
					begdt = line.split('|')[8]
					enddt = line.split('|')[9]
					headline = line.split('|')[10]
					text = line.split('|')[11]
					tag = line.split('|')[12]
					media = line.split('|')[13]
					tn = line.split('|')[14]
					credit = line.split('|')[15]
					caption = line.split('|')[16]
					eras = line.split('|')[17]
					e_begdt = line.split('|')[18]
					e_enddt = line.split('|')[19]
					e_head = line.split('|')[20]
					e_tag = line.split('|')[21]
					charts = line.split('|')[22]
					c_begdt = line.split('|')[23]
					c_enddt = line.split('|')[24]
					c_head = line.split('|')[25]
					c_val = line.split('|')[26]
					filedt = line.split('|')[27]
					exifdt = line.split('|')[28]
					tempdt = line.split('|')[29]
					desc = line.split('|')[30]
					b64 = line.split('|')[31]
					startdate=begdt
					enddate=enddt
#					media='<a href="{}" target=_blank><img src="{}" alt="{}" border=0></a>'.format( ht_pathfile, ht_pathfile, tn )
#					thumbnail='/imgs/btn/tn/tn_koeye.png'

					pathfile=media
					print '{} {} MSG_PSV: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)

				else:
					pathfile=line.split()[8]
					print '{} {} MSG_WL: wlfile={} pathfile={}'.format( progid,dttm,wlfile, pathfile)


				path=os.path.dirname(pathfile)
				base=os.path.basename(pathfile)
				file=os.path.splitext(base)[0]
				ext=os.path.splitext(base)[1]



				path=path.replace(document_root_ko0,'')
				path=path.replace(document_root_ko2,'')
				path=path.replace(document_root_ka10,'')
				path=path.replace(document_root_ka11,'')
				path=path.replace(document_root_ka12,'')

				print '{} {} do_tl MSG_2500: j={} pathfile={} path={} base={} file={} ext={}'.format( progid, dttm, j, pathfile, path, base, file, ext )
				ht_pathfile='{}{}{}'.format(path,file,ext)	

				o_pathfile_htm=a2.replace(".txt", ".htm")
				divid=a2.replace(".txt","")
				htmdiv='<div id="{}">\n'.format( divid )

# for filename in os.listdir(DIRECTORY):
#    if (filename.endswith(".mp4"): #or .avi, .mpeg, whatever.
#        os.system("ffmpeg -i {0} -f image2 -vf fps=fps=1 output%d.png".format(filename))
#    else:
#        continue

				i_pathfile='{}{}/{}'.format(document_root,path,base)
				i_pathfile_mp4='{}{}/{}'.format(document_root,path,base)
				o_pathfile_jpg='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				i_pathfile_jpg1='{}{}/img/{}_001.jpg'.format(document_root,path,file)
				i_pathfile_jpgs='{}{}/img/{}_*.jpg'.format(document_root,path,file)
				o_pathfile_png='{}{}/tn/tn_{}.png'.format(document_root,path,file)
				o_pathfile_gif='{}{}/tn/tn_{}.gif'.format(document_root,path,file)


				o_pathfile='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_im='{}{}/img/{}_%03d.jpg'.format(document_root,path,file)
				o_pathfile_tn='{}{}/img/{}_%03d.gif'.format(document_root,path,file)

				print "BUGS_141 i_pathfile={}".format(i_pathfile)
				print "BUGS_142 ht_pathfile={}".format(ht_pathfile)
				if ext=='.mp4' : print "BUGS_141 i_pathfile_mp4={}".format(i_pathfile_mp4)
				if ext=='.jpg' : print "BUGS_142 o_pathfile_jpg={}".format(o_pathfile_jpg)
#				if ext=='.jpg' : print "BUGS_144 i_pathfile_jpg1={}".format(i_pathfile_jpg1)
#				if ext=='.jpg' : print "BUGS_145 i_pathfile_jpgs={}".format(i_pathfile_jpgs)
				if ext=='.gif' : print "BUGS_146 o_pathfile_gif={}".format(o_pathfile_gif)
				if ext=='.png' : print "BUGS_146 o_pathfile_png={}".format(o_pathfile_png)


				abs_tn_path='{}{}/tn/'.format(document_root, path)
				tn_path='{}/tn/'.format(path)
				tn_base='tn_{}.gif'.format(file)

				abs_tn_pathfile='{}{}{}'.format( document_root, tn_path, tn_base )
				tn_pathfile='{}{}'.format( tn_path, tn_base )

				abs_im_path='{}{}/img/'.format(document_root,path)
				im_path='{}/img/'.format(path)
				im_base='{}.png'.format(file)
				abs_im_pathfile='{}{}{}'.format( document_root, im_path, im_base )
				im_pathfile='{}{}'.format(  im_path, im_base )


	

				json_detail+='{\n' 
				json_detail+='"startDate":"{}",\n'.format( startdate )
				json_detail+='"endDate":"{}",\n'.format(enddate)
				json_detail+='"headline":"{}",\n'.format(headline)
				json_detail+='"text":"{}",\n'.format(text)
				json_detail+='"tag":"{}",\n'.format(tag)
				json_detail+='"asset": { \n'
				json_detail+='	"media":"{}",\n'.format(media)
				json_detail+='	"thumbnail":"{}",\n'.format(tn)
				json_detail+='	"credit":"{}",\n'.format(credit)
				json_detail+='	"caption":"{}"\n'.format(caption)
				json_detail+='	}},'
#				print 'json_detail={}'.format(json_detail)





# json_end
	startdate_end='2020,12,01'
	enddate_end='2020,12,30'
	headline_end='headline_end'
	text_end='text_end'
	tag_end='tag_end'
	media_end='media_end'
	thumbnail_end='thumbnail_end'
	credit_end='credit_end'
	caption_end='caption_end'
	text_end='text_end'



	startdate_end=yyyymmdd
	enddate_end=yyyymmdd

	json_end=''
	json_end+='{\n'
	json_end+='"startDate":"{}",\n'.format(startdate_end)
	json_end+='"endDate":"{}",\n'.format(enddate_end)
	json_end+='"headline":"{}",\n'.format(enddate_end)
	json_end+='"text":"{}",\n'.format(enddate_end)
	json_end+='"tag":"{}",\n'.format(enddate_end)
	json_end+='"asset": {\n'
	json_end+='	"media":"{}",\n'.format(media_end)
	json_end+='	"thumbnail":"{}",\n'.format(thumbnail_end)
	json_end+='	"credit":"{}",\n'.format(credit_end)
	json_end+='	"caption":"{}" \n'.format(caption_end)
	json_end+='	}}]}}\n'
#	print 'json_end={}'.format(json_end)


	json=''
	json+=json_beg
	json+='\n\n'
	json+=json_detail
	json+='\n\n'
	json+=json_end

#	print 'json={}'.format(json)
	out_file=open( ofile, "wb" )
	out_file.write(json)
	out_file.close()
	dttm=ko_dttm()
	print '{} {} MSG_END: do_tl ofile={}'.format(progid, dttm, ofile )
	return(json)

def htmcss_popover(cssid):
	cssid="ko"
	url="{}.js".format(cssid)
	b64fil = "b64_{}_js.txt".format(cssid)
	b64txt = ""
	
	b64cmd = "base64 {} > b64_{}.txt".format(url,cssid)
#	os.system( b64cmd )
	b64 = open( b64fil, "rb" )
	for line in b64:
		b64txt += line
	b64.close()	
	htmcss_b64 = '<script id="script_{}" src="data:/text/plain;base64,{}"></script>'.format(cssid,b64txt)

	htmcss = ""
	htmcss += '<style id="style_{}" >{}:{}</style>'.format(cssid,cssid,cssid) 
	htmcss += '<!-- <script id="script_{}" src="{}" ></script> -->\n'.format(cssid, url)
	htmcss += htmcss_b64


	return(htmcss)

def main():
	startup()
	commands()


if __name__ == '__main__':
	main()

//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer