text stringlengths 81 112k |
|---|
Get all the group items in a network with a given attribute_id
def get_attribute_item_groups(network_id, attr_id, **kwargs):
"""
Get all the group items in a network with a given attribute_id
"""
user_id=kwargs.get('user_id')
network_i = _get_network(network_id)
network_i.check_read_permi... |
Populate attribute groups with items.
** attributegroupitems : a list of items, of the form:
```{
'attr_id' : X,
'group_id' : Y,
'network_id' : Z,
}```
Note that this approach supports the possibility of populat... |
remove attribute groups items .
** attributegroupitems : a list of items, of the form:
```{
'attr_id' : X,
'group_id' : Y,
'network_id' : Z,
}```
def delete_attribute_group_items(attributegroupitems, **kwargs):
"""... |
Share a network with a list of users, identified by their usernames.
The read_only flag ('Y' or 'N') must be set
to 'Y' to allow write access or sharing.
The share flat ('Y' or 'N') must be set to 'Y' to allow the
project to be shared with other users
def share_network(network_id, use... |
Un-Share a network with a list of users, identified by their usernames.
def unshare_network(network_id, usernames,**kwargs):
"""
Un-Share a network with a list of users, identified by their usernames.
"""
user_id = kwargs.get('user_id')
net_i = _get_network(network_id)
net_i.check_share_pe... |
Share an entire project with a list of users, identifed by
their usernames.
The read_only flag ('Y' or 'N') must be set
to 'Y' to allow write access or sharing.
The share flat ('Y' or 'N') must be set to 'Y' to allow the
project to be shared with other users
def share_project(... |
Un-share a project with a list of users, identified by their usernames.
def unshare_project(project_id, usernames,**kwargs):
"""
Un-share a project with a list of users, identified by their usernames.
"""
user_id = kwargs.get('user_id')
proj_i = _get_project(project_id)
proj_i.check_share_... |
Set permissions on a project to a list of users, identifed by
their usernames.
The read flag ('Y' or 'N') sets read access, the write
flag sets write access. If the read flag is 'N', then there is
automatically no write access or share access.
def set_project_permission(project_id, use... |
Set permissions on a network to a list of users, identifed by
their usernames. The read flag ('Y' or 'N') sets read access, the write
flag sets write access. If the read flag is 'N', then there is
automatically no write access or share access.
def set_network_permission(network_id, usernames, r... |
Hide a particular piece of data so it can only be seen by its owner.
Only an owner can hide (and unhide) data.
Data with no owner cannot be hidden.
The exceptions paramater lists the usernames of those with permission to view the data
read, write and share indicate whether these users c... |
Hide a particular piece of data so it can only be seen by its owner.
Only an owner can hide (and unhide) data.
Data with no owner cannot be hidden.
The exceptions paramater lists the usernames of those with permission to view the data
read, write and share indicate whether these users c... |
Get the project owner entries for all the requested projects.
If the project_ids argument is None, return all the owner entries
for ALL projects
def get_all_project_owners(project_ids=None, **kwargs):
"""
Get the project owner entries for all the requested projects.
If the project_i... |
Get the network owner entries for all the requested networks.
If the network_ids argument is None, return all the owner entries
for ALL networks
def get_all_network_owners(network_ids=None, **kwargs):
"""
Get the network owner entries for all the requested networks.
If the network_i... |
Set the project owner of multiple projects at once.
Accepts a list of JSONObjects which look like:
{
'project_id': XX,
'user_id' : YY,
'view' : 'Y'/ 'N'
'edit' : 'Y'/ 'N'
'share' : 'Y'/ 'N'
}
def bulk_set_... |
Set the network owner of multiple networks at once.
Accepts a list of JSONObjects which look like:
{
'network_id': XX,
'user_id' : YY,
'view' : 'Y'/ 'N'
'edit' : 'Y'/ 'N'
'share' : 'Y'/ 'N'
}
def bulk_set_... |
Get a single dataset, by ID
def get_dataset(dataset_id,**kwargs):
"""
Get a single dataset, by ID
"""
user_id = int(kwargs.get('user_id'))
if dataset_id is None:
return None
try:
dataset_rs = db.DBSession.query(Dataset.id,
Dataset.type,
Data... |
Get a single dataset, by ID
def clone_dataset(dataset_id,**kwargs):
"""
Get a single dataset, by ID
"""
user_id = int(kwargs.get('user_id'))
if dataset_id is None:
return None
dataset = db.DBSession.query(Dataset).filter(
Dataset.id==dataset_id).options(joinedload_all... |
Get a single dataset, by ID
def get_datasets(dataset_ids,**kwargs):
"""
Get a single dataset, by ID
"""
user_id = int(kwargs.get('user_id'))
datasets = []
if len(dataset_ids) == 0:
return []
try:
dataset_rs = db.DBSession.query(Dataset.id,
Dataset.type,
... |
Get multiple datasets, based on several
filters. If all filters are set to None, all
datasets in the DB (that the user is allowe to see)
will be returned.
def search_datasets(dataset_id=None,
dataset_name=None,
collection_name=None,
data_type=None... |
Update an existing dataset
def update_dataset(dataset_id, name, data_type, val, unit_id, metadata={}, flush=True, **kwargs):
"""
Update an existing dataset
"""
if dataset_id is None:
raise HydraError("Dataset must have an ID to be updated.")
user_id = kwargs.get('user_id')
datase... |
Data can exist without scenarios. This is the mechanism whereby
single pieces of data can be added without doing it through a scenario.
A typical use of this would be for setting default values on types.
def add_dataset(data_type, val, unit_id=None, metadata={}, name="", user_id=None, flush=False):
... |
Insert lots of datasets at once to reduce the number of DB interactions.
user_id indicates the user adding the data
source indicates the name of the app adding the data
both user_id and source are added as metadata
def _bulk_insert_data(bulk_data, user_id=None, source=None):
"""
Ins... |
Get all the metadata for a given list of datasets
def _get_metadata(dataset_ids):
"""
Get all the metadata for a given list of datasets
"""
metadata = []
if len(dataset_ids) == 0:
return []
if len(dataset_ids) > qry_in_threshold:
idx = 0
extent = qry_in_threshold
... |
Get all the datasets in a list of dataset IDS. This must be done in chunks of 999,
as sqlite can only handle 'in' with < 1000 elements.
def _get_datasets(dataset_ids):
"""
Get all the datasets in a list of dataset IDS. This must be done in chunks of 999,
as sqlite can only handle 'in' with ... |
Get a dataset collection by ID
:param collection ID
def _get_collection(collection_id):
"""
Get a dataset collection by ID
:param collection ID
"""
try:
collection = db.DBSession.query(DatasetCollection).filter(DatasetCollection.id==collection_id).one()
return collec... |
Get a single dataset collection entry by collection ID and dataset ID
:param collection ID
:param dataset ID
def _get_collection_item(collection_id, dataset_id):
"""
Get a single dataset collection entry by collection ID and dataset ID
:param collection ID
:param dataset ID
... |
Add a single dataset to a dataset collection.
def add_dataset_to_collection(dataset_id, collection_id, **kwargs):
"""
Add a single dataset to a dataset collection.
"""
collection_i = _get_collection(collection_id)
collection_item = _get_collection_item(collection_id, dataset_id)
if collecti... |
Add a single dataset to a dataset collection.
def remove_dataset_from_collection(dataset_id, collection_id, **kwargs):
"""
Add a single dataset to a dataset collection.
"""
collection_i = _get_collection(collection_id)
collection_item = _get_collection_item(collection_id, dataset_id)
if col... |
Check whether a dataset is contained inside a collection
:param dataset ID
:param collection ID
:returns 'Y' or 'N'
def check_dataset_in_collection(dataset_id, collection_id, **kwargs):
"""
Check whether a dataset is contained inside a collection
:param dataset ID
:p... |
Get all the datasets from the collection with the specified name
def get_collections_like_name(collection_name,**kwargs):
"""
Get all the datasets from the collection with the specified name
"""
try:
collections = db.DBSession.query(DatasetCollection).filter(DatasetCollection.name.like("%%%... |
Get all the datasets from the collection with the specified name
def get_collection_datasets(collection_id,**kwargs):
"""
Get all the datasets from the collection with the specified name
"""
collection_datasets = db.DBSession.query(Dataset).filter(Dataset.id==DatasetCollectionItem.dataset_id,
... |
Given a timestamp (or list of timestamps) and some timeseries data,
return the values appropriate to the requested times.
If the timestamp is before the start of the timeseries data, return
None If the timestamp is after the end of the timeseries data, return
the last value.
def get_val_at_time(datase... |
Given a timestamp (or list of timestamps) and a list of timeseries datasets,
return the values appropriate to the requested times.
If the timestamp is before the start of the timeseries data, return
None If the timestamp is after the end of the timeseries data, return
the last value.
def get_multiple_... |
Retrive data between two specified times within a timeseries. The times
need not be specified in the timeseries. This function will 'fill in the blanks'.
Two types of data retrieval can be done.
If the timeseries is timestamp-based, then start_time and end_time
must be datetimes and ti... |
Removes a piece of data from the DB.
CAUTION! Use with care, as this cannot be undone easily.
def delete_dataset(dataset_id,**kwargs):
"""
Removes a piece of data from the DB.
CAUTION! Use with care, as this cannot be undone easily.
"""
try:
d = db.DBSession.query(Dataset).f... |
Get all the notes for a resource, identifed by ref_key and ref_ido.
Returns [] if no notes are found or if the resource doesn't exist.
def get_notes(ref_key, ref_id, **kwargs):
"""
Get all the notes for a resource, identifed by ref_key and ref_ido.
Returns [] if no notes are found or if the... |
Add a new note
def add_note(note, **kwargs):
"""
Add a new note
"""
note_i = Note()
note_i.ref_key = note.ref_key
note_i.set_ref(note.ref_key, note.ref_id)
note_i.value = note.value
note_i.created_by = kwargs.get('user_id')
db.DBSession.add(note_i)
db.DBSession.flush()
... |
Update a note
def update_note(note, **kwargs):
"""
Update a note
"""
note_i = _get_note(note.id)
if note.ref_key != note_i.ref_key:
raise HydraError("Cannot convert a %s note to a %s note. Please create a new note instead."%(note_i.ref_key, note.ref_key))
note_i.set_ref(note.ref_key, ... |
Remove a note from the DB permenantly
def purge_note(note_id, **kwargs):
"""
Remove a note from the DB permenantly
"""
note_i = _get_note(note_id)
db.DBSession.delete(note_i)
db.DBSession.flush() |
Login a user, returning a dict containing their user_id and session_id
This does the DB login to check the credentials, and then creates a session
so that requests from apps do not need to perform a login
args:
username (string): The user's username
password(string): Th... |
Logout a user, removing their cookie if it exists and returning 'OK'
args:
session_id (string): The session ID to identify the cookie to remove
returns:
'OK'
raises:
HydraError if the logout fails
def logout(session_id, **kwargs):
"""
Logout a u... |
Given a session ID, get the user ID that it is associated with
args:
session_id (string): The user's ID to identify the cookie to remove
returns:
user_id (string) or None if the session does not exist
def get_session_user(session_id, **kwargs):
"""
Given a session ... |
Return the size of a multidimansional array.
def array_dim(arr):
"""Return the size of a multidimansional array.
"""
dim = []
while True:
try:
dim.append(len(arr))
arr = arr[0]
except TypeError:
return dim |
Check to ensure arrays are symmetrical, for example:
[[1, 2, 3], [1, 2]] is invalid
def check_array_struct(array):
"""
Check to ensure arrays are symmetrical, for example:
[[1, 2, 3], [1, 2]] is invalid
"""
#If a list is transformed into a numpy array and the sub elements
#of t... |
Reshape a multidimensional array to a vector.
def arr_to_vector(arr):
"""Reshape a multidimensional array to a vector.
"""
dim = array_dim(arr)
tmp_arr = []
for n in range(len(dim) - 1):
for inner in arr:
for i in inner:
tmp_arr.append(i)
arr = tmp_arr
... |
Reshape a vector to a multidimensional array with dimensions 'dim'.
def vector_to_arr(vec, dim):
"""Reshape a vector to a multidimensional array with dimensions 'dim'.
"""
if len(dim) <= 1:
return vec
array = vec
while len(dim) > 1:
i = 0
outer_array = []
for m in ra... |
Get the value(s) of a dataset as a single value or as 1-d list of
values. In the special case of timeseries, when a check is for time-based
criteria, you can return the entire timeseries.
def _get_val(val, full=False):
"""
Get the value(s) of a dataset as a single value or as 1-d list of
... |
turn:
::
<restrictions>
<restriction>
<type>MAXLEN</type>
<value>3</value>
</restriction>
<restriction>
<type>VALUERANGE</type>
<value><item>1</item><item>10</item></value>
... |
Test to ensure that the given value is contained in the provided list.
the value parameter must be either a single value or a 1-dimensional list.
All the values in this list must satisfy the ENUM
def validate_ENUM(in_value, restriction):
"""
Test to ensure that the given value is contained ... |
the value parameter must be either a single value or a 1-dimensional list.
All the values in this list must satisfy the condition
def validate_NUMPLACES(in_value, restriction):
"""
the value parameter must be either a single value or a 1-dimensional list.
All the values in this list must sa... |
Test to ensure that a value sits between a lower and upper bound.
Parameters: A Decimal value and a tuple, containing a lower and upper bound,
both as Decimal values.
def validate_VALUERANGE(in_value, restriction):
"""
Test to ensure that a value sits between a lower and upper bound.
... |
Test to ensure that the times in a timeseries fall between a lower and upper bound
Parameters: A timeseries in the form [(datetime, val), (datetime, val)..]
and a tuple containing the lower and upper bound as datetime objects.
def validate_DATERANGE(value, restriction):
"""
Test to ensure t... |
Test to ensure that a list has the prescribed length.
Parameters: A list and an integer, which defines the required length of
the list.
def validate_MAXLEN(value, restriction):
"""
Test to ensure that a list has the prescribed length.
Parameters: A list and an integer, which defines... |
Test to ensure that a value is less than a prescribed value.
Parameter: Two values, which will be compared for the difference..
def validate_LESSTHAN(in_value, restriction):
"""
Test to ensure that a value is less than a prescribed value.
Parameter: Two values, which will be compared for th... |
Test to ensure that a value is less than or equal to a prescribed value.
Parameter: Two values, which will be compared for the difference..
def validate_LESSTHANEQ(value, restriction):
"""
Test to ensure that a value is less than or equal to a prescribed value.
Parameter: Two values, which ... |
Test to ensure the values of a list sum to a specified value:
Parameters: a list of numeric values and a target to which the values
in the list must sum
def validate_SUMTO(in_value, restriction):
"""
Test to ensure the values of a list sum to a specified value:
Parameters: a list of... |
Test to ensure the values in a list are increasing.
Parameters: a list of values and None. The none is there simply
to conform with the rest of the validation routines.
def validate_INCREASING(in_value, restriction):
"""
Test to ensure the values in a list are increasing.
Parameters... |
Ensure that the timesteps in a timeseries are equal. If a restriction
is provided, they must be equal to the specified restriction.
Value is a pandas dataframe.
def validate_EQUALTIMESTEPS(value, restriction):
"""
Ensure that the timesteps in a timeseries are equal. If a restriction
... |
1: Turn a multi-dimensional array into a 1-dimensional array
2: Turn a timeseries of values into a single 1-dimensional array
def _flatten_value(value):
"""
1: Turn a multi-dimensional array into a 1-dimensional array
2: Turn a timeseries of values into a single 1-dimensional array
"""
... |
Count how many levels are in a dict:
scalar, list etc = 0
{} = 0
{'a':1} = 1
{'a' : {'b' : 1}} = 2
etc...
def count_levels(value):
"""
Count how many levels are in a dict:
scalar, list etc = 0
{} = 0
{'a':1} = 1
{'a' : {'b' : 1}} = 2
... |
Take a hashtable with multiple nested dicts and return a
dict where the keys are a concatenation of each sub-key.
The depth of the returned array is dictated by target_depth, defaulting to 1
ex: {'a' : {'b':1, 'c': 2}} ==> {'a_b': 1, 'a_c': 2}
Assumes a constant structure actoss all s... |
Convert a sqlalchemy object into a named tuple
def to_named_tuple(keys, values):
"""
Convert a sqlalchemy object into a named tuple
"""
values = [dbobject.__dict__[key] for key in dbobject.keys()]
tuple_object = namedtuple('DBObject', dbobject.keys())
tuple_instance = tuple_object._make(... |
Turn the string value of a dataset into an appropriate
value, be it a decimal value, array or time series.
If a timestamp is passed to this function,
return the values appropriate to the requested times.
If the timestamp is *before* the start of the timeseries data, return None
... |
Take a dict or string and return a string.
The dict will be json dumped.
The string will json parsed to check for json validity. In order to deal
with strings which have been json encoded multiple times, keep json decoding
until a dict is retrieved or until a non-json structure is identi... |
Take a dict or string and return a dict if the data is json-encoded.
The string will json parsed to check for json validity. In order to deal
with strings which have been json encoded multiple times, keep json decoding
until a dict is retrieved or until a non-json structure is identified.
def g... |
Return the username of a given user_id
def get_username(uid,**kwargs):
"""
Return the username of a given user_id
"""
rs = db.DBSession.query(User.username).filter(User.id==uid).one()
if rs is None:
raise ResourceNotFoundError("User with ID %s not found"%uid)
return rs.username |
Return a list of usernames like the given string.
def get_usernames_like(username,**kwargs):
"""
Return a list of usernames like the given string.
"""
checkname = "%%%s%%"%username
rs = db.DBSession.query(User.username).filter(User.username.like(checkname)).all()
return [r.username for r in... |
Add a user
def add_user(user, **kwargs):
"""
Add a user
"""
#check_perm(kwargs.get('user_id'), 'add_user')
u = User()
u.username = user.username
u.display_name = user.display_name
user_id = _get_user_id(u.username)
#If the user is already there, cannot add another with
... |
Update a user's display name
def update_user_display_name(user,**kwargs):
"""
Update a user's display name
"""
#check_perm(kwargs.get('user_id'), 'edit_user')
try:
user_i = db.DBSession.query(User).filter(User.id==user.id).one()
user_i.display_name = user.display_name
re... |
Update a user's password
def update_user_password(new_pwd_user_id, new_password,**kwargs):
"""
Update a user's password
"""
#check_perm(kwargs.get('user_id'), 'edit_user')
try:
user_i = db.DBSession.query(User).filter(User.id==new_pwd_user_id).one()
user_i.password = bcrypt.hash... |
Get a user by ID
def get_user(uid, **kwargs):
"""
Get a user by ID
"""
user_id=kwargs.get('user_id')
if uid is None:
uid = user_id
user_i = _get_user(uid)
return user_i |
Get a user by username
def get_user_by_name(uname,**kwargs):
"""
Get a user by username
"""
try:
user_i = db.DBSession.query(User).filter(User.username==uname).one()
return user_i
except NoResultFound:
return None |
Get a user by username
def get_user_by_id(uid,**kwargs):
"""
Get a user by username
"""
user_id = kwargs.get('user_id')
try:
user_i = _get_user(uid)
return user_i
except NoResultFound:
return None |
Delete a user
def delete_user(deleted_user_id,**kwargs):
"""
Delete a user
"""
#check_perm(kwargs.get('user_id'), 'edit_user')
try:
user_i = db.DBSession.query(User).filter(User.id==deleted_user_id).one()
db.DBSession.delete(user_i)
except NoResultFound:
raise Resour... |
Add a new role
def add_role(role,**kwargs):
"""
Add a new role
"""
#check_perm(kwargs.get('user_id'), 'add_role')
role_i = Role(name=role.name, code=role.code)
db.DBSession.add(role_i)
db.DBSession.flush()
return role_i |
Delete a role
def delete_role(role_id,**kwargs):
"""
Delete a role
"""
#check_perm(kwargs.get('user_id'), 'edit_role')
try:
role_i = db.DBSession.query(Role).filter(Role.id==role_id).one()
db.DBSession.delete(role_i)
except InvalidRequestError:
raise ResourceNotFound... |
Add a permission
def add_perm(perm,**kwargs):
"""
Add a permission
"""
#check_perm(kwargs.get('user_id'), 'add_perm')
perm_i = Perm(name=perm.name, code=perm.code)
db.DBSession.add(perm_i)
db.DBSession.flush()
return perm_i |
Delete a permission
def delete_perm(perm_id,**kwargs):
"""
Delete a permission
"""
#check_perm(kwargs.get('user_id'), 'edit_perm')
try:
perm_i = db.DBSession.query(Perm).filter(Perm.id==perm_id).one()
db.DBSession.delete(perm_i)
except InvalidRequestError:
raise Res... |
Apply `role_id` to `new_user_id`
Note this function returns the `Role` instance associated with `role_id`
def set_user_role(new_user_id, role_id, **kwargs):
"""
Apply `role_id` to `new_user_id`
Note this function returns the `Role` instance associated with `role_id`
"""
#check_per... |
Remove a user from a role
def delete_user_role(deleted_user_id, role_id,**kwargs):
"""
Remove a user from a role
"""
#check_perm(kwargs.get('user_id'), 'edit_role')
try:
_get_user(deleted_user_id)
_get_role(role_id)
roleuser_i = db.DBSession.query(RoleUser).filter(RoleUs... |
Insert a permission into a role
def set_role_perm(role_id, perm_id,**kwargs):
"""
Insert a permission into a role
"""
#check_perm(kwargs.get('user_id'), 'edit_perm')
_get_perm(perm_id)
role_i = _get_role(role_id)
roleperm_i = RolePerm(role_id=role_id, perm_id=perm_id)
role_i.rolep... |
Remove a permission from a role
def delete_role_perm(role_id, perm_id,**kwargs):
"""
Remove a permission from a role
"""
#check_perm(kwargs.get('user_id'), 'edit_perm')
_get_perm(perm_id)
_get_role(role_id)
try:
roleperm_i = db.DBSession.query(RolePerm).filter(RolePerm.role_id=... |
Update the role.
Used to add permissions and users to a role.
def update_role(role,**kwargs):
"""
Update the role.
Used to add permissions and users to a role.
"""
#check_perm(kwargs.get('user_id'), 'edit_role')
try:
role_i = db.DBSession.query(Role).filter(Role.id==role... |
Get the username & ID of all users.
Use the the filter if it has been provided
The filter has to be a list of values
def get_all_users(**kwargs):
"""
Get the username & ID of all users.
Use the the filter if it has been provided
The filter has to be a list of values
"""
... |
Get a role by its ID.
def get_role(role_id,**kwargs):
"""
Get a role by its ID.
"""
try:
role = db.DBSession.query(Role).filter(Role.id==role_id).one()
return role
except NoResultFound:
raise HydraError("Role not found (role_id={})".format(role_id)) |
Get the roles for a user.
@param user_id
def get_user_roles(uid,**kwargs):
"""
Get the roles for a user.
@param user_id
"""
try:
user_roles = db.DBSession.query(Role).filter(Role.id==RoleUser.role_id,
RoleUser.user_id==uid).a... |
Get the roles for a user.
@param user_id
def get_user_permissions(uid, **kwargs):
"""
Get the roles for a user.
@param user_id
"""
try:
_get_user(uid)
user_perms = db.DBSession.query(Perm).filter(Perm.id==RolePerm.perm_id,
... |
Get a role by its code
def get_role_by_code(role_code,**kwargs):
"""
Get a role by its code
"""
try:
role = db.DBSession.query(Role).filter(Role.code==role_code).one()
return role
except NoResultFound:
raise ResourceNotFoundError("Role not found (role_code={})".format(ro... |
Get all permissions
def get_perm(perm_id,**kwargs):
"""
Get all permissions
"""
try:
perm = db.DBSession.query(Perm).filter(Perm.id==perm_id).one()
return perm
except NoResultFound:
raise ResourceNotFoundError("Permission not found (perm_id={})".format(perm_id)) |
Get a permission by its code
def get_perm_by_code(perm_code,**kwargs):
"""
Get a permission by its code
"""
try:
perm = db.DBSession.query(Perm).filter(Perm.code==perm_code).one()
return perm
except NoResultFound:
raise ResourceNotFoundError("Permission not found (perm_... |
Builds a dataframe from the value
def _create_dataframe(cls, value):
"""
Builds a dataframe from the value
"""
try:
ordered_jo = json.loads(six.text_type(value), object_pairs_hook=collections.OrderedDict)
#Pandas does not maintain the order of dicts, so we ... |
Turn the value of an incoming dataset into a hydra-friendly value.
def parse_value(self):
"""
Turn the value of an incoming dataset into a hydra-friendly value.
"""
try:
if self.value is None:
log.warning("Cannot parse dataset. No value specified.")
... |
Convert a metadata json string into a dictionary.
Args:
user_id (int): Optional: Insert user_id into the metadata if specified
source (string): Optional: Insert source (the name of the app typically) into the metadata if necessary.
Returns:
dict: THe metadata as a p... |
Add a new group to a network.
def add_resourcegroup(group, network_id,**kwargs):
"""
Add a new group to a network.
"""
group_i = ResourceGroup()
group_i.name = group.name
group_i.description = group.description
group_i.status = group.statu... |
Add a new group to a scenario.
def delete_resourcegroup(group_id,**kwargs):
"""
Add a new group to a scenario.
"""
group_i = _get_group(group_id)
#This should cascaded to delete all the group items.
db.DBSession.delete(group_i)
db.DBSession.flush()
return 'OK' |
Add a new group to a network.
def update_resourcegroup(group,**kwargs):
"""
Add a new group to a network.
"""
group_i = _get_group(group.id)
group_i.name = group.name
group_i.description = group.description
group_i.status = group.status
db.D... |
return an inspector object
def create_sqlite_backup_db(audit_tables):
"""
return an inspector object
"""
#we always want to create a whole new DB, so delete the old one first
#if it exists.
try:
Popen("rm %s"%(config.get('sqlite', 'backup_url')), shell=True)
logging.warn("Ol... |
Is the specified user an admin
def _is_admin(user_id):
"""
Is the specified user an admin
"""
user = get_session().query(User).filter(User.id==user_id).one()
if user.is_admin():
return True
else:
return False |
Set the metadata on a dataset
**metadata_dict**: A dictionary of metadata key-vals.
Transforms this dict into an array of metadata objects for
storage in the DB.
def set_metadata(self, metadata_dict):
"""
Set the metadata on a dataset
**metadata_dic... |
Check whether this user can read this dataset
def check_user(self, user_id):
"""
Check whether this user can read this dataset
"""
if self.hidden == 'N':
return True
for owner in self.owners:
if int(owner.user_id) == int(user_id):
if... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.