UserPreferences

creating and editing


Creating and Editing UUIDs and u-forms

By now, you need to have one of the Repository APIs up and running. This documentation assumes that you are using the Python API, partly because this enables you to enter commands one at a time in the Python interpreter, which is probably the easiest step-by-step way to use the repository.

Other APIs work similarly. Feel free to add caveats to this, anyone ...

You can now do the following things:

Creating a UUID

In order to create a u-form, you'll want to give it a UUID. The best way to get a new UUID that you can guarantee is unique and distinct from any other UUID (past, present or even future) is to use the repository API to issue you with a UUID automatically. To do this, make sure you have imported the uuid library using the command

>>> from MAYA.VIA import uuid

(The symbols >>> are the Python command prompt - you don't actually type this in, it should be there already.)

This loads the uuid module which has a method called UUID. Calling this method gives you a UUID that is generated by combining information from your computer's address and your current time. Since nobody else can be using your computer at exactly the same instant, you can rest assured that this UUID is universally unique, as it should be.

To call this method, type

>>> uuid.UUID()

This should give you a response something like

uuid._ ( '~019a98e4603e5011d9a498360117ac40fb' ),

though your response should be at least slightly different from this one. (If not the system is badly broken!) To confirm this, try issuing the same command again and you should get a different answer.

This should bring home the following principle to you - never be afraid of using up a UUID. We're never going to run out of these numbers - there are simply too many of them. Every second you don't ask for a UUID, thousands of potential UUIDs are flying past you, never to be used. The UUID itself doesn't matter, it is just an identifier - all that matters is that it's guaranteed to be unique, and the MAYA library finctions gurantee this.

If you want to assign your new UUID to a variable so that you don't have to type it in again and again, use a command like

>>> my_new_uuid = uuid.UUID()

This calls upon the function uuid.UUID() to issue a new UUID object, and assigns it to the variable my_new_uuid. To check this, if you request the value of this variable by typing my_new_uuid you should see something like

>>> my_new_uuid 
uuid._ ( '~01a104f1823e5111d9a49805215dc76640' )

Creating a new u-form

You can also generate a whole new u-form object, including a UUID and space for attribute-value pairs. To do this, make sure you've imported the uform module by using the command

>>> from MAYA.VIA import uform

To get a new u-form, type the command.

>>> uf=uform.UForm()

This command creates a new u-form from scratch. It issues you with a completely new UUID and allows you to add attributes and values to this UUID. You can examine its contents by typing.

>>> uf
uform.UForm(uuid._ ( '~01e5c82750068f11d9b228477b55f07cf4' ),{})

This shows you that the only thing your u-form has so far is a UUID - it has no attributes and values yet.

If you want to see just the UUID of your u-form, type

>>> uf.uuid
uuid._ ( '~01e5c82750068f11d9b228477b55f07cf4' )

The repository gurantees that your UUID is completely unique by taking into account what time you're working and where you're working from (based on your computer's IP address). Since nobody else can be in the same place at the same time, this pretty much guarantees that nobody else could ever have been issued with this UUID. Just to confirm this, if you run the same commands over again, you'll get a different UUID - which, incidentally, should certainly be different from the one we've written down in this example! If you keep repeating the command uform.UForm(), you'll see new UUIDs every time. Don't worry about using them up! There are more possible UUIDs of this length than we could possibly use, even if we wanted to give a UUID to every particle in the universe.

Adding attributes and values to your u-form

>>> uf['test_attribute']='test_value'

If you examine the contents of the u-form again, you'll see that this attribute-value pair has been added to its contents.

>>> uf 
uform.UForm(uuid._ ( '~01e5c82750068f11d9b228477b55f07cf4' ),{'test_attribute': 'test_value'})

To commit the changes to the uform to your local repository, make sure you have first imported the repository library and instatiated your local repository object. (This means you should have a version of the Civium Workbench running and issued the commands

>>> from MAYA.VIA import repos
>>> r = repos.Repository('localhost:6200')

Then commit your new u-form using the command.

>>> r.setAttr(uf)

This is a broader version of the setAttr command we introduced in getting and setting attributes and values. Instead of setting attributes one at a time, if you've created an entire u-form object in memory, you can commit its contents to the repository all at once.

Manufacturing new UUIDs from old

As well as being issued with new UUIDs directly by your repository, there are useful methods that can be used to generate new UUIDs from old ones, or from UUIDs and plain strings, by using UUID Extension.


Back to Civium Documentation