Exemplo n.º 1
0
    def test_try_copying_a_cvt(self):

        # if follow_types is True, everything is kosher.
        domain_id = _create_domain()
        graph = dump_type(s, "/film/actor", follow_types=True)
        restore(s, graph, domain_id)

        newactor, realactor = s.mqlreadmulti([{
            "id": domain_id + "/actor",
            "/type/type/properties": {
                "return": "count"
            }
        }, {
            "id": "/film/actor",
            "/type/type/properties": {
                "return": "count"
            }
        }])
        self.assertEqual(newactor["/type/type/properties"],
                         realactor["/type/type/properties"])

        # if follow_types is False, if we try to upload a cvt, it should whine
        from freebase.schema import CVTError
        self.assertRaises(
            CVTError, lambda: dump_type(s, "/film/actor", follow_types=False))
 def test_try_copying_a_cvt(self):
     
     # if follow_types is True, everything is kosher.
     domain_id = _create_domain()
     graph = dump_type(s, "/film/actor", follow_types=True)
     restore(s, graph, domain_id)
     
     newactor, realactor = s.mqlreadmulti([{"id" : domain_id + "/actor", "/type/type/properties" : {"return" : "count" }}, 
                                           {"id" : "/film/actor", "/type/type/properties" : {"return" : "count" }}])
     self.assertEqual(newactor["/type/type/properties"], realactor["/type/type/properties"])
     
     # if follow_types is False, if we try to upload a cvt, it should whine
     from freebase.schema import CVTError
     self.assertRaises(CVTError, lambda: dump_type(s, "/film/actor", follow_types=False))
Exemplo n.º 3
0
def cmd_dump_type(fb, typeid, 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)
Exemplo n.º 4
0
def cmd_dump_type(fb, typeid, 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)
Exemplo n.º 5
0
def fb_save_type():
    op = OptionParser(usage='%prog [options] typeid ')
    
    op.disable_interspersed_args()

    op.add_option('-s', '--service', dest='service_host',
                    metavar='HOST',
                    default="freebase.com",
                    help='Freebase HTTP service address:port')
    
    op.add_option('-S', '--sandbox', dest='use_sandbox',
                    default=False, action='store_true',
                    help='shortcut for --service=sandbox-freebase.com')
    
    op.add_option('-n', '--no-follow', dest='follow',
                    default=False, action='store_false',
                    help="Don't follow types, only copy the one specified.")
    
    op.add_option('-f', '--follow', dest="follow",
                    default=True, action="store_true",
                    help="Follow the types (you might end up copying multiple types)")


    options,args = op.parse_args()
    
    service_host = options.service_host
    if options.use_sandbox:
        service_host = "sandbox-freebase.com"

    if len(args) < 1:
        op.error('Required typeid missing')
    
    if len(args) > 1:
        op.error('Too many arguments')
    
    s = HTTPMetawebSession(service_host)
    print json.dumps(dump_type(s, args[0], options.follow), indent=2)