Skip to content

Commit e7004d4

Browse files
committed
Restructures significantly.
1 parent 898d6ec commit e7004d4

10 files changed

Lines changed: 225 additions & 140 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.DS_Store
33
*pyc
44
.idea/*
5-
.idea
5+
.idea
6+
.cache/*
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
modified from http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_metadata
4+
-->
5+
<entry xmlns="http://www.w3.org/2005/Atom"
6+
xmlns:dcterms="http://purl.org/dc/terms/">
7+
<!-- some embedded metadata -->
8+
<dcterms:title>Roasting at Home</dcterms:title>
9+
<dcterms:creator>Peets, John</dcterms:creator>
10+
<dcterms:creator>Stumptown, Jane</dcterms:creator>
11+
12+
<!-- Producer with financial or admin responsibility of the data -->
13+
<dcterms:publisher>Coffee Bean State University</dcterms:publisher>
14+
15+
<!-- related publications -->
16+
<dcterms:isReferencedBy holdingsURI="http://dx.doi.org/10.1038/dvn333" agency="DOI"
17+
IDNo="10.1038/dvn333">Peets, J., &amp; Stumptown, J. (2013). Roasting at Home. New England Journal of Coffee, 3(1), 22-34.</dcterms:isReferencedBy>
18+
19+
<!-- production date -->
20+
<dcterms:date>2013-07-11</dcterms:date>
21+
22+
<!-- Other Identifier for the data in this study (or potentially global id if unused) -->
23+
<dcterms:identifier>doi:10.1000/182</dcterms:identifier>
24+
<!-- <dcterms:identifier>hdl:1XXZY.1/XYXZ</dcterms:identifier> -->
25+
26+
<dcterms:description>Considerations before you start roasting your own coffee at home.</dcterms:description>
27+
28+
<!-- keywords -->
29+
<dcterms:subject>coffee</dcterms:subject>
30+
<dcterms:subject>beverage</dcterms:subject>
31+
<dcterms:subject>caffeine</dcterms:subject>
32+
33+
<!-- geographic coverage -->
34+
<dcterms:coverage>United States</dcterms:coverage>
35+
<dcterms:coverage>Canada</dcterms:coverage>
36+
<!-- kind of data -->
37+
<dcterms:type>aggregate data</dcterms:type>
38+
<!-- List of sources of the data collection-->
39+
<dcterms:source>Stumptown, Jane. 2011. Home Roasting. Coffeemill Press.</dcterms:source>
40+
<!-- restrictions -->
41+
<dcterms:rights>Creative Commons CC-BY 3.0 (unported) http://creativecommons.org/licenses/by/3.0/</dcterms:rights>
42+
<!-- related materials -->
43+
<dcterms:relation>Peets, John. 2010. Roasting Coffee at the Coffee Shop. Coffeemill Press</dcterms:relation>
44+
45+
46+
<!-- unsupported fields! -->
47+
<dcterms:abstract>A real abstract!</dcterms:abstract>
48+
<dcterms:bibliographicCitation>Insert Journal Article Citation from OJS</dcterms:bibliographicCitation>
49+
</entry>

dvn_client/resources/atom2.xml

Lines changed: 0 additions & 41 deletions
This file was deleted.

dvn_client/src/connection.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def __init__(self, username, password, host, cert=None, sdUriOverride=None):
2424
self.username = username
2525
self.password = password
2626
self.host = host
27-
self.sdUri = "https://{host}/dvn/api/data-deposit/v1/swordv2/service-document".format(host=self.host) if not sdUriOverride else sdUriOverride.format(host=self.host)
27+
self.sdUri = "https://{host}/dvn/api/data-deposit/v1/swordv2/service-document".format(host=self.host) \
28+
if not sdUriOverride else sdUriOverride.format(host=self.host)
2829
self.cert = cert
2930

3031
# Connection Status and SWORD Properties
@@ -40,10 +41,12 @@ def __init__(self, username, password, host, cert=None, sdUriOverride=None):
4041

4142
# todo raise exception if connection fails?
4243
def _connect(self):
43-
self.swordConnection = sword2.Connection(self.sdUri,
44-
user_name = self.username,
45-
user_pass = self.password,
46-
ca_certs = self.cert)
44+
self.swordConnection = sword2.Connection(
45+
service_document_iri=self.sdUri,
46+
user_name=self.username,
47+
user_pass=self.password,
48+
ca_certs=self.cert,
49+
)
4750

4851
self.serviceDocument = self.swordConnection.get_service_document()
4952
self.connected = True

dvn_client/src/dataverse.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
# python base lib modules
55
import pprint
66

7-
#downloaded modules
7+
# downloaded modules
88
from lxml import etree
99

10-
#local modules
10+
# local modules
1111
from study import Study
1212
import utils
1313

@@ -33,10 +33,11 @@ def is_released(self):
3333
).text
3434
return bool(status)
3535

36-
def add_study(self, study):
36+
def add_study(self, study):
37+
# this creates the study AND generates a deposit receipt
3738
depositReceipt = self.connection.swordConnection.create(
39+
col_iri=self.collection.href,
3840
metadata_entry=study.entry,
39-
col_iri=self.collection.href
4041
)
4142

4243
study.hostDataverse = self
@@ -66,13 +67,13 @@ def get_studies(self):
6667
studiesResponse = self.connection.swordConnection.get_resource(self.collection.href)
6768

6869
return [
69-
Study.CreateStudyFromEntryElement(element, hostDataverse=self)
70+
Study.from_entry_element(element, hostDataverse=self)
7071
for element in utils.get_elements(studiesResponse.content, tag='entry')
7172
]
7273
# # get all the entry nodes and parse them into study objects
7374
# studies = []
7475
# for element in utils.get_elements(studiesResponse.content, tag="entry"):
75-
# s = Study.CreateStudyFromEntryElement(element, hostDataverse=self)
76+
# s = Study.from_entry_element(element, hostDataverse=self)
7677
# studies.append(s)
7778
#
7879
# return studies

dvn_client/src/example/config.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,21 @@
33
DEFAULT_HOST = "dvn-4.hmdc.harvard.edu"
44
DEFAULT_CERT = "dvn_client/resources/dvn-4.hmdc.harvard.edu"
55

6-
#EXAMPLE_FILE = "dvn_client/resources/atom-entry-study.xml"
7-
EXAMPLE_FILE = "dvn_client/resources/atom2.xml"
6+
EXAMPLE_DICT = {
7+
"title" : "ExampleTitle",
8+
"id" : "ExampleID",
9+
"author" : "ExampleAuthor",
10+
"producer" : "ExampleProducer",
11+
"date" : "1992-10-04",
12+
"description" : "ExampleDescription",
13+
"abstract" : "ExampleAbstract",
14+
"type" : "ExampleType",
15+
"source" : "ExampleSource",
16+
"restriction" : "ExampleRestriction",
17+
"relation" : "ExampleRelation",
18+
"keyword" : "ExampleKeyword",
19+
"coverage" : "ExampleCoverage",
20+
"publication" : "ExamplePublication",
21+
}
22+
23+
EXAMPLE_FILE = "dvn_client/resources/atom-example.xml"

dvn_client/src/example/dvn_example.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
from time import sleep
1717
import traceback
1818

19-
#downloaded modules
19+
# downloaded modules
2020

21-
#local modules
21+
# local modules
2222
from dvn_client.src.study import Study
2323
from dvn_client.src.connection import DvnConnection
24-
from config import DEFAULT_PASSWORD, DEFAULT_HOST, DEFAULT_CERT, DEFAULT_USERNAME, EXAMPLE_FILE
24+
from config import DEFAULT_PASSWORD, DEFAULT_HOST, DEFAULT_CERT, DEFAULT_USERNAME, EXAMPLE_FILE, \
25+
EXAMPLE_DICT
2526

2627
def parse_arguments():
2728
parser = argparse.ArgumentParser(description='dvn_client exercises the APIs available for a DataVerse Network')
@@ -44,7 +45,7 @@ def main():
4445
execfile(args.config, globals())
4546
execfile(args.runTests, globals())
4647

47-
dv = None #declare outside so except clause has access
48+
dv = None # declare outside so except clause has access
4849
try:
4950
dvc = DvnConnection(username=DEFAULT_USERNAME,
5051
password=DEFAULT_PASSWORD,
@@ -60,30 +61,36 @@ def main():
6061
dv = dvs[0]
6162

6263
# clean up the test dataverse
63-
#dv.delete_all_studies()
64-
print "RELEASED: ", dv.is_released()
64+
# dv.delete_all_studies()
65+
print "RELEASED:", dv.is_released()
6566

66-
#s = Study(title="My Very Own Study")
67-
#s = Study.CreateStudyFromDict(PICS_OF_CATS_STUDY)
68-
s = Study.CreateStudyFromAtomEntryXmlFile(EXAMPLE_FILE)
69-
dv.add_study(s)
70-
#s.add_files([INGEST_FILES])
71-
print s.get_citation()
72-
print s.get_state()
73-
74-
#sleep(3) #wait for ingest`
75-
76-
#fs = s.get_files()
77-
#print "FILES: ", len(fs)
78-
#s.delete_file(fs[-1])
79-
#fs = s.get_files()
80-
#print "FILES: ", len(fs)
81-
#s.delete_all_files()
82-
#fs = s.get_files()
83-
#print "FILES: ", len(fs)
67+
# s = Study.from_dict(EXAMPLE_DICT)
68+
# print dv.get_studies()
69+
s = Study.from_atom_xml_file(EXAMPLE_FILE)
70+
# dv.add_study(s)
71+
print s
72+
73+
# print s.get_entry()
74+
75+
# s.add_files([INGEST_FILES])
76+
# print s.get_citation()
77+
# print s.get_state()
78+
79+
# sleep(3) #wait for ingest`
8480

85-
#s.release()
81+
# fs = s.get_files()
82+
# print "FILES: ", len(fs)
83+
# s.delete_file(fs[-1])
84+
# fs = s.get_files()
85+
# print "FILES: ", len(fs)
86+
# s.delete_all_files()
87+
# fs = s.get_files()
88+
# print "FILES: ", len(fs)
8689

90+
# s.release()
91+
92+
# s.hostDataverse.delete_study(s)
93+
8794
print "\n\ndvn_client succeeded"
8895

8996
except Exception as e:

0 commit comments

Comments
 (0)