Best Python code snippet using slash
GF_extendor.py
Source:GF_extendor.py  
1import os2import re3#Find index number of where to append in DCECExt.txt4def findDCECExtLoc(string) :	5	f = open("DCECExt_o.gf", "r")6	count = 07	s_index = 08	copy = ""9	for line in f :10		copy +=line11		ind = line.find(string)12		if ind >= 0 :13			s_index = count + ind + len(string)14		count+=len(line)15	return (s_index, copy)16def findDCECExtLoc2(string, use_copy) :	17	f = use_copy18	ind = f.find(string)19	return (ind, use_copy)20#find index number of where to append in EngExt.txt21def findEngExtLoc(string) :22	f = open("EngExt_o.gf", "r")23	count = 024	s_index = 025	copy = ""26	for line in f :27		copy +=line28		ind = line.find(string)29		if ind >= 0 :30			s_index = count + ind + len(string)31		count+=len(line)32	return (s_index, copy)33def findEngExtLoc2(string, use_copy) :34	f = use_copy35	ind = f.find(string)36	return (ind,use_copy)37def agentAppend(f) :38	agentDCECExtAppend(f)39	agentEngExtAppend(f)40def agentDCECExtAppend(f) :41	tup = findDCECExtLoc("jack, cogito,")42	copy = str(tup[1])43	append_line = ""44	append_line=f45	append_line = append_line.replace(" m,", ",")46	append_line = append_line.replace(" f,", ",")47	new_copy = ""48	for i in range(0,tup[0]) : 49		new_copy+=copy[i]50	new_copy+= " "51	new_copy+=append_line52	new_copy+= " "53	for i in range (tup[0]+1, len(copy)) :54		new_copy+=copy[i]55	f2 = open("DCECExt.gf", "w")56	f2.write(new_copy)57	f2.close()58def agentEngExtAppend(f) :59	tup = findEngExtLoc('name = (mkNP (mkPN "Jack")) ; gender= masculine} ;')60	copy = tup[1]61	append_line = ""62	append_line=f63	new_copy = ""64	for i in range(0,tup[0]) :65		new_copy+=copy[i]66	temp = ""67	pairs = []68	for i in range(0,len(append_line)) :69		if append_line[i] != "," :70			temp+=append_line[i]71		else:72			pairs.append(temp)73			temp = ""74	append_list = []75	for p in pairs :76		p=p.lstrip(" ")77		if p[len(p)-1] == "m" :78			p = p[0:len(p)-2]79			s = "   " + p + '  = {descr = (mkNP (mkN human (mkN "named ' + p + '"))); name = (mkNP (mkPN "' + p + '")) ; gender= masculine} ;'80			append_list.append(s)81		else :82			p = p[0:len(p)-2]83			s = "   " + p + '  = {descr = (mkNP (mkN human (mkN "named ' + p + '"))); name = (mkNP (mkPN "' + p + '")) ; gender= feminine} ;'84			append_list.append(s)85	for i in append_list :86		new_copy+=i87	for i in range(tup[0]+1, len(copy)) :88		new_copy+=copy[i]89	f2 = open("EngExt.gf", "w")90	f2.write(new_copy)91	f2.close()92def unaryActionTypeAppend(f) :93	uActionTypeDCECExtAppend(f)94	uActionTypeEngExtAppend(f)95def uActionTypeDCECExtAppend(f) :96	uActionTypeDCECExtAppend1(f)97def uActionTypeEngExtAppend(f) :98	uActionTypeEngExtAppend1(f)99	#uActionTypeEngExtAppend2(f)100def uActionTypeDCECExtAppend1(f) :101	tup = findDCECExtLoc("laugh, sleep,")102	copy = str(tup[1])103	append_line=f104	new_copy = ""105	for i in range(0,tup[0]) : 106		new_copy+=copy[i]107	verb_set = []108	v_temp = ""109	for i in append_line :110		if i == ',' :111			verb_set.append(str(v_temp).lstrip(" "))112			v_temp = ""113		else:114			v_temp+=i115	append_set = []116	for v in verb_set :117		a_temp=""118		for i in v :119			if i == " " :120				append_set.append(a_temp)121				break122			else :123				a_temp+=i124	if len(append_set) > 0 :125		stich = ""126		for a in append_set :127			stich += a128			stich +=", "129		stich =stich[0:len(stich)-1]130	else :131		stich = ""132		for v in verb_set :133			stich += v134			stich +=", "135		stich = stich[0:len(stich)-1]136	new_copy+= " "137	new_copy+=stich138	new_copy+= " "139	for i in range (tup[0]+1, len(copy)) :140		new_copy+=copy[i]141	#f2 = open("DCECExt.gf", "w")142	#f2.write(new_copy)143	#f2.close()144	uActionTypeDCECExtAppend2(f, new_copy)145def uActionTypeDCECExtAppend2(f, use_copy) :146	tup = findDCECExtLoc2(" laugh_f, run_f, sleep_f,",use_copy)147	copy = use_copy148	append_line=f149	new_copy = ""150	for i in range(0,tup[0]) : 151		new_copy+=copy[i]152	verb_set = []153	v_temp = ""154	for i in append_line :155		if i == ',' :156			v_temp+="_f"157			verb_set.append(str(v_temp).lstrip(" "))158			v_temp = ""159		else:160			v_temp+=i161	append_set = []		#append set is for irrelgular verbs162	for v in verb_set :163		a_temp=""164		for i in v :165			if i == " " :166				append_set.append(a_temp)167				break168			else :169				a_temp+=i170	if len(append_set) > 0 :171		stich = ""172		for a in append_set :173			stich += (a + "_f")174			stich +=", "175		stich =stich[0:len(stich)-1]176	else :177		stich = ""178		for v in verb_set :179			print "v: "+ v180			stich += v181			stich +=", "182		stich = stich[0:len(stich)-1]183	new_copy+= " "184	new_copy+=stich185	new_copy+= " "186	for i in range (tup[0]+1, len(copy)) :187		new_copy+=copy[i]188	f2 = open("DCECExt.gf", "w")189	f2.write(new_copy)190	f2.close()	191def uActionTypeEngExtAppend1(f) :192	tup = findEngExtLoc('sleep = (unaryAction (mkV "sleep" "slept" "slept"));')193	copy = tup[1]194	append_line=f195	new_copy = ""196	for i in range(0,tup[0]) :197		new_copy+=copy[i]198	verb_set = []199	v_temp = ""200	for i in append_line :201		if i == ',' :202			verb_set.append(str(v_temp).lstrip(" "))203			v_temp = ""204		else:205			v_temp+=i206	verb_set_list = []207	for v in verb_set :208		list_v = v.split()209		verb_set_list.append(tuple(list_v))210	append_list = []211	212	if len(verb_set_list[0]) > 1 :213		for i in verb_set_list :214			s = "   " + i[0] + '  = (unaryAction (mkV "' + i[0] +'" "' + i[1] + '" "' + i[2] + '"));'215			append_list.append(s)216	else :217		for i in verb_set :218			s = "   "  + i + ' = (unaryAction (mkV "' + i + '"));'219			append_list.append(s)220	221	for a in append_list :222		new_copy+=a223	for i in range(tup[0]+1, len(copy)) :224		new_copy+=copy[i]225	uActionTypeEngExtAppend2(f, new_copy)226def uActionTypeEngExtAppend2(f, use_copy) :227	tup = findEngExtLoc2(' sleep_f agent= (activityFluent agent (mkV "sleep" "slept" "slept"));', use_copy)228	copy = use_copy229	append_line=f230	new_copy = ""231	for i in range(0,tup[0]) :232		new_copy+=copy[i]233	verb_set = []234	v_temp = ""235	for i in append_line :236		if i == ',' :237			verb_set.append(str(v_temp).lstrip(" "))238			v_temp = ""239		else:240			v_temp+=i241	verb_set_list = []242	for v in verb_set :243		list_v = v.split()244		verb_set_list.append(tuple(list_v))245	append_list = []246	247	if len(verb_set_list[0]) > 1 :248		for i in verb_set_list :249			i_tmp = i[0] + "_f"250			s = "   " + i_tmp + ' agent= (activityFluent agent (mkV "' + i[0] +'" "' + i[1] + '" "' + i[2] + '"));'251			append_list.append(s)252	else :253		for i in verb_set :254			i += "_f"255			s = "   "  + i + ' agent= (activityFluent agent (mkV "' + i[0:len(i)-2] + '"));'256			append_list.append(s)257	258	for a in append_list :259		new_copy+=a260	for i in range(tup[0]+1, len(copy)) :261		new_copy+=copy[i]262	f2 = open("EngExt.gf", "w")263	f2.write(new_copy)264	f2.close()265def binaryActionAgentAppend(f) :266	bActionAgentDCECExtAppend(f)267	bActionAgentEngExtAppend(f)268def bActionAgentDCECExtAppend(f) :269	tup = findDCECExtLoc("hurt, guard,")270	copy = str(tup[1])271	append_line=f272	new_copy = ""273	for i in range(0,tup[0]) : 274		new_copy+=copy[i]275	verb_set = []276	v_temp = ""277	for i in append_line :278		if i == ',' :279			verb_set.append(str(v_temp).lstrip(" "))280			v_temp = ""281		else:282			v_temp+=i283	append_set = []284	for v in verb_set :285		a_temp=""286		for i in v :287			if i == " " :288				append_set.append(a_temp)289				break290			else :291				a_temp+=i292	if len(append_set) > 0 :293		stich = ""294		for a in append_set :295			stich += a296			stich +=", "297		stich =stich[0:len(stich)-1]298	else :299		stich = ""300		for v in verb_set :301			stich += v302			stich +=", "303		stich = stich[0:len(stich)-1]304	new_copy+= " "305	new_copy+=stich306	new_copy+= " "307	for i in range (tup[0]+1, len(copy)) :308		new_copy+=copy[i]309	f2 = open("DCECExt.gf", "w")310	f2.write(new_copy)311	f2.close()312def bActionAgentEngExtAppend(f) :313	tup = findEngExtLoc('guard a= (binaryAction (mkV "guard") a);')314	copy = tup[1]315	append_line=f316	new_copy = ""317	for i in range(0,tup[0]) :318		new_copy+=copy[i]319	verb_set = []320	v_temp = ""321	for i in append_line :322		if i == ',' :323			verb_set.append(str(v_temp).lstrip(" "))324			v_temp = ""325		else:326			v_temp+=i327	verb_set_list = []328	for v in verb_set :329		list_v = v.split()330		verb_set_list.append(tuple(list_v))331	append_list = []332	if len(verb_set_list[0]) > 1 :333		for i in verb_set_list :334			s = "   " + i[0] + ' a= (binaryAction (mkV "' + i[0] +'" "' + i[1] + '" "' + i[2] + '") a);'335			append_list.append(s)336	else :337		for i in verb_set :338			s = "   "  + i + ' a= (binaryAction (mkV "' + i + '") a);'339			append_list.append(s)340	for a in append_list :341		new_copy+=a342	for i in range(tup[0]+1, len(copy)) :343		new_copy+=copy[i]344	f2 = open("EngExt.gf", "w")345	f2.write(new_copy)346	f2.close()347def binaryActionObjectAppend(f) :348	bActionObjectDCECExtAppend(f)349	bActionObjectEngExtAppend(f)350def bActionObjectDCECExtAppend(f) :351	tup = findDCECExtLoc("eat2,")352	copy = str(tup[1])353	append_line=f354	new_copy = ""355	for i in range(0,tup[0]) : 356		new_copy+=copy[i]357	verb_set = []358	v_temp = ""359	for i in append_line :360		if i == ',' :361			v_temp+="2"362			verb_set.append(str(v_temp).lstrip(" "))363			v_temp = ""364		else:365			v_temp+=i366	append_set = []367	for v in verb_set :368		a_temp=""369		for i in v :370			if i == " " :371				append_set.append(a_temp)372				break373			else :374				a_temp+=i375	if len(append_set) > 0 :376		stich = ""377		for a in append_set :378			stich += a379			stich +=", "380		stich =stich[0:len(stich)-1]381	else :382		stich = ""383		for v in verb_set :384			stich += v385			stich +=", "386		stich = stich[0:len(stich)-1]387	new_copy+= " "388	new_copy+=stich389	new_copy+= " "390	for i in range (tup[0], len(copy)) :391		new_copy+=copy[i]392	f2 = open("DCECExt.gf", "w")393	f2.write(new_copy)394	f2.close()395def bActionObjectEngExtAppend(f) :396	tup = findEngExtLoc('eat2 obj = (binaryAction (mkV "eat" "ate" "eaten") obj);')397	copy = tup[1]398	append_line=f399	new_copy = ""400	for i in range(0,tup[0]) :401		new_copy+=copy[i]402	verb_set = []403	v_temp = ""404	for i in append_line :405		if i == ',' :406			verb_set.append(str(v_temp).lstrip(" "))407			v_temp = ""408		else:409			v_temp+=i410	verb_set_list = []411	for v in verb_set :412		list_v = v.split()413		verb_set_list.append(tuple(list_v))414	append_list = []415	if len(verb_set_list[0]) > 1 :416		for i in verb_set_list :417			s = "   " + i[0] + '2 obj = (binaryAction (mkV "' + i[0] +'" "' + i[1] + '" "' + i[2] + '") obj);'418			append_list.append(s)419	else :420		for i in verb_set :421			s = "   "  + i + '2 obj = (binaryAction (mkV "' + i + '") obj);'422			append_list.append(s)423	for a in append_list :424		new_copy+=a425	for i in range(tup[0]+1, len(copy)) :426		new_copy+=copy[i]427	f2 = open("EngExt.gf", "w")428	f2.write(new_copy)429	f2.close()430def nullaryFluentAppend(f) :431	nFluentDCECExtAppend(f)432	nFluentEngExtAppend(f)433def nFluentDCECExtAppend(f) :434	tup = findDCECExtLoc("raining,")435	copy = str(tup[1])436	append_line=f437	new_copy = ""438	for i in range(0,tup[0]) : 439		new_copy+=copy[i]440	new_copy+= " "441	new_copy+=append_line442	new_copy+= " "443	for i in range (tup[0]+1, len(copy)) :444		new_copy+=copy[i]445	f2 = open("DCECExt.gf", "w")446	f2.write(new_copy)447	f2.close()448def nFluentEngExtAppend(f) :449	tup = findEngExtLoc('snowing = (nullaryFluent (mkV "snow"));')450	copy = tup[1]451	append_line=f452	new_copy = ""453	for i in range(0,tup[0]) :454		new_copy+=copy[i]455	temp = ""456	words = []457	for i in range(0,len(append_line)) :458		if append_line[i] != "," :459			temp+=append_line[i]460		else:461			words.append(temp)462			temp = ""463	append_list = []464	for w in words :465		w=w.lstrip(" ")466		s = "    " + w + ' = (nullaryFluent (mkV "'+ w[0:len(w)-3] +'"));'467		append_list.append(s)468	for i in append_list :469		new_copy+=i470	for i in range(tup[0]+1, len(copy)) :471		new_copy+=copy[i]472	f2 = open("EngExt.gf", "w")473	f2.write(new_copy)474	f2.close()475def unaryFluentAppend(f) :476	uFluentDCECExtAppend(f)477	uFluentEngExtAppend(f)478def uFluentDCECExtAppend(f) :479	tup = findDCECExtLoc("hungry,tired,")480	copy = str(tup[1])481	append_line=f482	new_copy = ""483	for i in range(0,tup[0]) : 484		new_copy+=copy[i]485	new_copy+= " "486	new_copy+=append_line487	new_copy+= " "488	for i in range (tup[0]+1, len(copy)) :489		new_copy+=copy[i]490	f2 = open("DCECExt.gf", "w")491	f2.write(new_copy)492	f2.close()493def uFluentEngExtAppend(f) :494	tup = findEngExtLoc('tired agent = (unaryFluent agent  (mkAP (mkA "tired"))) ;')495	copy = tup[1]496	append_line=f497	new_copy = ""498	for i in range(0,tup[0]) :499		new_copy+=copy[i]500	temp = ""501	words = []502	for i in range(0,len(append_line)) :503		if append_line[i] != "," :504			temp+=append_line[i]505		else:506			words.append(temp)507			temp = ""508	append_list = []509	for w in words :510		w=w.lstrip(" ")511		s = "    " + w + ' agent = (unaryFluent agent  (mkAP (mkA "'+ w + '"))) ;' 512		append_list.append(s)513	for i in append_list :514		new_copy+=i515	for i in range(tup[0]+1, len(copy)) :516		new_copy+=copy[i]517	f2 = open("EngExt.gf", "w")518	f2.write(new_copy)519	f2.close()520def directObjAppend(f) :521	directObjDCECExtAppend(f)522	directObjEngExtAppend(f)523def directObjDCECExtAppend(f) :524	tup = findDCECExtLoc("apple,")525	copy = str(tup[1])526	append_line=f527	new_copy = ""528	for i in range(0,tup[0]) : 529		new_copy+=copy[i]530	new_copy+= " "531	new_copy+=append_line532	new_copy+= " "533	for i in range (tup[0], len(copy)) :534		new_copy+=copy[i]535	f2 = open("DCECExt.gf", "w")536	f2.write(new_copy)537	f2.close()538def directObjEngExtAppend(f) :539	tup = findEngExtLoc('apple = {name = (mkN "apple"); indef = (mkN "an apple")};')540	copy = tup[1]541	append_line=f542	new_copy = ""543	for i in range(0,tup[0]) :544		new_copy+=copy[i]545	temp = ""546	words = []547	for i in range(0,len(append_line)) :548		if append_line[i] != "," :549			temp+=append_line[i]550		else:551			words.append(temp)552			temp = ""553	append_list = []554	for w in words :555		w=w.lstrip(" ")556		s = "    " + w + ' = {name = (mkN "'+ w +'"); indef = (mkN "a '+ w +'")};' 557		append_list.append(s)558	for i in append_list :559		new_copy+=i560	for i in range(tup[0]+1, len(copy)) :561		new_copy+=copy[i]562	print new_copy563	f2 = open("EngExt.gf", "w")564	f2.write(new_copy)565	f2.close()566#Stub function to append correct type of word567def stubAppend(choice,f):568	temp =""569	for line in f:570		temp = line571	if choice == 1:572		agentAppend(line)573	elif choice == 2:574		unaryActionTypeAppend(line)575	elif choice == 3:576		binaryActionAgentAppend(line)577	elif choice == 4:578		binaryActionObjectAppend(line)579	elif choice == 5:580		nullaryFluentAppend(line)581	elif choice == 6:582		unaryFluentAppend(line)583	else :584		directObjAppend(line)585if not os.path.isfile("./DCECExt_o.gf") :586	print "DCECExt_o.gf not found, terminating"587	exit(1)588if not os.path.isfile("./EngExt_o.gf") :589	print "EngExt_o.gf not found, terminating"590	exit(1)591if os.path.isfile("./input.txt") :592	f = open("input.txt", "r")593	print "Enter"594	print "1 for agent"595	print "2 for unary actiontype"596	print "3 for binary actiontype for agents (transitive verbs where direct object is another agent)"597	print "4 for binary actiontype for objects (any transitive verb)"598	print "5 for nullary fluent"599	print "6 for unary fluent"600	print "7 for direct objects"601	choice = int(input())602	stubAppend(choice, f)603	f.close()604else:...action_buildiso.py
Source:action_buildiso.py  
1"""2Builds non-live bootable CD's that have PXE-equivalent behavior3for all cobbler profiles currently in memory.4Copyright 2006-2008, Red Hat, Inc5Michael DeHaan <mdehaan@redhat.com>6This program is free software; you can redistribute it and/or modify7it under the terms of the GNU General Public License as published by8the Free Software Foundation; either version 2 of the License, or9(at your option) any later version.10This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the13GNU General Public License for more details.14You should have received a copy of the GNU General Public License15along with this program; if not, write to the Free Software16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA1702110-1301  USA18"""19import os20import os.path21import shutil22import sub_process23import sys24import traceback25import shutil26import sub_process27import utils28from cexceptions import *29from utils import _30# FIXME: lots of overlap with pxegen.py, should consolidate31# FIXME: disable timeouts and remove local boot for this?32HEADER = """33DEFAULT menu34PROMPT 035MENU TITLE Cobbler | http://cobbler.et.redhat.com36TIMEOUT 20037TOTALTIMEOUT 600038ONTIMEOUT local39LABEL local40        MENU LABEL (local)41        MENU DEFAULT42        KERNEL chain.c3243        APPEND hd0 044"""45class BuildIso:46    """47    Handles conversion of internal state to the tftpboot tree layout48    """49    def __init__(self,config,verbose=False):50        """51        Constructor52        """53        self.verbose     = verbose54        self.config      = config55        self.api         = config.api56        self.distros     = config.distros()57        self.profiles    = config.profiles()58        self.systems     = config.systems()59        self.distmap     = {}60        self.distctr     = 061    def make_shorter(self,distname):62        if self.distmap.has_key(distname):63            return self.distmap[distname]64        else:65            self.distctr = self.distctr + 166            self.distmap[distname] = str(self.distctr)67            return str(self.distctr)68    def run(self,iso=None,tempdir=None,profiles=None,systems=None):69        # if iso is none, create it in . as "kickstart.iso"70        if iso is None:71            iso = "kickstart.iso"72        if tempdir is None:73            tempdir = os.path.join(os.getcwd(), "buildiso")74        print _("- using/creating tempdir: %s") % tempdir 75        if not os.path.exists(tempdir):76            os.makedirs(tempdir)77        else:78            shutil.rmtree(tempdir)79            os.makedirs(tempdir)80        # if base of tempdir does not exist, fail81        # create all profiles unless filtered by "profiles"82        imagesdir = os.path.join(tempdir, "images")83        isolinuxdir = os.path.join(tempdir, "isolinux")       84        print _("- building tree for isolinux")85        if not os.path.exists(imagesdir):86            os.makedirs(imagesdir)87        if not os.path.exists(isolinuxdir):88            os.makedirs(isolinuxdir)89        print _("- copying miscellaneous files")90        isolinuxbin = "/usr/lib/syslinux/isolinux.bin"91        menu = "/var/lib/cobbler/menu.c32"92        chain = "/usr/lib/syslinux/chain.c32"93        files = [ isolinuxbin, menu, chain ]94        for f in files:95            if not os.path.exists(f):96               raise CX(_("Required file not found: %s") % f)97            else:98               utils.copyfile(f, os.path.join(isolinuxdir, os.path.basename(f)))99 100        print _("- copying kernels and initrds - for profiles")101        # copy all images in included profiles to images dir102        for profile in self.api.profiles():103           use_this = True104           if profiles is not None:105              which_profiles = profiles.split(",")106              if not profile.name in which_profiles:107                 use_this = False108           if use_this:109              dist = profile.get_conceptual_parent()110              if dist.name.lower().find("-xen") != -1:111                  print "skipping Xen distro: %s" % dist.name112                  continue113              distname = self.make_shorter(dist.name)114              # tempdir/isolinux/$distro/vmlinuz, initrd.img115              # FIXME: this will likely crash on non-Linux breeds116              shutil.copyfile(dist.kernel, os.path.join(isolinuxdir, "%s.krn" % distname))117              shutil.copyfile(dist.initrd, os.path.join(isolinuxdir, "%s.img" % distname))118        if systems is not None:119           print _("- copying kernels and initrds - for systems")120           # copy all images in included profiles to images dir121           for system in self.api.systems():122              if system.name in systems:123                 profile = system.get_conceptual_parent()124                 dist = profile.get_conceptual_parent()125                 if dist.name.find("-xen") != -1:126                    continue127                 distname = self.make_shorter(dist.name)128                 # tempdir/isolinux/$distro/vmlinuz, initrd.img129                 # FIXME: this will likely crash on non-Linux breeds130                 shutil.copyfile(dist.kernel, os.path.join(isolinuxdir, "%s.krn" % distname))131                 shutil.copyfile(dist.initrd, os.path.join(isolinuxdir, "%s.img" % distname))132        print _("- generating a isolinux.cfg")133        isolinuxcfg = os.path.join(isolinuxdir, "isolinux.cfg")134        cfg = open(isolinuxcfg, "w+")135        cfg.write(HEADER) # fixme, use template136        137        print _("- generating profile list...")138        for profile in self.api.profiles():139            use_this = True140            if profiles is not None:141                which_profiles = profiles.split(",")142                if not profile.name in which_profiles:143                    use_this = False144            if use_this:145                dist = profile.get_conceptual_parent()146                if dist.name.find("-xen") != -1:147                    continue148                data = utils.blender(self.api, True, profile)149                distname = self.make_shorter(dist.name)150                cfg.write("\n")151                cfg.write("LABEL %s\n" % profile.name)152                cfg.write("  MENU LABEL %s\n" % profile.name)153                cfg.write("  kernel %s.krn\n" % distname)154                if data["kickstart"].startswith("/"):155                    data["kickstart"] = "http://%s/cblr/svc/op/ks/profile/%s" % (156                        data["server"],157                        profile.name158                    )159                append_line = "  append initrd=%s.img" % distname160                append_line = append_line + " ks=%s " % data["kickstart"]161                append_line = append_line + " %s\n" % data["kernel_options"]162                length=len(append_line)163                if length>254:164                   print _("WARNING - append line length is greater than 254 chars: (%s chars)") % length 165                166                cfg.write(append_line)167 168        if systems is not None:169           print _("- generating system list...")170           cfg.write("\nMENU SEPARATOR\n")171           for system in self.api.systems():172               use_this = False173               if systems is not None:174                   which_systems = systems.split(",")175                   if system.name in which_systems:176                       use_this = True177               if use_this:178                   profile = system.get_conceptual_parent()179                   dist = profile.get_conceptual_parent()180                   if dist.name.find("-xen") != -1:181                       continue182                   data = utils.blender(self.api, True, system)183                   distname = self.make_shorter(dist.name)184                   cfg.write("\n")185                   cfg.write("LABEL %s\n" % system.name)186                   cfg.write("  MENU LABEL %s\n" % system.name)187                   cfg.write("  kernel %s.krn\n" % distname)188                   if data["kickstart"].startswith("/"):189                       data["kickstart"] = "http://%s/cblr/svc/op/ks/system/%s" % (190                           data["server"],191                           system.name192                       )193                   append_line = "  append initrd=%s.img" % distname194                   append_line = append_line + " ks=%s" % data["kickstart"]195                   append_line = append_line + " %s" % data["kernel_options"]196                   # add network info to avoid DHCP only if it is available197                   if data.has_key("ip_address_eth0") and data["ip_address_eth0"] != "":198                       append_line = append_line + " ip=%s" % data["ip_address_eth0"]199                   if data.has_key("subnet_eth0") and data["subnet_eth0"] != "":200                       append_line = append_line + " netmask=%s" % data["subnet_eth0"]201                   if data.has_key("gateway_eth0") and data["gateway_eth0"] != "":202                       append_line = append_line + " gateway=%s\n" % data["gateway_eth0"]203                   length=len(append_line)204                   if length > 254:205                      print _("WARNING - append line length is greater than 254 chars: (%s chars)") % length 206                207                   cfg.write(append_line)208        print _("- done writing config")        209        cfg.write("\n")210        cfg.write("MENU END\n")211        cfg.close()212 213        cmd = "mkisofs -o %s -r -b isolinux/isolinux.bin -c isolinux/boot.cat" % iso214        cmd = cmd + "  -no-emul-boot -boot-load-size 4 "215        cmd = cmd + "  -boot-info-table -V Cobbler\ Install -R -J -T %s" % tempdir216        print _("- running: %s") % cmd217        rc = sub_process.call(cmd, shell=True)218        if rc:219            raise CX(_("mkisofs failed"))220        221        print _("ISO build complete")222        print _("You may wish to delete: %s") % tempdir223        print _("The output file is: %s") % iso 224        ...log.py
Source:log.py  
...8version = '0.01'9log_file_name = r'~.log'1011# append log with LF12def append_line(s):13    log_file = open(log_file_name, 'a')14    s = str(datetime.datetime.today()) + ' : ' + s15    log_file.write(s)16    log_file.write("\n")17    log_file.close()1819# test procedure20def __auto_test():21    print ' Auto Testing ....',22    append_line('-------------------------------------')23    append_line('test start ... ')24    append_line('  time baseline')25    time.sleep(1)26    append_line('  delayed 1s after previous line')27    time.sleep(0.5)28    append_line('  delayed 0.5s after previous line')29    append_line('test end.')30    append_line('-------------------------------------')31    raw_input(' Done. Press "Enter" key to exit ...')323334if __name__ == '__main__':
...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
