def multiprocess_file(filename, worker_id, start, end, lock): ptds = PTdataStore(multi=True, lock=lock, worker=worker_id) debug = False if not ptds.connectToDB(debug): return 1 print("Started worker %s on offset %s with size %s" % (worker_id, start, (end - start))) ptds.storePTDFdataOffset(worker_id, filename, start, (end - start)) #print "QUERY COUNT: %s" % ptds.dbapi.query_count ptds.closeDB()
def main(): usage = "usage: %prog [options]\nexecute '%prog --help' to see options" version = "%prog 1.0" parser = OptionParser(usage=usage, version=version) parser.add_option("-j", "--jobs", type="int", dest="jobs", default=(int(cpu_count() * 1.25)), action="store", help="Specify the number of processes") parser.add_option("-d", "--debug", dest="debug", default=False, action="store_true", help="Enable Debugging") (options, ptdfs) = parser.parse_args(sys.argv[1:]) # ptdfname can be the name of a ptdf file or the name # of a directory containing ptdf files multi = PTDFMulti(options.jobs - 1) #Remove one job to allow this process to have a cpu ptds = PTdataStore(multi=(options.jobs > 1)) if not ptds.connectToDB(options.debug): return 1 try: for ptdfname in ptdfs: if (not os.path.exists(ptdfname)): print "File does not exist %s" % ptdfname raise Exception("File does not exist") mode = os.stat(ptdfname)[stat.ST_MODE] # if not a directory, just process a single ptdf file if not stat.S_ISDIR(mode): handle_file(ptds, multi, ptdfname) # else a directory, process all ptdf files in directory else: files = glob(ptdfname + "/*.ptdf") files.sort() for ptdfname in files: handle_file(ptds, multi, ptdfname) #print "QUERY COUNT: %s" % ptds.dbapi.query_count except Exception, a: print a multi.terminate()
def main(): ptds = PTdataStore() connected = ptds.connectToDB(False) if not connected: print "could not connect to DB" sys.exit(0) t = PTdS_t8() tests = [ t.test1, t.test2, t.test3, t.test4, t.test5, t.test6, t.test7, t.test8 ] for test in tests: test(ptds)
def main(): ptds = PTdataStore() connected = ptds.connectToDB(False) if not connected: print "could not connect to DB" sys.exit(0) tests = [test1, test2, test3, test4, test5, test6, test7, test8] pf = PassFail() for test in tests: test(ptds, pf) pf.test_info() return pf.failed_count > 0
def connectToDB(testMode, opt=None): ptds = PTdataStore() #create PTdataStore object if testMode: debugLevel = ptds.NO_WRITE else: debugLevel = ptds.NO_DEBUG if opt == None: connected = ptds.connectToDB(debugLevel) else: connected = ptds.connectToDB(debugLevel, ctb_db=opt.database, ctb_host=opt.host, ctb_pwd=opt.password, ctb_user=opt.user) if not connected: raise PTexception("Build.process: could not connect to database") return ptds
print "result: %s for adding /icc" % result result = testStore.getNewResourceName("/icc") print "result: %s for adding /icc" % result result = testStore.getNewResourceName("/frank") print "result: %s for adding /frank" % result testStore.abortTransaction() dbname = raw_input("Please enter your database username: "******"Please enter the tnsname for the database: ") dbpwd = getpass("Please enter your database password: "******"test1 real" test1(testStore, dbname, dbpwd, dbfullname) print "test1 fakename" test1(testStore, "lalala", dbpwd, dbfullname) print "test1 fakepwd" test1(testStore, dbname, "lalala", dbfullname) print "test1 fakefullname" test1(testStore, dbname, dbpwd, "lalala") print "test2" test2(testStore) print "test3" test3(testStore) print "test4" test4(testStore)
sql = "select type from resource_item where id = '" + str(rid) + "'" #ptds.cursor.execute(sql) ptds.dbapi.execute(ptds.cursor,sql) #type, = ptds.cursor.fetchone() type, = ptds.dbapi.fetchone(ptds.cursor) outfile.write ("ID: " + str(rid) + "\n") outfile.write ("NAME: " + rname + "\n") outfile.write ("TYPE: " + type + "\n") sql = "select name,value from resource_attribute where resource_id = '" \ + str(rid) + "'" #ptds.cursor.execute(sql) ptds.dbapi.execute(ptds.cursor, sql) #nameValueList = ptds.cursor.fetchall() nameValueList = ptds.dbapi.fetchall(ptds.cursor) outfile.write ("RESOURCE ATTRIBUTES:\n") for (name, value) in nameValueList: outfile.write (" name: " + name + "\n") outfile.write (" value: " + value + "\n\n") outfile.close() ptds.closeDB() return True ptds = PTdataStore() filename = raw_input("Enter a name to call the report: ") if filename == "": print "The report must have a valid name" sys.exit() getMachinesAndAttributes(filename)
import sys from PTdS_test1 import PTdS_t1 from PTdS_test2 import PTdS_t2 from PTdS_test3 import PTdS_t3 from PTdS_test4 import PTdS_t4 from PTdS_test5 import PTdS_t5 from PTdS_test6 import PTdS_t6 from PTdS_test7 import PTdS_t7 from PTdS_test8 import * from PTds import PTdataStore from mx.DateTime import * from PassFail import PassFail #from getpass import getpass pf = PassFail() testStore = PTdataStore() test1 = PTdS_t1(pf) test2 = PTdS_t2(pf) test3 = PTdS_t3(pf) test4 = PTdS_t4(pf) test5 = PTdS_t5(pf) test6 = PTdS_t6(pf) test7 = PTdS_t7(pf) test8 = PTdS_t8(pf) ##TEST 1 -- connection test print "test1.2 - connect, no optional parameters" #test1.test1_2(testStore) print "test1.3 - connect, with optional parameters"