def transfer_data_callback(src, dest, chunk, num_chunks, start, stop, offset, len, notify): station = config.input['station'] path = urlparse.urlparse(dest).path path = os.path.join(path, "%s.%d" % (os.path.basename(src), chunk)) dest = urlparse.urljoin(dest, path) scp.scp(src, dest, offset, len) if notify: s = jsonrpclib.Server(notify, verbose=0) print s.transfer_data_completed(station, chunk, num_chunks, time2vex(start), time2vex(stop), dest) pass return
def runtime(self): self.welcome() if self.avail(): # More methods can be added into this section scpMethod = scp.scp(self.param) scp_theory = scpMethod.eval_theory() scp_model = scpMethod.eval_model() hcpMethod = hcp.hcp(self.param) hcp_theory = hcpMethod.eval_theory() hcp_model = hcpMethod.eval_model() fcpMethod = fcp.fcp(self.param) fcp_theory = fcpMethod.eval_theory() fcp_model = fcpMethod.eval_model() res = [{ "method": "scp", "theory": scp_theory, "model": scp_model }, { "method": "hcp", "theory": hcp_theory, "model": hcp_model }, { "method": "fcp", "theory": fcp_theory, "model": fcp_model }] getFinal = final.final(res) else: self.noball()
def createwst_noCard_contra(): wst = scp.scp() # the d-> 3 rule wst.addKnowledge(knowledge_dimp3) wst.addVariable(card_d) wst.addVariable(card_3) wst.addVariable(pPrime) wst.addVariable(qPrime) wst.addVariable(card_7) wst.addVariable(card_k) wst.addKnowledge(knowledgeNotPtoP) wst.addKnowledge(knowledge_primeRelationp) #wst.addKnowledge(knowledge_primeRelationq) #wst.addKnowledge(knowledgeNotPtoP) wst.addNext(comp_addAB) wst.addNext(comp_weak) wst.addNext(comp_semantic) wst.addNext(comp_semantic) wst.addNext(comp_semantic) wst.addNext(comp_semantic) wst.addNext(comp_semantic) wst.insertAtPos(comp_modusTolens, 1) return copy.deepcopy(wst)
def unit_yuvalOnions(): yuval = scp.scp(epistemicStateType="dl") eatonionSoup = basicLogic.atom("eatOnionSoup") loveEating= basicLogic.atom("loveEating") eatOnions=basicLogic.atom("eatOnions") brushTeeth=basicLogic.atom("brushTeeth") careForHygiene=basicLogic.atom("careForHygiene") dontEatOnions=basicLogic.operator_monotonic_negation(eatOnions) rule1=basicLogic.operator_tritonic_defaultRule(eatonionSoup,[eatOnions],eatOnions) rule2=basicLogic.operator_tritonic_defaultRule(eatonionSoup,[loveEating],loveEating) rule3=basicLogic.operator_tritonic_defaultRule(loveEating,[brushTeeth],brushTeeth) rule4=basicLogic.operator_tritonic_defaultRule(brushTeeth,[careForHygiene],careForHygiene) rule5=basicLogic.operator_tritonic_defaultRule(careForHygiene,[dontEatOnions],dontEatOnions) factEatsOnionSoup = basicLogic.operator_bitonic_implication(basicLogic.TRUE,eatonionSoup) D = [rule1,rule2,rule3,rule4,rule5] W = [factEatsOnionSoup] V = [eatonionSoup, loveEating, eatOnions, brushTeeth, careForHygiene] yuval.addDList(D) yuval.addVList(V) yuval.addWList(W) yuval.addNext(comp_def_eval) print ("<<<<<<<<YUVAL>>>>>>>>>>") print (yuval.evaluate())
def testModificationSearch(goalV, limit=LIMIT): q = scp.scp() q.addM(M) q.addKnowledge(knowledge1) q.addKnowledge(knowledge2) q.addKnowledge(knowledge3) q.addVariable(e) q.addVariable(l) q.addVariable(o) #p.addNext(comp_addAB) q.addNext(comp_addAB) q.addNext(comp_weak) q.addNext(comp_semantic) q.addNext(comp_semantic) #q.addNext(comp_semantic) solutions = modificationSearch(q, goalV, limit) return solutions """" solutions = scpCombinationSearch(Mprime=[], depth=limit, _scp=q, goalV=goalV) print (strSCPList(solutions)) print ("Number of solutions found: " + str(len(solutions))) print ("The initial SCP was:") """ print(q)
def unit_quakersRepublicans(): dick = scp.scp(epistemicStateType="dl") republican = basicLogic.atom('republican') quaker = basicLogic.atom('quaker') pacifist = basicLogic.atom('pacifist') factRepublican = basicLogic.operator_bitonic_implication(basicLogic.TRUE, republican) factQuaker = basicLogic.operator_bitonic_implication(basicLogic.TRUE, quaker) notPacifist = basicLogic.operator_monotonic_negation(pacifist) #republicans are usually not pacifists rule1 = basicLogic.operator_tritonic_defaultRule(republican,[notPacifist],notPacifist) #quakers are usually pacifists rule2 = basicLogic.operator_tritonic_defaultRule(quaker,[pacifist],pacifist) D = [rule1,rule2] W = [factRepublican,factQuaker] V = [republican,quaker,pacifist] dick.addDList(D) dick.addWList(W) dick.addVList(V) dick.addNext(comp_def_eval) print ("<<<<<<<<DICK>>>>>>>>>>") print (dick.evaluate())
def unit_tweetyAndChilly (): #create the two birds as individual scps tweety = scp.scp(epistemicStateType="dl") chilly = scp.scp(epistemicStateType="dl") #variables flies = basicLogic.atom('flies') bird = basicLogic.atom('bird') notflies = basicLogic.operator_monotonic_negation(flies) #the only inference rule rule1 = basicLogic.operator_tritonic_defaultRule(bird,[flies],flies) fact_bird = basicLogic.operator_bitonic_implication(basicLogic.TRUE, bird) factNotFlies = basicLogic.operator_bitonic_implication(basicLogic.TRUE, notflies) #the set of concrete rules W_tweety=[fact_bird] W_chilly=[fact_bird,factNotFlies] #in this case both tweety and chilly share the same inference rules D = [rule1] V = [flies,bird] #create wteety tweety.addDList(D) tweety.addVList(V) tweety.addWList(W_tweety) #create chilly chilly.addDList(D) chilly.addVList(V) chilly.addWList(W_chilly) #add the complex operator for evaluating default rules tweety.addNext(comp_def_eval) chilly.addNext(comp_def_eval) print ("<<<<<<<<TWEETY>>>>>>>>>>") print (tweety.evaluate()) print (chilly.evaluate())
def predict(self, item, **kwargs): enc_string = item.task print(enc_string) epi = taskToBasicLogic(enc_string) #@TODOswitch s = scp.scp(epiState1=epi) #kbEvaluator(kb) print(s) #TODOsetupSoThatTaskWillWork M = self.getM_purposeBiltToolbox() #@TODO f() should be exact variable answer pattern match task = scpSearch.scpTask(si=epi, M=M, gamma=True, f=scpSearch.f_trivialFalse) """ print ("THE TASK IS") print (task) """ #@TODO there is a problem here!!! """ search = task.deNovoSearch(s=None,depth=2,validityType="All") print ("++++++++++++++++++++") #print(search) print ("++++++++++++++++++++") #once the scp has been evaluated, a choice from [choices] must be used to make a prediction #options for this: random, most-probable, highest scoring bestScp, bestScore = scpSearch.scpTask.getBestSCP(scpList=search, constraints=None) print ("Best SCP is ", bestScp) """ choices = item.choices print("<<--<<--<<--") print(choices) print(">>-->>-->>-->>-->>") #@TODO turning the results into basic logic is currently filing for some reason. choicesAsBasicLogic = taskToBasicLogic((choices)) print("<<--<<--<<--") print(choicesAsBasicLogic) print(">>-->>-->>-->>-->>") return item.choices[np.random.randint(0, len(item.choices))]
def createwst_card(variable, knowledge, epistemicStateType="wcs"): wst = scp.scp(epistemicStateType=epistemicStateType) # the d-> 3 rule wst.addKnowledge(knowledge_dimp3) # the observed card if knowledge != None: wst.addKnowledge(knowledge) wst.addVariable(card_d) wst.addVariable(card_3) if variable != None: wst.addVariable(variable) wst.addNext(comp_addAB) wst.addNext(comp_weak) wst.addNext(comp_semantic) wst.addNext(comp_semantic) wst.addNext(comp_semantic) return copy.deepcopy(wst)
def createsuppressionTask_noSuppression(): suppressionTask = scp.scp() #ADD THE FACTS TO THE INITIAL EPISTEMIC STATE suppressionTask.addKnowledge(knowledge1) suppressionTask.addKnowledge(knowledge2) #suppressionTask.addKnowledge(knowledge3) # LEAVE UNCOMMENTED TO TEST CASES THE WHERE WE HAVE KNOWLEDGE OF THE OPENNESS OF THE LIBRARY #a.addKnowledge(knowledge4) #INITIAL VARIABLE ASSIGNMENTS # This adds variables with unknown values to the V set of the epistemic state suppressionTask.addVariable(e) suppressionTask.addVariable(l) #suppressionTask.addVariable(o) suppressionTask.addNext(comp_addAB) suppressionTask.addNext(comp_weak) suppressionTask.addNext(comp_semantic) suppressionTask.addNext(comp_semantic) suppressionTask.addNext(comp_semantic) return suppressionTask
def testDeNovoSearch(goalV, limit=LIMIT): # the empty scp which will be used to find the solutions p = scp.scp() # add the list of allowable complex operations to the SCP p.addM(M) # add the known rules p.addKnowledge(knowledge1) p.addKnowledge(knowledge2) p.addKnowledge(knowledge3) # add the known variables p.addVariable(e) p.addVariable(l) p.addVariable(o) # add the initialise complex operation # add any other complex operations guaranteed to be performed next by p #p.addNext(comp_addAB) #p.addNext(comp_weak) # get a list of all possible successive SCPs which meet the given goal conditions solutions = scpDeNovoSearch(p, iteration=0, goalV=goalV, limit=limit) # print all the solutions found print(strSCPList(solutions)) print("Number of solutions found: " + str(len(solutions)))
management_ip = utils.get_management_server_ip() client = utils.get_rest_client(management_ip) deployments = client.deployments.list() magic_path = '/tmp/cloudify_migration_data_storage_3f53t9' magic_path2 = '/tmp/cloudify_migration_data_events_3f53t9' magic_path3 = '/tmp/cloudify_migration_script_3ho6o2' host_magic_dir = '/tmp/cloudify_migration_data_2g25qt4/' cmd = 'python {path} {id}' del_files = 'rm -f {0} {1}' if not os.path.exists(host_magic_dir): os.mkdir(host_magic_dir) scp(dump_script_path, magic_path3, True) for dep in deployments: dep_id = dep['id'] call(['cfy', 'ssh', '-c', cmd.format(path=magic_path3, id=dep_id)]) scp(host_magic_dir + 'migration_deps_storage', magic_path, False) scp(host_magic_dir + 'migration_deps_events', magic_path2, False) call(['cfy', 'ssh', '-c', del_files.format(magic_path, magic_path2)]) # These statements have to be executed as last. # Send the data to another script, running in a different virtenv with os.fdopen(3, 'w') as result_f: result_f.write(json.dumps(deployments))
"cloudify_storage/node_instance/_query?q=deployment_id:{} '") bulk_template = ("curl -s XPOST 'http://*****:*****@{file}") if deployments: for dep in deployments: new_dep = client.deployments.create( dep['blueprint_id'], dep['id'], dep['inputs'] ) with open(os.devnull, 'w') as FNULL: del_command = del_template.format(dep['id']) call(['cfy', 'ssh', '-c', del_command], stdout=FNULL, stderr=FNULL) scp(host_magic_dir + dep['id'] + '_storage', magic_file, True) call(['cfy', 'ssh', '-c', bulk_template.format( file=magic_file, index='cloudify_storage' )], stdout=FNULL, stderr=FNULL) scp(host_magic_dir + dep['id'] + '_events', magic_file, True) call(['cfy', 'ssh', '-c', bulk_template.format( file=magic_file, index='cloudify_events' )], stdout=FNULL, stderr=FNULL) print 'Recreated deployment %s' % (new_dep['id'],)
def deNovoSearch(self, s=None, depth=2, validityType="correct"): if s == None: s = scp.scp(self.si) solutions = self.ds(s=s, depth=depth, validityType=validityType) return solutions
def move(source, target): from scp import scp scp(source, target) remove(source)
def copy(source, target): from scp import scp scp(source, target)
del_command = del_template.format(dep['id']) call(['cfy', 'ssh', '-c', del_command], stdout=FNULL, stderr=FNULL) create_dep_execution = client.executions.list( deployment_id=new_dep.id )[0] create_deployment_executions.append(create_dep_execution.id) call(['cfy', 'ssh', '-c', update_exec_workflow_id_template.format( execution_id=create_dep_execution.id, w_id='create_deployment_environment_' + os.environ['NEW_MANAGER_VER'] )], stdout=FNULL, stderr=FNULL) print 'Recreated deployment %s' % (new_dep['id'],) scp(host_magic_dir + 'migration_deps_storage', magic_file, True) call(['cfy', 'ssh', '-c', bulk_template.format( file=magic_file, index='cloudify_storage' )], stdout=FNULL, stderr=FNULL) scp(host_magic_dir + 'migration_deps_events', magic_file, True) call(['cfy', 'ssh', '-c', bulk_template.format( file=magic_file, index='cloudify_events' )], stdout=FNULL, stderr=FNULL) for execution_id in create_deployment_executions: print 'Waiting for execution {0}'.format(execution_id) execution = client.executions.get(execution_id) while execution.status not in Execution.END_STATES:
def IDlog(method): prompt = True while prompt: NSID = promptID() print(method) if method == "SSH": print("importing modules...") try: import paramiko from scp import SCPClient as scp print("scp and paramiko imported successfully") except ImportError: promptm = True while promptm: i = input( "scp is required to use SSH, would you like to install the package? (Require pip) Y/n: " ) if i == "Y" or i == "y": subprocess.call( [sys.executable, "-m", "pip", "install", "scp"]) import paramiko from scp import SCPClient as scp print("successfully imported scp and paramiko") promptm = False if i == "N" or i == "n": print("exiting...") exit() portp = True while portp: port = input("Port: ") try: int(port) portp = False except: print("Invalid port") try: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(NSID[0], port, NSID[1], NSID[2]) scp = scp(ssh.get_transport()) print("connected on", NSID[0], "as", NSID[1]) return scp except TimeoutError: print( "Error: Connection timed out, probably due to wrong Port or IP" ) except TypeError: print("Invalid character in one of the input") except paramiko.ssh_exception.SSHException: print("Invalid identifiers") except gaierror: print("Error: URL is somehow invalid or isn't an URL at all") if method == "FTP": ftp = FTP() port = input("port: ") try: port = int(port) except NameError: print("Error: input isn't a port") except ValueError: print("Error: input isn't a valid port") try: connect = ftp.connect(NSID[0], port) if connect == '220 Service ready for new user.': ftp.login(NSID[1], NSID[2]) print("connected on", NSID[0], "as", NSID[1]) prompt = False return ftp else: print("Error: URL isn't associated with an FTP server") except gaierror: print("Error: URL is somehow invalid or isn't an URL at all") except TimeoutError: print("Error: Connection timed out due to wrong Port or IP") except error_perm: print("Identifiers provided invalid") except TypeError: print("Invalid character in one of the input")
create_dep_execution = client.executions.list( deployment_id=new_dep.id)[0] create_deployment_executions.append(create_dep_execution.id) call([ 'cfy', 'ssh', '-c', update_exec_workflow_id_template.format( execution_id=create_dep_execution.id, w_id='create_deployment_environment_' + os.environ['NEW_MANAGER_VER']) ], stdout=FNULL, stderr=FNULL) print 'Recreated deployment %s' % (new_dep['id'], ) scp(host_magic_dir + 'migration_deps_storage', magic_file, True) call([ 'cfy', 'ssh', '-c', bulk_template.format(file=magic_file, index='cloudify_storage') ], stdout=FNULL, stderr=FNULL) scp(host_magic_dir + 'migration_deps_events', magic_file, True) call([ 'cfy', 'ssh', '-c', bulk_template.format(file=magic_file, index='cloudify_events') ], stdout=FNULL, stderr=FNULL)