def config(self): json_data = open(self.configfile) data = json.load(json_data) self.servers = data['servers'] json_data.close() self.backups_dir = os.getcwd() return True
def fb_restore(): op = OptionParser(usage='%prog [options] new_location graph_output_from_dump*_command') op.disable_interspersed_args() op.add_option('-s', '--service', dest='service_host', metavar='HOST', 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 (default)') op.add_option('-F', '--freebase', dest='use_freebase', default=False, action='store_true', help='shortcut for --service=freebase.com (not default)') op.add_option('-u', '--username', dest='username', action='store', help='username for freebase service') op.add_option('-p', '--password', dest='password', action='store', help='password for freebase service') options,args = op.parse_args() if (options.username and not options.password) or (not options.username and options.password): op.error("You must supply both a username and password") if options.use_sandbox and options.use_freebase: op.error("You can't use both freebase and sandbox!") if options.service_host and (options.use_sandbox or options.use_freebase): op.error("You can't specify both --service and --freebase or --sandbox") if not options.service_host and not options.use_sandbox and not options.use_freebase: op.error("You have to specify to upload to sandbox or production (freebase)") service_host = options.service_host if options.use_sandbox: service_host = "sandbox-freebase.com" if options.use_freebase: service_host = "freebase.com" s = login(service_host, username=options.username, password=options.password) newlocation = args[0] if len(args) == 1: graphfile = "-" #stdin else: graphfile = args[1] if graphfile != "-": fg = open(graphfile, "r") graph = json.load(fg) fg.close() if graphfile == "-": # use stdin graph = json.load(sys.stdin) print "loaded graph", graph restore(s, graph, newlocation, ignore_types=None, debug=False)