diff options
Diffstat (limited to 'freebase/fcl')
| -rwxr-xr-x | freebase/fcl/commands.py | 27 | ||||
| -rwxr-xr-x | freebase/fcl/fcl.py | 1 | ||||
| -rwxr-xr-x | freebase/fcl/mktype.py | 49 | ||||
| -rw-r--r-- | freebase/fcl/schema.py | 41 |
4 files changed, 56 insertions, 62 deletions
diff --git a/freebase/fcl/commands.py b/freebase/fcl/commands.py index 4b517ec..4de2496 100755 --- a/freebase/fcl/commands.py +++ b/freebase/fcl/commands.py @@ -34,6 +34,7 @@ import simplejson import freebase.rison as rison from freebase.api import attrdict +from freebase.schema import connect_object, disconnect_object def cmd_help(fb, command=None): """get help on commands @@ -187,17 +188,8 @@ def cmd_ln(fb, src, dst): """ src = fb.absid(src) dst = fb.absid(dst) - dir,file = dirsplit(dst) - wq = { 'id': src, - 'key':{ - 'connect': 'insert', - 'namespace': dir, - 'value': file - } - } - - r = fb.mss.mqlwrite(wq) - + + return connect_object(fb.mss, src, dst) def cmd_rm(fb, path): """unlink a namespace key @@ -213,17 +205,8 @@ def cmd_rm(fb, path): disturb anything other than the one directory entry. """ path = fb.absid(path) - dir,file = dirsplit(path) - - wq = { 'id': path, - 'key':{ - 'connect': 'delete', - 'namespace': dir, - 'value': file - } - } - - r = fb.mss.mqlwrite(wq) + + return disconnect_object(fb.mss, path) def cmd_mv(fb, src, dst): """rename srcid to dstid. diff --git a/freebase/fcl/fcl.py b/freebase/fcl/fcl.py index a0299b8..8b484c5 100755 --- a/freebase/fcl/fcl.py +++ b/freebase/fcl/fcl.py @@ -254,6 +254,7 @@ class FbCommandHandler(object): self.import_commands('freebase.fcl.commands') self.import_commands('freebase.fcl.mktype') + self.import_commands('freebase.fcl.schema') cmd = args.pop(0) self.dispatch(cmd, args) diff --git a/freebase/fcl/mktype.py b/freebase/fcl/mktype.py index 30f8df7..f84d017 100755 --- a/freebase/fcl/mktype.py +++ b/freebase/fcl/mktype.py @@ -29,6 +29,7 @@ import os, sys, re, time from fbutil import * +from freebase.schema import create_object, create_type def cmd_mkobj(fb, id, typeid='/common/topic', name=''): """create a new object with a given type -- EXPERIMENTAL @@ -41,28 +42,10 @@ def cmd_mkobj(fb, id, typeid='/common/topic', name=''): """ id = fb.absid(id) - nsid, key = dirsplit(id) - - typeid = fb.absid(typeid) - - if name == '': - name = key - - wq = { 'create': 'unless_exists', - 'id': None, - 'name': name, - 'type': typeid, - 'key':{ - 'namespace': nsid, - 'value': key - }, - } - - # TODO add included types - - r = fb.mss.mqlwrite(wq) - print r.id,r.create - + + return create_object(fb.mss, name="", path=id, + included_types=type_id, create="unless_exists") + def cmd_mktype(fb, id, name=''): """create a new type -- EXPERIMENTAL %prog mktype new_id name @@ -73,26 +56,12 @@ def cmd_mktype(fb, id, name=''): this doesn't create any type hints. if present, name gives the display name of the new property + + For more options when creating a type, use the python library """ id = fb.absid(id) - - nsid, key = dirsplit(id) - - if name == '': - name = key - - wq = { 'create': 'unless_exists', - 'id': None, - 'name': name, - 'type': '/type/type', - 'key':{ - 'namespace': nsid, - 'value': key - }, - } - - r = fb.mss.mqlwrite(wq) - print r.id,r.create + ns, key = dirsplit(id) + return create_type(s, name, key, ns, cvt=False, tip=None, included=None, extra=None): def mkprop(fb, typeid, key, name='', vtype=None, master_property=None): """helper to create a new property diff --git a/freebase/fcl/schema.py b/freebase/fcl/schema.py new file mode 100644 index 0000000..47eb1fa --- /dev/null +++ b/freebase/fcl/schema.py @@ -0,0 +1,41 @@ +from freebase.schema import dump_base, dump_type, restore + +try: + import jsonlib2 as json +except ImportError: + try: + import simplejson as json + except ImportError: + import json + +import sys + +def cmd_dump_base(fb, baseid): + """dump a base to stdout + %prog dump_base baseid + + Dump a base by outputting a json representation + of the types and properties involved. + """ + print >> sys.stdout, json.dumps(dump_base(fb.mss, baseid), indent=2) + +def cmd_dump_type(fb, baseid, follow_types=True): + """dump a type to stdout + %prog dump_type typeid [follow_types=True] + + Dump a type by outputting a json representation + of the type and properties involved. + """ + print >> sys.stdout, json.dumps(dump_type(fb.mss, typeid, follow_types), indent=2) + +def cmd_restore(fb, newlocation, graphfile): + """restore a graph object to the graph + %prog restore newlocation graphfile + + Restore a graph object to the newlocation + """ + fh = open(graphfile, "r") + graph = json.loads(fh.read()) + fh.close() + return restore(fb.mss, graph, newlocation, ignore_types=None) + |
