Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(token, channel_list, value_list) = re.match("(\w+)/([\w+,]+)/setPropagate/([\d+,]+)/$", webargs).groups()
except Exception as e:
logger.error("Illegal setPropagate request. Wrong format {}. {}".format(webargs, e))
raise NDWSError("Illegal setPropagate request. Wrong format {}. {}".format(webargs, e))
# pattern for using contexts to close databases. get the project
proj = NDProject.fromTokenName(token)
for channel_name in channel_list.split(','):
ch = proj.getChannelObj(channel_name)
value = value_list[0]
# If the value is to be set under propagation and the project is not under propagation
if int(value) == UNDER_PROPAGATION and ch.propagate == NOT_PROPAGATED:
# and is not read only
if ch.readonly == READONLY_FALSE:
ch.propagate = UNDER_PROPAGATION
from sd.tasks import propagate
# then call propagate
propagate(token, channel_name)
#propagate.delay(token, channel_name)
else:
logger.error("Cannot Propagate this project. It is set to Read Only.")
raise NDWSError("Cannot Propagate this project. It is set to Read Only.")
# if the project is Propagated already you can set it to under propagation
elif int(value) == UNDER_PROPAGATION and ch.propagate == PROPAGATED:
logger.error("Cannot propagate a project which is propagated. Set to Not Propagated first.")
raise NDWSError("Cannot propagate a project which is propagated. Set to Not Propagated first.")
# If the value to be set is not propagated
elif int(value) == NOT_PROPAGATED:
# and the project is under propagation then throw an error
if ch.propagate == UNDER_PROPAGATION:
except Exception, e:
logger.error("Missing requred fields.")
return HttpResponseBadRequest("Missing requred fields.")
tk = Token.objects.get(token_name=token_name)
ur = User.objects.get(id=tk.user_id)
pr = Project.objects.get(project_name=tk.project_id)
try:
# Iterating over channel list to store channels
for channel_name in channels:
# Checking if the channel already exists or not
if Channel.objects.get(channel_name = channel_name, project = pr.project_name):
ch = Channel.objects.get(channel_name = channel_name, project = pr.project_name)
# Checking if channel is readonly or not
if ch.readonly == READONLY_FALSE:
# delete channel table using the ndproj interface
pd = NDProjectsDB().getProjDB(pr)
pd.deleteNDChannel(ch.channel_name)
ch.delete()
return HttpResponse("Success. Channels deleted.")
except Exception, e:
logger.error("Error saving models. The channels were not deleted.")
return HttpResponseBadRequest("Error saving models. The channels were not deleted.")
def h5ChannelInfo (proj, h5f):
"""Populate the HDF5 file with chanel information"""
chgrp = h5f.create_group('CHANNELS')
for ch in proj.projectChannels():
changrp = chgrp.create_group(ch.channel_name)
changrp.create_dataset('NAME', (1,), dtype=h5py.special_dtype(vlen=str), data=ch.channel_name)
changrp.create_dataset("TYPE", (1,), dtype=h5py.special_dtype(vlen=str), data=ch.channel_type)
changrp.create_dataset("DATATYPE", (1,), dtype=h5py.special_dtype(vlen=str), data=ch.channel_datatype)
changrp.create_dataset("RESOLUTION", (1,), dtype=np.uint8, data=ch.resolution)
changrp.create_dataset("READONLY", (1,), dtype=bool, data=(False if ch.readonly == READONLY_FALSE else True))
changrp.create_dataset("EXCEPTIONS", (1,), dtype=bool, data=(False if ch.exceptions == EXCEPTION_FALSE else True))
changrp.create_dataset("PROPAGATE", (1,), dtype=np.uint8, data=ch.propagate)
changrp.create_dataset("DEFAULT", (1,), dtype=bool, data=ch.default)
changrp.create_dataset("WINDOWRANGE", data=ch.window_range)
changrp.create_dataset("TIMERANGE", data=ch.time_range)