Showing posts with label paths. Show all posts
Showing posts with label paths. Show all posts

14 April 2011

Choice and Conformity in fdb

I’ve just pushed a new version of fdb.py to the GitHub repository.

The main change in this version is that I’ve added support for allowing the user to choose whether to use what we might call Unix-style paths or Fluidinfo-style paths.

Until now, fdb.py has, as part of its shell-like functionality, deliberately provided an alternative view of Fluidinfo from the underlying structure. The main features of this “Unix-style view” are as follows:

  • Full (absolute) fdb.py tag paths start with a leading slash. So my rating tag would be /njr/rating rather than njr/rating.
  • A tag path without a slash is taken to be a relative path, currently always relative to the user’s namespace (though there are alternate versions where there is a notion of a current working namespace (CWD) which can be changed with a cd command). Thus, when using my credentials, the Fluidinfo tag njr/rating can be referred to as rating while ntolls rating is ntoll/rating.
  • /about is provided as a synonym for the special tag fluiddb/about (the about tag).
  • /id is provided as a pseudo-tag that will report the value of the object’s Fluidinfo ID.

This was not carried all the way: I didn’t re-write queries, but, for me at least, it saved much typing and pain when using fdb from the command line.

This release (1.33) maintains this behaviour by default, but allows the user to configure or tell the system that she would prefer to use genuine, regular all-American Fluidinfo-style paths. There are two ways to invoke this alternative behaviour:

  • If you would always prefer to user regular Fluidinfo-style paths, the best thing to do is to add a third line to the credentials file that fdb uses saying

    unix-style-paths false

    (I need hardly add that using true instead of false sets the opposite preference.)

  • Alternatively, if you just want to override the configured or default behaviour for a one-off command, use the command-line flags -F. Similarly, to override the behaviour to force Unix-style paths, use -U.

When you choose Fluidinfo-style-paths, this is what happens:

  • Only command-line commands are affected: if you use fdb.py through the API, nothing changes unless you work quite hard.
  • Any time you specify a path, it needs to be an absolute path. In Terry’s world, absolutely all paths are absolute.
  • /about is not accepted as a synonym for fluiddb/about
  • The only special case is /id. Since this is a useful pseudo tag (in my view), and since it has no namespace, the same trick works as when using unix-style paths. Thus you can request the tag /id and it will return the object ID.
  • Output as well as input is affected, i.e. tag paths will be reported without a leading slash.

Examples

Old (default) behaviour:

$ fdb tags -a "Eiffel Tower"
Object with about="Eiffel Tower":
/objects/93bd1999-0998-49cc-8004-af457ce34ce4
  /njr/location = "Paris"
  /fluiddb/about = "Eiffel Tower"
  /njr/index/about

Behaviour with -F or with unix-style-paths false

$ fdb tags -F -a "Eiffel Tower"
Object with about="Eiffel Tower":
/objects/93bd1999-0998-49cc-8004-af457ce34ce4
  njr/location = "Paris"
  fluiddb/about = "Eiffel Tower"
  njr/index/about

Setting and showing tags (old/default behaviour):

$ fdb tag -a "Eiffel Tower" rating=7
$ fdb show -a "Eiffel Tower" rating
Object with about="Eiffel Tower":
  /njr/rating = 7

Behaviour with -F or with unix-style-paths false

$ fdb tag -F -a "Eiffel Tower" njr/rating=8
$ fdb show -F -a "Eiffel Tower" njr/rating
Object with about="Eiffel Tower":
  njr/rating = 8

The same behaviour works with untag:

$ fdb untag -F -a "Eiffel Tower" njr/rating
zero:$ fdb show -F -a "Eiffel Tower" njr/rating
Object with about="Eiffel Tower":
  (tag njr/rating not present)

I may have missed something, but as far as I can see, this works reliably. If I have missed something, let me know.

So: if you’ve always liked the look of fdb but disliked its unix-style paths, now might be a good time to get it. And if you already use it, but would prefer to use Fluidinfo-style paths, just add

unix-style-paths false

as the third line of your credentials file.

21 August 2009

Tagging and untagging from python with fdb.py 0.2

I extended fdb.py a bit. Version 0.2 is available where 0.1 used to be, at http://stochasticsolutions.com/fluiddb/fdb.py, but also at http://stochasticsolutions.com/fluiddb/fdb0.2.py. Version 0.1 is still available at http://stochasticsolutions.com/fluiddb/fdb0.1.py. (I know, I know, I should make it publicly available through a VCS, and I will, but this is much easier for me right now.)
Main new features are:
  • Ability to untag objects
  • More tests
  • Tests that work for users whose FluidDB name isn't njr
  • More tag path manipulation
  • Most (all?) of the commands on tags now accept relative or absolute tag names
It still doesn't support subnamespaces or (m)any queries yet, though.
The following code illustrates the new functionality:
import fdb
import types

db = fdb.FluidDB (fdb.Credentials (filename='/Users/njr/.fluidDBcredentials'))

# Create an object with about='DADGAD' (or look up ID is already exists)
o = db.create_object ('DADGAD')
assert type (o) != types.IntType        # Would indicate an error code
id_DADGAD = o.id

# Add njr/rating=10 to 
assert db.tag_object_by_id (id_DADGAD, 'rating', 10) == 0

# Read the value back and heck it's right
(status, value) = db.get_tag_value_by_id (id_DADGAD, 'rating')
assert value == 10

# Remove njr/rating from DADGAD object
assert db.untag_object_by_id (id_DADGAD, 'rating') == 0

# Again, using absolute tag path
assert db.untag_object_by_id (id_DADGAD, '/njr/rating') == 0

# Again, using absolute tag path
assert db.untag_object_by_id (id_DADGAD, '/njr/rating') == 0

# Yet again, requesting error if the tag or object isn't there
error = db.untag_object_by_id (id_DADGAD, '/njr/rating', False)
assert error == fdb.STATUS.NOT_FOUND    # 404 :-)

print 'Well, that all worked!'
This produces:
zero:$ time python taguntag.py
Well, that all worked!

real 0m3.920s
user 0m0.121s
sys 0m0.068s

20 August 2009

On tags, namespaces, paths

The full specification of a tag in fluidDB might be something like
http://fluidDB.fluidinfo.com/tags/njr/var/rating
The way we talk about this in FluidDB (at least, the bits we're agreed on) is as follows:
  • rating is the name of the tag;
  • njr/var is the name of a hierarchical namespace; njr is me and var is a (sub-)namespace that I've created under my username namespace njr/.
The problem, as usual, is that we may wish to refer to different bits of it. I am currently (for myself, and in my code) using the following names, though others will undoubtedly use others.
  • http://fluidDB.fluidinfo.com/tags/njr/var/rating is the tag URI;
  • /tags/njr/var/rating is the the full tag path;
  • /njr/var/rating is the absolute tag path;
  • /njr/var is the absolute namespace;
  • var/rating is the relative tag path;
  • rating is the short tag name;
Why do I care? Well, partly just so that we can talk about things, and partly because I want to make my functions be fairly liberal about what they accept (relative or absolute paths, filling in missing namespaces when appropraite) etc. I'm sure there'll be confusion for a while; hopefully followed by blissful clarity.

Labels