def launch(db, server, user=''): '''search db for matching entry and launch - this can use any part of the string but mainly use server name or wallixid''' for i in db: #convert record to long string and look for str matches recstr = "" for r in i.split('|'): recstr += r.lower() + "|" if re.search(server, recstr): #Launch and exit if i.split('|')[2] == 'PROD': profile = 'Production' elif i.split('|')[2] == 'DR': profile = 'DR' else: profile = 'Test' if user == '': user = i.split('|')[4] conn = i.split('|')[5] conn = re.sub('_U_', user, conn) if sys.platform == "linux" or sys.platform == "linux2": print "TBA" cmd = ['cat', '/dev/null'] elif sys.platform == "win32": f = open('wallix.rdp', 'w') f.write("full address:s:wallix\n") f.write("username:s:" + conn + "\n") f.write("drivestoredirect:s:*\n") f.close() cmd = ['start', 'wallix.rdp'] if debug: print cmd subprocess.Popen(cmd, shell=True) be.reset_colour() sys.exit()
def launch(db,server,user=''): '''search db for matching entry and launch - this can use any part of the string but mainly use server name or wallixid''' for i in db: #convert record to long string and look for str matches recstr="" for r in i.split('|'): recstr+=r.lower() + "|" if re.search(server,recstr): #Launch and exit #cmd=[ 'terminator','-e ssh',i.split('|')[4] + '@' + i.split('|')[5] + i.split('|')[6],'2>&1 >/dev/null' ] if i.split('|')[2] == 'PROD': profile='Production' elif i.split('|')[2] == 'DR': profile='DR' else: profile='Test' if user == '': user = i.split('|')[4] if sys.platform == "linux" or sys.platform == "linux2": print "TBA" cmd=['/usr/bin/putty', '-load', profile, user + '@' + i.split('|')[5] + '@' + i.split('|')[6] ] elif sys.platform == "win32": cmd=[ 'putty','-load', profile, user + '@' + i.split('|')[5] + '@' + i.split('|')[6] ] if debug: print cmd subprocess.Popen(cmd,shell=True) be.reset_colour() sys.exit()
def launch(db, server, user=''): '''search db for matching entry and launch - this can use any part of the string but mainly use server name or wallixid''' for i in db: #convert record to long string and look for str matches recstr = "" for r in i.split('|'): recstr += r.lower() + "|" if re.search(server, recstr): #Launch and exit if user == '': user = i.split('|')[4] if sys.platform == "linux" or sys.platform == "linux2": print "TBA" cmd = ['cat', '/dev/null'] elif sys.platform == "win32": cmd = [ 'winscp.exe', user + '@' + re.sub(':', '%3A', i.split('|')[5]) + '@' + i.split('|')[6] ] if debug: print cmd subprocess.Popen(cmd, shell=True) be.reset_colour() sys.exit()
def usage(self): be.cprint("green", "\nLords of the Realm II - Game File Editor\n") be.cprint("grey", "----------------------------------------\n\n") be.reset_colour() print " -h | --help Show this help" print " -l | --list <file> Display current values of game file" print " -e | --edit <file> Edit current values of game file" print " -s | --set <file> Update game file with defaults"
def usage(self): '''Usage screen''' be.cprint("green", "\nLords of the Realm II - County Game File Editor\n") be.cprint("grey", "-----------------------------------------------\n\n") be.reset_colour() print " -h | --help Show this help" print " -f | --file <file> Display current values of game file"
def searchdb(db, findstr, findstr2=''): '''search db for matching entries and display them''' be.cprint( "white", "{0:^15s} | {1:^10s} | {2:^8s} | {3:^10s} | {5:^30s} | {6:^14s}|\n". format("Server", "Customer", "Env", "Type", "User", "Connection String", "NAT", "Description")) be.cprint( "white", "{0:<15s}-|-{1:<10s}-|-{2:<8s}-|-{3:<10s}-|-{5:<30s}-|-{6:<14s}|\n". format("-" * 15, "-" * 10, "-" * 8, "-" * 10, "-", "-" * 30, "-" * 14, "-" * 30)) for i in db: #convert record to long string and look for str matches recstr = "" for r in i.split('|'): recstr += r.lower() + "|" found = False if re.search(findstr, recstr): found = True #look for second if exists if not recstr == '': if not re.search(findstr2, recstr): found = False if found: server, cust, custenv, stype, user, connstr, wabserver, wssnat, desc = i.split( '|') connstr = re.sub("^.*_U_@", "", connstr) c = "grey" if custenv == "TEST": c = "green" if custenv == "PROD": c = "cyan" if custenv == "DR": c = "red" be.cprint( c, "{0:<15s} | {1:<10s} | {2:<8s} | {3:<10s} | {5:<30s} | {6:<14s}|\n" .format(server.rstrip(), cust.rstrip(), custenv.rstrip(), stype.rstrip(), user.rstrip(), connstr.rstrip()[:30], wssnat.rstrip(), desc.rstrip()[:30])) #be.cprint(c, "{0:<15s} | {1:<10s} | {2:<8s} | {3:<10s} | {4:<10s} | {5:<30s} | {6:<14s} | {7:<30s}|\n".format(server.rstrip(), cust.rstrip(),custenv.rstrip(),stype.rstrip(),user.rstrip(),connstr.rstrip()[:30],wssnat.rstrip(),desc.rstrip()[:30])) be.reset_colour()
def editfile(self, filename): self.loadvalues(filename) be.cprint("green", "My Lord, Please supply your desired values:\n\n") be.reset_colour() #Gold print "{0:11}{1:10}({2:,})".format(" Gold: ", " ", self.gf_gold), print "\r Gold: ".format(self.gf_gold), be.set_colour("yellow") self.gf_gold = int(raw_input()) be.reset_colour() #Resources print "{0:11}{1:10}({2:,}/65535)".format(" Iron: ", " ", self.gf_iron), print "\r Iron: ".format(self.gf_iron), be.set_colour("brown") self.gf_iron = int(raw_input('')) be.reset_colour() print "{0:11}{1:10}({2:,}/65535)".format(" Stone: ", " ", self.gf_stone), print "\r Stone: ".format(self.gf_stone), be.set_colour("grey") self.gf_stone = int(raw_input("")) be.reset_colour() print "{0:11}{1:10}({2:,}/65535)".format(" Wood: ", " ", self.gf_wood), print "\r Wood: ".format(self.gf_wood), be.set_colour("green") self.gf_wood = int(raw_input('')) be.reset_colour() #Weapons print "{0:11}{1:10}({2:,}/65535)".format(" Armor: ", " ", self.gf_armor), print "\r Armor: ".format(self.gf_armor), be.set_colour("red") self.gf_armor = int(raw_input('')) be.reset_colour() print "{0:11}{1:10}({2:,}/65535)".format(" Bows: ", " ", self.gf_bows), print "\r Bows: ".format(self.gf_bows), be.set_colour("red") self.gf_bows = int(raw_input('')) be.reset_colour() print "{0:11}{1:10}({2:,}/65535)".format("Crossbows: ", " ", self.gf_xbows), print "\rCrossbows: ".format(self.gf_xbows), be.set_colour("red") self.gf_xbows = int(raw_input('')) be.reset_colour() print "{0:11}{1:10}({2:,}/65535)".format(" Swords: ", " ", self.gf_bows), print "\r Swords: ".format(self.gf_swords), be.set_colour("red") self.gf_swords = int(raw_input('')) be.reset_colour() self.savevalues(filename)
def listfile(self, filename): #validate file exists self.loadvalues(filename) be.cprint("green", "My Lord, the treasury reports the following:\n\n") be.reset_colour() print " Gold: ", be.set_colour("yellow") print "{0:,}".format(self.gf_gold) be.reset_colour() print " Iron: ", be.set_colour("brown") print "{0:,}".format(self.gf_iron) be.reset_colour() print " Stone: ", be.set_colour("grey") print "{0:,}".format(self.gf_stone) be.reset_colour() print " Wood: ", be.set_colour("green") print "{0:,}".format(self.gf_wood) be.reset_colour() print " Armor: ", be.set_colour("red") print "{0:,}".format(self.gf_armor) be.reset_colour() print " Bows: ", be.set_colour("red") print "{0:,}".format(self.gf_bows) be.reset_colour() print "Crossbows: ", be.set_colour("red") print "{0:,}".format(self.gf_xbows) be.reset_colour() print " Swords: ", be.set_colour("red") print "{0:,}".format(self.gf_swords) be.reset_colour()
opts, args = getopt.getopt(sys.argv[1:], "hles", ["help", "list", "edit", "set"]) if debug: print "Options:", opts if debug: print "Args:", args for o, a in opts: if debug: print "O:", o if o in ("-h", "--help"): gamefile.usage() sys.exit() elif o in ("-l", "--list"): if len(args) > 0: #list gamefile.listfile(args[0]) sys.exit() elif o in ("-e", "--edit"): if len(args) > 0: #edit gamefile.editfile(args[0]) sys.exit() elif o in ("-s", "--set"): if len(args) > 0: #Set good default values into game file gamefile.savevalues(args[0]) be.cprint("green", "T'is done my lord...\n") be.reset_colour() sys.exit() else: #assume garbage so exit be.cprint("red", "ERROR: Unknown, please read the help page") be.reset_colour()
def listCounties(self): '''Iterate through counties and allow to edit or just view the details of each county''' count = 1 while True: be.cprint( "green", "\nMy Lord, county {0}/{1} reports the following:\n\n".format( count, self.counties)) be.reset_colour() self.loadCounty(count - 1) print "Ruler: ", be.cprint(self.colors[self.county_color], "{0:}\n".format(self.rulers[self.county_ruler])) be.reset_colour() print "Tax: ", be.cprint("blue", "{0:}\n".format(self.county_tax)) be.reset_colour() print "Happiness: ", be.cprint("red", "{0:}\n".format(self.county_happiness)) be.reset_colour() print "Health: ", be.cprint("red", "{0:}\n".format(self.health[self.county_health])) be.reset_colour() print "Population: ", be.cprint("white", "{0:}\n".format(self.county_population)) be.reset_colour() print "Grain: ", be.cprint("yellow", "{0:}\n".format(self.county_grain)) be.reset_colour() print "Cattle: ", be.cprint("white", "{0:}\n".format(self.county_cattle)) be.reset_colour() be.cprint("grey", "(P)revious - (E)dit - (Q)uit - (N)ext: ") temp = raw_input("") if temp.lower() == 'p': count -= 1 if count < 1: count = 1 if temp.lower() == 'n': count += 1 if count > self.counties: count = self.counties if temp.lower() == 'q': be.cprint("green", "\nBye!\n") sys.exit(0) if temp.lower() == 'e': self.editCounty(count)
def editCounty(self, cnum): ''' Edit main stats of a county - population, health, grain, cattle ''' be.cprint( "green", "My Lord, What do you desire for county {0}/{1}:\n\n".format( cnum, self.counties)) be.reset_colour() while True: print "Ruler 0=None, 1=You, 2=Bishop, 3=Baron, 4=Countess,5=Knight: ", be.set_colour("blue") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 6: self.county_ruler = temp break while True: print "Color (0=None, 1=Red, 2=Yellow, 3=Grey, 4=Pink, 5=Blue, 6=Black): ", be.set_colour("blue") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 7: self.county_color = temp break while True: print "Happiness 0-100: ", be.set_colour("blue") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 101: self.county_happiness = temp break while True: print "Health (1=Plagued, 2=Weak, 3=Normal, 4=Perfect): ", be.set_colour("green") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 6: self.county_health = temp break while True: print "Population 0-65535: ", be.set_colour("blue") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 65535: self.county_population = temp break while True: print "Grain (0-65535): ", be.set_colour("yellow") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 65535: self.county_grain = temp break while True: print "Cattle (0-65535): ", be.set_colour("white") temp = int(raw_input()) be.reset_colour() if temp > -1 and temp < 65535: self.county_cattle = temp break self.saveCounty(cnum - 1)
def generate_refresh_package(self, db, checkonly=False): ''' generate the package refresh contents (packages + configdata (if node0)) ''' #create package directory dpath = os.environ['FK_IDENT'] + '_package_list_' + time.strftime( "%Y-%m-%d") if not checkonly: if not os.path.exists(dpath): os.makedirs(dpath) os.makedirs(os.path.join(dpath, 'configdata')) packagefile = open(os.path.join(dpath, 'packages.txt'), 'w') #gather packages in the order they are applied package_order = sorted(self.db, key=lambda x: (self.db[x]['install_time'])) for p in package_order: be.set_colour('white') print "{0:<25s} - {1:<15s}- {2:17s} -> ".format( self.db[p]['name'], self.db[p]['version'], self.db[p]['install_time_string']), if self.db[p]['status'] == 'OK': be.set_colour('green') #lets find the package in the archive directory pfile = glob.glob('archive/' + self.db[p]['name'] + '*' + self.db[p]['version'] + '.zip') if pfile: if not checkonly: shutil.copy(pfile[0], dpath) if os.path.isfile( os.path.join(dpath, os.path.split( pfile[0])[1])) or checkonly: print "OK" if not checkonly: packagefile.write( os.path.split(pfile[0])[1] + '\n') else: be.set_colour('red') print "ERROR - file copy failed" else: be.set_colour('red') print "ERROR - Package not found in archive" else: be.set_colour('grey') print self.db[p]['status'] be.reset_colour() if not checkonly: packagefile.close() #create configdata if app and node = 0 if self.isappserver: #check node name if exists nodeid = os.environ['FK_NODE_ID'] if not nodeid or nodeid == '0': be.set_colour('white') print "\nCreating backup of Configuration data... ", cmmtar = tarfile.open( os.path.join( dpath, 'configdata', os.environ['FK_IDENT'] + '_configdata_' + time.strftime("%Y-%m-%d") + ".tar.gz"), "w:gz") olddir = os.getcwd() os.chdir(os.environ['CMM_HOME']) cmmtar.add('./ConfigurationData') cmmtar.close() os.chdir(olddir) be.set_colour('green') print "OK" be.reset_colour() #create install script for packages os.chdir(dpath) be.set_colour('white') print "\nGenerating install script : ", if self.isappserver: #create install script for linux installfile = open('install.sh', 'w') installfile.write('#!/bin/bash\n') installfile.write('#Automatically generated!\n') installfile.write('echo Installing packages...\n') installfile.write('for p in `cat packages.txt`; do\n') installfile.write(' ../deploy_packages.sh $p\n') installfile.write('done\n') installfile.write('cp -prf log ..\n') installfile.write('fkhistory | sort -k 5\n') installfile.close() os.chmod('install.sh', 0755) else: #create install script for windows installfile = open('install.bat', 'w') installfile.write('@echo off\n') installfile.write( 'for /F "tokens=*" %%P in (packages.txt) do @call ..\deploy_packages.bat "%%P" \n' ) installfile.write('xcopy /Q /Y /E log* ..\\\n') installfile.write('xcopy /Q /Y /E log\\* ..\\log\n') installfile.write('fkhistory\n') installfile.close() be.set_colour('green') print "OK" be.set_colour('white') print "Generated Package Location: ", be.set_colour('green') print dpath be.set_colour('white')