A permission library using number or 2 digits of letters to indicate permission nodes, groups and users. Designed for TI Nspire CX II.
-
Download tns file from release tab, use https://nspireconnect.ti.com/nsc/ webapp to copy it in your calculator.
-
If you have PyLib folder, put the tns in it. If you don't have it, create one and put the tns there.
-
Refreash lib. Press 2>menu>B to refreash lib.
-
You are all setup! Just import it in your project.
Returns the current NumPerm version.
import nperm
print(nperm.version())Example result: (1, 1, 0)
A Group contains users and permission nodes and has its own weight.
Checks whether a group exists. Returns True or False.
from nperm import Group
if Group.exist("ad"):
print("Group exists.")Creates a group. The name is limited to 2 characters and the weight must be greater than 0. Returns 0 on success and -1 on failure.
Group.Create("ad", 100)Changes a group's weight. Returns 0 on success and -1 on failure.
Group.SetWeight("ad", 200)Removes a group. Returns 0 on success and -1 if the group does not exist.
Group.Remove("ad")Compares two group weights. Returns 1 if the first is greater, 2 if the second is greater, 3 if equal, and -1 if comparison fails.
result = Group.Compare("ad", "md")A Node is a permission node belonging to a group. Each node has its own weight.
Checks whether a node exists under a group. Returns True or False.
Node.exist("rd", "ad")Creates a node under a group. The name is limited to 2 characters and the weight must be greater than 0. Returns 0 on success and -1 on failure.
Node.Create("rd", "ad", 10)
Node.Create("wr", "ad", 20)Compares two node weights. Returns 1 if the first is greater, 2 if the second is greater, 3 if equal, and -1 if comparison fails.
result = Node.Compare("rd", "ad", "wr", "ad")Returns the node's weight, or -1 if the node does not exist.
weight = Node.GetWeight("rd", "ad")
print(weight)Changes a node's weight. Returns 0 on success and -1 on failure.
Node.SetWeight("rd", "ad", 30)Removes a node. Returns 0 on success and -1 if it does not exist.
Node.Remove("rd", "ad")A User belongs to a group, has its own weight, and can be assigned permission nodes.
Checks whether a user exists under a group. Returns True or False.
User.exist("ax", "ad")Creates a user under a group. The name is limited to 2 characters and the weight must be greater than 0. Returns 0 on success and -1 on failure.
User.Create("ax", "ad", 50)Changes a user's weight. Returns 0 on success and -1 on failure.
User.SetWeight("ax", "ad", 80)Compares two user weights. Returns 1 if the first is greater, 2 if the second is greater, 3 if equal, and -1 if comparison fails.
result = User.CompareUser("ax", "ad", "bo", "ad")Allocates a node to a user. Returns 0 on success and -1 on failure.
User.AllocateNode("ax", "ad", "rd")Removes an allocated node from a user. Returns 0 on success and -1 on failure.
User.RemoveNode("ax", "ad", "rd")Checks if an user has an allocated node from a group or not.
User.CheckNode("ax","ad","rd")Currently retained as a non-stable/reserved function in the source. It should not be treated as part of the stable API yet.
from nperm import Group, Node, User
# Create a group
Group.Create("ad", 100)
# Create permission nodes
Node.Create("rd", "ad", 10)
Node.Create("wr", "ad", 20)
# Create a user
User.Create("ax", "ad", 50)
# Allocate nodes to the user
User.AllocateNode("ax", "ad", "rd")
User.AllocateNode("ax", "ad", "wr")
#Check a user's node from a group.
User.CheckNode("ax", "ad", "rd")
# Get a node's weight
print(Node.GetWeight("rd", "ad"))
# Compare nodes
print(Node.Compare("rd", "ad", "wr", "ad"))
# Change weights
Node.SetWeight("rd", "ad", 30)
User.SetWeight("ax", "ad", 80)
# Compare users
print(User.CompareUser("ax", "ad", "ax", "ad"))
# Remove permissions first
User.RemoveNode("ax", "ad", "rd")
User.RemoveNode("ax", "ad", "wr")
# Remove the user
User.Remove("ax", "ad")
# Remove nodes
Node.Remove("rd", "ad")
Node.Remove("wr", "ad")
# Remove the group
Group.Remove("ad")| Return value | Meaning |
|---|---|
0 |
Operation succeeded |
-1 |
Operation failed |
Comparison APIs use 1 for the first object having greater weight, 2 for the second, and 3 for equal weights. Existence checks return True or False.
- Group names: maximum 2 characters.
- Node names: maximum 2 characters.
- User names: maximum 2 characters.
- Weights must be greater than
0.
The Allocated node from a user will remain their nodes after being removed. You should remove the nodes under a user first before you remove the Node, User and Group.