Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def retrieve_profile(self, username, domain, operation, update, defer):
transaction = None
try:
if self.dburi is None:
raise NoDatabase()
transaction = sqlhub.processConnection.transaction()
try:
db_account = SipAccount.select(AND(SipAccount.q.username == username, SipAccount.q.domain == domain), connection = transaction, forUpdate = update)[0]
except IndexError:
raise NotFound()
profile = db_account.profile
result = operation(profile) # NB: may modify profile!
if update:
db_account.profile = profile
transaction.commit(close=True)
except Exception, e:
if transaction:
transaction.rollback()
reactor.callFromThread(defer.errback, e)
else:
reactor.callFromThread(defer.callback, result)
finally:
if transaction:
transaction.cache.clear()
except sqlobject.main.SQLObjectNotFound, e:
license = License(license=data["LICENSE_RPM"], license_type="RPM")
created_something = True
# TODO: set created_something only if we remove a *different* record than we are adding
moduleLogVerbose.debug("\tadd LICENSE: %s" % data["LICENSE_RPM"])
for s in f.license:
if s.license_type != "RPM": continue
f.removeLicense(s)
f.addLicense(license)
del(data["LICENSE_RPM"])
skip_list = ("full_path", "basename")
for key, value in data.items():
if key in skip_list: continue
if not Tag.select(sqlobject.AND(Tag.q.filedata==f, Tag.q.tagname == key, Tag.q.tagvalue==value)).count():
moduleLogVerbose.debug("Add TAG: %s --> %s" % (key, value))
t = Tag(filedata=f, tagname=key, tagvalue=value)
created_something = True
if created_something:
moduleLogVerbose.info("Inserted : %s" % data["basename"])
else:
moduleLogVerbose.info("Already present : %s" % data["basename"])
return created_something
def payload(self):
"""
The function that actually does something useful...
Shamelessly taken from yokadid.py by Sébastien Renard
"""
now = datetime.today().replace(microsecond=0)
delayTasks = Task.select(AND(Task.q.dueDate < now + self.delta,
Task.q.dueDate > now,
*self.activeTaskFilter))
dueTasks = Task.select(AND(Task.q.dueDate < now,
*self.activeTaskFilter))
self.processTasks(delayTasks, self.triggeredDelayTasks, self.cmdDelayTemplate, self.suspend)
self.processTasks(dueTasks, self.triggeredDueTasks, self.cmdDueTemplate, self.suspend)
if dico['WinStationName'] == u'Console' and dico['State'] == 0:
sessionID = dico['SessionId']
if not sessionID:
raise Exception('Impossible to find the current session ID')
self.logInfo("Using session %s for output" %sessionID)
# Main loop itself
self.isRunning = True
while self.isRunning:
self.sleep(DELAY)
now=datetime.today().replace(microsecond=0)
delayTasks=Task.select(AND(Task.q.dueDate < now+delta,
Task.q.dueDate > now,
*activeTaskFilter))
dueTasks=Task.select(AND(Task.q.dueDate < now,
*activeTaskFilter))
self.processTasks(delayTasks, triggeredDelayTasks, cmdDelayTemplate, sessionID)
self.processTasks(dueTasks, triggeredDueTasks, cmdDueTemplate, sessionID)
def payload(self):
"""
The function that actually does something useful...
Shamelessly taken from yokadid.py by Sébastien Renard
"""
now = datetime.today().replace(microsecond=0)
delayTasks = Task.select(AND(Task.q.dueDate < now + self.delta,
Task.q.dueDate > now,
*self.activeTaskFilter))
dueTasks = Task.select(AND(Task.q.dueDate < now,
*self.activeTaskFilter))
self.processTasks(delayTasks, self.triggeredDelayTasks, self.cmdDelayTemplate, self.suspend)
self.processTasks(dueTasks, self.triggeredDueTasks, self.cmdDueTemplate, self.suspend)
def get_or_create_user(name, domain):
try:
user = models.User.select(AND(models.User.q.name==name, models.User.q.domain==domain))[0]
except IndexError:
user = models.User(name=name, domain=domain)
return user
def get(self, key):
# key is an object now (though could also be a name)
# add ID as will be a foreign key
objref1 = getattr(self.type.q, self.keyed_value_name + 'ID')
objref2 = getattr(self.type.q, self.other_key_name + 'ID')
sel = self.type.select(sqlobject.AND(
objref1 == self.keyed_value.id, objref2 == key.id)
)
sel = list(sel)
if len(sel) == 0:
msg = '%s not in this register' % key
raise Exception(msg)
# should have only one item
newkey = sel[0].id
return super(KeyedRegister, self).get(newkey)
def select_from_kw(class_, **kw):
"Returns a select object for a given set of keywords."
and_list = []
for key, value in kw.iteritems():
query_col = getattr(class_.q, key)
and_list.append(query_col==kw[key])
if len(and_list) == 0:
select = class_.select()
elif len(and_list) == 1:
select = class_.select(and_list[0])
else:
select = class_.select(so.AND(*and_list))
return select