Pointrel Data Repository System for Python

Paul Fernhout pdfernhout at kurtz-fernhout.com
Wed May 24 07:53:23 EDT 2000


Here is something I posted to the Idle development list 
(slightly reformatted). It may be of more general interest because 
the included code snippet for file versioning gives a sense of how 
Pointrel development feels. It's also an example of what a 
flexible data repository can be used for. Note the ad-hoc way
you can just keep adding new types of information to it --
by using new concepts to define new relationships.
[Disclaimer: In general, versioning and naming are complex topics
and the included code snippet just scratches the surface.]

=====

As Glyph Lefkowitz pointed out in this list on Sat, 1 April, it would be
nice if Idle had an built-in version control system for files (not
relying on CVS).

I just released the Pointrel Data Repository System for Python (version
0.01) available at:
    http://www.kurtz-fernhout.com/pointrel/

The core of the system is basically a 20K Python module
"PointrelRepository20000513.py" that provides a simple database-like
system with some unusual properties. It is released under an X11/MIT
type license so it should be Python license compatible. The
wxPython-based example file viewer included in that distribution
supports archiving and running of chosen versions of a Python file, but
it is *very* crude. Of course, editing Python files with Idle would be
much slicker than doing it in a text pane as done in that example.

I looked briefly at the Idle source code a while back with an eye to
adding version control. I think it might be possible with a days effort
or so for someone to integrate the Idle and the Pointrel system to
handle multiple versions of files. I believe most of the changes would
have to be made to "IOBinding.py".

Specifically, every time one saves a file to disk in Idle, a copy would
go into the repository under that files complete path name. Ideally, one
could also add a version name (or by default just increment a version
number and include the date and time). 

When a file was opened from a special menu item in Idle, a dialog could
pop up with alternate versions of that file that were listed in the
repository under the same name. 

Deleted or moved files would be hard to recover with this simple
interface -- you'd have to make an empty file in the right place and
open it. One would need a repository file list browser dialog to find
them otherwise; even in that case there are deeper issues to address. 

Relavant Pointrel API calls would include:

#returns a unique triad associated with a name string
Repository.triadForName(name)

#returns a triad with the specified A, B, C slots
Repository.addTriadABC(a, b, c)

#same as above, but also with an associated string
Repository.addTriadABCString(a, b, c, string)

#same as above, but with just a string and A, B, C of 0
Repository.addTriadString(string)

#returns list of Cs in triads which have the A and B
Repository.searchABForAllCs(a, b)

#returns list of triads which have the A and B
Repository.searchABForAllCLinks(a, b)

#returns the last added C triad with A and B
Repository.searchABForLatestCLink(a, b)

#returns string associated with this triad
Repository.triadString(triadIndex)

#returns unique triad representing concept with that name
Repository.triadForConcept(name) 

Here is a code fragment that uses these calls to store and retrieve
versions of a file.

#So adding "C:/MyDev/foo.py" could involve something like:
import PointrelRepository20000513
myRepository = PointrelRepository20000513.Repository()
myRepository.openFiles()
hasContentsConcept = myRepository.triadForConcept("has contents")
fileNameNode = myRepository.triadForName("C:/MyDev/foo.py")
fileContentsNode = myRepository.addTriadString("fileContentsOfFoo")
myRepository.addTriadABC(fileNameNode, hasContentsConcept, 
        fileContentsNode)
hasVersionNameConcept = myRepository.triadForConcept("has version name")
myRepository.addTriadABCString(fileContentsNode, hasVersionNameConcept, 
        0, "Version 0.0.1")

#Retrieving all versions of a file could involve something like:
hasContentsConcept = myRepository.triadForConcept("has contents")
fileNameNode = myRepository.triadForName("C:/MyDev/foo.py")
fileContentsNodes = myRepository.searchABForAllCs(fileNameNode,
hasContentsConcept)
for node in fileContentsNodes:
    contentsString = myRepository.triadString(node)
    print "Contents: ", contentsString
    versionInfoLinkNode = myRepository.searchABForLatestCLink(node, 
            hasVersionNameConcept)
    versionString = myRepository.triadString(versionInfoLinkNode)
    print "Version", versionString

If you ran this code three times and with a newly made repository (run
"PointrelRepository20000513.py" first), you should get this output on
the third run:
Contents:  fileContentsOfFoo
Version Version 0.0.1
Contents:  fileContentsOfFoo
Version Version 0.0.1
Contents:  fileContentsOfFoo
Version Version 0.0.1

Note that for performance one might eventually want to cache the
locations of the concept nodes somewhere in an Idle editor object. To
get fancy, one might then add difference reporting, and another later
improvement could be to group or tag versions of a files into a project
versions.

Would anyone on this list be interested in giving this Idle/Pointrel
System integration a try? I don't have the time to do the Idle
integration anytime soon myself, but I'd be happy to provide someone
interested in trying it with "technical support" on using the Pointrel
system (under the assumption the Idle integration results would be under
a Python or compatible license). 

The code I provided here should be enough to get started and over the
worst initial hurdles. It would help me out to get some intial feedback
on the usability of what I have just released, and it might just make a
nifty add-on for Idle.

-Paul Fernhout
Kurtz-Fernhout Software 
=========================================================
Developers of custom software and educational simulations
Creators of the Garden with Insight(TM) garden simulator
http://www.kurtz-fernhout.com



More information about the Python-list mailing list