mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-11 05:17:55 +03:00
Minor code fixes & updates
This commit is contained in:
parent
32b1ac71a9
commit
cc48b50dcb
@ -58,11 +58,11 @@ class Storage(object):
|
||||
if isinstance(data, unicode):
|
||||
data = data.encode('utf-8')
|
||||
data = data.encode(Storage.CODEC)
|
||||
attr1 = '' if attr1 == None else attr1
|
||||
attr1 = '' if attr1 is None else attr1
|
||||
try:
|
||||
dbStorage.objects.create(owner=self._owner, key=key, data=data, attr1=attr1)
|
||||
dbStorage.objects.create(owner=self._owner, key=key, data=data, attr1=attr1) # @UndefinedVariable
|
||||
except Exception:
|
||||
dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1)
|
||||
dbStorage.objects.filter(key=key).update(owner=self._owner, data=data, attr1=attr1) # @UndefinedVariable
|
||||
logger.debug('Key saved')
|
||||
|
||||
def put(self, skey, data):
|
||||
@ -78,7 +78,7 @@ class Storage(object):
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
logger.debug('Accesing to {0} {1}'.format(skey, key))
|
||||
c = dbStorage.objects.get(pk=key)
|
||||
c = dbStorage.objects.get(pk=key) # @UndefinedVariable
|
||||
val = c.data.decode(Storage.CODEC)
|
||||
|
||||
if fromPickle:
|
||||
@ -88,7 +88,7 @@ class Storage(object):
|
||||
return val.decode('utf-8') # Tries to encode in utf-8
|
||||
except:
|
||||
return val
|
||||
except dbStorage.DoesNotExist:
|
||||
except dbStorage.DoesNotExist: # @UndefinedVariable
|
||||
logger.debug('key not found')
|
||||
return None
|
||||
|
||||
@ -104,7 +104,7 @@ class Storage(object):
|
||||
def remove(self, skey):
|
||||
try:
|
||||
key = self.__getKey(skey)
|
||||
dbStorage.objects.filter(key=key).delete()
|
||||
dbStorage.objects.filter(key=key).delete() # @UndefinedVariable
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@ -112,25 +112,25 @@ class Storage(object):
|
||||
'''
|
||||
Use with care. If locked, it must be unlocked before returning
|
||||
'''
|
||||
dbStorage.objects.lock()
|
||||
dbStorage.objects.lock() # @UndefinedVariable
|
||||
|
||||
def unlock(self):
|
||||
'''
|
||||
Must be used to unlock table
|
||||
'''
|
||||
dbStorage.objects.unlock()
|
||||
dbStorage.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def locateByAttr1(self, attr1):
|
||||
res = []
|
||||
for v in dbStorage.objects.filter(attr1=attr1):
|
||||
for v in dbStorage.objects.filter(attr1=attr1): # @UndefinedVariable
|
||||
res.append(v.data.decode(Storage.CODEC))
|
||||
return res
|
||||
|
||||
@staticmethod
|
||||
def delete(owner=None):
|
||||
logger.info("Deleting storage items")
|
||||
if owner == None:
|
||||
objects = dbStorage.objects.all()
|
||||
if owner is None:
|
||||
objects = dbStorage.objects.all() # @UndefinedVariable
|
||||
else:
|
||||
objects = dbStorage.objects.filter(owner=owner)
|
||||
objects = dbStorage.objects.filter(owner=owner) # @UndefinedVariable
|
||||
objects.delete()
|
||||
|
@ -51,7 +51,7 @@ class UniqueIDGenerator(object):
|
||||
self._baseName = newBaseName
|
||||
|
||||
def __filter(self, rangeStart, rangeEnd=MAX_SEQ):
|
||||
return dbUniqueId.objects.filter(basename=self._baseName, seq__gte=rangeStart, seq__lte=rangeEnd)
|
||||
return dbUniqueId.objects.filter(basename=self._baseName, seq__gte=rangeStart, seq__lte=rangeEnd) # @UndefinedVariable
|
||||
|
||||
def get(self, rangeStart=0, rangeEnd=MAX_SEQ):
|
||||
'''
|
||||
@ -61,11 +61,11 @@ class UniqueIDGenerator(object):
|
||||
# First look for a name in the range defined
|
||||
stamp = getSqlDatetime(True)
|
||||
try:
|
||||
dbUniqueId.objects.lock()
|
||||
dbUniqueId.objects.lock() # @UndefinedVariable
|
||||
flt = self.__filter(rangeStart, rangeEnd)
|
||||
try:
|
||||
item = flt.filter(assigned=False).order_by('seq')[0]
|
||||
dbUniqueId.objects.filter(id=item.id).update(owner=self._owner, assigned=True, stamp=stamp)
|
||||
dbUniqueId.objects.filter(id=item.id).update(owner=self._owner, assigned=True, stamp=stamp) # @UndefinedVariable
|
||||
seq = item.seq
|
||||
except Exception: # No free element found
|
||||
try:
|
||||
@ -76,40 +76,40 @@ class UniqueIDGenerator(object):
|
||||
logger.debug('Found seq {0}'.format(seq))
|
||||
if seq > rangeEnd:
|
||||
return -1 # No ids free in range
|
||||
dbUniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp)
|
||||
dbUniqueId.objects.create(owner=self._owner, basename=self._baseName, seq=seq, assigned=True, stamp=stamp) # @UndefinedVariable
|
||||
return seq
|
||||
except Exception:
|
||||
logger.exception('Generating unique id sequence')
|
||||
return None
|
||||
finally:
|
||||
dbUniqueId.objects.unlock()
|
||||
dbUniqueId.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def transfer(self, seq, toUidGen):
|
||||
try:
|
||||
dbUniqueId.objects.lock()
|
||||
dbUniqueId.objects.lock() # @UndefinedVariable
|
||||
|
||||
obj = dbUniqueId.objects.get(owner=self._owner, seq=seq)
|
||||
obj = dbUniqueId.objects.get(owner=self._owner, seq=seq) # @UndefinedVariable
|
||||
obj.owner = toUidGen._owner
|
||||
obj.basename = toUidGen._baseName
|
||||
obj.stamp = getSqlDatetime(True)
|
||||
obj.save()
|
||||
|
||||
return True
|
||||
except:
|
||||
except Exception:
|
||||
logger.exception('EXCEPTION AT transfer')
|
||||
return False
|
||||
finally:
|
||||
dbUniqueId.objects.unlock()
|
||||
dbUniqueId.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def free(self, seq):
|
||||
try:
|
||||
logger.debug('Freeing seq {0} from {1} ({2})'.format(seq, self._owner, self._baseName))
|
||||
dbUniqueId.objects.lock()
|
||||
dbUniqueId.objects.lock() # @UndefinedVariable
|
||||
flt = self.__filter(0).filter(owner=self._owner, seq=seq).update(owner='', assigned=False, stamp=getSqlDatetime(True))
|
||||
if flt > 0:
|
||||
self.__purge()
|
||||
finally:
|
||||
dbUniqueId.objects.unlock()
|
||||
dbUniqueId.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def __purge(self):
|
||||
try:
|
||||
@ -121,17 +121,17 @@ class UniqueIDGenerator(object):
|
||||
|
||||
def release(self):
|
||||
try:
|
||||
dbUniqueId.objects.lock()
|
||||
dbUniqueId.objects.filter(owner=self._owner).update(assigned=False, owner='', stamp=getSqlDatetime(True))
|
||||
dbUniqueId.objects.lock() # @UndefinedVariable
|
||||
dbUniqueId.objects.filter(owner=self._owner).update(assigned=False, owner='', stamp=getSqlDatetime(True)) # @UndefinedVariable
|
||||
self.__purge()
|
||||
finally:
|
||||
dbUniqueId.objects.unlock()
|
||||
dbUniqueId.objects.unlock() # @UndefinedVariable
|
||||
|
||||
def releaseOlderThan(self, stamp):
|
||||
stamp = getSqlDatetime(True)
|
||||
try:
|
||||
dbUniqueId.objects.lock()
|
||||
dbUniqueId.objects.filter(owner=self._owner, stamp__lt=stamp).update(assigned=False, owner='', stamp=stamp)
|
||||
dbUniqueId.objects.lock() # @UndefinedVariable
|
||||
dbUniqueId.objects.filter(owner=self._owner, stamp__lt=stamp).update(assigned=False, owner='', stamp=stamp) # @UndefinedVariable
|
||||
self.__purge()
|
||||
finally:
|
||||
dbUniqueId.objects.unlock()
|
||||
dbUniqueId.objects.unlock() # @UndefinedVariable
|
||||
|
@ -39,7 +39,7 @@ options:
|
||||
|
||||
-X, --exclude_models
|
||||
exclude specific model(s) from the graph.
|
||||
|
||||
|
||||
-e, --inheritance
|
||||
show inheritance arrows.
|
||||
"""
|
||||
@ -68,12 +68,12 @@ from django.utils.translation import activate as activate_language
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.template import Context, loader
|
||||
from django.db import models
|
||||
from django.db.models import get_models
|
||||
from django.apps import apps as djApps
|
||||
from django.db.models.fields.related import \
|
||||
ForeignKey, OneToOneField, ManyToManyField, RelatedField
|
||||
|
||||
try:
|
||||
from django.db.models.fields.generic import GenericRelation
|
||||
from django.db.models.fields.generic import GenericRelation # pylint: disable=import-error, no-name-in-module
|
||||
except ImportError:
|
||||
from django.contrib.contenttypes.generic import GenericRelation
|
||||
|
||||
@ -81,7 +81,7 @@ except ImportError:
|
||||
def parse_file_or_list(arg):
|
||||
if not arg:
|
||||
return []
|
||||
if not ',' in arg and os.path.isfile(arg):
|
||||
if ',' not in arg and os.path.isfile(arg):
|
||||
return [e.strip() for e in open(arg).readlines()]
|
||||
return arg.split(',')
|
||||
|
||||
@ -129,11 +129,11 @@ digraph name {
|
||||
|
||||
apps = []
|
||||
if all_applications:
|
||||
apps = models.get_apps()
|
||||
apps = djApps.get_apps()
|
||||
|
||||
for app_label in app_labels:
|
||||
app = models.get_app(app_label)
|
||||
if not app in apps:
|
||||
app = djApps.get_app(app_label)
|
||||
if app not in apps:
|
||||
apps.append(app)
|
||||
|
||||
graphs = []
|
||||
@ -147,7 +147,7 @@ digraph name {
|
||||
'models': []
|
||||
})
|
||||
|
||||
appmodels = get_models(app)
|
||||
appmodels = djApps.get_models(app)
|
||||
abstract_models = []
|
||||
for appmodel in appmodels:
|
||||
abstract_models = abstract_models + \
|
||||
|
Loading…
Reference in New Issue
Block a user