output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
def set_link_status(link_id, status, **kwargs):
"""
Set the status of a link
"""
user_id = kwargs.get('user_id')
#check_perm(user_id, 'edit_topology')
try:
link_i = db.DBSession.query(Link).filter(Link.id == link_id).one()
except NoResultFound:
raise ResourceNotFoundError... | Write a Python 3 script to
set the status of a link. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Delete a link from DB completely | Can you generate the documentation for the following Python 3 function
def delete_link(link_id, purge_data,**kwargs):
user_id = kwargs.get('user_id')
try:
link_i = db.DBSession.query(Link).filter(Link.id == link_id).one()
except NoResultFound:
raise ResourceNotFoundError("Link %s not found"%... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def add_group(network_id, group,**kwargs):
"""
Add a resourcegroup to a network
"""
user_id = kwargs.get('user_id')
try:
net_i = db.DBSession.query(Network).filter(Network.id == network_id).one()
net_i.check_write_permission(user_id=user_id)
except NoResultFound:
rai... | Implement a Python 3 function for
adding a resourcegroup to a network | You are a Python code architect, reviewing and designing scalable and efficient code |
def update_group(group,**kwargs):
"""
Update a group.
If new attributes are present, they will be added to the group.
The non-presence of attributes does not remove them.
"""
user_id = kwargs.get('user_id')
try:
group_i = db.DBSession.query(ResourceGroup).filter(ResourceG... | Write a Python 3 script to
update a group. If new attributes are present, they will be added to the group. The non-presence of attributes does not remove them. | You are a Python code architect, reviewing and designing scalable and efficient code |
Set the status of a group to X | Make a summary of the following Python 3 code
def set_group_status(group_id, status, **kwargs):
user_id = kwargs.get('user_id')
try:
group_i = db.DBSession.query(ResourceGroup).filter(ResourceGroup.id == group_id).one()
except NoResultFound:
raise ResourceNotFoundError("ResourceGroup %s not ... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Delete group from DB completely | Make a summary of the following Python 3 code
def delete_group(group_id, purge_data,**kwargs):
user_id = kwargs.get('user_id')
try:
group_i = db.DBSession.query(ResourceGroup).filter(ResourceGroup.id == group_id).one()
except NoResultFound:
raise ResourceNotFoundError("Group %s not found"%(g... | You are a Python code generator, capable of creating scripts from specifications. |
Get all the scenarios in a given network. | Can you generate the documentation for the following Python 3 function
def get_scenarios(network_id,**kwargs):
user_id = kwargs.get('user_id')
try:
net_i = db.DBSession.query(Network).filter(Network.id == network_id).one()
net_i.check_read_permission(user_id=user_id)
except NoResultFound:
... | You are a Python code generator, capable of creating scripts from specifications. |
Validate that the network topology is valid. | Here you have a function in Python 3, explain what it does
def validate_network_topology(network_id,**kwargs):
user_id = kwargs.get('user_id')
try:
net_i = db.DBSession.query(Network).filter(Network.id == network_id).one()
net_i.check_write_permission(user_id=user_id)
except NoResultFound:
... | As a python code expert, you are capable of creating scripts from specifications. |
Get the nodes links and resource groups which have the type specified. | Here you have a function in Python 3, explain what it does
def get_resources_of_type(network_id, type_id, **kwargs):
nodes_with_type = db.DBSession.query(Node).join(ResourceType).filter(Node.network_id==network_id, ResourceType.type_id==type_id).all()
links_with_type = db.DBSession.query(Link).join(ResourceTyp... | As a Python code composer, you craft elegant and concise scripts. |
Delete any deleted nodes links resourcegroups and scenarios in a given network | Here you have a function in Python 3, explain what it does
def clean_up_network(network_id, **kwargs):
user_id = kwargs.get('user_id')
#check_perm(user_id, 'delete_network')
try:
log.debug("Querying Network %s", network_id)
net_i = db.DBSession.query(Network).filter(Network.id == network_id)... | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_all_resource_attributes_in_network(attr_id, network_id, **kwargs):
"""
Find every resource attribute in the network matching the supplied attr_id
"""
user_id = kwargs.get('user_id')
try:
a = db.DBSession.query(Attr).filter(Attr.id == attr_id).one()
except NoResultFound:
... | How would you code a function in Python 3 to
get all resource attributes in a network. | As a Python code composer, you craft elegant and concise scripts. |
Clone a network with the specified name and project. | Here you have a function in Python 3, explain what it does
def clone_network(network_id, recipient_user_id=None, new_network_name=None, project_id=None, project_name=None, new_project=True, **kwargs):
user_id = kwargs['user_id']
ex_net = db.DBSession.query(Network).filter(Network.id==network_id).one()
e... | You are a Python code analyst, evaluating scripts for potential improvements. |
def copy_data_from_scenario(resource_attrs, source_scenario_id, target_scenario_id, **kwargs):
"""
For a given list of resource attribute IDS copy the dataset_ids from
the resource scenarios in the source scenario to those in the 'target' scenario.
"""
#Get all the resource scenarios we wis... | Implement a function in Python 3 to
copy data from source to target scenario. | You are a Python code generator, capable of creating scripts from specifications. |
def get_scenario(scenario_id,**kwargs):
"""
Get the specified scenario
"""
user_id = kwargs.get('user_id')
scen_i = _get_scenario(scenario_id, user_id)
scen_j = JSONObject(scen_i)
rscen_rs = db.DBSession.query(ResourceScenario).filter(ResourceScenario.scenario_id==scenario_id).options... | How would you implement a function in Python 3 that
gets the specified scenario | You are a Python code generator, capable of creating scripts from specifications. |
Add a scenario to a network. | Can you tell what is the following Python 3 function doing
def add_scenario(network_id, scenario,**kwargs):
user_id = int(kwargs.get('user_id'))
log.info("Adding scenarios to network")
_check_network_ownership(network_id, user_id)
existing_scen = db.DBSession.query(Scenario).filter(Scenario.name==scen... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def update_scenario(scenario,update_data=True,update_groups=True,flush=True,**kwargs):
"""
Update a single scenario
as all resources already exist, there is no need to worry
about negative IDS
flush = True flushes to the DB at the end of the function.
flush = False does not ... | Write a Python 3 script to
update a single scenario in the DB. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Set the status of a scenario. | Here you have a function in Python 3, explain what it does
def set_scenario_status(scenario_id, status, **kwargs):
user_id = kwargs.get('user_id')
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
scenario_i = _get_scenario(scenario_id, user_id)
scenario_i.status = status
db.DBSession.flu... | You are a Python code architect, reviewing and designing scalable and efficient code |
def purge_scenario(scenario_id, **kwargs):
"""
Set the status of a scenario.
"""
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
user_id = kwargs.get('user_id')
scenario_i = _get_scenario(scenario_id, user_id)
db.DBSession.delete(scenario_i)
db.DBSession.flush()
retu... | Write a Python 3 script to
set the status of a scenario. | You are a Python code generator, capable of creating scripts from specifications. |
def _get_as_obj(obj_dict, name):
"""
Turn a dictionary into a named tuple so it can be
passed into the constructor of a complex model generator.
"""
if obj_dict.get('_sa_instance_state'):
del obj_dict['_sa_instance_state']
obj = namedtuple(name, tuple(obj_dict.keys()))
for k,... | Write a Python 3 function that can
turn a dictionary into a named tuple so it can be passed into the constructor of a complex model generator. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Get the resource scenario object for a given resource attribute and scenario. | Can you generate a brief explanation for the following Python 3 code
def get_resource_scenario(resource_attr_id, scenario_id, **kwargs):
user_id = kwargs.get('user_id')
_get_scenario(scenario_id, user_id)
try:
rs = db.DBSession.query(ResourceScenario).filter(ResourceScenario.resource_attr_id==reso... | You are a Python code architect, reviewing and designing scalable and efficient code |
Bulk update the data associated with a list of scenarios. | Here you have a function in Python 3, explain what it does
def bulk_update_resourcedata(scenario_ids, resource_scenarios,**kwargs):
user_id = kwargs.get('user_id')
res = None
res = {}
net_ids = db.DBSession.query(Scenario.network_id).filter(Scenario.id.in_(scenario_ids)).all()
if len(set(net_ids)... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Update the data associated with a resource scenario. | Can you generate the documentation for the following Python 3 function
def update_resourcedata(scenario_id, resource_scenarios,**kwargs):
user_id = kwargs.get('user_id')
res = None
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
scen_i = _get_scenario(scenario_id, user_id)
res = []
f... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def delete_resource_scenario(scenario_id, resource_attr_id, quiet=False, **kwargs):
"""
Remove the data associated with a resource in a scenario.
"""
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
_delete_resourcescenario(scenario_id, resource_attr_id, suppress_error=quiet) | Can you create a Python 3 function that
deletes the data associated with a resource in a scenario. | You are a Python code analyst, evaluating scripts for potential improvements. |
Delete the data associated with a resource in a scenario. | Here you have a function in Python 3, explain what it does
def delete_resourcedata(scenario_id, resource_scenario, quiet = False, **kwargs):
_check_can_edit_scenario(scenario_id, kwargs['user_id'])
_delete_resourcescenario(scenario_id, resource_scenario.resource_attr_id, suppress_error=quiet) | You are a Python code analyst, evaluating scripts for potential improvements. |
def _update_resourcescenario(scenario, resource_scenario, dataset=None, new=False, user_id=None, source=None):
"""
Insert or Update the value of a resource's attribute by first getting the
resource, then parsing the input data, then assigning the value.
returns a ResourceScenario object.
... | How would you code a function in Python 3 to
update the value of a resource attribute in a scenario. | You are a Python code analyst, evaluating scripts for potential improvements. |
Assign a value to a resource in a scenario. | Explain what the following Python 3 code does
def assign_value(rs, data_type, val,
unit_id, name, metadata={}, data_hash=None, user_id=None, source=None):
"""
Insert or update a piece of data in a scenario.
If the dataset is being shared by other resource scenarios, a new dataset is... | As a Python code composer, you craft elegant and concise scripts. |
Add data to a resource scenario in a network update the resource scenario | Can you generate the documentation for the following Python 3 function
def add_data_to_attribute(scenario_id, resource_attr_id, dataset,**kwargs):
user_id = kwargs.get('user_id')
_check_can_edit_scenario(scenario_id, user_id)
scenario_i = _get_scenario(scenario_id, user_id)
try:
r_scen_i = db... | As a python code expert, you are capable of creating scripts from specifications. |
def get_scenario_data(scenario_id,**kwargs):
"""
Get all the datasets from the group with the specified name
@returns a list of dictionaries
"""
user_id = kwargs.get('user_id')
scenario_data = db.DBSession.query(Dataset).filter(Dataset.id==ResourceScenario.dataset_id, ResourceScenario.s... | Can you implement a function in Python 3 that
gets all the datasets from the group with the specified name AttributeNames | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_attribute_data(attr_ids, node_ids, **kwargs):
"""
For a given attribute or set of attributes, return all the resources and
resource scenarios in the network
"""
node_attrs = db.DBSession.query(ResourceAttr).\
options(joinedload_all('attr')... | Write a Python 3 function for
getting all the resources and resource scenarios for a given attribute or set of attributes. | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_resource_data(ref_key, ref_id, scenario_id, type_id=None, expunge_session=True, **kwargs):
"""
Get all the resource scenarios for a given resource
in a given scenario. If type_id is specified, only
return the resource scenarios for the attributes
within the type.
"""
... | Create a Python 3 function to
get all the resource scenarios for a given ref_key in a given scenario. | You are a Python code generator, capable of creating scripts from specifications. |
Retrieve all the datasets in a scenario for a given attribute. | How would you explain what the following Python 3 function does
def get_attribute_datasets(attr_id, scenario_id, **kwargs):
user_id = kwargs.get('user_id')
scenario_i = _get_scenario(scenario_id, user_id)
try:
a = db.DBSession.query(Attr).filter(Attr.id == attr_id).one()
except NoResultFound:... | As a Python code analyst, you investigate and solve complex coding mysteries |
Get all the items in a group in a scenario. | Explain what the following Python 3 code does
def get_resourcegroupitems(group_id, scenario_id, **kwargs):
"""
Get all the items in a group, in a scenario. If group_id is None, return
all items across all groups in the scenario.
"""
rgi_qry = db.DBSession.query(ResourceGroupItem).\
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def delete_resourcegroupitems(scenario_id, item_ids, **kwargs):
"""
Delete specified items in a group, in a scenario.
"""
user_id = int(kwargs.get('user_id'))
#check the scenario exists
_get_scenario(scenario_id, user_id)
for item_id in item_ids:
rgi = db.DBSession.query(Resource... | Implement a Python 3 function for
deleting specified items in a group in a scenario. | As a Python code analyst, you investigate and solve complex coding mysteries |
def empty_group(group_id, scenario_id, **kwargs):
"""
Delete all itemas in a group, in a scenario.
"""
user_id = int(kwargs.get('user_id'))
#check the scenario exists
_get_scenario(scenario_id, user_id)
rgi = db.DBSession.query(ResourceGroupItem).\
filter(ResourceGroupItem.g... | Can you write a function in Python 3 where it
deletes all itemas in a group in a scenario. | As a Python code analyst, you investigate and solve complex coding mysteries |
Add items to a group in a scenario. | How would you explain what the following Python 3 function does
def add_resourcegroupitems(scenario_id, items, scenario=None, **kwargs):
"""
Get all the items in a group, in a scenario.
"""
user_id = int(kwargs.get('user_id'))
if scenario is None:
scenario = _get_scenario(scenario_id, ... | You are a Python code architect, reviewing and designing scalable and efficient code |
Add a resource group item to the database. | Can you tell what is the following Python 3 function doing
def _add_resourcegroupitem(group_item, scenario_id):
if group_item.id and group_item.id > 0:
try:
group_item_i = db.DBSession.query(ResourceGroupItem).filter(ResourceGroupItem.id == group_item.id).one()
except NoResultFound:
... | As a Python code analyst, you investigate and solve complex coding mysteries |
def update_value_from_mapping(source_resource_attr_id, target_resource_attr_id, source_scenario_id, target_scenario_id, **kwargs):
"""
Using a resource attribute mapping, take the value from the source and apply
it to the target. Both source and target scenarios must be specified (and therefor
... | Write a Python 3 script to
update the value of a resource attribute mapping between two scenarios. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get_plugins(**kwargs):
"""
Get all available plugins
"""
plugins = []
plugin_paths = []
#Look in directory or set of directories for
#plugins
base_plugin_dir = config.get('plugin', 'default_directory')
plugin_xsd_path = config.get('plugin', 'plugin_xsd_path')
... | Write a Python 3 function for
getting all available plugins and their details. | As a Python code analyst, you investigate and solve complex coding mysteries |
Run a plugin and return the pid | Make a summary of the following Python 3 code
def run_plugin(plugin,**kwargs):
args = [sys.executable]
#Get plugin executable
home = os.path.expanduser('~')
path_to_plugin = os.path.join(home, 'svn/HYDRA/HydraPlugins', plugin.location)
args.append(path_to_plugin)
#Parse plugin argument... | As a Python code composer, you craft elegant and concise scripts. |
This function loads a config file in the order of the file names. | Explain what the following Python 3 code does
def load_config():
global localfiles
global localfile
global repofile
global repofiles
global userfile
global userfiles
global sysfile
global sysfiles
global CONFIG
logging.basicConfig(level='INFO')
config = ConfigParser.ConfigPa... | You are a Python code generator, capable of creating scripts from specifications. |
Create a mysql database if it doesn t exist. | Can you generate the documentation for the following Python 3 function
def create_mysql_db(db_url):
#Remove trailing whitespace and forwardslashes
db_url = db_url.strip().strip('/')
#Check this is a mysql URL
if db_url.find('mysql') >= 0:
#Get the DB name from config and check if it's in th... | You are a Python code architect, reviewing and designing scalable and efficient code |
Add a new project returns a project object | Here you have a function in Python 3, explain what it does
def add_project(project,**kwargs):
user_id = kwargs.get('user_id')
existing_proj = get_project_by_name(project.name,user_id=user_id)
if len(existing_proj) > 0:
raise HydraError("A Project with the name \"%s\" already exists"%(project.name,... | As a Python code composer, you craft elegant and concise scripts. |
def update_project(project,**kwargs):
"""
Update a project
returns a project complexmodel
"""
user_id = kwargs.get('user_id')
#check_perm(user_id, 'update_project')
proj_i = _get_project(project.id)
proj_i.check_write_permission(user_id)
proj_i.name = project.name
... | How would you code a function in Python 3 to
update a project Returns a project | You are a Python code analyst, evaluating scripts for potential improvements. |
get a project complexmodel | Can you generate the documentation for the following Python 3 function
def get_project(project_id, include_deleted_networks=False, **kwargs):
user_id = kwargs.get('user_id')
proj_i = _get_project(project_id)
#lazy load owners
proj_i.owners
proj_i.check_read_permission(user_id)
proj_j = JSONOb... | As a python code expert, you are capable of creating scripts from specifications. |
get a project by a network_id | Given the following Python 3 function, write the documentation
def get_project_by_network_id(network_id,**kwargs):
user_id = kwargs.get('user_id')
projects_i = db.DBSession.query(Project).join(ProjectOwner).join(Network, Project.id==Network.project_id).filter(
... | As a Python code translator, you convert algorithms and pseudocode into Python. |
get a project by name | Make a summary of the following Python 3 code
def get_project_by_name(project_name,**kwargs):
user_id = kwargs.get('user_id')
projects_i = db.DBSession.query(Project).join(ProjectOwner).filter(
Project.name==project_name,
... | As a Python code composer, you craft elegant and concise scripts. |
def to_named_tuple(obj, visited_children=None, back_relationships=None, levels=None, ignore=[], extras={}):
"""
Altered from an example found on stackoverflow
http://stackoverflow.com/questions/23554119/convert-sqlalchemy-orm-result-to-dict
"""
if visited_children is None:
visited_c... | Can you create a Python 3 function that
converts SQLAlchemy object to a named tuple. | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_projects(uid, include_shared_projects=True, projects_ids_list_filter=None, **kwargs):
"""
Get all the projects owned by the specified user.
These include projects created by the user, but also ones shared with the user.
For shared projects, only include networks in those projects whi... | Write a Python 3 script for
getting all the projects owned by the specified user. | You are a Python code architect, reviewing and designing scalable and efficient code |
def set_project_status(project_id, status, **kwargs):
"""
Set the status of a project to 'X'
"""
user_id = kwargs.get('user_id')
#check_perm(user_id, 'delete_project')
project = _get_project(project_id)
project.check_write_permission(user_id)
project.status = status
db.DBSession.... | Write a Python 3 function that can
set the status of a project to X | You are a Python code generator, capable of creating scripts from specifications. |
def delete_project(project_id,**kwargs):
"""
Set the status of a project to 'X'
"""
user_id = kwargs.get('user_id')
#check_perm(user_id, 'delete_project')
project = _get_project(project_id)
project.check_write_permission(user_id)
db.DBSession.delete(project)
db.DBSession.flush()
... | Write a Python 3 function that can
set the status of a project to 'X' | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_networks(project_id, include_data='N', **kwargs):
"""
Get all networks in a project
Returns an array of network objects.
"""
log.info("Getting networks for project %s", project_id)
user_id = kwargs.get('user_id')
project = _get_project(project_id)
project.check_read_permi... | Implement a function in Python 3 to
get all networks in a project Returns an array of network objects. | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_network_project(network_id, **kwargs):
"""
get the project that a network is in
"""
net_proj = db.DBSession.query(Project).join(Network, and_(Project.id==Network.id, Network.id==network_id)).first()
if net_proj is None:
raise HydraError("Network %s not found"% network_id)
... | Can you write a function in Python 3 where it
gets the project that a network is in | You are a Python code generator, capable of creating scripts from specifications. |
def add_resource_types(resource_i, types):
"""
Save a reference to the types used for this resource.
@returns a list of type_ids representing the type ids
on the resource.
"""
if types is None:
return []
existing_type_ids = []
if resource_i.types:
for t in resource_i.t... | Write a Python 3 script to
save a reference to the types used for this resource. | You are a Python code analyst, evaluating scripts for potential improvements. |
Creates the default roles and perms for the current user and creates the default roles and perm. | Can you generate a brief explanation for the following Python 3 code
def create_default_users_and_perms():
# perms = db.DBSession.query(Perm).all()
# if len(perms) > 0:
# return
default_perms = ( ("add_user", "Add User"),
("edit_user", "Edit User"),
("add... | As a Python code analyst, you investigate and solve complex coding mysteries |
Creates the default units and dimensions for the current language. | Here you have a function in Python 3, explain what it does
def create_default_units_and_dimensions():
default_units_file_location = os.path.realpath(\
os.path.join(os.path.dirname(os.path.realpath(__file__)),
'../',
'static',
'default_units_and_... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Gets a dimension from the DB table. | Given the following Python 3 function, write the documentation
def get_dimension_from_db_by_name(dimension_name):
try:
dimension = db.DBSession.query(Dimension).filter(Dimension.name==dimension_name).one()
return JSONObject(dimension)
except NoResultFound:
raise ResourceNotFoundError("Di... | As a Python code composer, you craft elegant and concise scripts. |
Get all the rules for a given scenario. | Here you have a function in Python 3, explain what it does
def get_rules(scenario_id, **kwargs):
rules = db.DBSession.query(Rule).filter(Rule.scenario_id==scenario_id, Rule.status=='A').all()
return rules | As a Python code composer, you craft elegant and concise scripts. |
Get a specific attribute by its ID. | Here you have a function in Python 3, explain what it does
def get_attribute_by_id(attr_id, **kwargs):
try:
attr_i = db.DBSession.query(Attr).filter(Attr.id==attr_id).one()
return attr_i
except NoResultFound:
return None | As a Python code analyst, you investigate and solve complex coding mysteries |
Get a specific attribute by its ID. | Can you tell what is the following Python 3 function doing
def get_template_attributes(template_id, **kwargs):
try:
attrs_i = db.DBSession.query(Attr).filter(TemplateType.template_id==template_id).filter(TypeAttr.type_id==TemplateType.id).filter(Attr.id==TypeAttr.id).all()
log.debug(attrs_i)
... | As a Python code composer, you craft elegant and concise scripts. |
Get a specific attribute by its name and dimension_id. | Given the following Python 3 function, write the documentation
def get_attribute_by_name_and_dimension(name, dimension_id=None,**kwargs):
try:
attr_i = db.DBSession.query(Attr).filter(and_(Attr.name==name, Attr.dimension_id==dimension_id)).one()
log.debug("Attribute retrieved")
return attr_i... | As a Python code composer, you craft elegant and concise scripts. |
def add_attribute(attr,**kwargs):
"""
Add a generic attribute, which can then be used in creating
a resource attribute, and put into a type.
.. code-block:: python
(Attr){
id = 1020
name = "Test Attr"
dimension_id = 123
}
"""
log.debug("Addi... | Create a Python 3 function for
adding a generic attribute to the resource attribute list and return a dictionary of the new attribute. | You are a Python code architect, reviewing and designing scalable and efficient code |
Update an attribute in a resource attribute list. | Can you tell what is the following Python 3 function doing
def update_attribute(attr,**kwargs):
log.debug("Updating attribute: %s", attr.name)
attr_i = _get_attr(attr.id)
attr_i.name = attr.name
attr_i.dimension_id = attr.dimension_id
attr_i.description = attr.description
#Make sure an update ... | As a python code expert, you are capable of creating scripts from specifications. |
def add_attributes(attrs,**kwargs):
"""
Add a list of generic attributes, which can then be used in creating
a resource attribute, and put into a type.
.. code-block:: python
(Attr){
id = 1020
name = "Test Attr"
dimen = "very big"
}
"""
#Ch... | Write a Python 3 function that can
add a list of generic attributes to the internal list of resource attributes and returns a list of resource attributes. | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_attributes(**kwargs):
"""
Get all attributes
"""
attrs = db.DBSession.query(Attr).order_by(Attr.name).all()
return attrs | Can you write a function in Python 3 where it
gets all attributes in the hierarchy | You are a Python code analyst, evaluating scripts for potential improvements. |
def update_resource_attribute(resource_attr_id, is_var, **kwargs):
"""
Deletes a resource attribute and all associated data.
"""
user_id = kwargs.get('user_id')
try:
ra = db.DBSession.query(ResourceAttr).filter(ResourceAttr.id == resource_attr_id).one()
except NoResultFound:
... | Write a Python 3 function that can
update a resource attribute. | As a python code expert, you are capable of creating scripts from specifications. |
def delete_resource_attribute(resource_attr_id, **kwargs):
"""
Deletes a resource attribute and all associated data.
"""
user_id = kwargs.get('user_id')
try:
ra = db.DBSession.query(ResourceAttr).filter(ResourceAttr.id == resource_attr_id).one()
except NoResultFound:
raise Re... | Can you create a Python 3 function that
deletes a resource attribute and all associated data. | As a python code expert, you are capable of creating scripts from specifications. |
Add a resource attribute to a resource. | Can you generate a brief explanation for the following Python 3 code
def add_resource_attribute(resource_type, resource_id, attr_id, is_var, error_on_duplicate=True, **kwargs):
attr = db.DBSession.query(Attr).filter(Attr.id==attr_id).first()
if attr is None:
raise ResourceNotFoundError("Attribute with... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Adds all the attributes defined by a type to a node. | How would you explain what the following Python 3 function does
def add_resource_attrs_from_type(type_id, resource_type, resource_id,**kwargs):
type_i = _get_templatetype(type_id)
resource_i = _get_resource(resource_type, resource_id)
resourceattr_qry = db.DBSession.query(ResourceAttr).filter(ResourceAttr... | As a python code expert, you are capable of creating scripts from specifications. |
def get_all_resource_attributes(ref_key, network_id, template_id=None, **kwargs):
"""
Get all the resource attributes for a given resource type in the network.
That includes all the resource attributes for a given type within the network.
For example, if the ref_key is 'NODE', then it will r... | Write a Python 3 script to
get all the resource attributes for a given resource type within a given network. | You are a Python code analyst, evaluating scripts for potential improvements. |
Get all the resource attributes for a given resource. | Can you generate a brief explanation for the following Python 3 code
def get_resource_attributes(ref_key, ref_id, type_id=None, **kwargs):
user_id = kwargs.get('user_id')
resource_attr_qry = db.DBSession.query(ResourceAttr).filter(
ResourceAttr.ref_key == ref_key,
or_(
ResourceAttr... | You are a Python code generator, capable of creating scripts from specifications. |
def check_attr_dimension(attr_id, **kwargs):
"""
Check that the dimension of the resource attribute data is consistent
with the definition of the attribute.
If the attribute says 'volume', make sure every dataset connected
with this attribute via a resource attribute also has a dimen... | How would you code a function in Python 3 to
check that the dimension of the resource attribute data is consistent with the definition of the attribute. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Get a specific resource attribute by ID. | Here you have a function in Python 3, explain what it does
def get_resource_attribute(resource_attr_id, **kwargs):
resource_attr_qry = db.DBSession.query(ResourceAttr).filter(
ResourceAttr.id == resource_attr_id,
)
resource_attr = resource_attr_qry.first()
if resource_attr is None:
... | You are a Python code generator, capable of creating scripts from specifications. |
def set_attribute_mapping(resource_attr_a, resource_attr_b, **kwargs):
"""
Define one resource attribute from one network as being the same as
that from another network.
"""
user_id = kwargs.get('user_id')
ra_1 = get_resource_attribute(resource_attr_a)
ra_2 = get_resource_attribute(r... | Write a Python 3 script to
define one resource attribute from one network as being the same as the same as that from another network. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def delete_attribute_mapping(resource_attr_a, resource_attr_b, **kwargs):
"""
Define one resource attribute from one network as being the same as
that from another network.
"""
user_id = kwargs.get('user_id')
rm = aliased(ResourceAttrMap, name='rm')
log.info("Trying to delete attri... | How would you code a function in Python 3 to
delete the mapping between two resource attributes. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Delete all the resource attribute mappings in a network. | Can you generate a brief explanation for the following Python 3 code
def delete_mappings_in_network(network_id, network_2_id=None, **kwargs):
qry = db.DBSession.query(ResourceAttrMap).filter(or_(ResourceAttrMap.network_a_id == network_id, ResourceAttrMap.network_b_id == network_id))
if network_2_id is not None... | As a Python code composer, you craft elegant and concise scripts. |
def get_mappings_in_network(network_id, network_2_id=None, **kwargs):
"""
Get all the resource attribute mappings in a network. If another network
is specified, only return the mappings between the two networks.
"""
qry = db.DBSession.query(ResourceAttrMap).filter(or_(ResourceAttrMap.network... | Write a Python 3 function that can
get all the resource attribute mappings in a network. | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_node_mappings(node_id, node_2_id=None, **kwargs):
"""
Get all the resource attribute mappings in a network. If another network
is specified, only return the mappings between the two networks.
"""
qry = db.DBSession.query(ResourceAttrMap).filter(
or_(
and_(
... | Can you implement a function in Python 3 that
gets all the resource attribute mappings between two nodes. | As a python code expert, you are capable of creating scripts from specifications. |
def get_link_mappings(link_id, link_2_id=None, **kwargs):
"""
Get all the resource attribute mappings in a network. If another network
is specified, only return the mappings between the two networks.
"""
qry = db.DBSession.query(ResourceAttrMap).filter(
or_(
and_(
... | Can you implement a function in Python 3 that
gets all the resource attribute mappings in a network. | You are a Python code generator, capable of creating scripts from specifications. |
Get all the mappings between two networks. | Here you have a function in Python 3, explain what it does
def get_network_mappings(network_id, network_2_id=None, **kwargs):
qry = db.DBSession.query(ResourceAttrMap).filter(
or_(
and_(
ResourceAttrMap.resource_attr_id_a == ResourceAttr.id,
ResourceAttr.network_i... | You are a Python code analyst, evaluating scripts for potential improvements. |
def get_attribute_group(group_id, **kwargs):
"""
Get a specific attribute group
"""
user_id=kwargs.get('user_id')
try:
group_i = db.DBSession.query(AttrGroup).filter(
AttrGroup.id==group_id).one()
group_i.project.check_read_permission... | How would you implement a function in Python 3 that
gets a specific attribute group | You are a Python code generator, capable of creating scripts from specifications. |
Adds an attribute group to the list of available attributes. | How would you explain what the following Python 3 function does
def add_attribute_group(attributegroup, **kwargs):
log.info("attributegroup.project_id %s",attributegroup.project_id) # It is None while it should be valued
user_id=kwargs.get('user_id')
project_i = db.DBSession.query(Project).filter(Project.id... | As a Python code composer, you craft elegant and concise scripts. |
def update_attribute_group(attributegroup, **kwargs):
"""
Add a new attribute group.
An attribute group is a container for attributes which need to be grouped
in some logical way. For example, if the 'attr_is_var' flag isn't expressive
enough to delineate different groupings.
... | Implement a Python 3 function for
updating an attribute group. | You are a Python code analyst, evaluating scripts for potential improvements. |
Delete an attribute group. | Make a summary of the following Python 3 code
def delete_attribute_group(group_id, **kwargs):
user_id = kwargs['user_id']
try:
group_i = db.DBSession.query(AttrGroup).filter(AttrGroup.id==group_id).one()
group_i.project.check_write_permission(user_id)
db.DBSession.delete(group_i)
... | You are a Python code generator, capable of creating scripts from specifications. |
def get_network_attributegroup_items(network_id, **kwargs):
"""
Get all the group items in a network
"""
user_id=kwargs.get('user_id')
net_i = _get_network(network_id)
net_i.check_read_permission(user_id)
group_items_i = db.DBSession.query(AttrGroupItem).filter(
... | Implement a Python 3 function for
getting all the group items in a network | As a python code expert, you are capable of creating scripts from specifications. |
def get_group_attributegroup_items(network_id, group_id, **kwargs):
"""
Get all the items in a specified group, within a network
"""
user_id=kwargs.get('user_id')
network_i = _get_network(network_id)
network_i.check_read_permission(user_id)
group_items_i = db.DBSession.query(AttrGroup... | Implement a Python 3 function for
getting all the items in a specified group within a network | You are a Python code analyst, evaluating scripts for potential improvements. |
Get all the group items in a given attribute_id
| Can you generate a brief explanation for the following Python 3 code
def get_attribute_item_groups(network_id, attr_id, **kwargs):
user_id=kwargs.get('user_id')
network_i = _get_network(network_id)
network_i.check_read_permission(user_id)
group_items_i = db.DBSession.query(AttrGroupItem).filter(
... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Add a list of items to the attribute group. | Here you have a function in Python 3, explain what it does
def add_attribute_group_items(attributegroupitems, **kwargs):
"""
Populate attribute groups with items.
** attributegroupitems : a list of items, of the form:
```{
'attr_id' : X,
'group... | As a python code expert, you are capable of creating scripts from specifications. |
def delete_attribute_group_items(attributegroupitems, **kwargs):
"""
remove attribute groups items .
** attributegroupitems : a list of items, of the form:
```{
'attr_id' : X,
'group_id' : Y,
'network_id' : Z,
... | Write a Python 3 script for
deleting the items from the attribute group. | You are a Python code analyst, evaluating scripts for potential improvements. |
Share a network with a list of users identified by their usernames. | Explain what the following Python 3 code does
def share_network(network_id, usernames, read_only, share,**kwargs):
user_id = kwargs.get('user_id')
net_i = _get_network(network_id)
net_i.check_share_permission(user_id)
if read_only == 'Y':
write = 'N'
share = 'N'
else:
write... | You are a Python code architect, reviewing and designing scalable and efficient code |
Un - Share a network with a list of users identified by their usernames. | Explain what the following Python 3 code does
def unshare_network(network_id, usernames,**kwargs):
user_id = kwargs.get('user_id')
net_i = _get_network(network_id)
net_i.check_share_permission(user_id)
for username in usernames:
user_i = _get_user(username)
#Set the owner ship on the n... | As a python code expert, you are capable of creating scripts from specifications. |
Share an entire project with a list of users identifed by usernames. | Make a summary of the following Python 3 code
def share_project(project_id, usernames, read_only, share,**kwargs):
user_id = kwargs.get('user_id')
proj_i = _get_project(project_id)
#Is the sharing user allowed to share this project?
proj_i.check_share_permission(int(user_id))
user_id = int(user_i... | You are a Python code analyst, evaluating scripts for potential improvements. |
def set_project_permission(project_id, usernames, read, write, share,**kwargs):
"""
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
... | Create a Python 3 function for
setting permissions on a project to a list of users identifed by usernames. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Set permissions on a network to a list of users identifed by usernames. | Explain what the following Python 3 code does
def set_network_permission(network_id, usernames, read, write, share,**kwargs):
user_id = kwargs.get('user_id')
net_i = _get_network(network_id)
#Check if the user is allowed to share this network.
net_i.check_share_permission(user_id)
#You cannot ed... | As a python code expert, you are capable of creating scripts from specifications. |
def hide_dataset(dataset_id, exceptions, read, write, share,**kwargs):
"""
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 p... | Implement a function in Python 3 to
hide a particular piece of data by the specified user. | You are a Python code generator, capable of creating scripts from specifications. |
Unhide a particular piece of data from a dataset. | Given the following Python 3 function, write the documentation
def unhide_dataset(dataset_id,**kwargs):
user_id = kwargs.get('user_id')
dataset_i = _get_dataset(dataset_id)
#check that I can unhide the dataset
if dataset_i.created_by != int(user_id):
raise HydraError('Permission denied. '
... | As a Python code analyst, you investigate and solve complex coding mysteries |
def get_all_project_owners(project_ids=None, **kwargs):
"""
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
"""
projowner_qry = db.DBSession.query(ProjectOwner)
if project_ids is n... | Write a Python 3 function for
getting the project owner entries for all the requested projects. | As a python code expert, you are capable of creating scripts from specifications. |
Get the network owner entries for all the requested networks. | Explain what the following Python 3 code does
def get_all_network_owners(network_ids=None, **kwargs):
networkowner_qry = db.DBSession.query(NetworkOwner)
if network_ids is not None:
networkowner_qry = networkowner_qry.filter(NetworkOwner.network_id.in_(network_ids))
network_owners_i = networkowne... | As a Python code composer, you craft elegant and concise scripts. |
def bulk_set_project_owners(project_owners, **kwargs):
"""
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'... | Write a Python 3 script for
bulking set the project owner of multiple projects at once. | As a Python code composer, you craft elegant and concise scripts. |
def bulk_set_network_owners(network_owners, **kwargs):
"""
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'... | Create a Python 3 function to
bulk set the network owner of multiple networks at once. | As a Python code analyst, you investigate and solve complex coding mysteries |
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,
Dataset.unit_id,
... | Can you create a Python 3 function that
gets a single dataset by ID. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.