本文整理汇总了Python中Core.db.session.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan
def scan(self, uid, pa_id, gid=None):
page = urlopen(Config.get("URL","viewscan")%(pa_id,)).read()
page = decode(page)
m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
if not m:
print "Expired/non-matchinng scan (id: %s)" %(pa_id,)
return
scantype = m.group(1)[0].upper()
x = int(m.group(2))
y = int(m.group(3))
z = int(m.group(4))
tick = int(m.group(5))
planet = Planet.load(x,y,z)
if planet is None:
return
try:
scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, group_id=gid, scanner_id=uid)
planet.scans.append(scan)
session.commit()
scan_id = scan.id
except IntegrityError, e:
session.rollback()
print "Scan %s may already exist" %(pa_id,)
print e.__str__()
return
示例2: new
def new(self, message, user, params):
tick = Updates.current_tick()
comment = params.group(3) or ""
when = int(params.group(1))
if when < PA.getint("numbers", "protection"):
eta = when
when += tick
elif when <= tick:
message.alert(
"Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick)
)
return
else:
eta = when - tick
if when > 32767:
when = 32767
attack = Attack(landtick=when, comment=comment)
session.add(attack)
for coord in re.findall(loadable.coord, params.group(2)):
if not coord[4]:
galaxy = Galaxy.load(coord[0], coord[2])
if galaxy:
attack.addGalaxy(galaxy)
else:
planet = Planet.load(coord[0], coord[2], coord[4])
if planet:
attack.addPlanet(planet)
session.commit()
message.reply(str(attack))
示例3: parse_N
def parse_N(self, scan_id, scan, page):
#incoming fleets
#<td class=left valign=top>Incoming</td><td valign=top>851</td><td class=left valign=top>We have detected an open jumpgate from Tertiary, located at 18:5:11. The fleet will approach our system in tick 855 and appears to have roughly 95 ships.</td>
for m in re.finditer('<td class="left" valign="top">Incoming</td><td valign="top">(\d+)</td><td class="left" valign="top">We have detected an open jumpgate from ([^<]+), located at (\d+):(\d+):(\d+). The fleet will approach our system in tick (\d+) and appears to have roughly (\d+) ships.</td>', page):
fleetscan = FleetScan()
newstick = m.group(1)
fleetname = m.group(2)
originx = m.group(3)
originy = m.group(4)
originz = m.group(5)
arrivaltick = int(m.group(6))
numships = m.group(7)
fleetscan.mission = "Unknown"
fleetscan.fleet_name = fleetname
fleetscan.launch_tick = newstick
fleetscan.landing_tick = arrivaltick
fleetscan.fleet_size = numships
owner=Planet.load(originx,originy,originz)
if owner is None:
continue
fleetscan.owner = owner
fleetscan.target = scan.planet
try:
scan.fleets.append(fleetscan)
session.commit()
except Exception, e:
session.rollback()
print "Exception in news: "+e.__str__()
traceback.print_exc()
continue
print 'Incoming: ' + newstick + ':' + fleetname + '-' + originx + ':' + originy + ':' + originz + '-' + arrivaltick + '|' + numships
示例4: execute
def execute(self, page, uid, pa_id, gid=None):
scanlog("Scan: %s (group: %s)" %(pa_id,gid,))
page = decode(page)
m = re.search('>([^>]+) on (\d+)\:(\d+)\:(\d+) in tick (\d+)', page)
if not m:
scanlog("Expired/non-matchinng scan (id: %s)" %(pa_id,))
return
scantype = m.group(1)[0].upper()
x = int(m.group(2))
y = int(m.group(3))
z = int(m.group(4))
tick = int(m.group(5))
m = re.search("<p class=\"right scan_time\">Scan time: ([^<]*)</p>", page)
scantime = m.group(1)
planet = Planet.load(x,y,z,)
try:
Q = session.query(Scan).filter(Scan.pa_id == pa_id).filter(Scan.planet_id == None)
if Q.count() > 0:
scan = Q.first()
else:
scan = Scan(pa_id=pa_id, scantype=scantype, tick=tick, time=scantime, group_id=gid, scanner_id=uid)
session.add(scan)
if planet:
planet.scans.append(scan)
session.commit()
scan_id = scan.id
except IntegrityError, e:
session.rollback()
scanlog("Scan %s may already exist: %s" %(pa_id,str(e),))
return
示例5: execute
def execute(self, request, user, id, x, y, z, when):
planet = Planet.load(x,y,z)
if planet is None:
return self.attack(request, user, id, "No planet with coords %s:%s:%s" %(x,y,z,))
tick = Updates.current_tick()
when = int(when)
if when < PA.getint("numbers", "protection"):
eta = when
when += tick
elif when <= tick:
return self.attack(request, user, id, "Can not book targets in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
else:
eta = when - tick
if when > 32767:
when = 32767
if planet.intel and planet.alliance and planet.alliance.name == Config.get("Alliance","name"):
return self.attack(request, user, id, "%s:%s:%s is %s in %s. Quick, launch before they notice!" % (x,y,z, planet.intel.nick or 'someone', Config.get("Alliance","name"),))
try:
planet.bookings.append(Target(user=user, tick=when))
session.commit()
except IntegrityError:
session.rollback()
target = planet.bookings.filter(Target.tick == when).first()
if target is not None:
return self.attack(request, user, id, "Target %s:%s:%s is already booked for landing tick %s by user %s" % (x,y,z, when, target.user.name,))
else:
return self.attack(request, user, id, "Booked landing on %s:%s:%s tick %s (eta %s) for user %s" % (x,y,z, when, (when-tick), user.name,))
return self.attack(request, user, id)
示例6: execute
def execute(self, message, user, params):
fleetcount = int(params.group(1))
comment = params.group(2)
reply = ""
if user.planet:
scan = user.planet.scan("A")
if scan is None:
message.reply("Advanced Unit Scan not found for %s:%s:%s" % (user.planet.x, user.planet.y, user.planet.z))
return
else:
message.reply("Planet not set. Use !pref planet=x:y:z")
return
scanage = Updates.current_tick() - scan.tick
if scanage > 12:
reply += "Warning: Scan is %d ticks old.\n" % scanage
self.update_comment_and_fleetcount(user, fleetcount, comment)
user.fleets.delete()
for uscan in scan.units:
user.fleets.append(UserFleet(ship_id=uscan.ship_id, ship_count=uscan.amount))
session.commit()
ships = user.fleets.all()
reply += "Updated your def info to: fleetcount %s, updated: pt%s ships: " % (user.fleetcount, user. fleetupdated)
reply += ", ".join(map(lambda x:"%s %s" % (self.num2short(x.ship_count), x.ship.name), ships))
reply += " and comment: %s" %(user.fleetcomment)
message.reply(reply)
示例7: execute
def execute(self, message, user, params):
# assign param variables
dists=params.group(1)
user.dists = dists
session.commit()
message.reply("Update your distorters to %s"%(user.dists,))
示例8: execute
def execute(self, message, user, params):
username = params.group(1)
member = User.load(name=username, active=False)
if member is None:
message.alert("No such user '%s'" % (username,))
return
if member.access > user.access:
message.reply(
"You may not remove %s, his or her access (%s) exceeds your own (%s)"
% (member.name, member.access, user.access)
)
return
mbraxx = Config.getint("Access", "member")
home = Config.get("Channels", "home")
coraxx = Config.getint("Access", "core")
core = Config.get("Channels", "core")
if member.active and member.access >= mbraxx:
message.privmsg("remuser %s %s" % (home, member.name), "P")
if member.active and member.access >= coraxx:
message.privmsg("remuser %s %s" % (core, member.name), "P")
session.delete(member)
session.commit()
message.reply("Removed user %s" % (member.name,))
CUT.untrack_user(member.name)
示例9: execute
def execute(self, message, user, params):
# do stuff here
if params.group(1).lower() == Config.get("Connection","nick").lower():
message.reply("I'll peck your eyes out, cunt.")
return
idiot = User.load(name=params.group(1), access="member")
if idiot is None:
message.reply("That user isn't a member!")
return
if (not user.is_admin()) and user != idiot and idiot.sponsor != user.name:
message.reply("You do not have sufficent access to demote this member.")
return
if "galmate" in Config.options("Access"):
idiot.access = Config.getint("Access","galmate")
else:
idiot.access = 0
if idiot.planet is not None and idiot.planet.intel is not None:
intel = idiot.planet.intel
alliance = Alliance.load(Config.get("Alliance","name"))
if intel.alliance == alliance:
intel.alliance = None
session.commit()
message.privmsg("remuser %s %s"%(Config.get("Channels","home"), idiot.name,),'p')
message.privmsg("remuser %s %s"%(Config.get("Channels","core"), idiot.name,),'p')
if idiot.sponsor != user.name:
# message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p')
message.reply("%s has been reduced to \"galmate\" level and removed from the channel. "%(idiot.name,))
else:
# message.privmsg("note send %s You have been removed from private channels."%(idiot.name,),'p')
message.reply("%s has been reduced to \"galmate\" level and removed from the channel."%(idiot.name,))
示例10: update_available_cookies
def update_available_cookies(self, user):
now = datetime.datetime.now()
now = datetime.datetime(now.year,now.month,now.day)
if not user.last_cookie_date or (now - user.last_cookie_date).days > 0:
user.available_cookies = Config.getint("Alliance","cookies")
user.last_cookie_date = current_timestamp()
session.commit()
示例11: cancel
def cancel(self, message, user, params):
id = params.group(1)
prop = self.load_prop(id)
if prop is None:
message.reply("No proposition number %s exists (idiot)."%(id,))
return
if not prop.active:
message.reply("You can't cancel prop %d, it's already expired."%(prop.id,))
return
if prop.proposer is not user and not user.is_admin():
message.reply("Only %s may cancel proposition %d."%(prop.proposer.name,prop.id))
return
self.recalculate_carebears(prop)
yes, no, veto = self.sum_votes(prop)
vote_result = "cancel"
reply = self.text_result(vote_result, yes, no, veto)
reply+= self.text_summary(prop)
message.reply(reply)
prop.active = False
prop.closed = current_timestamp()
prop.vote_result = vote_result
session.commit()
示例12: run
def run(self, request, **kwargs):
try:
user, cookie, key, planet_id = self.router(request)
response = self.execute(request, user, **kwargs)
session = Session()
session.add(PageView(page = self.name,
full_request = request.get_full_path(),
username = user.name,
session = key,
planet_id = user.planet.id if user.planet else None,
hostname = request.META['REMOTE_ADDR'],))
session.commit()
if cookie is not None:
response.set_cookie(SESSION_KEY, cookie, expires=request.session.expire)
if planet_id is False:
response.delete_cookie(PLANET_KEY)
elif planet_id is not True:
response.set_cookie(PLANET_KEY, planet_id, expires=datetime.now()+timedelta(days=65))
return response
except UserError, e:
return self.login_page(request, str(e))
示例13: execute
def execute(self, message, user, params):
# assign param variables
amp=params.group(1)
user.amps = amp
session.commit()
message.reply("Update your Amplifiers to %s"%(user.amps,))
示例14: land
def land(self, message, user, params):
id = int(params.group(1))
attack = Attack.load(id)
if attack is None:
message.alert("No attack exists with id %d" %(id))
return
tick = Updates.current_tick()
when = int(params.group(2))
if when == 0:
session.delete(attack)
session.commit()
message.reply("Deleted Attack %d LT: %d | %s" %(attack.id,attack.landtick,attack.comment,))
return
if when < PA.getint("numbers", "protection"):
eta = when
when += tick
elif when <= tick:
message.alert("Can not create attacks in the past. You wanted tick %s, but current tick is %s." % (when, tick,))
return
else:
eta = when - tick
if when > 32767:
when = 32767
old = attack.landtick
attack.landtick = when
session.commit()
message.reply("Changed LT for attack %d from %d to %d"%(id,old,when))
示例15: execute
def execute(self, message, user, params):
adoptee = params.group(1)
if adoptee.lower() == Config.get("Connection", "nick").lower():
message.reply("Fuck off you stupid twat, stop trying to be a clever shit.")
return
if adoptee.lower() == user.name.lower():
message.reply("Stop wanking your own dick and find a daddy to do it for you, retard.")
return
a = User.load(name=adoptee, access="member")
if a is None:
message.reply("No members matching '%s'" % (adoptee,))
return
s = User.load(name=a.sponsor, access="member") if a.sponsor else None
if s is not None:
message.reply("%s already has a daddy you filthy would-be kidnapper!" % (a.name,))
return
anc = user.has_ancestor(a.name)
if anc is True:
message.reply("Ew, incest.")
return
if anc is None:
message.reply("Filthy orphans should be castrated.")
return
a.sponsor = user.name
session.commit()
message.reply("Congratulations! You're now the proud father of a not-so newly born %s!" % (a.name,))