本文整理汇总了Python中ckan.model.Package.maintainer方法的典型用法代码示例。如果您正苦于以下问题:Python Package.maintainer方法的具体用法?Python Package.maintainer怎么用?Python Package.maintainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ckan.model.Package
的用法示例。
在下文中一共展示了Package.maintainer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_stage
# 需要导入模块: from ckan.model import Package [as 别名]
# 或者: from ckan.model.Package import maintainer [as 别名]
def import_stage(self, harvest_object):
"""Import the metadata received in the fetch stage to a dataset and
create groups if ones are defined. Fill in metadata from study and
document description.
"""
try:
xml_dict = {}
xml_dict["source"] = harvest_object.content
udict = json.loads(harvest_object.content)
if "url" in udict:
f = urllib2.urlopen(udict["url"]).read()
ddi_xml = BeautifulSoup(f, "xml")
else:
self._save_object_error("No url in content!", harvest_object)
return False
except urllib2.URLError:
self._save_object_error("Could not fetch from url %s!" % udict["url"], harvest_object)
return False
except etree.XMLSyntaxError:
self._save_object_error("Unable to parse XML!", harvest_object)
return False
model.repo.new_revision()
study_descr = ddi_xml.codeBook.stdyDscr
document_info = ddi_xml.codeBook.docDscr.citation
title = study_descr.citation.titlStmt.titl.string
if not title:
title = document_info.titlStmt.titl.string
name = study_descr.citation.titlStmt.IDNo.string
update = True
pkg = Package.get(name)
if not pkg:
pkg = Package(name=name)
update = False
producer = study_descr.citation.prodStmt.producer
if not producer:
producer = study_descr.citation.rspStmt.AuthEnty
if not producer:
producer = study_descr.citation.rspStmt.othId
pkg.author = producer.string
pkg.maintainer = producer.string
if study_descr.citation.distStmt.contact:
pkg.maintainer = study_descr.citation.distStmt.contact.string
if document_info.titlStmt.IDNo:
pkg.id = document_info.titlStmt.IDNo.string
keywords = study_descr.stdyInfo.subject(re.compile("keyword|topcClas"))
keywords = list(set(keywords))
for kw in keywords:
if kw:
vocab = None
kw_str = ""
if kw.string:
kw_str = kw.string
if "vocab" in kw.attrs:
vocab = kw.attrs.get("vocab", None)
if vocab and kw.string:
kw_str = vocab + " " + kw.string
pkg.add_tag_by_name(munge_tag(kw_str))
if study_descr.stdyInfo.abstract:
description_array = study_descr.stdyInfo.abstract("p")
else:
description_array = study_descr.citation.serStmt.serInfo("p")
pkg.notes = "<br />".join([description.string for description in description_array])
pkg.title = title[:100]
pkg.url = udict["url"]
if not update:
ofs = get_ofs()
nowstr = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
idno = study_descr.citation.titlStmt.IDNo
agencyxml = (idno["agency"] if "agency" in idno.attrs else "") + idno.string
label = "%s/%s.xml" % (nowstr, agencyxml)
ofs.put_stream(BUCKET, label, f, {})
fileurl = config.get("ckan.site_url") + h.url_for("storage_file", label=label)
pkg.add_resource(url=fileurl, description="Original metadata record", format="xml", size=len(f))
pkg.add_resource(
url=document_info.holdings["URI"] if "URI" in document_info.holdings else "", description=title
)
metas = {}
descendants = [desc for desc in document_info.descendants] + [sdesc for sdesc in study_descr.descendants]
for docextra in descendants:
if isinstance(docextra, Tag):
if docextra:
if docextra.name == "p":
docextra.name = docextra.parent.name
if not docextra.name in metas and docextra.string:
metas[docextra.name] = docextra.string if docextra.string else self._collect_attribs(docextra)
else:
if docextra.string:
metas[docextra.name] += (
" " + docextra.string if docextra.string else self._collect_attribs(docextra)
)
if ddi_xml.codeBook.dataDscr and not update:
vars = ddi_xml.codeBook.dataDscr("var")
heads = self._get_headers()
c_heads = ["ID", "catValu", "labl", "catStat"]
f_var = StringIO.StringIO()
c_var = StringIO.StringIO()
varwriter = csv.DictWriter(f_var, heads)
codewriter = csv.DictWriter(c_var, c_heads)
heading_row = {}
for head in heads:
#.........这里部分代码省略.........