forked from mjgiarlo/opensrf101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro_client.py
60 lines (51 loc) · 1.68 KB
/
micro_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import bagit
import osrf.ses
import osrf.system
conf_file = "/opensrf/etc/opensrf_core.xml"
osrf.system.System.connect(config_file=conf_file,
config_context="config.opensrf")
datastore = "/mnt/datastore"
# take a file
d = "/home/mjg/Documents/bagme"
f = "/home/mjg/Documents/bagme/architecture_scratchpad.txt"
# generate an identifier
session = osrf.ses.ClientSession("psu.stewardship.identity")
request = session.request("psu.stewardship.identity.mint")
response = request.recv()
request.cleanup()
ark = response.content()
session.cleanup()
print "identifier %s minted for %s" % (ark, f)
# grab its fixity value
session = osrf.ses.ClientSession("psu.stewardship.fixity")
request = session.request("psu.stewardship.fixity.generate", f, "md5")
response = request.recv()
request.cleanup()
checksum = response.content()
session.cleanup()
print "fixity %s generated for %s" % (checksum, f)
# bag it up
bag = bagit.make_bag(d)
print "bag created at %s" % bag.path
if not bag.validate():
print "bag not valid"
sys.exit(1)
# stuff in a pairtree
session = osrf.ses.ClientSession("psu.stewardship.storage")
request = session.request("psu.stewardship.storage.store", datastore, ark, bag.path)
response = request.recv()
request.cleanup()
storage_location = response.content()
session.cleanup()
print "bag stored in %s" % storage_location
# create a version
session = osrf.ses.ClientSession("psu.stewardship.versioning")
request = session.request("psu.stewardship.versioning.init", storage_location)
response = request.recv()
request.cleanup()
version = response.content()
session.cleanup()
print "version %s of content created" % version
# check fixity?
# update version?