def connect(): if host.startswith("/"): conn = MySQLdb.connect(unix_socket=host, user=user, passwd=pw, db=db) else: conn = MySQLdb.connect(host=host, user=user, passwd=pw, db=db, port=3306) return conn
with file(twissfile, 'r') as f: for line in f.readlines(): if not line.strip().startswith('#'): lineparts = line.split() assert len(lineparts) == len(twisscols), 'Twiss header does not match data instance in the body' tmpdict = {} for i in range(1, len(lineparts)): if skipcols[i]: pass else: tmpdict[twisscols[i]] = lineparts[i] twissdict[lineparts[0]] = tmpdict return twissdict if __name__ == '__main__': if host.startswith("/"): conn = MySQLdb.connect(unix_socket=host, user=user, passwd=pw, db=db) else: conn = MySQLdb.connect(host=host, user=user, passwd=pw, db=db, port=3306) # cleanmodeldb(conn) modelinst = model(conn) latticename = 'CD3-Oct3-12-30Cell-addID-par' latticeversion = 20121003 latticebranch = 'test' modelhead1 = {'CD3-Oct3-12-30Cell-addID-par bare': { # header information 'description': 'an instance for lattice CD3-Oct3-12-30Cell-addID-par', 'creator': 'Guobao Shen',
lineparts = line.split() assert len(lineparts) == len( twisscols ), 'Twiss header does not match data instance in the body' tmpdict = {} for i in range(1, len(lineparts)): if skipcols[i]: pass else: tmpdict[twisscols[i]] = lineparts[i] twissdict[lineparts[0]] = tmpdict return twissdict if __name__ == '__main__': if host.startswith("/"): conn = MySQLdb.connect(unix_socket=host, user=user, passwd=pw, db=db) else: conn = MySQLdb.connect(host=host, user=user, passwd=pw, db=db, port=3306) # cleanmodeldb(conn) modelinst = model(conn) latticename = 'CD3-Oct3-12-30Cell-addID-par' latticeversion = 20121003 latticebranch = 'test'