-
Notifications
You must be signed in to change notification settings - Fork 5
Creating New Configuration
Go to graph_db/configurations and create a new file my_config.py:
from graph_db.configuration import Configuration
class MyConfig(Configuration):
def __init__(self):
Configuration.__init__(self)Here we importing a base class Configuration that is an API root of PyCDB. Then we create a child class TestConfig that just has a constructor with calling a constructor of a parent class.
Now we can add two configuration classes to the constructor after calling a parent one:
self.addEntityClass(1, "pc", "PC", "Personal Computer", [
makeAttribute("title", "Title", "Title of the PC", self.TYPE_STRING, "untitled"),
])
self.addEntityClass(2, "device", "Device", "Digital Device", [
makeAttribute("title", "Title", "Title of the device", self.TYPE_STRING, "untitled"),
])We have added classes by calling parent class method addEntityClass, which is a very tiny wrapper of creating a dictionary class description. The first class has class id 1, its api name is pc, title for users is PC and more detailed description is Personal Computer. The fifth argument is a python list of attributes, pc class has just one attribute that is created by shortcut function makeAttribute. Each attribute has name (in the example attribute it is title), title text (it is Title), description text (it is Title of the PC), attribute type (one of the types, listed as base class attribute, in the example the type is self.TYPE_STRING) and the last argument is default value of the attribute (it is untitled). The description of second class is pretty same.
Now, we could try our configuration. Open local configuration file (conf/local_[installation_name].py) and find the setting CONFIGURATION = {}, now we could fill it as follow:
CONFIGURATIONS = {
"tst_config" : ConfigurationInfo("My Configuration", "graph_db.configurations.my_config.MyConfig", PROJECT_DIR + "/graph_db/databases/my_config.gpickle"),
}CONFIGURATIONS is a dictionary of available connections. Its keys are connection identifiers that could be further used in automated import/export scripts. Values stored in it are ConfigurationInfo class instances that specifies 3 configuration parameters: connection title (My Configuration), dotted path to configuration class (graph_db.configurations.my_config.MyConfig) and path to persistent storage (PROJECT_DIR + "/graph_db/databases/my_config.gpickle")