def add_resource2(self, job): """ Add a new resource to store""" created = None rtype = None created_triple = [] lvres = job.get() for vres in lvres: rid = vres.get_id() rtype = self.app.ask.get_property(rid, RDF['type']) if rtype: # It means that resource already exists # So keep basic triples: created and related resources keep_triples = [] created = self.app.ask.get_property(rid, NAO['created']) keep_triples.append((rid, NAO['created'], Literal(created))) annotations = self.app.ask.get_annotations(URIRef(rid)) for annoid in annotations: keep_triples.append((rid, NAO['annotation'], URIRef(annoid))) self.delete_resources([rid]) self.add_triples(keep_triples) self.commit() for p, o in vres.get_metadata(): self.store.add_triple(s, p, o) try: contents = vres.get_content() if len(contents) != 0: filename = os.path.join(LPATH['RESOURCES'], str(rid)[9:]) create_file(filename, contents) #self.log.info("Created file: %s" % filename) except Exception, error: pass #self.log.error(error)
def generate_case(feature, yaml_name): ct = Case_Templates(feature, yaml_name) maincase = ct.case_templates_main() # 创建用例文件,写入用例头内容 yaml_name1 = yaml_name.split(".")[0] test_path = os.path.join(TEST_PATH, "{}_test.py".format(yaml_name1)) create_file(test_path, maincase) # 创建模块目录 # feature_path = os.path.join(case_path(), feature) # mkdir(feature_path) # 读取yaml文件,写入用例方法内容 try: rd = ReadFileData() yaml_all = rd.load_yaml(os.path.join(DATA_DIR, yaml_name)) all_api_items = yaml_all.items() n = 0 for k, v in all_api_items: n = n + 1 yaml_title = k method = v['method'] yaml_data = v['data'] num = str(n).zfill(2) commoncase = ct.case_templates_common(yaml_title, method, yaml_data, num) write_file(test_path, commoncase) print('文件生成完毕') except Exception as e: print(e) os.remove(test_path) # 如果有异常,删除之前创建的文件 print('文件生成失败,已自动删除')
def add_resource(self, job): """ Add a new resource to store""" created = None rtype = None created_triple = [] lvres = job.get() for vres in lvres: rid = vres.get_id() rtype = self.app.ask.get_property(rid, RDF['type']) # Does exists resource in graph? if rtype: # Track changes modified = str(datetime.now())[0:19] self.add_triples([(URIRef(rid), NAO['modified'], Literal(modified))]) # It means that resource already exists # So keep basic triples: created and related resources for p, o in vres.get_metadata(): o0 = self.app.ask.get_property(rid, p) #Avoid delete 'created' property if p != NAO['created']: # Restrict to one title if p == NIE['title']: triples = self.app.ask.get_triples(URIRef(rid), p, None) self.delete_triples([triples]) # Finally delete only those triples that change if o != o0: self.delete_triples([(rid, p, o0)]) else: pass # Always identify Resource with PIM Owner user_owner_pim_uri = self.app.cfgmgr.get_value('PIMO', 'PIM') self.add_triples([(URIRef(rid), PIMO['isDefinedBy'], URIRef(user_owner_pim_uri))]) # Insert metadata into Graph for p, o in vres.get_metadata(): self.add_triples([(rid, p, o)]) # Save contents (if any) into Repository try: contents = vres.get_content() if len(contents) != 0: filename = os.path.join(LPATH['RESOURCES'], str(rid)[9:]) create_file(filename, contents) #self.log.info("Created file: %s" % filename) except Exception, error: pass #self.log.error(error) # Commit changes to Graph self.commit()